Skip to content

Commit 2cb4109

Browse files
authored
Merge pull request #20503 from Mugen87/dev51
Examples: More clean up.
2 parents be673e6 + 75427aa commit 2cb4109

File tree

76 files changed

+2022
-2010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2022
-2010
lines changed

examples/webgl_animation_cloth.html

Lines changed: 91 additions & 95 deletions
Large diffs are not rendered by default.

examples/webgl_animation_keyframes.html

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,56 +37,55 @@
3737
import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
3838
import { DRACOLoader } from './jsm/loaders/DRACOLoader.js';
3939

40-
var scene, camera, dirLight, stats;
41-
var renderer, mixer, controls;
40+
let mixer;
4241

43-
var clock = new THREE.Clock();
44-
var container = document.getElementById( 'container' );
42+
const clock = new THREE.Clock();
43+
const container = document.getElementById( 'container' );
4544

46-
stats = new Stats();
45+
const stats = new Stats();
4746
container.appendChild( stats.dom );
4847

49-
renderer = new THREE.WebGLRenderer( { antialias: true } );
48+
const renderer = new THREE.WebGLRenderer( { antialias: true } );
5049
renderer.setPixelRatio( window.devicePixelRatio );
5150
renderer.setSize( window.innerWidth, window.innerHeight );
5251
renderer.outputEncoding = THREE.sRGBEncoding;
5352
container.appendChild( renderer.domElement );
5453

55-
scene = new THREE.Scene();
54+
const scene = new THREE.Scene();
5655
scene.background = new THREE.Color( 0xbfe3dd );
5756

58-
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
57+
const camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
5958
camera.position.set( 5, 2, 8 );
6059

61-
controls = new OrbitControls( camera, renderer.domElement );
60+
const controls = new OrbitControls( camera, renderer.domElement );
6261
controls.target.set( 0, 0.5, 0 );
6362
controls.update();
6463
controls.enablePan = false;
6564
controls.enableDamping = true;
6665

6766
scene.add( new THREE.HemisphereLight( 0xffffff, 0x000000, 0.4 ) );
6867

69-
dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
68+
const dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
7069
dirLight.position.set( 5, 2, 8 );
7170
scene.add( dirLight );
7271

