提交 b01aa8f0 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #10174 from sunag/sea3d_1.8.1

SEA3D 1.8.1
此差异已折叠。
此差异已折叠。
/**
* SEA3D - o3dgc
* @author Sunag / http://www.sunag.com.br/
*/
'use strict';
//
// Lossy Compression
//
SEA3D.GeometryGC = function ( name, data, sea3d ) {
this.name = name;
this.data = data;
this.sea3d = sea3d;
var i;
var attrib = data.readUShort();
var uvIDs = [], jointID, weightID;
this.isBig = ( attrib & 1 ) != 0;
data.readVInt = this.isBig ? data.readUInt : data.readUShort;
// Geometry Flags
// ..
// 1 isBig
// 2 groups
// 4 uv
// 8 tangent
// 16 colors
// 32 joints
// 64 morph
// 128 vertex-animation
// ..
if ( attrib & 2 ) {
this.groups = [];
var numGroups = data.readUByte(),
groupOffset = 0;
for ( i = 0; i < numGroups; i ++ ) {
var groupLength = data.readVInt() * 3;
this.groups.push( {
start: groupOffset,
count: groupLength,
} );
groupOffset += groupLength;
}
} else {
this.groups = [];
}
if ( attrib & 4 ) {
this.uv = [];
var uvCount = data.readUByte();
for ( i = 0; i < uvCount; i ++ ) {
uvIDs[ i ] = data.readUByte();
}
}
if ( attrib & 32 ) {
jointID = data.readUByte();
weightID = data.readUByte();
}
var size = data.readUInt();
var bytes = data.concat( data.position, size );
var bstream = new o3dgc.BinaryStream( bytes.buffer );
var decoder = new o3dgc.SC3DMCDecoder();
var ifs = new o3dgc.IndexedFaceSet();
decoder.DecodeHeader( ifs, bstream );
var numIndexes = ifs.GetNCoordIndex();
var numVertex = ifs.GetNCoord();
if ( ! this.groups.length ) this.groups.push( { start: 0, count: numIndexes * 3 } );
this.indexes = this.isBig ? new Uint32Array( numIndexes * 3 ) : new Uint16Array( numIndexes * 3 );
this.vertex = new Float32Array( numVertex * 3 );
ifs.SetCoordIndex( this.indexes );
ifs.SetCoord( this.vertex );
if ( ifs.GetNNormal() > 0 ) {
this.normal = new Float32Array( numVertex * 3 );
ifs.SetNormal( this.normal );
}
for ( i = 0; i < uvIDs.length; i ++ ) {
this.uv[ i ] = new Float32Array( numVertex * 2 );
ifs.SetFloatAttribute( uvIDs[ i ], this.uv[ i ] );
}
if ( jointID !== undefined ) {
this.jointPerVertex = ifs.GetIntAttributeDim( jointID );
this.joint = new Uint16Array( numVertex * this.jointPerVertex );
this.weight = new Float32Array( numVertex * this.jointPerVertex );
ifs.SetIntAttribute( jointID, this.joint );
ifs.SetFloatAttribute( weightID, this.weight );
}
// decode mesh
decoder.DecodePlayload( ifs, bstream );
};
SEA3D.GeometryGC.prototype.type = "s3D";
//
// Extension
//
THREE.SEA3D.EXTENSIONS_LOADER.push( {
setTypeRead: function () {
this.file.addClass( SEA3D.GeometryGC, true );
this.file.typeRead[ SEA3D.GeometryGC.prototype.type ] = this.readGeometryBuffer;
}
} );
......@@ -9,19 +9,23 @@
// Header
//
THREE.SEA3D.prototype._onHead = THREE.SEA3D.prototype.onHead;
THREE.SEA3D.prototype._updateTransform = THREE.SEA3D.prototype.updateTransform;
THREE.SEA3D.prototype._readVertexAnimation = THREE.SEA3D.prototype.readVertexAnimation;
THREE.SEA3D.prototype._readGeometryBuffer = THREE.SEA3D.prototype.readGeometryBuffer;
THREE.SEA3D.prototype._readLine = THREE.SEA3D.prototype.readLine;
THREE.SEA3D.prototype._getSkeletonAnimation = THREE.SEA3D.prototype.getSkeletonAnimation;
THREE.SEA3D.prototype._applyDefaultAnimation = THREE.SEA3D.prototype.applyDefaultAnimation;
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,
_getSkeletonAnimation: THREE.SEA3D.prototype.getSkeletonAnimation,
_applyDefaultAnimation: THREE.SEA3D.prototype.applyDefaultAnimation
} );
//
// Utils
//
THREE.SEA3D.prototype.isLegacy = function( sea ) {
THREE.SEA3D.prototype.isLegacy = function ( sea ) {
var sea3d = sea.sea3d;
......@@ -37,7 +41,7 @@ THREE.SEA3D.prototype.isLegacy = function( sea ) {
};
THREE.SEA3D.prototype.flipZVec3 = function( v ) {
THREE.SEA3D.prototype.flipZVec3 = function ( v ) {
if ( ! v ) return;
......@@ -55,7 +59,7 @@ THREE.SEA3D.prototype.flipZVec3 = function( v ) {
};
THREE.SEA3D.prototype.expandJoints = function( sea ) {
THREE.SEA3D.prototype.expandJoints = function ( sea ) {
var numJoints = sea.numVertex * 4;
......@@ -92,7 +96,7 @@ THREE.SEA3D.prototype.expandJoints = function( sea ) {
};
THREE.SEA3D.prototype.compressJoints = function( sea ) {
THREE.SEA3D.prototype.compressJoints = function ( sea ) {
var numJoints = sea.numVertex * 4;
......@@ -129,7 +133,7 @@ THREE.SEA3D.prototype.compressJoints = function( sea ) {
};
THREE.SEA3D.prototype.flipZIndex = function( v ) {
THREE.SEA3D.prototype.flipZIndex = function ( v ) {
var i = 1; // y >-< z
......@@ -147,12 +151,12 @@ THREE.SEA3D.prototype.flipZIndex = function( v ) {
};
THREE.SEA3D.prototype.flipMatrixBone = function( mtx ) {
THREE.SEA3D.prototype.flipMatrixBone = function ( mtx ) {
var zero = new THREE.Vector3();
var buf1 = new THREE.Matrix4();
return function( mtx ) {
return function ( mtx ) {
buf1.copy( mtx );
......@@ -170,13 +174,13 @@ THREE.SEA3D.prototype.flipMatrixBone = function( mtx ) {
}();
THREE.SEA3D.prototype.flipMatrixScale = function( local, global, parent, parentGlobal ) {
THREE.SEA3D.prototype.flipMatrixScale = function ( local, global, parent, parentGlobal ) {
var pos = new THREE.Vector3();
var qua = new THREE.Quaternion();
var slc = new THREE.Vector3();
return function( local, global, parent, parentGlobal ) {
return function ( local, global, parent, parentGlobal ) {
if ( parent ) local.multiplyMatrices( parent, local );
......@@ -213,7 +217,7 @@ THREE.SEA3D.prototype.flipMatrixScale = function( local, global, parent, parentG
// Legacy
//
THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
THREE.SEA3D.prototype.updateAnimationSet = function ( obj3d ) {
var buf1 = new THREE.Matrix4();
var buf2 = new THREE.Matrix4();
......@@ -226,7 +230,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
var to_qua = new THREE.Quaternion();
var to_slc = new THREE.Vector3();
return function( obj3d ) {
return function ( obj3d ) {
var anmSet = obj3d.animation.animationSet;
var relative = obj3d.animation.relative;
......@@ -246,15 +250,17 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
var numFrames = raw.length / data.blockLength;
switch ( kind ) {
case SEA3D.Animation.POSITION:
case SEA3D.Animation.ROTATION:
case SEA3D.Animation.SCALE:
t_anm.push( {
kind : kind,
numFrames : numFrames,
raw : raw
kind: kind,
numFrames: numFrames,
raw: raw
} );
break;
}
}
......@@ -269,8 +275,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
buf1.identity();
parent = this.flipMatrixScale( buf2.copy( obj3d.matrixWorld ) );
}
else {
} else {
if ( obj3d.parent ) {
......@@ -292,6 +297,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
kind = t_anm[ t ].kind;
switch ( kind ) {
case SEA3D.Animation.POSITION:
c = f * 3;
......@@ -345,6 +351,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
kind = t_anm[ t ].kind;
switch ( kind ) {
case SEA3D.Animation.POSITION:
c = f * 3;
......@@ -375,6 +382,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
raw[ c + 2 ] = to_slc.z;
break;
}
}
......@@ -390,7 +398,7 @@ THREE.SEA3D.prototype.updateAnimationSet = function( obj3d ) {
}();
THREE.SEA3D.prototype.applyDefaultAnimation = function( sea, animatorClass ) {
THREE.SEA3D.prototype.applyDefaultAnimation = function ( sea, animatorClass ) {
this._applyDefaultAnimation( sea, animatorClass );
......@@ -402,12 +410,12 @@ THREE.SEA3D.prototype.applyDefaultAnimation = function( sea, animatorClass ) {
};
THREE.SEA3D.prototype.updateTransform = function( obj3d, sea ) {
THREE.SEA3D.prototype.updateTransform = function ( obj3d, sea ) {
var buf1 = new THREE.Matrix4();
var identity = new THREE.Matrix4();
return function( obj3d, sea ) {
return function ( obj3d, sea ) {
if ( this.isLegacy( sea ) ) {
......@@ -430,8 +438,7 @@ THREE.SEA3D.prototype.updateTransform = function( obj3d, sea ) {
obj3d.updateMatrixWorld();
}
else {
} else {
this._updateTransform( obj3d, sea );
......@@ -441,7 +448,7 @@ THREE.SEA3D.prototype.updateTransform = function( obj3d, sea ) {
}();
THREE.SEA3D.prototype.readSkeleton = function( sea ) {
THREE.SEA3D.prototype.readSkeleton = function ( sea ) {
var mtx_tmp_inv = new THREE.Matrix4(),
mtx_local = new THREE.Matrix4(),
......@@ -449,7 +456,7 @@ THREE.SEA3D.prototype.readSkeleton = function( sea ) {
pos = new THREE.Vector3(),
qua = new THREE.Quaternion();
return function( sea ) {
return function ( sea ) {
var bones = [],
isLegacy = sea.sea3d.config.legacy;
......@@ -509,21 +516,21 @@ THREE.SEA3D.prototype.readSkeleton = function( sea ) {
}();
THREE.SEA3D.prototype.getSkeletonAnimation = function( sea, skl ) {
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.getSkeletonAnimationLegacy = function ( sea, skl ) {
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 ) {
return function ( sea, skl ) {
if ( sea.tag ) return sea.tag;
......@@ -588,8 +595,7 @@ THREE.SEA3D.prototype.getSkeletonAnimationLegacy = function( sea, skl ) {
mtx_local.multiplyMatrices( mtx_parent, mtx_global );
}
else {
} else {
this.flipMatrixBone( mtx_local );
......@@ -627,7 +633,7 @@ THREE.SEA3D.prototype.getSkeletonAnimationLegacy = function( sea, skl ) {
}();
THREE.SEA3D.prototype.readVertexAnimation = function( sea ) {
THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
if ( this.isLegacy( sea ) ) {
......@@ -646,7 +652,7 @@ THREE.SEA3D.prototype.readVertexAnimation = function( sea ) {
};
THREE.SEA3D.prototype.readGeometryBuffer = function( sea ) {
THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
if ( this.isLegacy( sea ) ) {
......@@ -664,7 +670,7 @@ THREE.SEA3D.prototype.readGeometryBuffer = function( sea ) {
};
THREE.SEA3D.prototype.readLines = function( sea ) {
THREE.SEA3D.prototype.readLines = function ( sea ) {
if ( this.isLegacy( sea ) ) {
......@@ -676,13 +682,13 @@ THREE.SEA3D.prototype.readLines = function( sea ) {
};
THREE.SEA3D.prototype.onHead = function( args ) {
THREE.SEA3D.prototype.onHead = function ( args ) {
// TODO: Ignore sign
};
THREE.SEA3D.EXTENSIONS_LOADER.push( { setTypeRead: function() {
THREE.SEA3D.EXTENSIONS_LOADER.push( { setTypeRead: function () {
// CONFIG
......
......@@ -28,7 +28,8 @@
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">sea3d</a>
<a href="http://threejs.org" target="_blank">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Exporter</a> and edited by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Studio</a><br>
Asset by <a href="http://vhalldez.cgsociety.org/" style="color:#FFFFFF" target="_blank">Valdez Araujo</a>
</div>
<script src="../build/three.js"></script>
......
......@@ -28,7 +28,9 @@
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">sea3d</a>
<a href="http://threejs.org" target="_blank">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Exporter</a> and edited by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Studio</a><br>
High geometry compression with <a href="https://github.com/amd/rest3d/tree/master/server/o3dgc" style="color:#FFFFFF" target="_blank">Open3DGC</a> and LZMA<br>
Asset by <a href="http://vhalldez.cgsociety.org/" style="color:#FFFFFF" target="_blank">Valdez Araujo</a>
</div>
<script src="../build/three.js"></script>
......@@ -46,6 +48,9 @@
<script src="js/loaders/sea3d/SEA3D.js"></script>
<script src="js/loaders/sea3d/SEA3DLZMA.js"></script>
<script src="js/loaders/sea3d/SEA3DLoader.js"></script>
<script src="js/libs/o3dgc.js"></script>
<script src="js/loaders/sea3d/SEA3DGC.js"></script>
<script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script>
......@@ -99,7 +104,8 @@
};
loader.load( './models/sea3d/robot.tjs.sea' );
// Open3DGC - Export by SEA3D Studio
loader.load( './models/sea3d/robot.o3dgc.tjs.sea' );
//
......
......@@ -28,7 +28,7 @@
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">sea3d</a>
<a href="http://threejs.org" target="_blank">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Exporter</a><br>
<div id="description">Click to play</div>
</div>
......
......@@ -28,7 +28,7 @@
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">sea3d</a>
<a href="http://threejs.org" target="_blank">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Exporter</a><br>
<div id="description">Flag is Vertex Animation / Teapot is Morpher</div>
</div>
......
......@@ -67,7 +67,7 @@
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - asset by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">sea3d</a>
<a href="http://threejs.org" target="_blank">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Exporter</a> and edited by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank">SEA3D Studio</a><br>
</div>
<div id="blocker">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册