Skip to content

Commit 2b97005

Browse files
authored
Examples: Improved webgl_geometry_spline_editor.html (#22616)
1 parent 6089e18 commit 2b97005

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

examples/webgl_geometry_spline_editor.html

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626

2727
import * as THREE from '../build/three.module.js';
2828

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

3231
import { OrbitControls } from './jsm/controls/OrbitControls.js';
3332
import { TransformControls } from './jsm/controls/TransformControls.js';
3433

35-
let container, stats;
34+
let container;
3635
let camera, scene, renderer;
3736
const splineHelperObjects = [];
3837
let splinePointsLength = 4;
@@ -62,7 +61,6 @@
6261
};
6362

6463
init();
65-
animate();
6664

6765
function init() {
6866

@@ -108,20 +106,18 @@
108106
renderer.shadowMap.enabled = true;
109107
container.appendChild( renderer.domElement );
110108

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

116-
gui.add( params, 'uniform' );
111+
gui.add( params, 'uniform' ).onChange( render );
117112
gui.add( params, 'tension', 0, 1 ).step( 0.01 ).onChange( function ( value ) {
118113

119114
splines.uniform.tension = value;
120115
updateSplineOutline();
116+
render();
121117

122118
} );
123-
gui.add( params, 'centripetal' );
124-
gui.add( params, 'chordal' );
119+
gui.add( params, 'centripetal' ).onChange( render );
120+
gui.add( params, 'chordal' ).onChange( render );
125121
gui.add( params, 'addPoint' );
126122
gui.add( params, 'removePoint' );
127123
gui.add( params, 'exportSpline' );
@@ -150,6 +146,7 @@
150146
document.addEventListener( 'pointerdown', onPointerDown );
151147
document.addEventListener( 'pointerup', onPointerUp );
152148
document.addEventListener( 'pointermove', onPointerMove );
149+
window.addEventListener( 'resize', onWindowResize );
153150

154151
/*******
155152
* Curves
@@ -211,6 +208,8 @@
211208
new THREE.Vector3( - 91.40118730204415, 176.4306956436485, - 6.958271935582161 ),
212209
new THREE.Vector3( - 383.785318791128, 491.1365363371675, 47.869296953772746 ) ] );
213210

211+
render();
212+
214213
}
215214

216215
function addSplineObject( position ) {
@@ -246,6 +245,8 @@
246245

247246
updateSplineOutline();
248247

248+
render();
249+
249250
}
250251

251252
function removePoint() {
@@ -265,6 +266,8 @@
265266

266267
updateSplineOutline();
267268

269+
render();
270+
268271
}
269272

270273
function updateSplineOutline() {
@@ -331,14 +334,6 @@
331334

332335
}
333336

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

344339
splines.uniform.mesh.visible = params.uniform;
@@ -387,6 +382,16 @@
387382

388383
}
389384

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

391396
</script>
392397

0 commit comments

Comments
 (0)