|
26 | 26 |
|
27 | 27 | import * as THREE from '../build/three.module.js'; |
28 | 28 |
|
29 | | - import Stats from './jsm/libs/stats.module.js'; |
30 | 29 | import { GUI } from './jsm/libs/dat.gui.module.js'; |
31 | 30 |
|
32 | 31 | import { OrbitControls } from './jsm/controls/OrbitControls.js'; |
33 | 32 | import { TransformControls } from './jsm/controls/TransformControls.js'; |
34 | 33 |
|
35 | | - let container, stats; |
| 34 | + let container; |
36 | 35 | let camera, scene, renderer; |
37 | 36 | const splineHelperObjects = []; |
38 | 37 | let splinePointsLength = 4; |
|
62 | 61 | }; |
63 | 62 |
|
64 | 63 | init(); |
65 | | - animate(); |
66 | 64 |
|
67 | 65 | function init() { |
68 | 66 |
|
|
108 | 106 | renderer.shadowMap.enabled = true; |
109 | 107 | container.appendChild( renderer.domElement ); |
110 | 108 |
|
111 | | - stats = new Stats(); |
112 | | - container.appendChild( stats.dom ); |
113 | | - |
114 | 109 | const gui = new GUI(); |
115 | 110 |
|
116 | | - gui.add( params, 'uniform' ); |
| 111 | + gui.add( params, 'uniform' ).onChange( render ); |
117 | 112 | gui.add( params, 'tension', 0, 1 ).step( 0.01 ).onChange( function ( value ) { |
118 | 113 |
|
119 | 114 | splines.uniform.tension = value; |
120 | 115 | updateSplineOutline(); |
| 116 | + render(); |
121 | 117 |
|
122 | 118 | } ); |
123 | | - gui.add( params, 'centripetal' ); |
124 | | - gui.add( params, 'chordal' ); |
| 119 | + gui.add( params, 'centripetal' ).onChange( render ); |
| 120 | + gui.add( params, 'chordal' ).onChange( render ); |
125 | 121 | gui.add( params, 'addPoint' ); |
126 | 122 | gui.add( params, 'removePoint' ); |
127 | 123 | gui.add( params, 'exportSpline' ); |
|
150 | 146 | document.addEventListener( 'pointerdown', onPointerDown ); |
151 | 147 | document.addEventListener( 'pointerup', onPointerUp ); |
152 | 148 | document.addEventListener( 'pointermove', onPointerMove ); |
| 149 | + window.addEventListener( 'resize', onWindowResize ); |
153 | 150 |
|
154 | 151 | /******* |
155 | 152 | * Curves |
|
211 | 208 | new THREE.Vector3( - 91.40118730204415, 176.4306956436485, - 6.958271935582161 ), |
212 | 209 | new THREE.Vector3( - 383.785318791128, 491.1365363371675, 47.869296953772746 ) ] ); |
213 | 210 |
|
| 211 | + render(); |
| 212 | + |
214 | 213 | } |
215 | 214 |
|
216 | 215 | function addSplineObject( position ) { |
|
246 | 245 |
|
247 | 246 | updateSplineOutline(); |
248 | 247 |
|
| 248 | + render(); |
| 249 | + |
249 | 250 | } |
250 | 251 |
|
251 | 252 | function removePoint() { |
|
265 | 266 |
|
266 | 267 | updateSplineOutline(); |
267 | 268 |
|
| 269 | + render(); |
| 270 | + |
268 | 271 | } |
269 | 272 |
|
270 | 273 | function updateSplineOutline() { |
|
331 | 334 |
|
332 | 335 | } |
333 | 336 |
|
334 | | - function animate() { |
335 | | - |
336 | | - requestAnimationFrame( animate ); |
337 | | - render(); |
338 | | - stats.update(); |
339 | | - |
340 | | - } |
341 | | - |
342 | 337 | function render() { |
343 | 338 |
|
344 | 339 | splines.uniform.mesh.visible = params.uniform; |
|
387 | 382 |
|
388 | 383 | } |
389 | 384 |
|
| 385 | + function onWindowResize() { |
| 386 | + |
| 387 | + camera.aspect = window.innerWidth / window.innerHeight; |
| 388 | + camera.updateProjectionMatrix(); |
| 389 | + |
| 390 | + renderer.setSize( window.innerWidth, window.innerHeight ); |
| 391 | + |
| 392 | + render(); |
| 393 | + |
| 394 | + } |
390 | 395 |
|
391 | 396 | </script> |
392 | 397 |
|
|
0 commit comments