Browse Source

Merge pull request #10262 from sunag/sea3d_1.8.1

Sea3d 1.8.1 updates
Mr.doob 8 years ago
parent
commit
afd1a774ce

+ 11 - 2
examples/js/loaders/sea3d/SEA3D.js

@@ -9,7 +9,7 @@ var SEA3D = { VERSION: 18100 };
 
 SEA3D.getVersion = function () {
 
-	// Max = 16777215 - VVSSBB  | V = Version | S = Subversion | B = Buildversion
+	// Max = 16777215 - VV.S.S.BB  | V = Version | S = Subversion | B = Buildversion
 	var v = SEA3D.VERSION.toString(), l = v.length;
 	return v.substring( 0, l - 4 ) + "." + v.substring( l - 4, l - 3 ) + "." + v.substring( l - 3, l - 2 ) + "." + parseFloat( v.substring( l - 2, l ) ).toString();
 
@@ -99,6 +99,7 @@ SEA3D.Stream.sizeOf = function ( kind ) {
 };
 
 SEA3D.Stream.prototype = {
+
 	constructor: SEA3D.Stream,
 
 	set buffer( val ) {
@@ -278,7 +279,15 @@ SEA3D.Stream.prototype.readUTF8 = function ( len ) {
 
 	var buffer = this.readBytes( len );
 
-	return window.TextDecoder ? new TextDecoder().decode( buffer ) : String.fromCharCode.apply( undefined, new Uint16Array( new Uint8Array( buffer ) ) );
+	if ( window.TextDecoder ) {
+
+		return new TextDecoder().decode( buffer );
+
+	} else {
+
+		return decodeURIComponent( escape( String.fromCharCode.apply( null, new Uint8Array( buffer ) ) ) );
+
+	}
 
 };
 

+ 85 - 64
examples/js/loaders/sea3d/SEA3DLegacy.js

@@ -16,8 +16,8 @@ Object.assign( THREE.SEA3D.prototype, {
 	_readVertexAnimation: THREE.SEA3D.prototype.readVertexAnimation,
 	_readGeometryBuffer: THREE.SEA3D.prototype.readGeometryBuffer,
 	_readLine: THREE.SEA3D.prototype.readLine,
-	_getSkeletonAnimation: THREE.SEA3D.prototype.getSkeletonAnimation,
-	_applyDefaultAnimation: THREE.SEA3D.prototype.applyDefaultAnimation
+	_getAnimationType: THREE.SEA3D.prototype.getAnimationType,
+	_readAnimation: THREE.SEA3D.prototype.readAnimation
 
 } );
 
@@ -41,11 +41,11 @@ THREE.SEA3D.prototype.isLegacy = function ( sea ) {
 
 };
 
-THREE.SEA3D.prototype.flipZVec3 = function ( v ) {
+THREE.SEA3D.prototype.flipXVec3 = function ( v ) {
 
 	if ( ! v ) return;
 
-	var i = 2; // z
+	var i = 0; // z
 
 	while ( i < v.length ) {
 
@@ -133,7 +133,7 @@ THREE.SEA3D.prototype.compressJoints = function ( sea ) {
 
 };
 
-THREE.SEA3D.prototype.flipZIndex = function ( v ) {
+THREE.SEA3D.prototype.flipYZIndex = function ( v ) {
 
 	var i = 1; // y >-< z
 
@@ -151,21 +151,17 @@ THREE.SEA3D.prototype.flipZIndex = function ( v ) {
 
 };
 
-THREE.SEA3D.prototype.flipMatrixBone = function ( mtx ) {
+THREE.SEA3D.prototype.flipMatrixBone = function () {
 
 	var zero = new THREE.Vector3();
-	var buf1 = new THREE.Matrix4();
 
 	return function ( mtx ) {
 
-		buf1.copy( mtx );
+		var pos = THREE.SEA3D.VECBUF.setFromMatrixPosition( mtx );
+		pos.x = - pos.x;
 
 		mtx.setPosition( zero );
-		mtx.multiplyMatrices( THREE.SEA3D.MTXBUF.makeRotationZ( THREE.Math.degToRad( 180 ) ), mtx );
-		mtx.makeRotationFromQuaternion( THREE.SEA3D.QUABUF.setFromRotationMatrix( mtx ) );
-
-		var pos = THREE.SEA3D.VECBUF.setFromMatrixPosition( buf1 );
-		pos.z = - pos.z;
+		mtx.multiplyMatrices( THREE.SEA3D.MTXBUF.makeRotationX( THREE.Math.degToRad( 180 ) ), mtx );
 		mtx.setPosition( pos );
 
 		return mtx;
@@ -174,34 +170,33 @@ THREE.SEA3D.prototype.flipMatrixBone = function ( mtx ) {
 
 }();
 
-THREE.SEA3D.prototype.flipMatrixScale = function ( local, global, parent, parentGlobal ) {
+THREE.SEA3D.prototype.flipMatrixScale = function () {
 
 	var pos = new THREE.Vector3();
 	var qua = new THREE.Quaternion();
 	var slc = new THREE.Vector3();
 
-	return function ( local, global, parent, parentGlobal ) {
+	return function ( local, rotate, parent, parentRotate ) {
 
 		if ( parent ) local.multiplyMatrices( parent, local );
 
 		local.decompose( pos, qua, slc );
 
-		slc.z = - slc.z;
+		slc.x = - slc.x;
 
-		if ( global ) {
+		local.compose( pos, qua, slc );
 
-			slc.y = - slc.y;
-			slc.x = - slc.x;
+		if ( rotate ) {
 
-		}
+			local.multiplyMatrices( local, THREE.SEA3D.MTXBUF.makeRotationX( THREE.Math.degToRad( 180 ) ) );
 
-		local.compose( pos, qua, slc );
+		}
 
 		if ( parent ) {
 
 			parent = parent.clone();
 
-			this.flipMatrixScale( parent, parentGlobal );
+			this.flipMatrixScale( parent, parentRotate );
 
 			local.multiplyMatrices( parent.getInverse( parent ), local );
 
@@ -217,7 +212,7 @@ THREE.SEA3D.prototype.flipMatrixScale = function ( local, global, parent, parent
 //	Legacy
 //
 
-THREE.SEA3D.prototype.updateAnimationSet = function ( obj3d ) {
+THREE.SEA3D.prototype.flipDefaultAnimation = function () {
 
 	var buf1 = new THREE.Matrix4();
 	var buf2 = new THREE.Matrix4();
@@ -230,35 +225,32 @@ THREE.SEA3D.prototype.updateAnimationSet = function ( obj3d ) {
 	var to_qua = new THREE.Quaternion();
 	var to_slc = new THREE.Vector3();
 
-	return function ( obj3d ) {
-
-		var anmSet = obj3d.animation.animationSet;
-		var relative = obj3d.animation.relative;
-		var anms = anmSet.animations;
+	return function ( animation, obj3d, relative ) {
 
-		if ( anmSet.flip && ! anms.length )
-			return;
+		if ( animation.isFliped ) return;
 
-		var dataList = anms[ 0 ].dataList,
+		var dataList = animation.dataList,
 			t_anm = [];
 
 		for ( var i = 0; i < dataList.length; i ++ ) {
 
-			var data = dataList[ i ];
-			var raw = dataList[ i ].data;
-			var kind = data.kind;
-			var numFrames = raw.length / data.blockLength;
+			var data = dataList[ i ],
+				raw = data.data,
+				kind = data.kind,
+				numFrames = raw.length / data.blockSize;
 
 			switch ( kind ) {
 
 				case SEA3D.Animation.POSITION:
 				case SEA3D.Animation.ROTATION:
 				case SEA3D.Animation.SCALE:
+
 					t_anm.push( {
 						kind: kind,
 						numFrames: numFrames,
 						raw: raw
 					} );
+
 					break;
 
 			}
@@ -270,7 +262,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function ( obj3d ) {
 			var numFrames = t_anm[ 0 ].numFrames,
 				parent = undefined;
 
-			if ( obj3d.animation.relative ) {
+			if ( relative ) {
 
 				buf1.identity();
 				parent = this.flipMatrixScale( buf2.copy( obj3d.matrixWorld ) );
@@ -391,26 +383,61 @@ THREE.SEA3D.prototype.updateAnimationSet = function ( obj3d ) {
 
 		}
 
-		anmSet.flip = true;
+		animation.isFliped = true;
 
 	};
 
 }();
 
+THREE.SEA3D.prototype.readAnimation = function ( sea ) {
+
+	if ( ! this.isLegacy( sea ) ) {
+
+		this._readAnimation( sea );
+
+	}
+
+};
+
+THREE.SEA3D.prototype.getAnimationType = function ( req ) {
+
+	var sea = req.sea;
+
+	if ( this.isLegacy( sea ) ) {
+
+		switch ( sea.type ) {
 
-THREE.SEA3D.prototype.applyDefaultAnimation = function ( sea, animatorClass ) {
+			case SEA3D.SkeletonAnimation.prototype.type:
 
-	this._applyDefaultAnimation( sea, animatorClass );
+				this.readSkeletonAnimationLegacy( sea, req.skeleton );
 
-	if ( this.isLegacy( sea ) && sea.tag.animation ) {
+				return sea.tag;
 
-		this.updateAnimationSet( sea.tag );
+				break;
+
+			case SEA3D.Animation.prototype.type:
+
+				if ( req.scope instanceof THREE.Object3D ) {
+
+					this.flipDefaultAnimation( sea, req.scope, req.relative );
+
+				}
+
+				this._readAnimation( sea );
+
+				return sea.tag;
+
+				break;
+
+		}
 
 	}
 
+	return this._getAnimationType( req );
+
 };
 
-THREE.SEA3D.prototype.updateTransform = function ( obj3d, sea ) {
+THREE.SEA3D.prototype.updateTransform = function () {
 
 	var buf1 = new THREE.Matrix4();
 	var identity = new THREE.Matrix4();
@@ -448,7 +475,7 @@ THREE.SEA3D.prototype.updateTransform = function ( obj3d, sea ) {
 
 }();
 
-THREE.SEA3D.prototype.readSkeleton = function ( sea ) {
+THREE.SEA3D.prototype.readSkeleton = function () {
 
 	var mtx_tmp_inv = new THREE.Matrix4(),
 		mtx_local = new THREE.Matrix4(),
@@ -516,14 +543,7 @@ THREE.SEA3D.prototype.readSkeleton = function ( sea ) {
 
 }();
 
-THREE.SEA3D.prototype.getSkeletonAnimation = function ( sea, skl ) {
-
-	if ( this.isLegacy( sea ) ) return this.getSkeletonAnimationLegacy( sea, skl );
-	else return this._getSkeletonAnimation( sea, skl );
-
-};
-
-THREE.SEA3D.prototype.getSkeletonAnimationLegacy = function ( sea, skl ) {
+THREE.SEA3D.prototype.readSkeletonAnimationLegacy = function () {
 
 	var mtx_tmp_inv = new THREE.Matrix4(),
 		mtx_local = new THREE.Matrix4(),
@@ -619,15 +639,12 @@ THREE.SEA3D.prototype.getSkeletonAnimationLegacy = function ( sea, skl ) {
 
 			}
 
-			var anm = THREE.AnimationClip.parseAnimation( animation, skl.tag );
-			anm.loop = seq.repeat;
-			anm.timeScale = 1;
-
-			animations.push( anm );
+			animations.push( THREE.SEA3D.AnimationClip.fromClip( THREE.AnimationClip.parseAnimation( animation, skl.tag ), seq.repeat ) );
 
 		}
 
-		return sea.tag = animations;
+		this.domain.clips = this.clips = this.clips || [];
+		this.clips.push( this.objects[ sea.name + '.anm' ] = sea.tag = animations );
 
 	};
 
@@ -641,8 +658,8 @@ THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
 
 			var frame = sea.frame[ i ];
 
-			this.flipZVec3( frame.vertex );
-			this.flipZVec3( frame.normal );
+			this.flipXVec3( frame.vertex );
+			this.flipXVec3( frame.normal );
 
 		}
 
@@ -656,10 +673,10 @@ THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
 
 	if ( this.isLegacy( sea ) ) {
 
-		this.flipZVec3( sea.vertex );
-		this.flipZVec3( sea.normal );
+		this.flipXVec3( sea.vertex );
+		this.flipXVec3( sea.normal );
 
-		this.flipZIndex( sea.indexes );
+		this.flipYZIndex( sea.indexes );
 
 		if ( sea.jointPerVertex > 4 ) this.compressJoints( sea );
 		else if ( sea.jointPerVertex < 4 ) this.expandJoints( sea );
@@ -674,7 +691,7 @@ THREE.SEA3D.prototype.readLines = function ( sea ) {
 
 	if ( this.isLegacy( sea ) ) {
 
-		this.flipZVec3( sea.vertex );
+		this.flipXVec3( sea.vertex );
 
 	}
 
@@ -684,7 +701,11 @@ THREE.SEA3D.prototype.readLines = function ( sea ) {
 
 THREE.SEA3D.prototype.onHead = function ( args ) {
 
-	// TODO: Ignore sign
+	if ( args.sign != "S3D" && args.sign != "TJS" ) {
+
+		throw new Error( "Sign '" + args.sign + "' unknown." );
+
+	}
 
 };
 

+ 721 - 0
examples/js/loaders/sea3d/SEA3DLegacyZ.js

@@ -0,0 +1,721 @@
+/**
+ * 	SEA3D Legacy for Three.JS
+ * 	@author Sunag / http://www.sunag.com.br/
+ */
+
+'use strict';
+
+//
+//	Header
+//
+
+Object.assign( THREE.SEA3D.prototype, {
+
+	_onHead: THREE.SEA3D.prototype.onHead,
+	_updateTransform: THREE.SEA3D.prototype.updateTransform,
+	_readVertexAnimation: THREE.SEA3D.prototype.readVertexAnimation,
+	_readGeometryBuffer: THREE.SEA3D.prototype.readGeometryBuffer,
+	_readLine: THREE.SEA3D.prototype.readLine,
+	_getAnimationType: THREE.SEA3D.prototype.getAnimationType,
+	_readAnimation: THREE.SEA3D.prototype.readAnimation
+
+} );
+
+//
+//	Utils
+//
+
+THREE.SEA3D.prototype.isLegacy = function ( sea ) {
+
+	var sea3d = sea.sea3d;
+
+	if ( sea3d.sign == 'S3D' && ! sea._legacy ) {
+
+		sea._legacy = sea3d.typeUnique[ sea.type ] == true;
+
+		return sea3d.config.legacy;
+
+	}
+
+	return false;
+
+};
+
+THREE.SEA3D.prototype.flipZVec3 = function ( v ) {
+
+	if ( ! v ) return;
+
+	var i = 2; // z
+
+	while ( i < v.length ) {
+
+		v[ i ] = - v[ i ];
+
+		i += 3;
+
+	}
+
+	return v;
+
+};
+
+THREE.SEA3D.prototype.expandJoints = function ( sea ) {
+
+	var numJoints = sea.numVertex * 4;
+
+	var joint = sea.isBig ? new Uint32Array( numJoints ) : new Uint16Array( numJoints );
+	var weight = new Float32Array( numJoints );
+
+	var w = 0, jpv = sea.jointPerVertex;
+
+	for ( var i = 0; i < sea.numVertex; i ++ ) {
+
+		var tjsIndex = i * 4;
+		var seaIndex = i * jpv;
+
+		joint[ tjsIndex ] = sea.joint[ seaIndex ];
+		if ( jpv > 1 ) joint[ tjsIndex + 1 ] = sea.joint[ seaIndex + 1 ];
+		if ( jpv > 2 ) joint[ tjsIndex + 2 ] = sea.joint[ seaIndex + 2 ];
+		if ( jpv > 3 ) joint[ tjsIndex + 3 ] = sea.joint[ seaIndex + 3 ];
+
+		weight[ tjsIndex ] = sea.weight[ seaIndex ];
+		if ( jpv > 1 ) weight[ tjsIndex + 1 ] = sea.weight[ seaIndex + 1 ];
+		if ( jpv > 2 ) weight[ tjsIndex + 2 ] = sea.weight[ seaIndex + 2 ];
+		if ( jpv > 3 ) weight[ tjsIndex + 3 ] = sea.weight[ seaIndex + 3 ];
+
+		w = weight[ tjsIndex ] + weight[ tjsIndex + 1 ] + weight[ tjsIndex + 2 ] + weight[ tjsIndex + 3 ];
+
+		weight[ tjsIndex ] += 1 - w;
+
+	}
+
+	sea.joint = joint;
+	sea.weight = weight;
+
+	sea.jointPerVertex = 4;
+
+};
+
+THREE.SEA3D.prototype.compressJoints = function ( sea ) {
+
+	var numJoints = sea.numVertex * 4;
+
+	var joint = sea.isBig ? new Uint32Array( numJoints ) : new Uint16Array( numJoints );
+	var weight = new Float32Array( numJoints );
+
+	var w = 0, jpv = sea.jointPerVertex;
+
+	for ( var i = 0; i < sea.numVertex; i ++ ) {
+
+		var tjsIndex = i * 4;
+		var seaIndex = i * jpv;
+
+		joint[ tjsIndex ] = sea.joint[ seaIndex ];
+		joint[ tjsIndex + 1 ] = sea.joint[ seaIndex + 1 ];
+		joint[ tjsIndex + 2 ] = sea.joint[ seaIndex + 2 ];
+		joint[ tjsIndex + 3 ] = sea.joint[ seaIndex + 3 ];
+
+		weight[ tjsIndex ] = sea.weight[ seaIndex ];
+		weight[ tjsIndex + 1 ] = sea.weight[ seaIndex + 1 ];
+		weight[ tjsIndex + 2 ] = sea.weight[ seaIndex + 2 ];
+		weight[ tjsIndex + 3 ] = sea.weight[ seaIndex + 3 ];
+
+		w = weight[ tjsIndex ] + weight[ tjsIndex + 1 ] + weight[ tjsIndex + 2 ] + weight[ tjsIndex + 3 ];
+
+		weight[ tjsIndex ] += 1 - w;
+
+	}
+
+	sea.joint = joint;
+	sea.weight = weight;
+
+	sea.jointPerVertex = 4;
+
+};
+
+THREE.SEA3D.prototype.flipZIndex = function ( v ) {
+
+	var i = 1; // y >-< z
+
+	while ( i < v.length ) {
+
+		var idx = v[ i + 1 ];
+		v[ i + 1 ] = v[ i ];
+		v[ i ] = idx;
+
+		i += 3;
+
+	}
+
+	return v;
+
+};
+
+THREE.SEA3D.prototype.flipMatrixBone = function () {
+
+	var zero = new THREE.Vector3();
+	var buf1 = new THREE.Matrix4();
+
+	return function ( mtx ) {
+
+		buf1.copy( mtx );
+
+		mtx.setPosition( zero );
+		mtx.multiplyMatrices( THREE.SEA3D.MTXBUF.makeRotationZ( THREE.Math.degToRad( 180 ) ), mtx );
+		mtx.makeRotationFromQuaternion( THREE.SEA3D.QUABUF.setFromRotationMatrix( mtx ) );
+
+		var pos = THREE.SEA3D.VECBUF.setFromMatrixPosition( buf1 );
+		pos.z = - pos.z;
+		mtx.setPosition( pos );
+
+		return mtx;
+
+	};
+
+}();
+
+THREE.SEA3D.prototype.flipMatrixScale = function () {
+
+	var pos = new THREE.Vector3();
+	var qua = new THREE.Quaternion();
+	var slc = new THREE.Vector3();
+
+	return function ( local, global, parent, parentGlobal ) {
+
+		if ( parent ) local.multiplyMatrices( parent, local );
+
+		local.decompose( pos, qua, slc );
+
+		slc.z = - slc.z;
+
+		if ( global ) {
+
+			slc.y = - slc.y;
+			slc.x = - slc.x;
+
+		}
+
+		local.compose( pos, qua, slc );
+
+		if ( parent ) {
+
+			parent = parent.clone();
+
+			this.flipMatrixScale( parent, parentGlobal );
+
+			local.multiplyMatrices( parent.getInverse( parent ), local );
+
+		}
+
+		return local;
+
+	};
+
+}();
+
+//
+//	Legacy
+//
+
+THREE.SEA3D.prototype.flipDefaultAnimation = function () {
+
+	var buf1 = new THREE.Matrix4();
+	var buf2 = new THREE.Matrix4();
+
+	var pos = new THREE.Vector3();
+	var qua = new THREE.Quaternion();
+	var slc = new THREE.Vector3();
+
+	var to_pos = new THREE.Vector3();
+	var to_qua = new THREE.Quaternion();
+	var to_slc = new THREE.Vector3();
+
+	return function ( animation, obj3d, relative ) {
+
+		if ( animation.isFliped ) return;
+
+		var dataList = animation.dataList,
+			t_anm = [];
+
+		for ( var i = 0; i < dataList.length; i ++ ) {
+
+			var data = dataList[ i ],
+				raw = data.data,
+				kind = data.kind,
+				numFrames = raw.length / data.blockSize;
+
+			switch ( kind ) {
+
+				case SEA3D.Animation.POSITION:
+				case SEA3D.Animation.ROTATION:
+				case SEA3D.Animation.SCALE:
+
+					t_anm.push( {
+						kind: kind,
+						numFrames: numFrames,
+						raw: raw
+					} );
+
+					break;
+
+			}
+
+		}
+
+		if ( t_anm.length > 0 ) {
+
+			var numFrames = t_anm[ 0 ].numFrames,
+				parent = undefined;
+
+			if ( relative ) {
+
+				buf1.identity();
+				parent = this.flipMatrixScale( buf2.copy( obj3d.matrixWorld ) );
+
+			} else {
+
+				if ( obj3d.parent ) {
+
+					parent = this.flipMatrixScale( buf2.copy( obj3d.parent.matrixWorld ) );
+
+				}
+
+				this.flipMatrixScale( buf1.copy( obj3d.matrix ), false, parent );
+
+			}
+
+			buf1.decompose( pos, qua, slc );
+
+			for ( var f = 0, t, c; f < numFrames; f ++ ) {
+
+				for ( t = 0; t < t_anm.length; t ++ ) {
+
+					var raw = t_anm[ t ].raw,
+						kind = t_anm[ t ].kind;
+
+					switch ( kind ) {
+
+						case SEA3D.Animation.POSITION:
+
+							c = f * 3;
+
+							pos.set(
+								raw[ c ],
+								raw[ c + 1 ],
+								raw[ c + 2 ]
+							);
+
+							break;
+
+						case SEA3D.Animation.ROTATION:
+
+							c = f * 4;
+
+							qua.set(
+								raw[ c ],
+								raw[ c + 1 ],
+								raw[ c + 2 ],
+								raw[ c + 3 ]
+							);
+
+							break;
+
+						case SEA3D.Animation.SCALE:
+
+							c = f * 4;
+
+							slc.set(
+								raw[ c ],
+								raw[ c + 1 ],
+								raw[ c + 2 ]
+							);
+
+							break;
+
+					}
+
+				}
+
+				buf1.compose( pos, qua, slc );
+
+				this.flipMatrixScale( buf1, false, buf2 );
+
+				buf1.decompose( to_pos, to_qua, to_slc );
+
+				for ( t = 0; t < t_anm.length; t ++ ) {
+
+					var raw = t_anm[ t ].raw,
+						kind = t_anm[ t ].kind;
+
+					switch ( kind ) {
+
+						case SEA3D.Animation.POSITION:
+
+							c = f * 3;
+
+							raw[ c ] = to_pos.x;
+							raw[ c + 1 ] = to_pos.y;
+							raw[ c + 2 ] = to_pos.z;
+
+							break;
+
+						case SEA3D.Animation.ROTATION:
+
+							c = f * 4;
+
+							raw[ c ] = to_qua.x;
+							raw[ c + 1 ] = to_qua.y;
+							raw[ c + 2 ] = to_qua.z;
+							raw[ c + 3 ] = to_qua.w;
+
+							break;
+
+						case SEA3D.Animation.SCALE:
+
+							c = f * 3;
+
+							raw[ c ] = to_slc.x;
+							raw[ c + 1 ] = to_slc.y;
+							raw[ c + 2 ] = to_slc.z;
+
+							break;
+
+					}
+
+				}
+
+			}
+
+		}
+
+		animation.isFliped = true;
+
+	};
+
+}();
+
+THREE.SEA3D.prototype.readAnimation = function ( sea ) {
+
+	if ( ! this.isLegacy( sea ) ) {
+
+		this._readAnimation( sea );
+
+	}
+
+};
+
+THREE.SEA3D.prototype.getAnimationType = function ( req ) {
+
+	var sea = req.sea;
+
+	if ( this.isLegacy( sea ) ) {
+
+		switch ( sea.type ) {
+
+			case SEA3D.SkeletonAnimation.prototype.type:
+
+				this.readSkeletonAnimationLegacy( sea, req.skeleton );
+
+				return sea.tag;
+
+				break;
+
+			case SEA3D.Animation.prototype.type:
+
+				if ( req.scope instanceof THREE.Object3D ) {
+
+					this.flipDefaultAnimation( sea, req.scope, req.relative );
+
+				}
+
+				this._readAnimation( sea );
+
+				return sea.tag;
+
+				break;
+
+		}
+
+	}
+
+	return this._getAnimationType( req );
+
+};
+
+THREE.SEA3D.prototype.updateTransform = function () {
+
+	var buf1 = new THREE.Matrix4();
+	var identity = new THREE.Matrix4();
+
+	return function ( obj3d, sea ) {
+
+		if ( this.isLegacy( sea ) ) {
+
+			if ( sea.transform ) buf1.elements.set( sea.transform );
+			else buf1.makeTranslation( sea.position.x, sea.position.y, sea.position.z );
+
+			this.flipMatrixScale(
+				buf1, false,
+				obj3d.parent ? obj3d.parent.matrixWorld : identity,
+				obj3d.parent instanceof THREE.Bone
+			);
+
+			obj3d.position.setFromMatrixPosition( buf1 );
+			obj3d.scale.setFromMatrixScale( buf1 );
+
+			// ignore rotation scale
+
+			buf1.scale( THREE.SEA3D.VECBUF.set( 1 / obj3d.scale.x, 1 / obj3d.scale.y, 1 / obj3d.scale.z ) );
+			obj3d.rotation.setFromRotationMatrix( buf1 );
+
+			obj3d.updateMatrixWorld();
+
+		} else {
+
+			this._updateTransform( obj3d, sea );
+
+		}
+
+	};
+
+}();
+
+THREE.SEA3D.prototype.readSkeleton = function () {
+
+	var mtx_tmp_inv = new THREE.Matrix4(),
+		mtx_local = new THREE.Matrix4(),
+		mtx_parent = new THREE.Matrix4(),
+		pos = new THREE.Vector3(),
+		qua = new THREE.Quaternion();
+
+	return function ( sea ) {
+
+		var bones = [],
+			isLegacy = sea.sea3d.config.legacy;
+
+		for ( var i = 0; i < sea.joint.length; i ++ ) {
+
+			var bone = sea.joint[ i ];
+
+			// get world inverse matrix
+
+			mtx_tmp_inv.elements = bone.inverseBindMatrix;
+
+			// convert to world matrix
+
+			mtx_local.getInverse( mtx_tmp_inv );
+
+			// convert to three.js order
+
+			if ( isLegacy ) this.flipMatrixBone( mtx_local );
+
+			if ( bone.parentIndex > - 1 ) {
+
+				// to world
+
+				mtx_tmp_inv.elements = sea.joint[ bone.parentIndex ].inverseBindMatrix;
+				mtx_parent.getInverse( mtx_tmp_inv );
+
+				// convert parent to three.js order
+
+				if ( isLegacy ) this.flipMatrixBone( mtx_parent );
+
+				// to local
+
+				mtx_parent.getInverse( mtx_parent );
+
+				mtx_local.multiplyMatrices( mtx_parent, mtx_local );
+
+			}
+
+			// apply matrix
+
+			pos.setFromMatrixPosition( mtx_local );
+			qua.setFromRotationMatrix( mtx_local );
+
+			bones[ i ] = {
+				name: bone.name,
+				pos: [ pos.x, pos.y, pos.z ],
+				rotq: [ qua.x, qua.y, qua.z, qua.w ],
+				parent: bone.parentIndex
+			};
+
+		}
+
+		return sea.tag = bones;
+
+	};
+
+}();
+
+THREE.SEA3D.prototype.readSkeletonAnimationLegacy = function () {
+
+	var mtx_tmp_inv = new THREE.Matrix4(),
+		mtx_local = new THREE.Matrix4(),
+		mtx_global = new THREE.Matrix4(),
+		mtx_parent = new THREE.Matrix4();
+
+	return function ( sea, skl ) {
+
+		if ( sea.tag ) return sea.tag;
+
+		var animations = [],
+			delta = ( 1000 / sea.frameRate ) / 1000,
+			scale = [ 1, 1, 1 ];
+
+		for ( var i = 0; i < sea.sequence.length; i ++ ) {
+
+			var seq = sea.sequence[ i ];
+
+			var start = seq.start;
+			var end = start + seq.count;
+
+			var animation = {
+				name: seq.name,
+				repeat: seq.repeat,
+				fps: sea.frameRate,
+				JIT: 0,
+				length: delta * seq.count,
+				hierarchy: []
+			};
+
+			var numJoints = sea.numJoints,
+				raw = sea.raw;
+
+			for ( var j = 0; j < numJoints; j ++ ) {
+
+				var bone = skl.joint[ j ],
+					node = { parent: bone.parentIndex, keys: [] },
+					keys = node.keys,
+					time = 0;
+
+				for ( var frame = start; frame < end; frame ++ ) {
+
+					var idx = ( frame * numJoints * 7 ) + ( j * 7 );
+
+					mtx_local.makeRotationFromQuaternion( THREE.SEA3D.QUABUF.set( raw[ idx + 3 ], raw[ idx + 4 ], raw[ idx + 5 ], raw[ idx + 6 ] ) );
+					mtx_local.setPosition( THREE.SEA3D.VECBUF.set( raw[ idx ], raw[ idx + 1 ], raw[ idx + 2 ] ) );
+
+					if ( bone.parentIndex > - 1 ) {
+
+						// to global
+
+						mtx_tmp_inv.elements = skl.joint[ bone.parentIndex ].inverseBindMatrix;
+
+						mtx_parent.getInverse( mtx_tmp_inv );
+
+						mtx_global.multiplyMatrices( mtx_parent, mtx_local );
+
+						// convert to three.js matrix
+
+						this.flipMatrixBone( mtx_global );
+
+						// flip parent inverse
+
+						this.flipMatrixBone( mtx_parent );
+
+						// to local
+
+						mtx_parent.getInverse( mtx_parent );
+
+						mtx_local.multiplyMatrices( mtx_parent, mtx_global );
+
+					} else {
+
+						this.flipMatrixBone( mtx_local );
+
+					}
+
+					var posQ = THREE.SEA3D.VECBUF.setFromMatrixPosition( mtx_local );
+					var newQ = THREE.SEA3D.QUABUF.setFromRotationMatrix( mtx_local );
+
+					keys.push( {
+						time: time,
+						pos: [ posQ.x, posQ.y, posQ.z ],
+						rot: [ newQ.x, newQ.y, newQ.z, newQ.w ],
+						scl: scale
+					} );
+
+					time += delta;
+
+				}
+
+				animation.hierarchy[ j ] = node;
+
+			}
+
+			animations.push( THREE.SEA3D.AnimationClip.fromClip( THREE.AnimationClip.parseAnimation( animation, skl.tag ), seq.repeat ) );
+
+		}
+
+		this.domain.clips = this.clips = this.clips || [];
+		this.clips.push( this.objects[ sea.name + '.anm' ] = sea.tag = animations );
+
+	};
+
+}();
+
+THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
+
+	if ( this.isLegacy( sea ) ) {
+
+		for ( var i = 0, l = sea.frame.length; i < l; i ++ ) {
+
+			var frame = sea.frame[ i ];
+
+			this.flipZVec3( frame.vertex );
+			this.flipZVec3( frame.normal );
+
+		}
+
+	}
+
+	this._readVertexAnimation( sea );
+
+};
+
+THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
+
+	if ( this.isLegacy( sea ) ) {
+
+		this.flipZVec3( sea.vertex );
+		this.flipZVec3( sea.normal );
+
+		this.flipZIndex( sea.indexes );
+
+		if ( sea.jointPerVertex > 4 ) this.compressJoints( sea );
+		else if ( sea.jointPerVertex < 4 ) this.expandJoints( sea );
+
+	}
+
+	this._readGeometryBuffer( sea );
+
+};
+
+THREE.SEA3D.prototype.readLines = function ( sea ) {
+
+	if ( this.isLegacy( sea ) ) {
+
+		this.flipZVec3( sea.vertex );
+
+	}
+
+	this._readLines( sea );
+
+};
+
+THREE.SEA3D.prototype.onHead = function ( args ) {
+
+	// TODO: Ignore sign
+
+};
+
+THREE.SEA3D.EXTENSIONS_LOADER.push( { setTypeRead: function () {
+
+	// CONFIG
+
+	this.config.legacy = this.config.legacy == undefined ? true : this.config.legacy;
+
+	this.file.typeRead[ SEA3D.Skeleton.prototype.type ] = this.readSkeleton;
+
+} } );

File diff suppressed because it is too large
+ 427 - 244
examples/js/loaders/sea3d/SEA3DLoader.js


+ 10 - 7
examples/webgl_loader_sea3d_skinning.html

@@ -95,17 +95,20 @@
 				player = loader.getMesh("Player");
 				hat = loader.getMesh("Hat");
 
-				// events
-
 				// on animation complete example
-				player.animationsData['pass#1'].onComplete = function() {
 
-					console.log("Animation completed!");
+				//player.animation['pass#1'].onComplete = function(e) { console.log("Animation completed!", e); };
+
+				// or
+
+				player.animation['pass#1'].addEventListener(THREE.SEA3D.Animation.COMPLETE, function(e) {
+
+					console.log("Animation completed!", e);
 
-				};
+				} );
 
-				window.addEventListener( 'click', onMouseClick, false );
-				window.addEventListener( 'contextmenu', onRightClick, false );
+				window.addEventListener( 'click', onMouseClick );
+				window.addEventListener( 'contextmenu', onRightClick );
 
 				animate();
 

Some files were not shown because too many files changed in this diff