diff --git a/examples/js/ShaderTerrain.js b/examples/js/ShaderTerrain.js index d9b75e5e607cb123d4b1239e096ceb9e92ac0eae..122247478b32d2782ec5bc25f727300e95e8eaa9 100644 --- a/examples/js/ShaderTerrain.js +++ b/examples/js/ShaderTerrain.js @@ -84,8 +84,6 @@ THREE.ShaderTerrain = { "varying vec3 vNormal;", "varying vec2 vUv;", - "uniform vec3 ambientLightColor;", - "varying vec3 vViewPosition;", THREE.ShaderChunk[ "common" ], diff --git a/examples/js/loaders/sea3d/SEA3D.js b/examples/js/loaders/sea3d/SEA3D.js index 7602f06db75482bb300cc3d4ebd08d50a3c95b6a..975dd7d61f9071a7f3a3a410af390caf4b4dddfa 100644 --- a/examples/js/loaders/sea3d/SEA3D.js +++ b/examples/js/loaders/sea3d/SEA3D.js @@ -121,6 +121,12 @@ SEA3D.Stream.prototype = { } }; +SEA3D.Stream.prototype.getByte = function( pos ) { + + return this.data.getInt8( pos ); + +}; + SEA3D.Stream.prototype.readBytes = function( len ) { var buf = this.buf.slice( this.position, this.position + len ); @@ -165,6 +171,14 @@ SEA3D.Stream.prototype.readUShort = function() { SEA3D.Stream.prototype.readUInt24 = function() { + var v = this.data.getUint32( this.position, true ) & 0xFFFFFF; + this.position += 3; + return v; + +}; + +SEA3D.Stream.prototype.readUInt24F = function() { + return this.readUShort() | ( this.readUByte() << 16 ); }; @@ -395,7 +409,7 @@ SEA3D.Stream.prototype.readTags = function( callback ) { }; -SEA3D.Stream.prototype.readProperties = function( sea ) { +SEA3D.Stream.prototype.readProperties = function( sea3d ) { var count = this.readUByte(), props = {}, types = {}; @@ -407,7 +421,7 @@ SEA3D.Stream.prototype.readProperties = function( sea ) { var name = this.readUTF8(), type = this.readUByte(); - props[ name ] = this.readToken( type, sea ); + props[ name ] = this.readToken( type, sea3d ); types[ name ] = type; } @@ -416,7 +430,7 @@ SEA3D.Stream.prototype.readProperties = function( sea ) { }; -SEA3D.Stream.prototype.readAnimationList = function( sea ) { +SEA3D.Stream.prototype.readAnimationList = function( sea3d ) { var list = [], count = this.readUByte(); @@ -431,7 +445,7 @@ SEA3D.Stream.prototype.readAnimationList = function( sea ) { if ( attrib & 2 ) anm.timeScale = this.readFloat(); - anm.tag = sea.getObject( this.readUInt() ); + anm.tag = sea3d.getObject( this.readUInt() ); list[ i ++ ] = anm; @@ -441,7 +455,7 @@ SEA3D.Stream.prototype.readAnimationList = function( sea ) { }; -SEA3D.Stream.prototype.readScriptList = function( sea ) { +SEA3D.Stream.prototype.readScriptList = function( sea3d ) { var list = [], count = this.readUByte(); @@ -456,7 +470,7 @@ SEA3D.Stream.prototype.readScriptList = function( sea ) { if ( attrib & 4 ) { - var numParams = data.readUByte(); + var numParams = this.readUByte(); script.params = {}; @@ -464,7 +478,7 @@ SEA3D.Stream.prototype.readScriptList = function( sea ) { var name = this.readUTF8(); - script.params[ name ] = this.readObject( sea ); + script.params[ name ] = this.readObject( sea3d ); } @@ -476,7 +490,7 @@ SEA3D.Stream.prototype.readScriptList = function( sea ) { } - script.tag = sea.getObject( this.readUInt() ); + script.tag = sea3d.getObject( this.readUInt() ); list[ i ++ ] = script; @@ -486,13 +500,13 @@ SEA3D.Stream.prototype.readScriptList = function( sea ) { }; -SEA3D.Stream.prototype.readObject = function( sea ) { +SEA3D.Stream.prototype.readObject = function( sea3d ) { - return this.readToken( this.readUByte(), sea ); + return this.readToken( this.readUByte(), sea3d ); }; -SEA3D.Stream.prototype.readToken = function( type, sea ) { +SEA3D.Stream.prototype.readToken = function( type, sea3d ) { switch ( type ) { @@ -537,7 +551,7 @@ SEA3D.Stream.prototype.readToken = function( type, sea ) { // Undefined Values case SEA3D.Stream.STRING_TINY: - return data.readUTF8(); + return this.readUTF8(); break; case SEA3D.Stream.STRING_SHORT: @@ -545,12 +559,12 @@ SEA3D.Stream.prototype.readToken = function( type, sea ) { break; case SEA3D.Stream.STRING_LONG: - return v.readUTF8Long(); + return this.readUTF8Long(); break case SEA3D.Stream.ASSET: var asset = this.readUInt(); - return asset > 0 ? sea.getObject( asset - 1 ).tag : null; + return asset > 0 ? sea3d.getObject( asset - 1 ).tag : null; break; default: @@ -1578,13 +1592,13 @@ SEA3D.AnimationHandler.prototype.update = function( delta ) { SEA3D.AnimationHandler.prototype.updateState = function() { - var i, state; + var i, l, state; this.currentState.node.setTime( this.time - this.currentState.offset ); if ( this.currentState.weight < 1 && this.crossfade > 0 ) { - var delta = Math.abs( this.delta ) / ( 1000.0 * this.crossfade ); + var delta = Math.abs( this.delta ) / ( this.crossfade * 1000 ); var weight = 1; if ( this.blendMethod === SEA3D.AnimationBlendMethod.EASING ) { @@ -1593,11 +1607,11 @@ SEA3D.AnimationHandler.prototype.updateState = function() { } - for ( i = 0; i < this.states.length; ++ i ) { + for ( i = 0, l = this.states.length; i < l; ++ i ) { state = this.states[ i ]; - if ( state !== this.currentState ) { + if ( state.weight > 0 && state !== this.currentState ) { if ( this.blendMethod === SEA3D.AnimationBlendMethod.LINEAR ) { @@ -1854,12 +1868,12 @@ SEA3D.AnimationHandler.animations = []; // Object // -SEA3D.Object = function( name, data, type, sea ) { +SEA3D.Object = function( name, data, type, sea3d ) { this.name = name; this.data = data; this.type = type; - this.sea = sea; + this.sea3d = sea3d; }; @@ -1867,11 +1881,11 @@ SEA3D.Object = function( name, data, type, sea ) { // Geometry Base // -SEA3D.GeometryBase = function( name, data, sea ) { +SEA3D.GeometryBase = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUShort(); @@ -1890,9 +1904,9 @@ SEA3D.GeometryBase = function( name, data, sea ) { // Geometry // -SEA3D.Geometry = function( name, data, sea ) { +SEA3D.Geometry = function( name, data, sea3d ) { - SEA3D.GeometryBase.call( this, name, data, sea ); + SEA3D.GeometryBase.call( this, name, data, sea3d ); var i, j, vec, len; @@ -1965,16 +1979,20 @@ SEA3D.Geometry = function( name, data, sea ) { this.groups = []; - if ( this.attrib & 2 ) { + if ( this.attrib & 1024 ) { // INDEXES for ( i = 0, len = 0; i < count; i ++ ) { + j = data.readVInt() * 3; + this.groups.push( { start : len, - count : len += ( data.readVInt() * 3 ), + count : j, } ); + len += j; + } this.indexes = this.isBig ? data.readUIntArray( len ) : data.readUShortArray( len ); @@ -1994,7 +2012,7 @@ SEA3D.Geometry = function( name, data, sea ) { count : len, } ); - len += j; + j += len; bytearray.add( data.readUByteArray( len * stride ) ); @@ -2011,119 +2029,15 @@ SEA3D.Geometry.prototype.constructor = SEA3D.Geometry; SEA3D.Geometry.prototype.type = "geo"; -// -// Geometry 16 Bit -// - -SEA3D.Geometry16 = function( name, data, sea ) { - - SEA3D.GeometryBase.call( this, name, data, sea ); - - var i, len; - - // NORMAL - if ( this.attrib & 4 ) { - - this.normal = data.readFloatArray( this.length ); - - } - - // TANGENT - if ( this.attrib & 8 ) { - - this.tangent = data.readFloatArray( this.length ); - - } - - // UV - if ( this.attrib & 32 ) { - - this.uv = []; - this.uv.length = data.readUByte(); - - len = this.numVertex * 2; - - i = 0; - while ( i < this.uv.length ) { - - // UV VERTEX DATA - this.uv[ i ++ ] = data.readFloatArray( len ); - - } - - } - - // JOINT-INDEXES / WEIGHTS - if ( this.attrib & 64 ) { - - this.jointPerVertex = data.readUByte(); - - var jntLen = this.numVertex * this.jointPerVertex; - - this.joint = data.readUShortArray( jntLen ); - this.weight = data.readFloatArray( jntLen ); - - } - - // VERTEX_COLOR - if ( this.attrib & 128 ) { - - var colorAttrib = data.readUByte(); - - this.numColor = ( ( ( colorAttrib & 64 ) >> 6 ) | ( ( colorAttrib & 128 ) >> 6 ) ) + 1; - - this.color = []; - - for ( i = 0, len = colorAttrib & 15; i < len; i ++ ) { - - this.color.push( data.readFloatArray( this.numVertex * this.numColor ) ); - - } - - } - - // VERTEX - this.vertex = data.readFloatArray( this.length ); - - // SUB-MESHES - var count = data.readUByte(); - - this.indexes = new Uint16Array(); - this.groups = []; - - // INDEXES - for ( i = 0, j = 0; i < count; i ++ ) { - - len = data.readVInt() * 3; - - this.groups.push( { - start : j, - count : len, - } ); - - len += j; - - this.indexes = this.isBig ? data.readUIntArray( len ) : data.readUShortArray( len ); - - } - -}; - - -SEA3D.Geometry16.prototype = Object.create( SEA3D.GeometryBase.prototype ); -SEA3D.Geometry16.prototype.constructor = SEA3D.Geometry16; - -SEA3D.Geometry16.prototype.type = "ge16"; - // // Geometry Delta Base // -SEA3D.GeometryDeltaBase = function( name, data, sea ) { +SEA3D.GeometryDeltaBase = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUShort(); @@ -2150,9 +2064,9 @@ SEA3D.GeometryDeltaBase = function( name, data, sea ) { // Geometry Delta // -SEA3D.GeometryDelta = function( name, data, sea ) { +SEA3D.GeometryDelta = function( name, data, sea3d ) { - SEA3D.GeometryDeltaBase.call( this, name, data, sea ); + SEA3D.GeometryDeltaBase.call( this, name, data, sea3d ); var i, j, start, delta, len, vec; @@ -2433,28 +2347,30 @@ SEA3D.GeometryDelta.prototype.type = "geDL"; // Object3D // -SEA3D.Object3D = function( name, data, sea ) { +SEA3D.Object3D = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.isStatic = false; + this.visible = true; this.attrib = data.readUShort(); - if ( this.attrib & 1 ) this.parent = sea.getObject( data.readUInt() ); + if ( this.attrib & 1 ) this.parent = sea3d.getObject( data.readUInt() ); - if ( this.attrib & 2 ) this.animations = data.readAnimationList( sea ); + if ( this.attrib & 2 ) this.animations = data.readAnimationList( sea3d ); - if ( this.attrib & 4 ) this.scripts = data.readScriptList( sea ); + if ( this.attrib & 4 ) this.scripts = data.readScriptList( sea3d ); - if ( this.attrib & 16 ) this.properties = sea.getObject( data.readUInt() ); + if ( this.attrib & 16 ) this.properties = sea3d.getObject( data.readUInt() ); if ( this.attrib & 32 ) { var objectType = data.readUByte(); - this.isStatic = objectType & 1; + this.isStatic = ( objectType & 1 ) != 0; + this.visible = ( objectType & 2 ) != 0; } @@ -2468,9 +2384,9 @@ SEA3D.Object3D.prototype.readTag = function( kind, data, size ) { // Entity3D // -SEA3D.Entity3D = function( name, data, sea ) { +SEA3D.Entity3D = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.castShadows = true; @@ -2491,15 +2407,15 @@ SEA3D.Entity3D.prototype.constructor = SEA3D.Entity3D; // Sound3D // -SEA3D.Sound3D = function( name, data, sea ) { +SEA3D.Sound3D = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.autoPlay = ( this.attrib & 64 ) != 0; - if ( this.attrib & 128 ) this.mixer = sea.getObject( data.readUInt() ); + if ( this.attrib & 128 ) this.mixer = sea3d.getObject( data.readUInt() ); - this.sound = sea.getObject( data.readUInt() ); + this.sound = sea3d.getObject( data.readUInt() ); this.volume = data.readFloat(); }; @@ -2511,9 +2427,9 @@ SEA3D.Sound3D.prototype.constructor = SEA3D.Sound3D; // Sound Point // -SEA3D.SoundPoint = function( name, data, sea ) { +SEA3D.SoundPoint = function( name, data, sea3d ) { - SEA3D.Sound3D.call( this, name, data, sea ); + SEA3D.Sound3D.call( this, name, data, sea3d ); this.position = data.readVector3(); this.distance = data.readFloat(); @@ -2531,9 +2447,9 @@ SEA3D.SoundPoint.prototype.type = "sp"; // Container3D // -SEA3D.Container3D = function( name, data, sea ) { +SEA3D.Container3D = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.transform = data.readMatrix(); @@ -2550,11 +2466,11 @@ SEA3D.Container3D.prototype.type = "c3d"; // Texture URL // -SEA3D.TextureURL = function( name, data, sea ) { +SEA3D.TextureURL = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.url = data.readUTF( data.length ); @@ -2566,11 +2482,11 @@ SEA3D.TextureURL.prototype.type = "urlT"; // Actions // -SEA3D.Actions = function( name, data, sea ) { +SEA3D.Actions = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.count = data.readUInt(); this.actions = []; @@ -2621,22 +2537,22 @@ SEA3D.Actions = function( name, data, sea ) { switch ( kind ) { case SEA3D.Actions.RTT_TARGET: - act.source = sea.getObject( data.readUInt() ); - act.target = sea.getObject( data.readUInt() ); + act.source = sea3d.getObject( data.readUInt() ); + act.target = sea3d.getObject( data.readUInt() ); break; case SEA3D.Actions.LOOK_AT: - act.source = sea.getObject( data.readUInt() ); - act.target = sea.getObject( data.readUInt() ); + act.source = sea3d.getObject( data.readUInt() ); + act.target = sea3d.getObject( data.readUInt() ); break; case SEA3D.Actions.PLAY_SOUND: - act.sound = sea.getObject( data.readUInt() ); + act.sound = sea3d.getObject( data.readUInt() ); act.offset = data.readUInt(); break; case SEA3D.Actions.PLAY_ANIMATION: - act.object = sea.getObject( data.readUInt() ); + act.object = sea3d.getObject( data.readUInt() ); act.name = data.readUTF8(); break; @@ -2647,23 +2563,23 @@ SEA3D.Actions = function( name, data, sea ) { break; case SEA3D.Actions.ENVIRONMENT: - act.texture = sea.getObject( data.readUInt() ); + act.texture = sea3d.getObject( data.readUInt() ); break; case SEA3D.Actions.ENVIRONMENT_COLOR: - act.color = data.readUInt24(); + act.color = data.readUInt24F(); break; case SEA3D.Actions.CAMERA: - act.camera = sea.getObject( data.readUInt() ); + act.camera = sea3d.getObject( data.readUInt() ); break; case SEA3D.Actions.SCRIPTS: - act.scripts = data.readScriptList( sea ); + act.scripts = data.readScriptList( sea3d ); break; case SEA3D.Actions.CLASS_OF: - act.classof = sea.getObject( data.readUInt() ); + act.classof = sea3d.getObject( data.readUInt() ); break; default: @@ -2696,13 +2612,13 @@ SEA3D.Actions.prototype.type = "act"; // Properties // -SEA3D.Properties = function( name, data, sea ) { +SEA3D.Properties = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.tag = data.readProperties( sea ); + this.tag = data.readProperties( sea3d ); this.tag.__name = name; }; @@ -2713,16 +2629,16 @@ SEA3D.Properties.prototype.type = "prop"; // File Info // -SEA3D.FileInfo = function( name, data, sea ) { +SEA3D.FileInfo = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.tag = data.readProperties( sea ); + this.tag = data.readProperties( sea3d ); this.tag.__name = name; - sea.info = this.tag; + sea3d.info = this.tag; }; @@ -2732,11 +2648,11 @@ SEA3D.FileInfo.prototype.type = "info"; // Java Script // -SEA3D.JavaScript = function( name, data, sea ) { +SEA3D.JavaScript = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.src = data.readUTF( data.length ); @@ -2748,11 +2664,11 @@ SEA3D.JavaScript.prototype.type = "js"; // Java Script Method // -SEA3D.JavaScriptMethod = function( name, data, sea ) { +SEA3D.JavaScriptMethod = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; var count = data.readUShort(); @@ -2777,11 +2693,11 @@ SEA3D.JavaScriptMethod.prototype.type = "jsm"; // GLSL // -SEA3D.GLSL = function( name, data, sea ) { +SEA3D.GLSL = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.src = data.readUTF( data.length ); @@ -2793,9 +2709,9 @@ SEA3D.GLSL.prototype.type = "glsl"; // Dummy // -SEA3D.Dummy = function( name, data, sea ) { +SEA3D.Dummy = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.transform = data.readMatrix(); @@ -2816,9 +2732,9 @@ SEA3D.Dummy.prototype.type = "dmy"; // Line // -SEA3D.Line = function( name, data, sea ) { +SEA3D.Line = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.count = ( this.attrib & 64 ? data.readUInt() : data.readUShort() ) * 3; this.closed = ( this.attrib & 128 ) != 0; @@ -2846,13 +2762,13 @@ SEA3D.Line.prototype.type = "line"; // Mesh2D // -SEA3D.Mesh2D = function( name, data, sea ) { +SEA3D.Mesh2D = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); if ( this.attrib & 256 ) { - this.material = sea.getObject( data.readUInt() ); + this.material = sea3d.getObject( data.readUInt() ); } @@ -2874,9 +2790,9 @@ SEA3D.Mesh2D.prototype.type = "m2d"; // Mesh // -SEA3D.Mesh = function( name, data, sea ) { +SEA3D.Mesh = function( name, data, sea3d ) { - SEA3D.Entity3D.call( this, name, data, sea ); + SEA3D.Entity3D.call( this, name, data, sea3d ); // MATERIAL if ( this.attrib & 256 ) { @@ -2885,7 +2801,7 @@ SEA3D.Mesh = function( name, data, sea ) { var len = data.readUByte(); - if ( len == 1 ) this.material[ 0 ] = sea.getObject( data.readUInt() ); + if ( len == 1 ) this.material[ 0 ] = sea3d.getObject( data.readUInt() ); else { var i = 0; @@ -2893,7 +2809,7 @@ SEA3D.Mesh = function( name, data, sea ) { var matIndex = data.readUInt(); - if ( matIndex > 0 ) this.material[ i ++ ] = sea.getObject( matIndex - 1 ); + if ( matIndex > 0 ) this.material[ i ++ ] = sea3d.getObject( matIndex - 1 ); else this.material[ i ++ ] = undefined; } @@ -2910,15 +2826,24 @@ SEA3D.Mesh = function( name, data, sea ) { for ( var i = 0; i < len; i ++ ) { - this.modifiers[ i ] = sea.getObject( data.readUInt() ); + this.modifiers[ i ] = sea3d.getObject( data.readUInt() ); } } + if ( this.attrib & 1024 ) { + + this.reference = { + type : data.readUByte(), + ref : sea3d.getObject( data.readUInt() ) + }; + + } + this.transform = data.readMatrix(); - this.geometry = sea.getObject( data.readUInt() ); + this.geometry = sea3d.getObject( data.readUInt() ); data.readTags( this.readTag.bind( this ) ); @@ -2933,11 +2858,11 @@ SEA3D.Mesh.prototype.type = "m3d"; // Skeleton // -SEA3D.Skeleton = function( name, data, sea ) { +SEA3D.Skeleton = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; var length = data.readUShort(); @@ -2961,11 +2886,11 @@ SEA3D.Skeleton.prototype.type = "skl"; // Skeleton Local // -SEA3D.SkeletonLocal = function( name, data, sea ) { +SEA3D.SkeletonLocal = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; var length = data.readUShort(); @@ -2997,11 +2922,11 @@ SEA3D.SkeletonLocal.prototype.type = "sklq"; // Animation Base // -SEA3D.AnimationBase = function( name, data, sea ) { +SEA3D.AnimationBase = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; var flag = data.readUByte(); @@ -3043,26 +2968,25 @@ SEA3D.AnimationBase = function( name, data, sea ) { // Animation // -SEA3D.Animation = function( name, data, sea ) { +SEA3D.Animation = function( name, data, sea3d ) { - SEA3D.AnimationBase.call( this, name, data, sea ); + SEA3D.AnimationBase.call( this, name, data, sea3d ); this.dataList = []; - this.dataList.length = data.readUByte(); - for ( var i = 0; i < this.dataList.length; i ++ ) { + for ( var i = 0, l = data.readUByte(); i < l; i ++ ) { var kind = data.readUShort(), type = data.readUByte(); var anmRaw = data.readVector( type, this.numFrames, 0 ); - this.dataList[ i ] = { + this.dataList.push( { kind: kind, type: type, blockSize: SEA3D.Stream.sizeOf( type ), data: anmRaw - } + } ); } @@ -3111,15 +3035,15 @@ SEA3D.Animation.prototype.type = "anm"; // Skeleton Animation // -SEA3D.SkeletonAnimation = function( name, data, sea ) { +SEA3D.SkeletonAnimation = function( name, data, sea3d ) { - SEA3D.AnimationBase.call( this, name, data, sea ); + SEA3D.AnimationBase.call( this, name, data, sea3d ); this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.numJoints = data.readUShort() + this.numJoints = data.readUShort(); this.raw = data.readFloatArray( this.numFrames * this.numJoints * 7 ); @@ -3131,9 +3055,9 @@ SEA3D.SkeletonAnimation.prototype.type = "skla"; // Morph // -SEA3D.Morph = function( name, data, sea ) { +SEA3D.Morph = function( name, data, sea3d ) { - SEA3D.GeometryBase.call( this, name, data, sea ); + SEA3D.GeometryBase.call( this, name, data, sea3d ); var useVertex = ( this.attrib & 2 ) != 0; var useNormal = ( this.attrib & 4 ) != 0; @@ -3165,9 +3089,9 @@ SEA3D.Morph.prototype.type = "mph"; // Vertex Animation // -SEA3D.VertexAnimation = function( name, data, sea ) { +SEA3D.VertexAnimation = function( name, data, sea3d ) { - SEA3D.AnimationBase.call( this, name, data, sea ); + SEA3D.AnimationBase.call( this, name, data, sea3d ); var flags = data.readUByte(); @@ -3206,9 +3130,9 @@ SEA3D.VertexAnimation.prototype.type = "vtxa"; // Camera // -SEA3D.Camera = function( name, data, sea ) { +SEA3D.Camera = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); if ( this.attrib & 64 ) { @@ -3236,11 +3160,11 @@ SEA3D.Camera.prototype.type = "cam"; // Joint Object // -SEA3D.JointObject = function( name, data, sea ) { +SEA3D.JointObject = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); - this.target = sea.getObject( data.readUInt() ); + this.target = sea3d.getObject( data.readUInt() ); this.joint = data.readUShort(); data.readTags( this.readTag.bind( this ) ); @@ -3256,9 +3180,9 @@ SEA3D.JointObject.prototype.type = "jnt"; // Light // -SEA3D.Light = function( name, data, sea ) { +SEA3D.Light = function( name, data, sea3d ) { - SEA3D.Object3D.call( this, name, data, sea ); + SEA3D.Object3D.call( this, name, data, sea3d ); this.attenStart = Number.MAX_VALUE; this.attenEnd = Number.MAX_VALUE; @@ -3293,9 +3217,9 @@ SEA3D.Light.prototype.constructor = SEA3D.Light; // Point Light // -SEA3D.PointLight = function( name, data, sea ) { +SEA3D.PointLight = function( name, data, sea3d ) { - SEA3D.Light.call( this, name, data, sea ); + SEA3D.Light.call( this, name, data, sea3d ); if ( this.attrib & 128 ) { @@ -3321,9 +3245,9 @@ SEA3D.PointLight.prototype.type = "plht"; // Hemisphere Light // -SEA3D.HemisphereLight = function( name, data, sea ) { +SEA3D.HemisphereLight = function( name, data, sea3d ) { - SEA3D.Light.call( this, name, data, sea ); + SEA3D.Light.call( this, name, data, sea3d ); if ( this.attrib & 128 ) { @@ -3349,9 +3273,9 @@ SEA3D.HemisphereLight.prototype.type = "hlht"; // Directional Light // -SEA3D.DirectionalLight = function( name, data, sea ) { +SEA3D.DirectionalLight = function( name, data, sea3d ) { - SEA3D.Light.call( this, name, data, sea ); + SEA3D.Light.call( this, name, data, sea3d ); this.transform = data.readMatrix(); @@ -3368,11 +3292,11 @@ SEA3D.DirectionalLight.prototype.type = "dlht"; // Material // -SEA3D.Material = function( name, data, sea ) { +SEA3D.Material = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.technique = []; @@ -3397,7 +3321,7 @@ SEA3D.Material = function( name, data, sea ) { this.blendMode = data.readBlendMode(); if ( this.attrib & 128 ) - this.animations = data.readAnimationList( sea ); + this.animations = data.readAnimationList( sea3d ); this.depthMask = ( this.attrib & 256 ) == 0; @@ -3423,28 +3347,28 @@ SEA3D.Material = function( name, data, sea ) { break; case SEA3D.Material.COMPOSITE_TEXTURE: tech = { - composite: sea.getObject( data.readUInt() ) + composite: sea3d.getObject( data.readUInt() ) }; break; case SEA3D.Material.DIFFUSE_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) }; break; case SEA3D.Material.SPECULAR_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) }; break; case SEA3D.Material.NORMAL_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) }; break; case SEA3D.Material.REFLECTION: case SEA3D.Material.FRESNEL_REFLECTION: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), alpha: data.readFloat() }; @@ -3457,7 +3381,7 @@ SEA3D.Material = function( name, data, sea ) { break; case SEA3D.Material.REFRACTION: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), alpha: data.readFloat(), ior: data.readFloat() }; @@ -3472,14 +3396,14 @@ SEA3D.Material = function( name, data, sea ) { break; case SEA3D.Material.LIGHT_MAP: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), channel: data.readUByte(), blendMode: data.readBlendMode() }; break; case SEA3D.Material.DETAIL_MAP: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), scale: data.readFloat(), blendMode: data.readBlendMode() }; @@ -3504,8 +3428,8 @@ SEA3D.Material = function( name, data, sea ) { methodAttrib = data.readUByte(); tech = { - texture: sea.getObject( data.readUInt() ), - secondaryTexture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ), + secondaryTexture: sea3d.getObject( data.readUInt() ) }; if ( methodAttrib & 1 ) { @@ -3528,26 +3452,26 @@ SEA3D.Material = function( name, data, sea ) { break; case SEA3D.Material.MIRROR_REFLECTION: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), alpha: data.readFloat() }; break; case SEA3D.Material.AMBIENT_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) } break; case SEA3D.Material.ALPHA_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) }; break; case SEA3D.Material.EMISSIVE_MAP: tech = { - texture: sea.getObject( data.readUInt() ) + texture: sea3d.getObject( data.readUInt() ) }; break; @@ -3573,7 +3497,7 @@ SEA3D.Material = function( name, data, sea ) { blue: data.readUInt24() }; - if ( methodAttrib & 1 ) tech.mask = sea.getObject( data.readUInt() ); + if ( methodAttrib & 1 ) tech.mask = sea3d.getObject( data.readUInt() ); if ( methodAttrib & 2 ) tech.alpha = data.readFloat(); @@ -3581,7 +3505,7 @@ SEA3D.Material = function( name, data, sea ) { case SEA3D.Material.REFLECTION_SPHERICAL: tech = { - texture: sea.getObject( data.readUInt() ), + texture: sea3d.getObject( data.readUInt() ), alpha: data.readFloat() }; break; @@ -3632,11 +3556,11 @@ SEA3D.Material.prototype.type = "mat"; // Composite // -SEA3D.Composite = function( name, data, sea ) { +SEA3D.Composite = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; var layerCount = data.readUByte(); @@ -3644,7 +3568,7 @@ SEA3D.Composite = function( name, data, sea ) { for ( var i = 0; i < layerCount; i ++ ) { - this.layer[ i ] = new SEA3D.Composite.prototype.Layer( data, sea ); + this.layer[ i ] = new SEA3D.Composite.prototype.Layer( data, sea3d ); } @@ -3664,16 +3588,16 @@ SEA3D.Composite.prototype.getLayerByName = function( name ) { }; -SEA3D.Composite.prototype.Layer = function( data, sea ) { +SEA3D.Composite.prototype.Layer = function( data, sea3d ) { var attrib = data.readUShort(); - if ( attrib & 1 ) this.texture = new SEA3D.Composite.LayerBitmap( data, sea ); + if ( attrib & 1 ) this.texture = new SEA3D.Composite.LayerBitmap( data, sea3d ); else this.color = data.readUInt24(); if ( attrib & 2 ) { - this.mask = new SEA3D.Composite.LayerBitmap( data, sea ); + this.mask = new SEA3D.Composite.LayerBitmap( data, sea3d ); } @@ -3689,9 +3613,9 @@ SEA3D.Composite.prototype.Layer = function( data, sea ) { }; -SEA3D.Composite.LayerBitmap = function( data, sea ) { +SEA3D.Composite.LayerBitmap = function( data, sea3d ) { - this.map = sea.getObject( data.readUInt() ); + this.map = sea3d.getObject( data.readUInt() ); var attrib = data.readUShort(); @@ -3703,7 +3627,7 @@ SEA3D.Composite.LayerBitmap = function( data, sea ) { this.scaleV = attrib & 32 ? data.readFloat() : 1; this.rotation = attrib & 64 ? data.readFloat() : 0; - if ( attrib & 128 ) this.animation = data.readAnimationList( sea ); + if ( attrib & 128 ) this.animation = data.readAnimationList( sea3d ); }; @@ -3713,11 +3637,11 @@ SEA3D.Composite.prototype.type = "ctex"; // Sphere // -SEA3D.Sphere = function( name, data, sea ) { +SEA3D.Sphere = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.radius = data.readFloat(); @@ -3729,11 +3653,11 @@ SEA3D.Sphere.prototype.type = "sph"; // Box // -SEA3D.Box = function( name, data, sea ) { +SEA3D.Box = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.width = data.readFloat(); this.height = data.readFloat(); @@ -3747,11 +3671,11 @@ SEA3D.Box.prototype.type = "box"; // Cone // -SEA3D.Cone = function( name, data, sea ) { +SEA3D.Cone = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.radius = data.readFloat(); this.height = data.readFloat(); @@ -3764,11 +3688,11 @@ SEA3D.Cone.prototype.type = "cone"; // Capsule // -SEA3D.Capsule = function( name, data, sea ) { +SEA3D.Capsule = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.radius = data.readFloat(); this.height = data.readFloat(); @@ -3781,11 +3705,11 @@ SEA3D.Capsule.prototype.type = "cap"; // Cylinder // -SEA3D.Cylinder = function( name, data, sea ) { +SEA3D.Cylinder = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.radius = data.readFloat(); this.height = data.readFloat(); @@ -3795,54 +3719,81 @@ SEA3D.Cylinder = function( name, data, sea ) { SEA3D.Cylinder.prototype.type = "cyl"; // -// Geometry Shape +// Convex Geometry // -SEA3D.GeometryShape = function( name, data, sea ) { +SEA3D.ConvexGeometry = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.geometry = sea.getObject( data.readUInt() ); + this.geometry = sea3d.getObject( data.readUInt() ); this.subGeometryIndex = data.readUByte(); }; -SEA3D.GeometryShape.prototype.type = "gs"; +SEA3D.ConvexGeometry.prototype.type = "gs"; // -// Static Geometry Shape +// Triangle Geometry // -SEA3D.StaticGeometryShape = function( name, data, sea ) { +SEA3D.TriangleGeometry = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.geometry = sea.getObject( data.readUInt() ); + this.geometry = sea3d.getObject( data.readUInt() ); this.subGeometryIndex = data.readUByte(); }; -SEA3D.StaticGeometryShape.prototype.type = "sgs"; +SEA3D.TriangleGeometry.prototype.type = "sgs"; + +// +// Compound +// + +SEA3D.Compound = function( name, data, sea3d ) { + + this.name = name; + this.data = data; + this.sea3d = sea3d; + + this.compounds = []; + + var count = data.readUByte(); + + for ( var i = 0; i < count; i ++ ) { + + this.compounds.push( { + shape : sea3d.getObject( data.readUInt() ), + transform : data.readMatrix() + } ); + + } + +}; + +SEA3D.Compound.prototype.type = "cmps"; // // Physics // -SEA3D.Physics = function( name, data, sea ) { +SEA3D.Physics = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUShort(); - this.shape = sea.getObject( data.readUInt() ); + this.shape = sea3d.getObject( data.readUInt() ); - if ( this.attrib & 1 ) this.target = sea.getObject( data.readUInt() ); + if ( this.attrib & 1 ) this.target = sea3d.getObject( data.readUInt() ); else this.transform = data.readMatrix(); }; @@ -3855,9 +3806,9 @@ SEA3D.Physics.prototype.readTag = function( kind, data, size ) { // Rigidy Body Base // -SEA3D.RigidBodyBase = function( name, data, sea ) { +SEA3D.RigidBodyBase = function( name, data, sea3d ) { - SEA3D.Physics.call( this, name, data, sea ); + SEA3D.Physics.call( this, name, data, sea3d ); if ( this.attrib & 32 ) { @@ -3884,9 +3835,9 @@ SEA3D.RigidBodyBase.prototype.constructor = SEA3D.RigidBodyBase; // Rigidy Body // -SEA3D.RigidBody = function( name, data, sea ) { +SEA3D.RigidBody = function( name, data, sea3d ) { - SEA3D.RigidBodyBase.call( this, name, data, sea ); + SEA3D.RigidBodyBase.call( this, name, data, sea3d ); data.readTags( this.readTag.bind( this ) ); @@ -3901,9 +3852,9 @@ SEA3D.RigidBody.prototype.type = "rb"; // Car Controller // -SEA3D.CarController = function( name, data, sea ) { +SEA3D.CarController = function( name, data, sea3d ) { - SEA3D.RigidBodyBase.call( this, name, data, sea ); + SEA3D.RigidBodyBase.call( this, name, data, sea3d ); this.suspensionStiffness = data.readFloat(); this.suspensionCompression = data.readFloat(); @@ -3921,7 +3872,7 @@ SEA3D.CarController = function( name, data, sea ) { for ( var i = 0; i < count; i ++ ) { - this.wheel[ i ] = new SEA3D.CarController.Wheel( data, sea ); + this.wheel[ i ] = new SEA3D.CarController.Wheel( data, sea3d ); } @@ -3929,16 +3880,16 @@ SEA3D.CarController = function( name, data, sea ) { }; -SEA3D.CarController.Wheel = function( data, sea ) { +SEA3D.CarController.Wheel = function( data, sea3d ) { this.data = data; - this.sea = sea; + this.sea3d = sea3d; var attrib = data.readUShort(); this.isFront = ( attrib & 1 ) != 0, - this.target = sea.getObject( data.readUInt() ); + this.target = sea3d.getObject( data.readUInt() ); this.pos = data.readVector3(); this.dir = data.readVector3(); @@ -3958,22 +3909,22 @@ SEA3D.CarController.prototype.type = "carc"; // Constraints // -SEA3D.Constraints = function( name, data, sea ) { +SEA3D.Constraints = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUShort(); this.disableCollisionsBetweenBodies = this.attrib & 1 != 0; - this.targetA = sea.getObject( data.readUInt() ); + this.targetA = sea3d.getObject( data.readUInt() ); this.pointA = data.readVector3(); if ( this.attrib & 2 ) { - this.targetB = sea.getObject( data.readUInt() ); + this.targetB = sea3d.getObject( data.readUInt() ); this.pointB = data.readVector3(); } @@ -3984,13 +3935,13 @@ SEA3D.Constraints = function( name, data, sea ) { // P2P Constraint // -SEA3D.P2PConstraint = function( name, data, sea ) { +SEA3D.P2PConstraint = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - SEA3D.Constraints.call( this, name, data, sea ); + SEA3D.Constraints.call( this, name, data, sea3d ); }; @@ -4003,9 +3954,9 @@ SEA3D.P2PConstraint.prototype.type = "p2pc"; // Hinge Constraint // -SEA3D.HingeConstraint = function( name, data, sea ) { +SEA3D.HingeConstraint = function( name, data, sea3d ) { - SEA3D.Constraints.call( this, name, data, sea ); + SEA3D.Constraints.call( this, name, data, sea3d ); this.axisA = data.readVector3(); @@ -4047,9 +3998,9 @@ SEA3D.HingeConstraint.prototype.type = "hnec"; // Cone Twist Constraint // -SEA3D.ConeTwistConstraint = function( name, data, sea ) { +SEA3D.ConeTwistConstraint = function( name, data, sea3d ) { - SEA3D.Constraints.call( this, name, data, sea ); + SEA3D.Constraints.call( this, name, data, sea3d ); this.axisA = data.readVector3(); @@ -4083,11 +4034,11 @@ SEA3D.ConeTwistConstraint.prototype.type = "ctwc"; // Planar Render // -SEA3D.PlanarRender = function( name, data, sea ) { +SEA3D.PlanarRender = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUByte(); @@ -4102,11 +4053,11 @@ SEA3D.PlanarRender.prototype.type = "rttp"; // Cube Render // -SEA3D.CubeRender = function( name, data, sea ) { +SEA3D.CubeRender = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.attrib = data.readUByte(); @@ -4121,11 +4072,11 @@ SEA3D.CubeRender.prototype.type = "rttc"; // Cube Maps // -SEA3D.CubeMap = function( name, data, sea ) { +SEA3D.CubeMap = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.transparent = false; @@ -4151,11 +4102,11 @@ SEA3D.CubeMap.prototype.type = "cmap"; // JPEG // -SEA3D.JPEG = function( name, data, sea ) { +SEA3D.JPEG = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.transparent = false; @@ -4167,11 +4118,11 @@ SEA3D.JPEG.prototype.type = "jpg"; // JPEG_XR // -SEA3D.JPEG_XR = function( name, data, sea ) { +SEA3D.JPEG_XR = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; this.transparent = true; @@ -4183,13 +4134,13 @@ SEA3D.JPEG_XR.prototype.type = "wdp"; // PNG // -SEA3D.PNG = function( name, data, sea ) { +SEA3D.PNG = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.transparent = data.buffer[ 25 ] == 0x06; + this.transparent = data.getByte( 25 ) == 0x06; }; @@ -4199,13 +4150,13 @@ SEA3D.PNG.prototype.type = "png"; // GIF // -SEA3D.GIF = function( name, data, sea ) { +SEA3D.GIF = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; - this.transparent = data.buffer[ 11 ] > 0; + this.transparent = data.getByte( 11 ) > 0; }; @@ -4215,11 +4166,11 @@ SEA3D.GIF.prototype.type = "gif"; // OGG // -SEA3D.OGG = function( name, data, sea ) { +SEA3D.OGG = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; }; @@ -4229,11 +4180,11 @@ SEA3D.OGG.prototype.type = "ogg"; // MP3 // -SEA3D.MP3 = function( name, data, sea ) { +SEA3D.MP3 = function( name, data, sea3d ) { this.name = name; this.data = data; - this.sea = sea; + this.sea3d = sea3d; }; @@ -4294,8 +4245,9 @@ SEA3D.File = function( data ) { this.addClass( SEA3D.Cone ); this.addClass( SEA3D.Capsule ); this.addClass( SEA3D.Cylinder ); - this.addClass( SEA3D.GeometryShape ); - this.addClass( SEA3D.StaticGeometryShape ); + this.addClass( SEA3D.ConvexGeometry ); + this.addClass( SEA3D.TriangleGeometry ); + this.addClass( SEA3D.Compound ); this.addClass( SEA3D.RigidBody ); this.addClass( SEA3D.P2PConstraint ); this.addClass( SEA3D.HingeConstraint ); @@ -4338,7 +4290,7 @@ SEA3D.File.prototype.readHead = function() { return false; if ( this.stream.readUTF( 3 ) != "SEA" ) - console.error( "Invalid SEA3D format." ); + throw new Error( "Invalid SEA3D format." ); this.sign = this.stream.readUTF( 3 ); @@ -4561,7 +4513,7 @@ SEA3D.File.prototype.readComplete = function() { this.stream.position = this.dataPosition; - if ( this.stream.readUInt24() != 0x5EA3D1 ) + if ( this.stream.readUInt24F() != 0x5EA3D1 ) console.warn( "SEA3D file is corrupted." ); delete this.state; diff --git a/examples/js/loaders/sea3d/SEA3DDeflate.js b/examples/js/loaders/sea3d/SEA3DDeflate.js index 2d8136486a4b44cbefdd6dc04e4ba9feedab82fa..97e9c5b9c981369eafb1272893e5b440f6655973 100644 --- a/examples/js/loaders/sea3d/SEA3DDeflate.js +++ b/examples/js/loaders/sea3d/SEA3DDeflate.js @@ -600,8 +600,8 @@ var zip_inflate_dynamic = function(buff, off, size) { if(zip_bl == 0) // no literals or lengths h.status = 1; if(h.status != 0) { - if(h.status == 1) - ;// **incomplete literal tree** + /*if(h.status == 1) + ;// **incomplete literal tree** */ return -1; // incomplete code set } zip_tl = h.root; @@ -619,9 +619,9 @@ var zip_inflate_dynamic = function(buff, off, size) { return -1; } - if(h.status == 1) { + /*if(h.status == 1) { ;// **incomplete distance tree** - } + }*/ if(h.status != 0) return -1; diff --git a/examples/js/loaders/sea3d/SEA3DLegacy.js b/examples/js/loaders/sea3d/SEA3DLegacy.js new file mode 100644 index 0000000000000000000000000000000000000000..43bf14714c4c51641bf3a007dc1eab5b437b944b --- /dev/null +++ b/examples/js/loaders/sea3d/SEA3DLegacy.js @@ -0,0 +1,690 @@ +/** + * SEA3D Legacy for Three.JS + * @author Sunag / http://www.sunag.com.br/ + */ + +'use strict'; + +// +// 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; + +// +// 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( mtx ) { + + 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( 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 ) { + + 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.updateAnimationSet = function( obj3d ) { + + 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( obj3d ) { + + var anmSet = obj3d.animation.animationSet; + var relative = obj3d.animation.relative; + var anms = anmSet.animations; + + if ( anmSet.flip && ! anms.length ) + return; + + var dataList = anms[ 0 ].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; + + 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 ( obj3d.animation.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; + } + + } + + } + + } + + anmSet.flip = true; + + }; + +}(); + + +THREE.SEA3D.prototype.applyDefaultAnimation = function( sea, animatorClass ) { + + this._applyDefaultAnimation( sea, animatorClass ); + + if ( this.isLegacy( sea ) && sea.tag.animation ) { + + this.updateAnimationSet( sea.tag ); + + } + +}; + +THREE.SEA3D.prototype.updateTransform = function( obj3d, sea ) { + + 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( sea ) { + + 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.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 ) { + + 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 = 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 ns = sea.name + "/" + seq.name; + + var animation = { + name: ns, + repeat: seq.repeat, + fps: sea.frameRate, + JIT: 0, + length: delta * ( seq.count - 1 ), + 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( animation ); + + } + + return 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.push( function() { + + // CONFIG + + this.config.legacy = this.config.legacy == undefined ? true : this.config.legacy; + + this.file.typeRead[ SEA3D.Skeleton.prototype.type ] = this.readSkeleton; + +} ); diff --git a/examples/js/loaders/sea3d/SEA3DLoader.js b/examples/js/loaders/sea3d/SEA3DLoader.js index 87002f84580500db2c5fb9d7fac2f0c603398be0..5edf6f4f30c0faf5d20df7683724a82c81c430ee 100644 --- a/examples/js/loaders/sea3d/SEA3DLoader.js +++ b/examples/js/loaders/sea3d/SEA3DLoader.js @@ -22,6 +22,7 @@ THREE.SEA3D = function( config ) { if ( this.config.timeLimit == undefined ) this.config.timeLimit = 10; if ( this.config.streaming == undefined ) this.config.streaming = true; if ( this.config.lights == undefined ) this.config.lights = true; + if ( this.config.useVertexTexture == undefined ) this.config.useVertexTexture = true; }; @@ -58,6 +59,10 @@ THREE.SEA3D.RTT_SIZE = 512; // Shader // +// +// Shader +// + THREE.SEA3D.ShaderLib = {}; THREE.SEA3D.ShaderLib.replaceCode = function( src, target, replace ) { @@ -92,7 +97,6 @@ THREE.SEA3D.ShaderLib.fragStdMtl = THREE.SEA3D.ShaderLib.replaceCode( THREE.Shad 'vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight * diffuse;' ] ); - // // Standard Material // @@ -106,32 +110,42 @@ THREE.SEA3D.StandardMaterial = function () { THREE.SEA3D.StandardMaterial.prototype = Object.create( THREE.MeshPhongMaterial.prototype ); THREE.SEA3D.StandardMaterial.prototype.constructor = THREE.SEA3D.StandardMaterial; -THREE.SEA3D.StandardMaterial.prototype.copy = function ( source ) { - - THREE.MeshPhongMaterial.prototype.copy.call( this, source ); +THREE.SEA3D.StandardMaterial.prototype.lightMapUV = 1; - return this; -}; +THREE.SEA3D.StandardMaterial.prototype.__defineSetter__( "__webglShader", function( val ) { -THREE.SEA3D.StandardMaterial.prototype.clone = function() { + val.fragmentShader = THREE.SEA3D.ShaderLib.fragStdMtl; - return new THREE.SEA3D.StandardMaterial().copy( this ); + if ( this.lightMapUV == 0 ) { -}; + val.fragmentShader = THREE.SEA3D.ShaderLib.replaceCode( val.fragmentShader, "texture2D( aoMap, vUv2 )", "texture2D( aoMap, vUv )" ); -THREE.SEA3D.StandardMaterial.prototype.__defineSetter__( "__webglShader", function( val ) { + } - val.fragmentShader = THREE.SEA3D.ShaderLib.fragStdMtl; this.__webglShader__ = val; -} ) +} ); THREE.SEA3D.StandardMaterial.prototype.__defineGetter__( "__webglShader", function() { return this.__webglShader__; -} ) +} ); + +THREE.SEA3D.StandardMaterial.prototype.copy = function ( source ) { + + THREE.MeshPhongMaterial.prototype.copy.call( this, source ); + + return this; + +}; + +THREE.SEA3D.StandardMaterial.prototype.clone = function() { + + return new this.constructor().copy( this ); + +}; // // Container @@ -248,7 +262,7 @@ THREE.SEA3D.Dummy.MATERIAL = new THREE.MeshBasicMaterial( { wireframe: true, col THREE.SEA3D.Dummy.prototype.clone = function ( object ) { - return new THREE.SEA3D.Dummy( this.width, this.height, this.depth ).copy( this ); + return new this.constructor( this.width, this.height, this.depth ).copy( this ); }; @@ -299,7 +313,7 @@ THREE.SEA3D.Mesh.prototype.copy = function ( source ) { THREE.SEA3D.Mesh.prototype.clone = function ( object ) { - return new THREE.SEA3D.Mesh( this.geometry, this.material ).copy( this ); + return new this.constructor( this.geometry, this.material ).copy( this ); }; @@ -362,36 +376,28 @@ THREE.SEA3D.SkinnedMesh.prototype.resume = function() { THREE.SEA3D.SkinnedMesh.prototype.play = function( name, crossfade, offset ) { - this.previousAnimation = this.currentAnimation; - this.currentAnimation = this.animations[ name ]; + var animation = this.animations[ name ]; - if ( ! this.currentAnimation ) + if ( ! animation ) throw new Error( 'Animation "' + name + '" not found.' ); - if ( this.previousAnimation && this.previousAnimation !== this.currentAnimation && crossfade > 0 ) { - - this.previousAnimation.play( this.previousAnimation.currentTime, this.previousAnimation.weight ); - this.currentAnimation.play( offset !== undefined ? offset : this.currentAnimation.currentTime, this.currentAnimation.weight ); - - THREE.SEA3D.AnimationHandler.addCrossfade( this, crossfade ); - - } else { - - this.currentAnimation.play( offset !== undefined ? offset : this.currentAnimation.currentTime, 1 ); + animation.play( offset !== undefined ? offset : animation.currentTime, animation.weight ); - } + this.currentAnimation = animation; this.isPlaying = true; + THREE.SEA3D.AnimationHandler.addCrossfade( this, crossfade !== undefined ? crossfade : 0 ); + }; THREE.SEA3D.SkinnedMesh.prototype.setAnimations = function( animations ) { - this.animations = []; - this.weightSchedule = []; - this.warpSchedule = []; - var nsIndex = animations[ 0 ].name.indexOf( "/" ) + 1; + + this.animations = []; + this.easeSpeed = 2; + this.blendMethod = SEA3D.AnimationBlendMethod.LINEAR; this.animationNamespace = animations[ 0 ].name.substring( 0, nsIndex ); for ( var i = 0; i < animations.length; i ++ ) { @@ -429,25 +435,9 @@ THREE.SEA3D.SkinnedMesh.prototype.copy = function ( source ) { if ( this.animation ) this.animation = source.animation.clone( this ); - this.animations = []; - - if ( source.geometry.animations ) { - - var refAnimations = source.geometry.animations; - var nsIndex = refAnimations[ 0 ].name.indexOf( "/" ) + 1; - - for ( var i = 0; i < refAnimations.length; i ++ ) { - - var name = refAnimations[ i ].name.substring( nsIndex ); - var data = refAnimations[ i ]; - - data.initialized = false; - - this.animations[ i ] = new THREE.SEA3D.Animation( this, data ); - this.animations[ i ].loop = refAnimations[ i ].repeat; - this.animations[ i ].name = name; + if ( this.geometry.animations ) { - } + this.setAnimations( this.geometry.animations ); } @@ -457,7 +447,7 @@ THREE.SEA3D.SkinnedMesh.prototype.copy = function ( source ) { THREE.SEA3D.SkinnedMesh.prototype.clone = function ( object ) { - return new THREE.SEA3D.SkinnedMesh( this.geometry, this.material, this.useVertexTexture ).copy( this ); + return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this ); }; @@ -533,7 +523,7 @@ THREE.SEA3D.VertexAnimationMesh.prototype.stop = function() { THREE.SEA3D.VertexAnimationMesh.prototype.clone = function ( object ) { - return new THREE.SEA3D.VertexAnimationMesh( this.geometry, this.material, this.fps ).copy( this ); + return new this.constructor( this.geometry, this.material, this.fps ).copy( this ); }; @@ -572,32 +562,64 @@ THREE.SEA3D.AnimationHandler = { update : function( dt ) { - var i, cf = THREE.SEA3D.AnimationHandler.crossfade, ups = THREE.SEA3D.AnimationHandler.updates; + var i, j, cf = THREE.SEA3D.AnimationHandler.crossfade, ups = THREE.SEA3D.AnimationHandler.updates; // crossfade + i = 0; while ( i < cf.length ) { - var mesh = cf[ i ]; + var mesh = cf[ i ], + len = mesh.animations.length, + weight = 1, + delta = Math.abs( dt ) / mesh.crossfade; - mesh.currentAnimation.weight += dt / mesh.crossfade; + if ( mesh.blendMethod === SEA3D.AnimationBlendMethod.EASING ) { - if ( mesh.currentAnimation.weight > 1 ) { + delta *= mesh.easeSpeed; - mesh.previousAnimation.weight = 0; - mesh.currentAnimation.weight = 1; + } - if ( mesh.onCrossfadeComplete ) mesh.onCrossfadeComplete( mesh ); + while ( len ) { + + var state = mesh.animations[ -- len ]; + + if ( state.weight > 0 && state != mesh.currentAnimation ) { + + if ( mesh.blendMethod === SEA3D.AnimationBlendMethod.LINEAR ) { + + state.weight -= delta; + + } + else if ( mesh.blendMethod === SEA3D.AnimationBlendMethod.EASING ) { + + state.weight -= state.weight * delta; + + } + + if ( state.weight < 0 ) state.weight = 0; + + weight -= state.weight; + + } + + } + + if ( weight < 0 ) weight = 0; + + mesh.currentAnimation.weight = weight; + + if ( weight == 1 ) { cf.splice( i, 1 ); delete mesh.crossfade; + if ( mesh.onCrossfadeComplete ) mesh.onCrossfadeComplete( mesh ); + } else ++ i; - mesh.previousAnimation.weight = 1 - mesh.currentAnimation.weight; - } // updates @@ -614,15 +636,40 @@ THREE.SEA3D.AnimationHandler = { addCrossfade : function( mesh, crossfade ) { - if ( mesh.crossfade !== undefined ) { + var fadelist = THREE.SEA3D.AnimationHandler.crossfade; + + if ( crossfade > 0 ) + { + + if ( ! mesh.crossfade ) fadelist.push( mesh ); - THREE.SEA3D.AnimationHandler.crossfade.splice( THREE.SEA3D.AnimationHandler.crossfade.indexOf( mesh ), 1 ); + mesh.crossfade = crossfade; } + else + { + + var len = mesh.animations.length; + + while ( len ) { + + mesh.animations[ -- len ].weight = 0; + + } + + if ( mesh.crossfade ) { + + fadelist.splice( fadelist.indexOf( mesh ), 1 ); + + delete mesh.crossfade; + + if ( mesh.onCrossfadeComplete ) mesh.onCrossfadeComplete( mesh ); + + } - mesh.crossfade = crossfade; + mesh.currentAnimation.weight = 1; - THREE.SEA3D.AnimationHandler.crossfade.push( mesh ); + } }, @@ -638,7 +685,7 @@ THREE.SEA3D.AnimationHandler = { if ( index !== - 1 ) { - THREE.SEA3D.AnimationHandler.crossfade.splice( THREE.SEA3D.AnimationHandler.updates.indexOf( func ), 1 ); + THREE.SEA3D.AnimationHandler.updates.splice( THREE.SEA3D.AnimationHandler.updates.indexOf( func ), 1 ); } @@ -681,6 +728,7 @@ THREE.SEA3D.Animation.prototype.reset = function() { THREE.SEA3D.MTXBUF = new THREE.Matrix4(); THREE.SEA3D.VECBUF = new THREE.Vector3(); +THREE.SEA3D.QUABUF = new THREE.Quaternion(); THREE.SEA3D.prototype.setShadowMap = function( light, opacity ) { @@ -688,7 +736,7 @@ THREE.SEA3D.prototype.setShadowMap = function( light, opacity ) { light.shadowMapHeight = 2048; light.castShadow = true; - light.shadowDarkness = opacity !== undefined ? opacity : 1; + light.shadowDarkness = opacity == undefined ? 1 : opacity; }; @@ -871,6 +919,8 @@ THREE.SEA3D.prototype.addSceneObject = function( sea ) { else if ( this.config.container ) this.config.container.add( obj3d ); + obj3d.visible = sea.visible; + }; THREE.SEA3D.prototype.createObjectURL = function( raw, mime ) { @@ -1104,6 +1154,7 @@ THREE.SEA3D.prototype.readGeometryBuffer = function( sea ) { for ( var i = 0; i < sea.groups.length; i ++ ) { var g = sea.groups[ i ]; + geo.addGroup( g.start, g.count, i ); } @@ -1127,8 +1178,8 @@ THREE.SEA3D.prototype.readGeometryBuffer = function( sea ) { if ( sea.joint ) { - geo.addAttribute( 'skinIndex', new THREE.Float32Attribute( sea.joint, 4 ) ); - geo.addAttribute( 'skinWeight', new THREE.Float32Attribute( sea.weight, 4 ) ); + geo.addAttribute( 'skinIndex', new THREE.Float32Attribute( sea.joint, sea.jointPerVertex ) ); + geo.addAttribute( 'skinWeight', new THREE.Float32Attribute( sea.weight, sea.jointPerVertex ) ); } @@ -1262,6 +1313,7 @@ THREE.SEA3D.prototype.readMesh = function( sea ) { var mod = sea.modifiers[ i ]; switch ( mod.type ) { + case SEA3D.Skeleton.prototype.type: case SEA3D.SkeletonLocal.prototype.type: skeleton = mod; @@ -1339,7 +1391,7 @@ THREE.SEA3D.prototype.readMesh = function( sea ) { if ( skeleton ) { - mesh = new THREE.SEA3D.SkinnedMesh( geo, mat, false ); + mesh = new THREE.SEA3D.SkinnedMesh( geo, mat, this.config.useVertexTexture ); if ( skeletonAnimation ) { @@ -1448,39 +1500,14 @@ THREE.SEA3D.prototype.readCubeRender = function( sea ) { THREE.SEA3D.prototype.readImage = function( sea ) { - var image = new Image(), texture = new THREE.Texture(), scope = this; - + var image = new Image(), texture = new THREE.Texture(); + image.src = this.bufferToTexture( sea.data.buffer ); + texture.name = sea.name; texture.wrapS = texture.wrapT = THREE.RepeatWrapping; texture.flipY = false; - - image.onload = function () { - - if ( ! scope.isPowerOfTwo( image.width ) || - ! scope.isPowerOfTwo( image.height ) ) { - - var width = scope.nearestPowerOfTwo( image.width ), - height = scope.nearestPowerOfTwo( image.height ); - - var canvas = document.createElement( "canvas" ); - - canvas.width = width; - canvas.height = height; - - var ctx = canvas.getContext( "2d" ); - - ctx.drawImage( image, 0, 0, width, height ); - - image = canvas; - - } - - texture.image = image; - texture.needsUpdate = true; - - } - - image.src = this.bufferToTexture( sea.data.buffer ); + texture.image = image; + texture.needsUpdate = true; this.domain.textures = this.textures = this.textures || []; this.textures.push( this.objects[ "tex/" + sea.name ] = sea.tag = texture ); @@ -1573,6 +1600,15 @@ THREE.SEA3D.prototype.readTextureURL = function( sea ) { THREE.SEA3D.SCRIPT = new SEA3D.ScriptManager(); +THREE.SEA3D.SCRIPT.dispatchUpdate = function( delta ) { + + this.dispatchEvent( { + type : "update", + delta : delta + } ); + +}; + THREE.SEA3D.Domain = function( id, objects, container, extensions ) { SEA3D.Domain.call( this, id ); @@ -1884,6 +1920,8 @@ THREE.SEA3D.prototype.materialTechnique = if ( tech.blendMode == "multiply" ) mat.aoMap = tech.texture.tag; else mat.lightMap = tech.texture.tag; + mat.lightMapUV = tech.channel; + } return techniques; @@ -2026,7 +2064,7 @@ THREE.SEA3D.prototype.readCamera = function( sea ) { var camera = new THREE.SEA3D.Camera( sea.fov ); camera.name = sea.name; - this.domain.cameras = this.cameras = this.camera || []; + this.domain.cameras = this.cameras = this.cameras || []; this.cameras.push( this.objects[ "cam/" + sea.name ] = sea.tag = camera ); this.addSceneObject( sea ); @@ -2084,8 +2122,7 @@ THREE.SEA3D.prototype.getSkeletonAnimation = function( sea, skl ) { if ( sea.tag ) return sea.tag; var animations = [], - delta = sea.frameRate / 1000, - scale = [ 1, 1, 1 ]; + delta = ( 1000 / sea.frameRate ) / 1000; for ( var i = 0; i < sea.sequence.length; i ++ ) { @@ -2122,7 +2159,7 @@ THREE.SEA3D.prototype.getSkeletonAnimation = function( sea, skl ) { time: time, pos: [ raw[ idx ], raw[ idx + 1 ], raw[ idx + 2 ] ], rot: [ raw[ idx + 3 ], raw[ idx + 4 ], raw[ idx + 5 ], raw[ idx + 6 ] ], - scl: scale + scl: [ 1, 1, 1 ] } ); time += delta; @@ -2388,7 +2425,7 @@ THREE.SEA3D.prototype.onHead = function( args ) { if ( args.sign != 'TJS' ) { - throw "Sign '" + args.sign + "' not supported! Use SEA3D Studio to export."; + throw new Error( "Sign '" + args.sign + "' not supported! Use SEA3D Studio to publish or SEA3DLegacy.js" ); } @@ -2402,6 +2439,7 @@ THREE.SEA3D.prototype.loadBytes = function( data ) { this.file = new SEA3D.File(); this.file.scope = this; + this.file.config = this.config; this.file.streaming = this.config.streaming; this.file.timeLimit = this.config.timeLimit; this.file.onProgress = this.onLoadProgress; diff --git a/examples/models/sea3d/skin.sea b/examples/models/sea3d/skin.sea index 0875f75ba1d47e39551e2c1260606fdbcc0d8dcb..7193ed43f1c927ea6eaa77dbdd6e2fec5e3fd831 100644 Binary files a/examples/models/sea3d/skin.sea and b/examples/models/sea3d/skin.sea differ diff --git a/examples/models/sea3d/skin.tjs.sea b/examples/models/sea3d/skin.tjs.sea index 8d60e2de2ba1c68a175b7fb966a964f1886ac9c2..dd591bbdebe481fbf49e4f7d48ecdb1fc5f317ed 100644 Binary files a/examples/models/sea3d/skin.tjs.sea and b/examples/models/sea3d/skin.tjs.sea differ diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index 2360c7f7c823b7fca73ffc41b99372cfb650fec1..c3f497a0590121268d5b53d6ff9566acd0f22277 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -727,3 +727,7 @@ THREE.TextGeometry = function () { console.error( 'THREE.FontUtils has been moved to /examples/js/utils/FontUtils.js' ); }; + +// + +THREE.MeshFaceMaterial = THREE.MultiMaterial; diff --git a/src/materials/MultiMaterial.js b/src/materials/MultiMaterial.js index d932bdb6f0507d423238d8041f2a6d6178351a83..3aff3fbdd502aa825f68dd9b8552b4c19001c38c 100644 --- a/src/materials/MultiMaterial.js +++ b/src/materials/MultiMaterial.js @@ -65,7 +65,3 @@ THREE.MultiMaterial.prototype = { } }; - -// backwards compatibility - -THREE.MeshFaceMaterial = THREE.MultiMaterial; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index e456145f397455c0da0a414fde48e4d4a582d782..d0a64b6347f7439aa4e458a7f495000eb869d476 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -1314,7 +1314,7 @@ THREE.WebGLRenderer = function ( parameters ) { var geometry = objects.update( object ); - if ( material instanceof THREE.MeshFaceMaterial ) { + if ( material instanceof THREE.MultiMaterial ) { var groups = geometry.groups; var materials = material.materials;