Skip to content

Commit 9d2353f

Browse files
committed
lights: animation edge-case
1 parent e2a151c commit 9d2353f

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

build/app.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ function init$3( scene ) {
10161016
}
10171017

10181018
let
1019-
objects;
1019+
objects,
1020+
finished;
10201021

10211022
const
10221023
clock = new THREE.Clock();
@@ -1054,24 +1055,37 @@ function init$4( scene ) {
10541055
scene.add( ambientLight, spotLight, spotLight2, spotLight3, directionalLight, directionalLight2 );
10551056
objects = [ ambientLight, spotLight, spotLight2, spotLight3, directionalLight, directionalLight2 ];
10561057

1058+
finished = false;
1059+
10571060
}
10581061

10591062
function easing( t, c ) {
10601063
if ( ( t /= 1 / 2 ) < 1 ) return c / 2 * t * t * t;
10611064
return c / 2 * ( ( t -= 2 ) * t * t + 2 );
10621065
}
10631066

1067+
function updateLights( time ) {
1068+
1069+
for ( let i = 0; i < objects.length; i++ )
1070+
objects[ i ].intensity = objects[ i ].baseIntensity * easing( ( time - 1 ) / 3, 1.0 );
1071+
1072+
}
1073+
10641074
function update$1( ) {
10651075

1076+
if ( finished ) return;
1077+
10661078
const time = clock.getElapsedTime();
10671079

10681080
if ( time > 1 && time < 4 ) {
10691081

1070-
for ( let i = 0; i < objects.length; i++ ) {
1082+
updateLights( time );
10711083

1072-
objects[ i ].intensity = objects[ i ].baseIntensity * easing( ( time - 1 ) / 3, 1.0 );
1084+
} else if ( time > 4 ) {
10731085

1074-
}
1086+
updateLights( 4 );
1087+
1088+
finished = true;
10751089

10761090
}
10771091

@@ -1110,7 +1124,6 @@ function init$5() {
11101124

11111125
// initialization block;
11121126
init( scene$1 );
1113-
init$4( scene$1 );
11141127
init$3( scene$1 );
11151128

11161129
init$1( camera$2, renderer$1.domElement );
@@ -1119,6 +1132,9 @@ function init$5() {
11191132
// dispose of calculation data
11201133
dispose();
11211134

1135+
// initialize light
1136+
init$4( scene$1 );
1137+
11221138
// start program
11231139
animate();
11241140

build/app.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function init() {
3838

3939
// initialization block;
4040
BG.init( scene );
41-
LIGHTS.init( scene );
4241
CLOTH.init( scene );
4342

4443
MOUSE.init( camera, renderer.domElement );
@@ -47,6 +46,9 @@ function init() {
4746
// dispose of calculation data
4847
PRE.dispose();
4948

49+
// initialize light
50+
LIGHTS.init( scene );
51+
5052
// start program
5153
animate();
5254

src/modules/lights.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
let
3-
objects;
3+
objects,
4+
finished;
45

56
const
67
clock = new THREE.Clock();
@@ -38,24 +39,37 @@ function init( scene ) {
3839
scene.add( ambientLight, spotLight, spotLight2, spotLight3, directionalLight, directionalLight2 );
3940
objects = [ ambientLight, spotLight, spotLight2, spotLight3, directionalLight, directionalLight2 ];
4041

42+
finished = false;
43+
4144
}
4245

4346
function easing( t, c ) {
4447
if ( ( t /= 1 / 2 ) < 1 ) return c / 2 * t * t * t;
4548
return c / 2 * ( ( t -= 2 ) * t * t + 2 );
4649
}
4750

51+
function updateLights( time ) {
52+
53+
for ( let i = 0; i < objects.length; i++ )
54+
objects[ i ].intensity = objects[ i ].baseIntensity * easing( ( time - 1 ) / 3, 1.0 );
55+
56+
}
57+
4858
function update( ) {
4959

60+
if ( finished ) return;
61+
5062
const time = clock.getElapsedTime();
5163

5264
if ( time > 1 && time < 4 ) {
5365

54-
for ( let i = 0; i < objects.length; i++ ) {
66+
updateLights( time );
67+
68+
} else if ( time > 4 ) {
5569

56-
objects[ i ].intensity = objects[ i ].baseIntensity * easing( ( time - 1 ) / 3, 1.0 );
70+
updateLights( 4 );
5771

58-
}
72+
finished = true;
5973

6074
}
6175

0 commit comments

Comments
 (0)