|
@@ -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 );
|
|
|
|
|
|
}
|
|
|
|