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

Merge pull request #10352 from sunag/sea3d_1.8.1

Sea3d 1.8.1 - tjs2
......@@ -2130,9 +2130,11 @@ SEA3D.Material = function ( name, data, sea3d ) {
if ( this.attrib & 128 )
this.animations = data.readAnimationList( sea3d );
this.depthMask = ( this.attrib & 256 ) == 0;
this.depthWrite = ( this.attrib & 256 ) == 0;
this.depthTest = ( this.attrib & 512 ) == 0;
this.premultipliedAlpha = ( this.attrib & 1024 ) != 0;
var count = data.readUByte();
for ( var i = 0; i < count; ++ i ) {
......
......@@ -41,11 +41,11 @@ THREE.SEA3D.prototype.isLegacy = function ( sea ) {
};
THREE.SEA3D.prototype.flipXVec3 = function ( v ) {
THREE.SEA3D.prototype.flipVec3 = function ( v ) {
if ( ! v ) return;
var i = 0; // z
var i = 2;
while ( i < v.length ) {
......@@ -133,7 +133,7 @@ THREE.SEA3D.prototype.compressJoints = function ( sea ) {
};
THREE.SEA3D.prototype.flipYZIndex = function ( v ) {
THREE.SEA3D.prototype.flipIndexes = function ( v ) {
var i = 1; // y >-< z
......@@ -151,17 +151,17 @@ THREE.SEA3D.prototype.flipYZIndex = function ( v ) {
};
THREE.SEA3D.prototype.flipMatrixBone = function () {
THREE.SEA3D.prototype.flipBoneMatrix = function () {
var zero = new THREE.Vector3();
return function ( mtx ) {
var pos = THREE.SEA3D.VECBUF.setFromMatrixPosition( mtx );
pos.x = - pos.x;
pos.z = - pos.z;
mtx.setPosition( zero );
mtx.multiplyMatrices( THREE.SEA3D.MTXBUF.makeRotationX( THREE.Math.degToRad( 180 ) ), mtx );
mtx.multiplyMatrices( THREE.SEA3D.MTXBUF.makeRotationZ( THREE.Math.degToRad( 180 ) ), mtx );
mtx.setPosition( pos );
return mtx;
......@@ -170,7 +170,7 @@ THREE.SEA3D.prototype.flipMatrixBone = function () {
}();
THREE.SEA3D.prototype.flipMatrixScale = function () {
THREE.SEA3D.prototype.flipScaleMatrix = function () {
var pos = new THREE.Vector3();
var qua = new THREE.Quaternion();
......@@ -182,13 +182,13 @@ THREE.SEA3D.prototype.flipMatrixScale = function () {
local.decompose( pos, qua, slc );
slc.x = - slc.x;
slc.z = - slc.z;
local.compose( pos, qua, slc );
if ( rotate ) {
local.multiplyMatrices( local, THREE.SEA3D.MTXBUF.makeRotationX( THREE.Math.degToRad( 180 ) ) );
local.multiplyMatrices( local, THREE.SEA3D.MTXBUF.makeRotationZ( THREE.Math.degToRad( 180 ) ) );
}
......@@ -196,7 +196,7 @@ THREE.SEA3D.prototype.flipMatrixScale = function () {
parent = parent.clone();
this.flipMatrixScale( parent, parentRotate );
this.flipScaleMatrix( parent, parentRotate );
local.multiplyMatrices( parent.getInverse( parent ), local );
......@@ -265,17 +265,17 @@ THREE.SEA3D.prototype.flipDefaultAnimation = function () {
if ( relative ) {
buf1.identity();
parent = this.flipMatrixScale( buf2.copy( obj3d.matrixWorld ) );
parent = this.flipScaleMatrix( buf2.copy( obj3d.matrixWorld ) );
} else {
if ( obj3d.parent ) {
parent = this.flipMatrixScale( buf2.copy( obj3d.parent.matrixWorld ) );
parent = this.flipScaleMatrix( buf2.copy( obj3d.parent.matrixWorld ) );
}
this.flipMatrixScale( buf1.copy( obj3d.matrix ), false, parent );
this.flipScaleMatrix( buf1.copy( obj3d.matrix ), false, parent );
}
......@@ -333,7 +333,7 @@ THREE.SEA3D.prototype.flipDefaultAnimation = function () {
buf1.compose( pos, qua, slc );
this.flipMatrixScale( buf1, false, buf2 );
this.flipScaleMatrix( buf1, false, buf2 );
buf1.decompose( to_pos, to_qua, to_slc );
......@@ -449,7 +449,7 @@ THREE.SEA3D.prototype.updateTransform = function () {
if ( sea.transform ) buf1.elements.set( sea.transform );
else buf1.makeTranslation( sea.position.x, sea.position.y, sea.position.z );
this.flipMatrixScale(
this.flipScaleMatrix(
buf1, false,
obj3d.parent ? obj3d.parent.matrixWorld : identity,
obj3d.parent instanceof THREE.Bone
......@@ -502,7 +502,7 @@ THREE.SEA3D.prototype.readSkeleton = function () {
// convert to three.js order
if ( isLegacy ) this.flipMatrixBone( mtx_local );
if ( isLegacy ) this.flipBoneMatrix( mtx_local );
if ( bone.parentIndex > - 1 ) {
......@@ -513,7 +513,7 @@ THREE.SEA3D.prototype.readSkeleton = function () {
// convert parent to three.js order
if ( isLegacy ) this.flipMatrixBone( mtx_parent );
if ( isLegacy ) this.flipBoneMatrix( mtx_parent );
// to local
......@@ -603,11 +603,11 @@ THREE.SEA3D.prototype.readSkeletonAnimationLegacy = function () {
// convert to three.js matrix
this.flipMatrixBone( mtx_global );
this.flipBoneMatrix( mtx_global );
// flip parent inverse
this.flipMatrixBone( mtx_parent );
this.flipBoneMatrix( mtx_parent );
// to local
......@@ -617,7 +617,7 @@ THREE.SEA3D.prototype.readSkeletonAnimationLegacy = function () {
} else {
this.flipMatrixBone( mtx_local );
this.flipBoneMatrix( mtx_local );
}
......@@ -658,8 +658,8 @@ THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
var frame = sea.frame[ i ];
this.flipXVec3( frame.vertex );
this.flipXVec3( frame.normal );
this.flipVec3( frame.vertex );
this.flipVec3( frame.normal );
}
......@@ -673,10 +673,10 @@ THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
if ( this.isLegacy( sea ) ) {
this.flipXVec3( sea.vertex );
this.flipXVec3( sea.normal );
this.flipVec3( sea.vertex, true );
this.flipVec3( sea.normal, true );
this.flipYZIndex( sea.indexes );
this.flipIndexes( sea.indexes );
if ( sea.jointPerVertex > 4 ) this.compressJoints( sea );
else if ( sea.jointPerVertex < 4 ) this.expandJoints( sea );
......@@ -691,7 +691,7 @@ THREE.SEA3D.prototype.readLines = function ( sea ) {
if ( this.isLegacy( sea ) ) {
this.flipXVec3( sea.vertex );
this.flipVec3( sea.vertex );
}
......
......@@ -35,7 +35,6 @@ THREE.SEA3D = function ( config ) {
useEnvironment: true,
useVertexTexture: true,
forceStatic: false,
forcePremultipliedAlpha: false,
streaming: true,
async: true,
paths: {},
......@@ -100,6 +99,16 @@ Object.defineProperties( THREE.SEA3D.prototype, {
}
},
elapsedTime: {
get: function () {
return this.file.timer.elapsedTime;
}
}
} );
......@@ -1147,6 +1156,19 @@ THREE.SEA3D.Object3D.prototype = Object.assign( Object.create( THREE.Object3D.pr
return this.animate != undefined;
},
copy: function ( source ) {
THREE.Object3D.prototype.copy.call( this, source );
this.attribs = source.attribs;
this.scripts = source.scripts;
if ( source.animator ) this.animator = source.animator.clone( this );
return this;
}
} );
......@@ -2019,6 +2041,7 @@ THREE.SEA3D.prototype.readMesh = function ( sea ) {
}
mesh.name = sea.name;
mesh.castShadow = sea.castShadows;
......@@ -2519,6 +2542,22 @@ THREE.SEA3D.prototype.materialTechnique =
};
// EMISSIVE
techniques[ SEA3D.Material.EMISSIVE ] =
function ( mat, tech ) {
mat.emissive.setHex( tech.color );
};
// EMISSIVE_MAP
techniques[ SEA3D.Material.EMISSIVE_MAP ] =
function ( mat, tech ) {
mat.emissiveMap = tech.texture.tag;
};
// ALPHA_MAP
techniques[ SEA3D.Material.ALPHA_MAP ] =
function ( mat, tech, sea ) {
......@@ -2594,7 +2633,11 @@ THREE.SEA3D.prototype.readMaterial = function ( sea ) {
var mat = this.createMaterial( sea );
mat.name = sea.name;
mat.premultipliedAlpha = this.config.forcePremultipliedAlpha;
mat.depthWrite = sea.depthWrite;
mat.depthTest = sea.depthTest;
mat.premultipliedAlpha = sea.premultipliedAlpha;
mat.side = sea.bothSides ? THREE.DoubleSide : THREE.FrontSide;
this.setBlending( mat, sea.blendMode );
......
......@@ -11,12 +11,15 @@
'use strict';
SEA3D.AMMO = {
world: null,
rigidBodies: [],
rigidBodiesTarget: [],
rigidBodiesOffset: [],
rigidBodiesEnabled: [],
constraints: [],
vehicles: [],
vehiclesWheels: [],
......@@ -89,26 +92,29 @@ SEA3D.AMMO = {
setEnabledRigidBody: function ( rb, enabled ) {
if ( this.getEnabledRigidBody( rb ) == enabled ) return;
var index = this.rigidBodies.indexOf( rb );
if ( this.rigidBodiesEnabled[ index ] == enabled ) return;
if ( enabled ) this.world.addRigidBody( rb );
else this.world.removeRigidBody( rb );
this.rigidBodiesEnabled[ index ] = true;
return this;
},
getEnabledRigidBody: function ( rb ) {
return this.rigidBodiesEnabled[ this.rigidBodies.indexOf( rb ) ] === true;
return this.rigidBodiesEnabled[ this.rigidBodies.indexOf( rb ) ];
},
addRigidBody: function ( rb, target, offset, enabled ) {
addRigidBody: function ( rb, target, enabled ) {
enabled = enabled !== undefined ? enabled : true;
this.rigidBodies.push( rb );
this.rigidBodiesTarget.push( target );
this.rigidBodiesOffset.push( offset );
this.rigidBodiesEnabled.push( false );
this.setEnabledRigidBody( rb, enabled );
......@@ -124,7 +130,6 @@ SEA3D.AMMO = {
this.rigidBodies.splice( index, 1 );
this.rigidBodiesTarget.splice( index, 1 );
this.rigidBodiesOffset.splice( index, 1 );
this.rigidBodiesEnabled.splice( index, 1 );
if ( destroy ) Ammo.destroy( rb );
......@@ -332,12 +337,7 @@ SEA3D.AMMO = {
var pos = transform.getOrigin(),
quat = transform.getRotation();
if ( offset == undefined ) {
obj3d.position.set( pos.x(), pos.y(), pos.z() );
obj3d.quaternion.set( quat.x(), quat.y(), quat.z(), quat.w() );
} else {
if ( offset ) {
position.set( pos.x(), pos.y(), pos.z() );
quaternion.set( quat.x(), quat.y(), quat.z(), quat.w() );
......@@ -349,6 +349,11 @@ SEA3D.AMMO = {
obj3d.position.setFromMatrixPosition( matrix );
obj3d.quaternion.setFromRotationMatrix( matrix );
} else {
obj3d.position.set( pos.x(), pos.y(), pos.z() );
obj3d.quaternion.set( quat.x(), quat.y(), quat.z(), quat.w() );
}
return this;
......@@ -377,7 +382,7 @@ SEA3D.AMMO = {
if ( wheelTarget ) {
this.updateTargetTransform( wheelTarget, wheelsTransform );
this.updateTargetTransform( wheelTarget, wheelsTransform, wheelTarget.physics ? wheelTarget.physics.offset : null );
}
......@@ -388,12 +393,11 @@ SEA3D.AMMO = {
for ( i = 0; i < this.rigidBodies.length; i ++ ) {
var rb = this.rigidBodies[ i ],
target = this.rigidBodiesTarget[ i ],
offset = this.rigidBodiesOffset[ i ];
target = this.rigidBodiesTarget[ i ];
if ( target && rb.isActive() ) {
this.updateTargetTransform( target, rb.getWorldTransform(), offset );
this.updateTargetTransform( target, rb.getWorldTransform(), target.physics ? target.physics.offset : null );
}
......
......@@ -146,10 +146,15 @@ THREE.SEA3D.prototype.readCompound = function ( sea ) {
THREE.SEA3D.prototype.readRigidBodyBase = function ( sea ) {
var shape = sea.shape.tag,
transform;
transform, target;
if ( sea.target ) {
target = sea.target.tag;
target.physics = { enabled: true };
target.updateMatrix();
transform = SEA3D.AMMO.getTransformFromMatrix( sea.target.tag.matrix );
} else {
......@@ -173,6 +178,23 @@ THREE.SEA3D.prototype.readRigidBodyBase = function ( sea ) {
var rb = new Ammo.btRigidBody( info );
if ( target ) {
target.physics.rigidBody = rb;
if ( sea.offset ) {
var offset = new THREE.Matrix4();
offset.elements.set( sea.offset );
target.physics.offset = offset;
}
}
Ammo.destroy( info );
this.domain.rigidBodies = this.rigidBodies = this.rigidBodies || [];
this.rigidBodies.push( this.objects[ "rb/" + sea.name ] = sea.tag = rb );
......@@ -188,7 +210,7 @@ THREE.SEA3D.prototype.readRigidBody = function ( sea ) {
var rb = this.readRigidBodyBase( sea );
SEA3D.AMMO.addRigidBody( rb, sea.target ? sea.target.tag : undefined, sea.offset ? new THREE.Matrix4().elements.set( sea.offset ) : undefined, this.config.enabledPhysics );
SEA3D.AMMO.addRigidBody( rb, sea.target ? sea.target.tag : undefined, this.config.enabledPhysics );
};
......@@ -238,6 +260,17 @@ THREE.SEA3D.prototype.readCarController = function ( sea ) {
if ( target ) {
target.physics = { enabled: true, rigidBody: wheelInfo };
if ( wheel.offset ) {
var offset = new THREE.Matrix4();
offset.elements.set( wheel.offset );
target.physics.offset = offset;
}
if ( target.parent ) {
target.parent.remove( target );
......@@ -260,7 +293,7 @@ THREE.SEA3D.prototype.readCarController = function ( sea ) {
}
SEA3D.AMMO.addVehicle( vehicle, wheels );
SEA3D.AMMO.addRigidBody( body, sea.target ? sea.target.tag : undefined, sea.offset ? new THREE.Matrix4().elements.set( sea.offset ) : undefined, this.config.enabledPhysics );
SEA3D.AMMO.addRigidBody( body, sea.target ? sea.target.tag : undefined, this.config.enabledPhysics );
this.domain.vehicles = this.vehicles = this.vehicles || [];
this.vehicles.push( this.objects[ "vhc/" + sea.name ] = sea.tag = vehicle );
......
......@@ -168,6 +168,12 @@ SEA3D.Physics = function ( name, data, sea3d ) {
if ( this.attrib & 1 ) this.target = sea3d.getObject( data.readUInt() );
else this.transform = data.readMatrix();
if ( this.attrib & 2 ) this.offset = data.readMatrix();
if ( this.attrib & 4 ) this.scripts = data.readScriptList( sea3d );
if ( this.attrib & 16 ) this.attributes = sea3d.getObject( data.readUInt() );
};
SEA3D.Physics.prototype.readTag = function ( kind, data, size ) {
......@@ -257,11 +263,21 @@ SEA3D.CarController.Wheel = function ( data, sea3d ) {
this.data = data;
this.sea3d = sea3d;
var attrib = data.readUShort();
this.attrib = data.readUShort();
this.isFront = ( this.attrib & 1 ) != 0;
if ( this.attrib & 2 ) {
this.isFront = ( attrib & 1 ) != 0,
this.target = sea3d.getObject( data.readUInt() );
this.target = sea3d.getObject( data.readUInt() );
}
if ( this.attrib & 4 ) {
this.offset = data.readMatrix();
}
this.pos = data.readVector3();
this.dir = data.readVector3();
......
......@@ -107,7 +107,7 @@
};
// Open3DGC - Export by SEA3D Studio
loader.load( './models/sea3d/robot.o3dgc.tjs.sea' );
loader.load( './models/sea3d/robot.tjs.sea' );
//
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - sea3d / keyframe</title>
<title>three.js webgl - sea3d / physics</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
......@@ -115,7 +115,7 @@
var domain = this.loader.clone( { lights : false, runScripts : false, autoPlay: false, enabledPhysics : false } );
offset += 180;
offset -= 180;
domain.container.position.x += offset;
domain.applyContainerTransform();
......@@ -138,7 +138,7 @@
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 15000 );
camera.position.set( -300, 200, 300 );
camera.position.set( 300, 200, -300 );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - sea3d / skin</title>
<title>three.js webgl - sea3d / skinning</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - sea3d</title>
<title>three.js webgl - sea3d / sound</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册