index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - playground</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link rel="stylesheet" href="fonts/open-sans/open-sans.css" type="text/css"/>
  8. <link rel="stylesheet" href="fonts/tabler-icons/tabler-icons.min.css" type="text/css"/>
  9. <style>
  10. body {
  11. overflow: hidden;
  12. width: 100%;
  13. height: 100%;
  14. top: 0;
  15. left: 0;
  16. margin: 0;
  17. position: fixed;
  18. overscroll-behavior: none;
  19. background: #191919ed;
  20. }
  21. .renderer {
  22. position: absolute;
  23. top: 0;
  24. left: 0;
  25. height: 100%;
  26. width: 100%;
  27. }
  28. flow {
  29. position: absolute;
  30. top: 0;
  31. left: 0;
  32. height: 100%;
  33. width: 100%;
  34. box-shadow: inset 0 0 20px 0px #000000;
  35. pointer-events: none;
  36. overflow: hidden;
  37. }
  38. flow > * {
  39. pointer-events: auto;
  40. }
  41. flow f-canvas.focusing {
  42. pointer-events: none;
  43. }
  44. flow f-canvas:not(.focusing) {
  45. background: #191919ed;
  46. }
  47. flow f-menu {
  48. white-space: nowrap;
  49. }
  50. node-editor {
  51. position: relative;
  52. width: 100%;
  53. height: 100%;
  54. }
  55. f-preview {
  56. display: block;
  57. position: relative;
  58. width: 100%;
  59. height: 100%;
  60. }
  61. f-gutter {
  62. position: absolute;
  63. cursor: ew-resize;
  64. height: 100%;
  65. top: 0px;
  66. width: 2px;
  67. background-color: #191919ed;
  68. border-style: none solid none solid;
  69. border-width: 1px;
  70. border-color: #aaaaaa;
  71. box-shadow: 0 0 5px 0px #000000;
  72. z-index: 30;
  73. }
  74. .panel {
  75. position: absolute;
  76. overflow: visible;
  77. float: left;
  78. }
  79. </style>
  80. </head>
  81. <body>
  82. <script src="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.min.js"></script>
  83. <script type="importmap">
  84. {
  85. "imports": {
  86. "three": "../build/three.module.js",
  87. "three/addons/": "../examples/jsm/",
  88. "three/nodes": "../examples/jsm/nodes/Nodes.js",
  89. "flow": "./libs/flow.module.js"
  90. }
  91. }
  92. </script>
  93. <script type="module">
  94. import * as THREE from 'three';
  95. import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
  96. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  97. import { NodeEditor } from './NodeEditor.js';
  98. let camera, scene, renderer, composer;
  99. let nodeEditor;
  100. init();
  101. async function init() {
  102. const container = document.createElement( 'node-editor' );
  103. document.body.appendChild( container );
  104. //
  105. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.5, 200 );
  106. camera.position.set( 0.0, 3, 4 * 3 );
  107. scene = new THREE.Scene();
  108. scene.background = new THREE.Color( 0x333333 );
  109. //
  110. renderer = new WebGPURenderer( { antialias: true } );
  111. renderer.setAnimationLoop( animate );
  112. renderer.setPixelRatio( window.devicePixelRatio );
  113. renderer.toneMapping = THREE.LinearToneMapping;
  114. renderer.toneMappingExposure = 1;
  115. // Additional container required for determining accurate pixel dimensions of the canvas when resizing
  116. const rendererContainer = document.createElement( 'f-preview' );
  117. container.appendChild( rendererContainer );
  118. rendererContainer.appendChild( renderer.domElement );
  119. renderer.domElement.className = 'renderer panel';
  120. //
  121. const controls = new OrbitControls( camera, renderer.domElement );
  122. controls.minDistance = 1;
  123. controls.maxDistance = 30;
  124. window.addEventListener( 'resize', onWindowResize );
  125. initEditor( container );
  126. onWindowResize();
  127. }
  128. function initEditor( container ) {
  129. nodeEditor = new NodeEditor( scene, renderer, composer );
  130. nodeEditor.addEventListener( 'new', () => {
  131. //renderer.dispose();
  132. } );
  133. container.appendChild( nodeEditor.domElement );
  134. nodeEditor.domElement.className = 'panel';
  135. }
  136. function onWindowResize() {
  137. checkResize();
  138. nodeEditor.setSize( window.innerWidth, window.innerHeight );
  139. }
  140. //
  141. function animate() {
  142. render();
  143. }
  144. function render() {
  145. checkResize();
  146. renderer.render( scene, camera );
  147. }
  148. function checkResize() {
  149. const canvas = renderer.domElement;
  150. const rendererContainer = canvas.parentNode;
  151. const width = rendererContainer.clientWidth;
  152. const height = rendererContainer.clientHeight;
  153. if ( canvas.width !== width || canvas.height !== height ) {
  154. camera.aspect = width / height;
  155. camera.updateProjectionMatrix();
  156. renderer.setSize( width, height );
  157. }
  158. }
  159. </script>
  160. </body>
  161. </html>