|
22 | 22 | <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - geometry - catmull spline editor |
23 | 23 | </div> |
24 | 24 |
|
| 25 | + <script type="importmap"> |
| 26 | + { |
| 27 | + "imports": { |
| 28 | + "three": "../build/three.module.js" |
| 29 | + } |
| 30 | + } |
| 31 | + </script> |
25 | 32 | <script type="module"> |
26 | 33 |
|
27 | | - import * as THREE from '../build/three.module.js'; |
| 34 | + import * as THREE from 'three'; |
28 | 35 |
|
29 | | - import Stats from './jsm/libs/stats.module.js'; |
30 | 36 | import { GUI } from './jsm/libs/dat.gui.module.js'; |
31 | 37 |
|
32 | 38 | import { OrbitControls } from './jsm/controls/OrbitControls.js'; |
33 | 39 | import { TransformControls } from './jsm/controls/TransformControls.js'; |
34 | 40 |
|
35 | | - let container, stats; |
| 41 | + let container; |
36 | 42 | let camera, scene, renderer; |
37 | 43 | const splineHelperObjects = []; |
38 | 44 | let splinePointsLength = 4; |
|
62 | 68 | }; |
63 | 69 |
|
64 | 70 | init(); |
65 | | - animate(); |
66 | 71 |
|
67 | 72 | function init() { |
68 | 73 |
|
|
108 | 113 | renderer.shadowMap.enabled = true; |
109 | 114 | container.appendChild( renderer.domElement ); |
110 | 115 |
|
111 | | - stats = new Stats(); |
112 | | - container.appendChild( stats.dom ); |
113 | | - |
114 | 116 | const gui = new GUI(); |
115 | 117 |
|
116 | | - gui.add( params, 'uniform' ); |
| 118 | + gui.add( params, 'uniform' ).onChange( render ); |
117 | 119 | gui.add( params, 'tension', 0, 1 ).step( 0.01 ).onChange( function ( value ) { |
118 | 120 |
|
119 | 121 | splines.uniform.tension = value; |
120 | 122 | updateSplineOutline(); |
| 123 | + render(); |
121 | 124 |
|
122 | 125 | } ); |
123 | | - gui.add( params, 'centripetal' ); |
124 | | - gui.add( params, 'chordal' ); |
| 126 | + gui.add( params, 'centripetal' ).onChange( render ); |
| 127 | + gui.add( params, 'chordal' ).onChange( render ); |
125 | 128 | gui.add( params, 'addPoint' ); |
126 | 129 | gui.add( params, 'removePoint' ); |
127 | 130 | gui.add( params, 'exportSpline' ); |
|
150 | 153 | document.addEventListener( 'pointerdown', onPointerDown ); |
151 | 154 | document.addEventListener( 'pointerup', onPointerUp ); |
152 | 155 | document.addEventListener( 'pointermove', onPointerMove ); |
| 156 | + window.addEventListener( 'resize', onWindowResize ); |
153 | 157 |
|
154 | 158 | /******* |
155 | 159 | * Curves |
|
211 | 215 | new THREE.Vector3( - 91.40118730204415, 176.4306956436485, - 6.958271935582161 ), |
212 | 216 | new THREE.Vector3( - 383.785318791128, 491.1365363371675, 47.869296953772746 ) ] ); |
213 | 217 |
|
| 218 | + render(); |
| 219 | + |
214 | 220 | } |
215 | 221 |
|
216 | 222 | function addSplineObject( position ) { |
|
246 | 252 |
|
247 | 253 | updateSplineOutline(); |
248 | 254 |
|
| 255 | + render(); |
| 256 | + |
249 | 257 | } |
250 | 258 |
|
251 | 259 | function removePoint() { |
|
265 | 273 |
|
266 | 274 | updateSplineOutline(); |
267 | 275 |
|
| 276 | + render(); |
| 277 | + |
268 | 278 | } |
269 | 279 |
|
270 | 280 | function updateSplineOutline() { |
|
331 | 341 |
|
332 | 342 | } |
333 | 343 |
|
334 | | - function animate() { |
335 | | - |
336 | | - requestAnimationFrame( animate ); |
337 | | - render(); |
338 | | - stats.update(); |
339 | | - |
340 | | - } |
341 | | - |
342 | 344 | function render() { |
343 | 345 |
|
344 | 346 | splines.uniform.mesh.visible = params.uniform; |
|
387 | 389 |
|
388 | 390 | } |
389 | 391 |
|
| 392 | + function onWindowResize() { |
| 393 | + |
| 394 | + camera.aspect = window.innerWidth / window.innerHeight; |
| 395 | + camera.updateProjectionMatrix(); |
| 396 | + |
| 397 | + renderer.setSize( window.innerWidth, window.innerHeight ); |
| 398 | + |
| 399 | + render(); |
| 400 | + |
| 401 | + } |
390 | 402 |
|
391 | 403 | </script> |
392 | 404 |
|
|
0 commit comments