Skip to content

Commit d29ae17

Browse files
sunagmrdoob
authored andcommitted
sea3d animation to animator keyframe variable name (mrdoob#8963)
* animation to animator keyframe variable name * golden ratio align and descriptions * text to description * play with computed offset negative timeScale animation * clampWhenFinished only for non-loop animations
1 parent 4f4bf13 commit d29ae17

File tree

4 files changed

+54
-38
lines changed

4 files changed

+54
-38
lines changed

examples/js/loaders/sea3d/SEA3DLoader.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,13 @@ THREE.SEA3D.Animator.prototype.updateAnimations = function( mixer ) {
502502
this.animations = [];
503503
this.animationsData = {};
504504

505-
var animations = this instanceof THREE.SEA3D.Animator ? this.clips : this.geometry.animations;
505+
this.clips = this instanceof THREE.SEA3D.Animator ? this.clips : this.geometry.animations;
506506

507-
for ( var i = 0; i < animations.length; i ++ ) {
507+
for ( var i = 0, clips = this.clips; i < clips.length; i ++ ) {
508508

509-
var name = animations[ i ].name;
509+
var name = clips[ i ].name;
510510

511-
this.animations[ name ] = this.animations[ i ] = animations[ i ];
511+
this.animations[ name ] = this.animations[ i ] = clips[ i ];
512512
this.animationsData[ name ] = this.animationsData[ i ] = {};
513513

514514
}
@@ -579,7 +579,9 @@ THREE.SEA3D.Animator.prototype.play = function( name, crossfade, offset, weight
579579

580580
if ( animation == this.currentAnimation ) {
581581

582-
if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset : 0;
582+
if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset :
583+
( this.currentAnimationAction.timeScale >= 0 ? 0 : this.currentAnimation.duration );
584+
583585
this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
584586
this.currentAnimationAction.paused = false;
585587

@@ -594,15 +596,17 @@ THREE.SEA3D.Animator.prototype.play = function( name, crossfade, offset, weight
594596

595597
this.previousAnimationAction = this.currentAnimationAction;
596598
this.currentAnimationAction = this.mixer.clipAction( animation ).setLoop( animation.loop ? THREE.LoopRepeat : THREE.LoopOnce, Infinity ).reset();
597-
this.currentAnimationAction.clampWhenFinished = true;
599+
this.currentAnimationAction.clampWhenFinished = ! animation.loop;
598600
this.currentAnimationAction.paused = false;
599601

600602
this.previousAnimationData = this.currentAnimationData;
601603
this.currentAnimationData = this.animationsData[ name ];
602604

603605
this.updateTimeScale();
604606

605-
if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset : 0;
607+
if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset :
608+
( this.currentAnimationAction.timeScale >= 0 ? 0 : this.currentAnimation.duration );
609+
606610
this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
607611

608612
this.currentAnimationAction.play();
@@ -857,7 +861,7 @@ THREE.SEA3D.Dummy.prototype.copy = function( source ) {
857861
this.props = source.props;
858862
this.scripts = source.scripts;
859863

860-
if ( this.animation ) this.animation = source.animation.clone( this );
864+
if ( this.animator ) this.animator = source.animator.clone( this );
861865

862866
return this;
863867

@@ -903,7 +907,7 @@ THREE.SEA3D.Mesh.prototype.copy = function( source ) {
903907
this.props = source.props;
904908
this.scripts = source.scripts;
905909

906-
if ( this.animation ) this.animation = source.animation.clone( this );
910+
if ( this.animator ) this.animator = source.animator.clone( this );
907911

908912
return this;
909913

@@ -948,7 +952,7 @@ THREE.SEA3D.SkinnedMesh.prototype.copy = function( source ) {
948952
this.props = source.props;
949953
this.scripts = source.scripts;
950954

951-
if ( this.animation ) this.animation = source.animation.clone( this );
955+
if ( this.animator ) this.animator = source.animator.clone( this );
952956

953957
return this;
954958

@@ -982,7 +986,7 @@ THREE.SEA3D.VertexAnimationMesh.prototype.copy = function( source ) {
982986
this.props = source.props;
983987
this.scripts = source.scripts;
984988

985-
if ( this.animation ) this.animation = source.animation.clone( this );
989+
if ( this.animator ) this.animator = source.animator.clone( this );
986990

987991
return this;
988992

@@ -1010,7 +1014,7 @@ THREE.SEA3D.Camera.prototype.copy = function( source ) {
10101014
this.props = source.props;
10111015
this.scripts = source.scripts;
10121016

1013-
if ( this.animation ) this.animation = source.animation.clone( this );
1017+
if ( this.animator ) this.animator = source.animator.clone( this );
10141018

10151019
return this;
10161020

@@ -1038,7 +1042,7 @@ THREE.SEA3D.OrthographicCamera.prototype.copy = function( source ) {
10381042
this.props = source.props;
10391043
this.scripts = source.scripts;
10401044

1041-
if ( this.animation ) this.animation = source.animation.clone( this );
1045+
if ( this.animator ) this.animator = source.animator.clone( this );
10421046

10431047
return this;
10441048

@@ -1066,7 +1070,7 @@ THREE.SEA3D.PointLight.prototype.copy = function( source ) {
10661070
this.props = source.props;
10671071
this.scripts = source.scripts;
10681072

1069-
if ( this.animation ) this.animation = source.animation.clone( this );
1073+
if ( this.animator ) this.animator = source.animator.clone( this );
10701074

10711075
return this;
10721076

@@ -1339,16 +1343,16 @@ THREE.SEA3D.prototype.applyDefaultAnimation = function( sea, animatorClass ) {
13391343

13401344
switch ( anm.tag.type ) {
13411345
case SEA3D.Animation.prototype.type:
1342-
obj.animation = new animatorClass( anm.tag.tag, obj );
1343-
obj.animation.setRelative( anm.relative );
1346+
obj.animator = new animatorClass( anm.tag.tag, obj );
1347+
obj.animator.setRelative( anm.relative );
13441348

13451349
if ( this.config.autoPlay ) {
13461350

1347-
obj.animation.play( 0 );
1351+
obj.animator.play( 0 );
13481352

13491353
}
13501354

1351-
return obj.animation;
1355+
return obj.animator;
13521356
break;
13531357
}
13541358

@@ -2371,7 +2375,7 @@ THREE.SEA3D.PointSound.prototype.copy = function( source ) {
23712375
this.props = source.props;
23722376
this.scripts = source.scripts;
23732377

2374-
if ( this.animation ) this.animation = source.animation.clone( this );
2378+
if ( this.animator ) this.animator = source.animator.clone( this );
23752379

23762380
return this;
23772381

examples/webgl_loader_sea3d_hierarchy.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181

8282
for(var i = 0; i < loader.meshes.length; i++) {
8383

84-
if (loader.meshes[i].animation)
85-
loader.meshes[i].animation.play( "root" );
84+
if (loader.meshes[i].animator)
85+
loader.meshes[i].animator.play( "root" );
8686

8787
}
8888

examples/webgl_loader_sea3d_keyframe.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107

108108
for(var i = 0; i < loader.meshes.length; i++) {
109109

110-
if (loader.meshes[i].animation)
111-
loader.meshes[i].animation.play(id, crossfade, offset);
110+
if (loader.meshes[i].animator)
111+
loader.meshes[i].animator.play(id, crossfade, offset);
112112

113113
}
114114

@@ -118,8 +118,8 @@
118118

119119
for(var i = 0; i < loader.meshes.length; i++) {
120120

121-
if (loader.meshes[i].animation)
122-
loader.meshes[i].animation.setTimeScale( timeScale );
121+
if (loader.meshes[i].animator)
122+
loader.meshes[i].animator.setTimeScale( timeScale );
123123

124124
}
125125

@@ -129,8 +129,8 @@
129129

130130
for(var i = 0; i < loader.meshes.length; i++) {
131131

132-
if (loader.meshes[i].animation)
133-
loader.meshes[i].animation.stop();
132+
if (loader.meshes[i].animator)
133+
loader.meshes[i].animator.stop();
134134

135135
}
136136

@@ -239,15 +239,15 @@
239239

240240
var fracture99 = loader.getMesh("Object099");
241241

242-
//fracture99.animation.setTimeScale( 1 );
243-
//fracture99.animation.playing
244-
//fracture99.animation.currentAnimation
245-
//fracture99.animation.previousAnimation
242+
//fracture99.animator.setTimeScale( 1 );
243+
//fracture99.animator.playing
244+
//fracture99.animator.currentAnimation
245+
//fracture99.animator.previousAnimation
246246

247-
fracture99.animation.play("crash#2", .5, 0);
248-
//fracture99.animation.stop();
249-
//fracture99.animation.pause();
250-
//fracture99.animation.resume();
247+
fracture99.animator.play("crash#2", .5, 0);
248+
//fracture99.animator.stop();
249+
//fracture99.animator.pause();
250+
//fracture99.animator.resume();
251251

252252
description("crash#2 in single object - crossfade 0.5 seconds");
253253

examples/webgl_loader_sea3d_skinning.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<div id="info">
3131
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFF" target="_blank">sea3d</a>
3232
<br/>BoneObject: Object3D attached in a Bone
33-
<br/>Left Click to hidden/show the hat - Right click to run - Middle click to clone
33+
<br/>Left Click to hidden/show the hat - Right click to run
34+
<br/><div id="playercount"></div>
3435
</div>
3536

3637
<script src="../build/three.js"></script>
@@ -107,19 +108,30 @@
107108

108109
animate();
109110

111+
updatePlayerCountDescription( 1 );
112+
110113
};
111114

112115
loader.load( './models/sea3d/skin.tjs.sea' );
113116

114117
//
115118

119+
function updatePlayerCountDescription( count ) {
120+
121+
document.getElementById("playercount").innerText = "Numbers of players " + count + " | Middle click to clone";
122+
123+
}
124+
116125
var cloneAsset = function() {
117126

118-
var count = 0, size = 50;
127+
var count = 2, size = 25;
119128

120129
return function() {
121130

122-
var angle = ( Math.PI / 4 ) * count++;
131+
updatePlayerCountDescription( count );
132+
133+
var PHI = Math.PI * 2 * (Math.sqrt(5) + 1) / 2; // golden ratio
134+
var angle = PHI * count++;
123135

124136
var container = new THREE.Object3D();
125137
container.position.z = ( size * count ) * Math.cos( angle );

0 commit comments

Comments
 (0)