Permalink
Browse files

morph animation

  • Loading branch information...
sunag committed Oct 16, 2017
1 parent 9d173e8 commit 853922b252bf011cfd6870b1741204b52da43ced
Showing with 60 additions and 3 deletions.
  1. +29 −0 Source/Three.JS/SEA3D.js
  2. +31 −3 Source/Three.JS/SEA3DLoader.js
View
@@ -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;
@@ -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
//
@@ -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 );
@@ -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 ++ ) {
@@ -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;
}
}
@@ -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;
@@ -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 ) {
@@ -3126,6 +3147,12 @@ THREE.SEA3D.prototype.readAnimation = function ( sea ) {
break;
case SEA3D.Animation.MORPH:
name = '.morphTargetInfluences[' + anm.name + ']';
break;
}
if ( ! name ) continue;
@@ -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;
@@ -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;

0 comments on commit 853922b

Please sign in to comment.