Skip to content

Commit

Permalink
morph animation
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Oct 16, 2017
1 parent 9d173e8 commit 853922b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Source/Three.JS/SEA3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,8 @@ SEA3D.Animation.ANGLE = 12;
SEA3D.Animation.ALPHA = 13;
SEA3D.Animation.VOLUME = 14;

SEA3D.Animation.MORPH = 250;

SEA3D.Animation.prototype = Object.create( SEA3D.AnimationBase.prototype );
SEA3D.Animation.prototype.constructor = SEA3D.Animation;

Expand Down Expand Up @@ -1882,6 +1884,32 @@ SEA3D.Morph.prototype.constructor = SEA3D.Morph;

SEA3D.Morph.prototype.type = "mph";

//
// Morph Animation
//

SEA3D.MorphAnimation = function ( name, data, sea3d ) {

SEA3D.AnimationBase.call( this, name, data, sea3d );

this.dataList = [];

for ( var i = 0, l = data.readUByte(); i < l; i ++ ) {

this.dataList.push( {
kind: SEA3D.Animation.MORPH,
type: SEA3D.Stream.FLOAT,
name: data.readUTF8Tiny(),
blockSize: 1,
data: data.readVector( SEA3D.Stream.FLOAT, this.numFrames, 0 )
} );

}

};

SEA3D.MorphAnimation.prototype.type = "mpha";

//
// Vertex Animation
//
Expand Down Expand Up @@ -2793,6 +2821,7 @@ SEA3D.File = function ( config ) {
this.addClass( SEA3D.Camera );
this.addClass( SEA3D.OrthographicCamera );
this.addClass( SEA3D.Morph, true );
this.addClass( SEA3D.MorphAnimation, true );
this.addClass( SEA3D.VertexAnimation, true );
this.addClass( SEA3D.CubeMap, true );
this.addClass( SEA3D.Dummy );
Expand Down
34 changes: 31 additions & 3 deletions Source/Three.JS/SEA3DLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ THREE.SEA3D.prototype.readSprite = function ( sea ) {

THREE.SEA3D.prototype.readMesh = function ( sea ) {

var i, count, geo = sea.geometry.tag, mesh, mat, skeleton, skeletonAnimation, vertexAnimation, uvwAnimationClips, morpher;
var i, count, geo = sea.geometry.tag, mesh, mat, skeleton, morpher, skeletonAnimation, vertexAnimation, uvwAnimationClips, morphAnimation;

for ( i = 0, count = sea.modifiers ? sea.modifiers.length : 0; i < count; i ++ ) {

Expand Down Expand Up @@ -2047,11 +2047,19 @@ THREE.SEA3D.prototype.readMesh = function ( sea ) {
case SEA3D.UVWAnimation.prototype.type:

uvwAnimationClips = anmTag.tag || this.getAnimationType( {
sea: anmTag,
sea: anmTag
} );

break;

case SEA3D.MorphAnimation.prototype.type:

morphAnimation = anmTag.tag || this.getAnimationType( {
sea: anmTag
} );

break;

}

}
Expand Down Expand Up @@ -2131,6 +2139,18 @@ THREE.SEA3D.prototype.readMesh = function ( sea ) {

}

if ( morphAnimation ) {

mesh.morphAnimator = new THREE.SEA3D.Animator( morphAnimation, new THREE.AnimationMixer( mesh ) );

if ( this.config.autoPlay ) {

mesh.morphAnimator.play( 0 );

}

}

mesh.name = sea.name;

mesh.castShadow = sea.castShadows;
Expand Down Expand Up @@ -3021,6 +3041,7 @@ THREE.SEA3D.prototype.readMorpher = function ( sea ) {
var node = sea.node[ i ];

attribs.position[ i ] = new THREE.Float32BufferAttribute( node.vertex, 3 );
attribs.position[ i ].name = node.name;

if ( node.normal ) {

Expand Down Expand Up @@ -3126,6 +3147,12 @@ THREE.SEA3D.prototype.readAnimation = function ( sea ) {

break;

case SEA3D.Animation.MORPH:

name = '.morphTargetInfluences[' + anm.name + ']';

break;

}

if ( ! name ) continue;
Expand All @@ -3151,7 +3178,7 @@ THREE.SEA3D.prototype.readAnimation = function ( sea ) {

}

tracks.push( new THREE.VectorKeyframeTrack( name, times, values, intrpl ) );
tracks.push( new THREE.NumberKeyframeTrack( name, times, values, intrpl ) );

break;

Expand Down Expand Up @@ -3688,6 +3715,7 @@ THREE.SEA3D.prototype.setTypeRead = function () {
this.file.typeRead[ SEA3D.CubeMap.prototype.type ] = this.readCubeMap;
this.file.typeRead[ SEA3D.CubeRender.prototype.type ] = this.readCubeRender;
this.file.typeRead[ SEA3D.Animation.prototype.type ] =
this.file.typeRead[ SEA3D.MorphAnimation.prototype.type ] =
this.file.typeRead[ SEA3D.UVWAnimation.prototype.type ] = this.readAnimation;
this.file.typeRead[ SEA3D.SoundPoint.prototype.type ] = this.readSoundPoint;
this.file.typeRead[ SEA3D.TextureURL.prototype.type ] = this.readTextureURL;
Expand Down

0 comments on commit 853922b

Please sign in to comment.