|
@@ -116,7 +116,7 @@
|
|
if (meshChildren.length) {
|
|
if (meshChildren.length) {
|
|
var processMesh = (localPosition: Vector3, mesh: AbstractMesh) => {
|
|
var processMesh = (localPosition: Vector3, mesh: AbstractMesh) => {
|
|
|
|
|
|
- if (!currentRotation || ! mesh.rotationQuaternion) {
|
|
|
|
|
|
+ if (!currentRotation || !mesh.rotationQuaternion) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -263,10 +263,31 @@
|
|
returnValue = new this.BJSCANNON.Plane();
|
|
returnValue = new this.BJSCANNON.Plane();
|
|
break;
|
|
break;
|
|
case PhysicsImpostor.MeshImpostor:
|
|
case PhysicsImpostor.MeshImpostor:
|
|
|
|
+ // should transform the vertex data to world coordinates!!
|
|
var rawVerts = object.getVerticesData ? object.getVerticesData(VertexBuffer.PositionKind) : [];
|
|
var rawVerts = object.getVerticesData ? object.getVerticesData(VertexBuffer.PositionKind) : [];
|
|
var rawFaces = object.getIndices ? object.getIndices() : [];
|
|
var rawFaces = object.getIndices ? object.getIndices() : [];
|
|
|
|
+ if (!rawVerts) return;
|
|
|
|
+ // get only scale! so the object could transform correctly.
|
|
|
|
+ let oldPosition = object.position.clone();
|
|
|
|
+ let oldRotation = object.rotation && object.rotation.clone();
|
|
|
|
+ let oldQuaternion = object.rotationQuaternion && object.rotationQuaternion.clone();
|
|
|
|
+ object.position.copyFromFloats(0, 0, 0);
|
|
|
|
+ object.rotation && object.rotation.copyFromFloats(0, 0, 0);
|
|
|
|
+ object.rotationQuaternion && object.rotationQuaternion.copyFromFloats(0, 0, 0, 1);
|
|
|
|
+ let transform = object.computeWorldMatrix(true);
|
|
|
|
+ // convert rawVerts to object space
|
|
|
|
+ var temp = new Array<number>();
|
|
|
|
+ var index: number;
|
|
|
|
+ for (index = 0; index < rawVerts.length; index += 3) {
|
|
|
|
+ Vector3.TransformCoordinates(Vector3.FromArray(rawVerts, index), transform).toArray(temp, index);
|
|
|
|
+ }
|
|
|
|
+
|
|
Tools.Warn("MeshImpostor only collides against spheres.");
|
|
Tools.Warn("MeshImpostor only collides against spheres.");
|
|
- returnValue = new this.BJSCANNON.Trimesh(<number[]>rawVerts, <number[]>rawFaces);
|
|
|
|
|
|
+ returnValue = new this.BJSCANNON.Trimesh(temp, <number[]>rawFaces);
|
|
|
|
+ //now set back the transformation!
|
|
|
|
+ object.position.copyFrom(oldPosition);
|
|
|
|
+ oldRotation && object.rotation && object.rotation.copyFrom(oldRotation);
|
|
|
|
+ oldQuaternion && object.rotationQuaternion && object.rotationQuaternion.copyFrom(oldQuaternion);
|
|
break;
|
|
break;
|
|
case PhysicsImpostor.HeightmapImpostor:
|
|
case PhysicsImpostor.HeightmapImpostor:
|
|
returnValue = this._createHeightmap(object);
|
|
returnValue = this._createHeightmap(object);
|
|
@@ -289,7 +310,7 @@
|
|
let boundingInfo = <BoundingInfo>(object.getBoundingInfo());
|
|
let boundingInfo = <BoundingInfo>(object.getBoundingInfo());
|
|
var dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.z);
|
|
var dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.z);
|
|
var minY = boundingInfo.boundingBox.extendSizeWorld.y;
|
|
var minY = boundingInfo.boundingBox.extendSizeWorld.y;
|
|
-
|
|
|
|
|
|
+
|
|
var elementSize = dim * 2 / arraySize;
|
|
var elementSize = dim * 2 / arraySize;
|
|
|
|
|
|
for (var i = 0; i < pos.length; i = i + 3) {
|
|
for (var i = 0; i < pos.length; i = i + 3) {
|
|
@@ -349,8 +370,11 @@
|
|
//make sure it is updated...
|
|
//make sure it is updated...
|
|
object.computeWorldMatrix && object.computeWorldMatrix(true);
|
|
object.computeWorldMatrix && object.computeWorldMatrix(true);
|
|
// The delta between the mesh position and the mesh bounding box center
|
|
// The delta between the mesh position and the mesh bounding box center
|
|
|
|
+ let bInfo = object.getBoundingInfo();
|
|
|
|
+ if (!bInfo) return;
|
|
var center = impostor.getObjectCenter();
|
|
var center = impostor.getObjectCenter();
|
|
- this._tmpDeltaPosition.copyFrom(object.position.subtract(center));
|
|
|
|
|
|
+ //m.getAbsolutePosition().subtract(m.getBoundingInfo().boundingBox.centerWorld)
|
|
|
|
+ this._tmpDeltaPosition.copyFrom(object.getAbsolutePivotPoint().subtract(center));
|
|
this._tmpPosition.copyFrom(center);
|
|
this._tmpPosition.copyFrom(center);
|
|
var quaternion = object.rotationQuaternion;
|
|
var quaternion = object.rotationQuaternion;
|
|
|
|
|
|
@@ -401,7 +425,7 @@
|
|
mesh.computeWorldMatrix(true);
|
|
mesh.computeWorldMatrix(true);
|
|
} else if (impostor.type === PhysicsImpostor.MeshImpostor) {
|
|
} else if (impostor.type === PhysicsImpostor.MeshImpostor) {
|
|
this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
|
|
this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
|
|
- this._tmpPosition.copyFrom(object.position);
|
|
|
|
|
|
+ //this._tmpPosition.copyFrom(object.position);
|
|
}
|
|
}
|
|
|
|
|
|
impostor.setDeltaPosition(this._tmpDeltaPosition);
|
|
impostor.setDeltaPosition(this._tmpDeltaPosition);
|
|
@@ -414,11 +438,15 @@
|
|
impostor.object.position.copyFrom(impostor.physicsBody.position);
|
|
impostor.object.position.copyFrom(impostor.physicsBody.position);
|
|
if (impostor.object.rotationQuaternion) {
|
|
if (impostor.object.rotationQuaternion) {
|
|
impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
|
|
impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
|
|
|
|
+ //impostor.object.rotationQuaternion.y *= -1;
|
|
|
|
+ //impostor.object.rotationQuaternion.z *= -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
|
|
public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
|
|
impostor.physicsBody.position.copy(newPosition);
|
|
impostor.physicsBody.position.copy(newPosition);
|
|
|
|
+ //newRotation.y *= -1;
|
|
|
|
+ //newRotation.z *= -1;
|
|
impostor.physicsBody.quaternion.copy(newRotation);
|
|
impostor.physicsBody.quaternion.copy(newRotation);
|
|
}
|
|
}
|
|
|
|
|