Skip to content

Commit 20a248f

Browse files
committed
Examples: Improved webgl_geometry_spline_editor.html
1 parent b1ede81 commit 20a248f

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

examples/webgl_geometry_spline_editor.html

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@
2222
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - geometry - catmull spline editor
2323
</div>
2424

25+
<script type="importmap">
26+
{
27+
"imports": {
28+
"three": "../build/three.module.js"
29+
}
30+
}
31+
</script>
2532
<script type="module">
2633

27-
import * as THREE from '../build/three.module.js';
34+
import * as THREE from 'three';
2835

29-
import Stats from './jsm/libs/stats.module.js';
3036
import { GUI } from './jsm/libs/dat.gui.module.js';
3137

3238
import { OrbitControls } from './jsm/controls/OrbitControls.js';
3339
import { TransformControls } from './jsm/controls/TransformControls.js';
3440

35-
let container, stats;
41+
let container;
3642
let camera, scene, renderer;
3743
const splineHelperObjects = [];
3844
let splinePointsLength = 4;
@@ -62,7 +68,6 @@
6268
};
6369

6470
init();
65-
animate();
6671

6772
function init() {
6873

@@ -108,20 +113,18 @@
108113
renderer.shadowMap.enabled = true;
109114
container.appendChild( renderer.domElement );
110115

111-
stats = new Stats();
112-
container.appendChild( stats.dom );
113-
114116
const gui = new GUI();
115117

116-
gui.add( params, 'uniform' );
118+
gui.add( params, 'uniform' ).onChange( render );
117119
gui.add( params, 'tension', 0, 1 ).step( 0.01 ).onChange( function ( value ) {
118120

119121
splines.uniform.tension = value;
120122
updateSplineOutline();
123+
render();
121124

122125
} );
123-
gui.add( params, 'centripetal' );
124-
gui.add( params, 'chordal' );
126+
gui.add( params, 'centripetal' ).onChange( render );
127+
gui.add( params, 'chordal' ).onChange( render );
125128
gui.add( params, 'addPoint' );
126129
gui.add( params, 'removePoint' );
127130
gui.add( params, 'exportSpline' );
@@ -150,6 +153,7 @@
150153
document.addEventListener( 'pointerdown', onPointerDown );
151154
document.addEventListener( 'pointerup', onPointerUp );
152155
document.addEventListener( 'pointermove', onPointerMove );
156+
window.addEventListener( 'resize', onWindowResize );
153157

154158
/*******
155159
* Curves
@@ -211,6 +215,8 @@
211215
new THREE.Vector3( - 91.40118730204415, 176.4306956436485, - 6.958271935582161 ),
212216
new THREE.Vector3( - 383.785318791128, 491.1365363371675, 47.869296953772746 ) ] );
213217

218+
render();
219+
214220
}
215221

216222
function addSplineObject( position ) {
@@ -246,6 +252,8 @@
246252

247253
updateSplineOutline();
248254

255+
render();
256+
249257
}
250258

251259
function removePoint() {
@@ -265,6 +273,8 @@
265273

266274
updateSplineOutline();
267275

276+
render();
277+
268278
}
269279

270280
function updateSplineOutline() {
@@ -331,14 +341,6 @@
331341

332342
}
333343

334-
function animate() {
335-
336-
requestAnimationFrame( animate );
337-
render();
338-
stats.update();
339-
340-
}
341-
342344
function render() {
343345

344346
splines.uniform.mesh.visible = params.uniform;
@@ -387,6 +389,16 @@
387389

388390
}
389391

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+
}
390402

391403
</script>
392404

0 commit comments

Comments
 (0)