If the mesh of the model has parameters attribute like SphereBufferGeometry , BoxBufferGeometry,.then I can traverse to get the length, width and height of the Geometry in the model and create the corresponding ammojs physical model.
Hey, im using this function ATM. I need to scale up the geometry to get the right shape, so if anyone knows how to improve, let me know. This is for static rigid bodies / kinematic bodies only!
function createTriangleShapeByBufferGeometry(geometry, scalingFactor) {
var mesh = new Ammo.btTriangleMesh(true, true);
var vertexPositionArray = geometry.attributes.position.array;
for (var i = 0; i < geometry.attributes.position.count/3; i++) {
mesh.addTriangle(
new Ammo.btVector3(vertexPositionArray[i*9+0]*scalingFactor, vertexPositionArray[i*9+1]*scalingFactor, vertexPositionArray[i*9+2]*scalingFactor ),
new Ammo.btVector3(vertexPositionArray[i*9+3]*scalingFactor, vertexPositionArray[i*9+4]*scalingFactor, vertexPositionArray[i*9+5]*scalingFactor),
new Ammo.btVector3(vertexPositionArray[i*9+6]*scalingFactor, vertexPositionArray[i*9+7]*scalingFactor, vertexPositionArray[i*9+8]*scalingFactor),
false
);
}
var shape = new Ammo.btBvhTriangleMeshShape(mesh, true, true);
return shape;
}