7372
// envmap
74-
var path = 'textures/cube/Park2/';
75-
var format = '.jpg';
76-
var envMap = new THREE.CubeTextureLoader().load( [
73+
const path = 'textures/cube/Park2/';
74+
const format = '.jpg';
75+
const envMap = new THREE.CubeTextureLoader().load( [
7776
path + 'posx' + format, path + 'negx' + format,
7877
path + 'posy' + format, path + 'negy' + format,
7978
path + 'posz' + format, path + 'negz' + format
8079
] );
8180

82-
var dracoLoader = new DRACOLoader();
81+
const dracoLoader = new DRACOLoader();
8382
dracoLoader.setDecoderPath( 'js/libs/draco/gltf/' );
8483

85-
var loader = new GLTFLoader();
84+
const loader = new GLTFLoader();
8685
loader.setDRACOLoader( dracoLoader );
8786
loader.load( 'models/gltf/LittlestTokyo.glb', function ( gltf ) {
8887

89-
var model = gltf.scene;
88+
const model = gltf.scene;
9089
model.position.set( 1, 1, 0 );
9190
model.scale.set( 0.01, 0.01, 0.01 );
9291
model.traverse( function ( child ) {
@@ -123,7 +122,7 @@
123122

124123
requestAnimationFrame( animate );
125124

126-
var delta = clock.getDelta();
125+
const delta = clock.getDelta();
127126

128127
mixer.update( delta );
129128

examples/webgl_animation_multiple.html

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
//////////////////////////////
2525
// Global objects
2626
//////////////////////////////
27-
var worldScene = null; // THREE.Scene where it all will be rendered
28-
var renderer = null;
29-
var camera = null;
30-
var clock = null;
31-
var mixers = []; // All the THREE.AnimationMixer objects for all the animations in the scene
27+
let worldScene = null; // THREE.Scene where it all will be rendered
28+
let renderer = null;
29+
let camera = null;
30+
let clock = null;
31+
const mixers = []; // All the THREE.AnimationMixer objects for all the animations in the scene
3232
//////////////////////////////
3333

3434

@@ -40,15 +40,15 @@
4040
// A model may have multiple SkinnedMesh objects as well as several rigs (armatures). Units will define which
4141
// meshes, armatures and animations to use. We will load the whole scene for each object and clone it for each unit.
4242
// Models are from https://www.mixamo.com/
43-
var MODELS = [
43+
const MODELS = [
4444
{ name: "Soldier" },
4545
{ name: "Parrot" },
4646
// { name: "RiflePunch" },
4747
];
4848

4949
// Here we define instances of the models that we want to place in the scene, their position, scale and the animations
5050
// that must be played.
51-
var UNITS = [
51+
const UNITS = [
5252
{
5353
modelName: "Soldier", // Will use the 3D model from file models/gltf/Soldier.glb
5454
meshName: "vanguard_Mesh", // Name of the main mesh to animate
@@ -91,7 +91,7 @@
9191
//////////////////////////////
9292
// The main setup happens here
9393
//////////////////////////////
94-
var numLoadedModels = 0;
94+
let numLoadedModels = 0;
9595
initScene();
9696
initRenderer();
9797
loadModels();
@@ -109,9 +109,9 @@
109109
*/
110110
function loadModels() {
111111

112-
for ( var i = 0; i < MODELS.length; ++ i ) {
112+
for ( let i = 0; i < MODELS.length; ++ i ) {
113113

114-
var m = MODELS[ i ];
114+
const m = MODELS[ i ];
115115

116116
loadGltfModel( m, function () {
117117

@@ -136,25 +136,25 @@
136136
*/
137137
function instantiateUnits() {
138138

139-
var numSuccess = 0;
139+
let numSuccess = 0;
140140

141-
for ( var i = 0; i < UNITS.length; ++ i ) {
141+
for ( let i = 0; i < UNITS.length; ++ i ) {
142142

143-
var u = UNITS[ i ];
144-
var model = getModelByName( u.modelName );
143+
const u = UNITS[ i ];
144+
const model = getModelByName( u.modelName );
145145

146146
if ( model ) {
147147

148-
var clonedScene = SkeletonUtils.clone( model.scene );
148+
const clonedScene = SkeletonUtils.clone( model.scene );
149149

150150
if ( clonedScene ) {
151151

152152
// THREE.Scene is cloned properly, let's find one mesh and launch animation for it
153-
var clonedMesh = clonedScene.getObjectByName( u.meshName );
153+
const clonedMesh = clonedScene.getObjectByName( u.meshName );
154154

155155
if ( clonedMesh ) {
156156

157-
var mixer = startAnimation( clonedMesh, model.animations, u.animationName );
157+
const mixer = startAnimation( clonedMesh, model.animations, u.animationName );
158158

159159
// Save the animation mixer in the list, will need it in the animation loop
160160
mixers.push( mixer );
@@ -211,12 +211,12 @@
211211
*/
212212
function startAnimation( skinnedMesh, animations, animationName ) {
213213

214-
var mixer = new THREE.AnimationMixer( skinnedMesh );
215-
var clip = THREE.AnimationClip.findByName( animations, animationName );
214+
const mixer = new THREE.AnimationMixer( skinnedMesh );
215+
const clip = THREE.AnimationClip.findByName( animations, animationName );
216216

217217
if ( clip ) {
218218

219-
var action = mixer.clipAction( clip );
219+
const action = mixer.clipAction( clip );
220220
action.play();
221221

222222
}
@@ -232,7 +232,7 @@
232232
*/
233233
function getModelByName( name ) {
234234

235-
for ( var i = 0; i < MODELS.length; ++ i ) {
235+
for ( let i = 0; i < MODELS.length; ++ i ) {
236236

237237
if ( MODELS[ i ].name === name ) {
238238

@@ -253,12 +253,12 @@
253253
*/
254254
function loadGltfModel( model, onLoaded ) {
255255

256-
var loader = new GLTFLoader();
257-
var modelName = "models/gltf/" + model.name + ".glb";
256+
const loader = new GLTFLoader();
257+
const modelName = "models/gltf/" + model.name + ".glb";
258258

259259
loader.load( modelName, function ( gltf ) {
260260

261-
var scene = gltf.scene;
261+
const scene = gltf.scene;
262262

263263
model.animations = gltf.animations;
264264
model.scene = scene;
@@ -292,11 +292,11 @@
292292

293293
// Get the time elapsed since the last frame
294294

295-
var mixerUpdateDelta = clock.getDelta();
295+
const mixerUpdateDelta = clock.getDelta();
296296

297297
// Update all the animation frames
298298

299-
for ( var i = 0; i < mixers.length; ++ i ) {
299+
for ( let i = 0; i < mixers.length; ++ i ) {
300300

301301
mixers[ i ].update( mixerUpdateDelta );
302302

@@ -316,7 +316,7 @@
316316
*/
317317
function initRenderer() {
318318

319-
var container = document.getElementById( 'container' );
319+
const container = document.getElementById( 'container' );
320320
renderer = new THREE.WebGLRenderer( { antialias: true } );
321321
renderer.setPixelRatio( window.devicePixelRatio );
322322
renderer.setSize( window.innerWidth, window.innerHeight );
@@ -342,11 +342,11 @@
342342
worldScene.background = new THREE.Color( 0xa0a0a0 );
343343
worldScene.fog = new THREE.Fog( 0xa0a0a0, 10, 22 );
344344

345-
var hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
345+
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
346346
hemiLight.position.set( 0, 20, 0 );
347347
worldScene.add( hemiLight );
348348

349-
var dirLight = new THREE.DirectionalLight( 0xffffff );
349+
const dirLight = new THREE.DirectionalLight( 0xffffff );
350350
dirLight.position.set( - 3, 10, - 10 );
351351
dirLight.castShadow = true;
352352
dirLight.shadow.camera.top = 10;
@@ -358,7 +358,7 @@
358358
worldScene.add( dirLight );
359359

360360
// ground
361-
var groundMesh = new THREE.Mesh(
361+
const groundMesh = new THREE.Mesh(
362362
new THREE.PlaneBufferGeometry( 40, 40 ),
363363
new THREE.MeshPhongMaterial( {
364364
color: 0x999999,

examples/webgl_animation_skinning_additive_blending.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
import { OrbitControls } from './jsm/controls/OrbitControls.js';
3737
import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
3838

39-
var scene, renderer, camera, stats;
40-
var model, skeleton, mixer, clock;
39+
let scene, renderer, camera, stats;
40+
let model, skeleton, mixer, clock;
4141

42-
var crossFadeControls = [];
42+
const crossFadeControls = [];
4343

44-
var currentBaseAction = 'idle';
44+
let currentBaseAction = 'idle';
4545
const allActions = [];
4646
const baseActions = {
4747
idle: { weight: 1 },
@@ -54,24 +54,24 @@
5454
agree: { weight: 0 },
5555
headShake: { weight: 0 }
5656
};
57-
var panelSettings, numAnimations;
57+
let panelSettings, numAnimations;
5858

5959
init();
6060

6161
function init() {
6262

63-
var container = document.getElementById( 'container' );
63+
const container = document.getElementById( 'container' );
6464
clock = new THREE.Clock();
6565

6666
scene = new THREE.Scene();
6767
scene.background = new THREE.Color( 0xa0a0a0 );
6868
scene.fog = new THREE.Fog( 0xa0a0a0, 10, 50 );
6969

70-
var hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
70+
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
7171
hemiLight.position.set( 0, 20, 0 );
7272
scene.add( hemiLight );
7373

74-
var dirLight = new THREE.DirectionalLight( 0xffffff );
74+
const dirLight = new THREE.DirectionalLight( 0xffffff );
7575
dirLight.position.set( 3, 10, 10 );
7676
dirLight.castShadow = true;
7777
dirLight.shadow.camera.top = 2;
@@ -84,12 +84,12 @@
8484

8585
// ground
8686

87-
var mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 100, 100 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
87+
const mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 100, 100 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
8888
mesh.rotation.x = - Math.PI / 2;
8989
mesh.receiveShadow = true;
9090
scene.add( mesh );
9191

92-
var loader = new GLTFLoader();
92+
const loader = new GLTFLoader();
9393
loader.load( 'models/gltf/Xbot.glb', function ( gltf ) {
9494

9595
model = gltf.scene;
@@ -105,7 +105,7 @@
105105
skeleton.visible = false;
106106
scene.add( skeleton );
107107

108-
var animations = gltf.animations;
108+
const animations = gltf.animations;
109109
mixer = new THREE.AnimationMixer( model );
110110

111111
numAnimations = animations.length;
@@ -160,7 +160,7 @@
160160
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 100 );
161161
camera.position.set( - 1, 2, 3 );
162162

163-
var controls = new OrbitControls( camera, renderer.domElement );
163+
const controls = new OrbitControls( camera, renderer.domElement );
164164
controls.enablePan = false;
165165
controls.enableZoom = false;
166166
controls.target.set( 0, 1, 0 );
@@ -175,11 +175,11 @@
175175

176176
function createPanel() {
177177

178-
var panel = new GUI( { width: 310 } );
178+
const panel = new GUI( { width: 310 } );
179179

180-
var folder1 = panel.addFolder( 'Base Actions' );
181-
var folder2 = panel.addFolder( 'Additive Action Weights' );
182-
var folder3 = panel.addFolder( 'General Speed' );
180+
const folder1 = panel.addFolder( 'Base Actions' );
181+
const folder2 = panel.addFolder( 'Additive Action Weights' );
182+
const folder3 = panel.addFolder( 'General Speed' );
183183

184184
panelSettings = {
185185
'modify time scale': 1.0
@@ -404,7 +404,7 @@
404404

405405
// Get the time elapsed since the last frame, used for mixer update
406406

407-
var mixerUpdateDelta = clock.getDelta();
407+
const mixerUpdateDelta = clock.getDelta();
408408

409409
// Update the animation mixer, the stats panel, and render this frame
410410

0 commit comments

Comments
 (0)