webgl_nodes_playground.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. @ -1,189 +0,0 @@
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <title>three.js webgl - node-editor playground</title>
  6. <meta charset="utf-8">
  7. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  8. <link rel="stylesheet" href="fonts/open-sans/open-sans.css" type="text/css"/>
  9. <link rel="stylesheet" href="fonts/tabler-icons/tabler-icons.min.css" type="text/css"/>
  10. <link type="text/css" rel="stylesheet" href="main.css">
  11. <style>
  12. body {
  13. overflow: hidden;
  14. width: 100%;
  15. height: 100%;
  16. }
  17. .renderer {
  18. position: absolute;
  19. top: 0;
  20. left: 0;
  21. height: 50%;
  22. width: 100%;
  23. }
  24. flow {
  25. position: absolute;
  26. top: 50%;
  27. left: 0;
  28. height: 50%;
  29. width: 100%;
  30. background: #222;
  31. box-shadow: inset 0 0 20px 0px #000000;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div id="info">
  37. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGL - Node Editor ( Playground version )<br />
  38. </div>
  39. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  40. <script type="importmap">
  41. {
  42. "imports": {
  43. "three": "../build/three.module.js"
  44. }
  45. }
  46. </script>
  47. <script type="module">
  48. import * as THREE from 'three';
  49. import { nodeFrame } from './jsm/renderers/webgl/nodes/WebGLNodes.js';
  50. import { NodeEditor } from './jsm/node-editor/NodeEditor.js';
  51. import { MeshEditor } from './jsm/node-editor/scene/MeshEditor.js';
  52. import * as Nodes from './jsm/renderers/nodes/Nodes.js';
  53. import Stats from './jsm/libs/stats.module.js';
  54. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  55. import { FBXLoader } from './jsm/loaders/FBXLoader.js';
  56. let stats;
  57. let camera, scene, renderer;
  58. let model;
  59. init();
  60. animate();
  61. function init() {
  62. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 5000 );
  63. camera.position.set( 0.0, 300, 400 * 3 );
  64. scene = new THREE.Scene();
  65. scene.background = new THREE.Color( 0x333333 );
  66. // Lights
  67. const topLight = new THREE.PointLight( 0xF4F6F0, 1 );
  68. topLight.position.set( 0, 100000, 100000 );
  69. scene.add( topLight );
  70. const backLight = new THREE.PointLight( 0x0c1445, 1.4 );
  71. backLight.position.set( - 100, 20, - 260 );
  72. scene.add( backLight );
  73. renderer = new THREE.WebGLRenderer( { antialias: true } );
  74. document.body.appendChild( renderer.domElement );
  75. renderer.outputEncoding = THREE.sRGBEncoding;
  76. renderer.domElement.className = 'renderer';
  77. //
  78. stats = new Stats();
  79. document.body.appendChild( stats.dom );
  80. const controls = new OrbitControls( camera, renderer.domElement );
  81. controls.minDistance = 500;
  82. controls.maxDistance = 3000;
  83. window.addEventListener( 'resize', onWindowResize );
  84. onWindowResize();
  85. initEditor();
  86. }
  87. function initEditor() {
  88. const nodeEditor = new NodeEditor( scene );
  89. nodeEditor.addEventListener( 'new', () => {
  90. const materialEditor = new MeshEditor( model );
  91. nodeEditor.add( materialEditor );
  92. nodeEditor.centralizeNode( materialEditor );
  93. } );
  94. document.body.appendChild( nodeEditor.domElement );
  95. const loaderFBX = new FBXLoader();
  96. loaderFBX.load( 'models/fbx/stanford-bunny.fbx', ( object ) => {
  97. const defaultMaterial = new Nodes.MeshBasicNodeMaterial();
  98. defaultMaterial.colorNode = new Nodes.FloatNode( 0 );
  99. const sphere = new THREE.Mesh( new THREE.SphereGeometry( 200, 32, 16 ), defaultMaterial ) ;
  100. sphere.name = 'Sphere';
  101. sphere.position.set( 500, 0, -500 );
  102. scene.add( sphere );
  103. const box = new THREE.Mesh( new THREE.BoxGeometry( 200, 200, 200 ), defaultMaterial ) ;
  104. box.name = 'Box';
  105. box.position.set( -500, 0, -500 );
  106. scene.add( box );
  107. const defaultPointsMaterial = new Nodes.PointsNodeMaterial();
  108. defaultPointsMaterial.colorNode = new Nodes.FloatNode( 0 );
  109. const torusKnot = new THREE.Points( new THREE.TorusKnotGeometry( 100, 30, 100, 16 ), defaultPointsMaterial ) ;
  110. torusKnot.name = 'Torus Knot ( Points )';
  111. torusKnot.position.set( 0, 0, -500 );
  112. scene.add( torusKnot );
  113. model = object.children[ 0 ];
  114. model.position.set( 0, 0, 10 );
  115. model.scale.setScalar( 1 );
  116. model.material = defaultMaterial;
  117. scene.add( model );
  118. const materialEditor = new MeshEditor( model );
  119. nodeEditor.add( materialEditor );
  120. nodeEditor.centralizeNode( materialEditor );
  121. } );
  122. }
  123. function onWindowResize() {
  124. const width = window.innerWidth;
  125. const height = window.innerHeight / 2;
  126. camera.aspect = width / height;
  127. camera.updateProjectionMatrix();
  128. renderer.setSize( width, height );
  129. }
  130. //
  131. function animate() {
  132. requestAnimationFrame( animate );
  133. nodeFrame.update();
  134. render();
  135. stats.update();
  136. }
  137. function render() {
  138. //if ( model ) model.rotation.y = performance.now() / 5000;
  139. renderer.render( scene, camera );
  140. }
  141. </script>
  142. </body>
  143. </html>