index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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/monaco-editor@0.48.0/min/vs/loader.min.js"></script>
  83. <script type="importmap">
  84. {
  85. "imports": {
  86. "three": "../build/three.webgpu.js",
  87. "three/tsl": "../build/three.webgpu.js",
  88. "three/addons/": "../examples/jsm/",
  89. "flow": "./libs/flow.module.js"
  90. }
  91. }
  92. </script>
  93. <script type="module">
  94. import * as THREE from 'three';
  95. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  96. import { NodeEditor } from './NodeEditor.js';
  97. let camera, scene, renderer, composer;
  98. let nodeEditor;
  99. init();
  100. async function init() {
  101. const container = document.createElement( 'node-editor' );
  102. document.body.appendChild( container );
  103. //
  104. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.5, 200 );
  105. camera.position.set( 0.0, 3, 4 * 3 );
  106. scene = new THREE.Scene();
  107. scene.background = new THREE.Color( 0x333333 );
  108. //
  109. renderer = new THREE.WebGPURenderer( { antialias: true } );
  110. renderer.setAnimationLoop( animate );
  111. renderer.setPixelRatio( window.devicePixelRatio );
  112. renderer.toneMapping = THREE.LinearToneMapping;
  113. renderer.toneMappingExposure = 1;
  114. // Additional container required for determining accurate pixel dimensions of the canvas when resizing
  115. const rendererContainer = document.createElement( 'f-preview' );
  116. container.appendChild( rendererContainer );
  117. rendererContainer.appendChild( renderer.domElement );
  118. renderer.domElement.className = 'renderer panel';
  119. //
  120. const controls = new OrbitControls( camera, renderer.domElement );
  121. controls.minDistance = 1;
  122. controls.maxDistance = 30;
  123. window.addEventListener( 'resize', onWindowResize );
  124. initEditor( container );
  125. onWindowResize();
  126. }
  127. function initEditor( container ) {
  128. nodeEditor = new NodeEditor( scene, renderer, composer );
  129. nodeEditor.addEventListener( 'new', () => {
  130. //renderer.dispose();
  131. } );
  132. container.appendChild( nodeEditor.domElement );
  133. nodeEditor.domElement.className = 'panel';
  134. }
  135. function onWindowResize() {
  136. checkResize();
  137. nodeEditor.setSize( window.innerWidth, window.innerHeight );
  138. }
  139. //
  140. function animate() {
  141. render();
  142. }
  143. function render() {
  144. checkResize();
  145. renderer.render( scene, camera );
  146. }
  147. function checkResize() {
  148. const canvas = renderer.domElement;
  149. const rendererContainer = canvas.parentNode;
  150. const width = rendererContainer.clientWidth;
  151. const height = rendererContainer.clientHeight;
  152. if ( canvas.width !== width || canvas.height !== height ) {
  153. camera.aspect = width / height;
  154. camera.updateProjectionMatrix();
  155. renderer.setSize( width, height );
  156. }
  157. }
  158. </script>
  159. </body>
  160. </html>