Yo @Cedric or any other Havok Gurus out there.
I am trying to make the big switch from Ammo.JS to Havok for the Babylon Unity Exporter.
I got most things working but really need some help with a few things.
First and foremost… Terrain Heightfield… In Ammo.js i was directly setting the heights using a Float32Array of heights
public static CreateHeightfieldTerrainShapeFromMesh(terrainMesh:BABYLON.Mesh, terrainWidth:number, terrainDepth:number, terrainMinHeight:number, terrainMaxHeight:number, terrainWidthExtents:number, terrainDepthExtents:number, flipQuadEdges:boolean = false):any {
// This parameter is not really used, since we are using PHY_FLOAT height data type and hence it is ignored
const heightScale = 1;
// Up axis = 0 for X, 1 for Y, 2 for Z. Normally 1 = Y is used.
const upAxis = 1;
// hdt, height data type. "PHY_FLOAT" is used. Possible values are "PHY_FLOAT", "PHY_UCHAR", "PHY_SHORT"
const hdt = "PHY_FLOAT";
// Create heightfield physics shape
const heightData:FloatArray = terrainMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
// Creates height data buffer in Ammo heap
(<any>terrainMesh).ammoHeightData = Ammo._malloc(4 * terrainWidth * terrainDepth);
let height = 0, p2 = 0;
for (let i = 0; i < heightData.length / 3; i++) {
height = heightData[i * 3 + 1]; // Note: Get The Y Component Only
// ..
// FIXME: Maybe Minus The Mesh Position Y To Offset Not A Zero Origin - ???
// ..
Ammo.HEAPF32[(<any>terrainMesh).ammoHeightData + p2 >> 2] = height;
// 4 bytes/float
p2 += 4;
}
// Creates the heightfield physics shape
const heightFieldShape:any = new Ammo.btHeightfieldTerrainShape(
terrainWidth,
terrainDepth,
(<any>terrainMesh).ammoHeightData,
heightScale,
terrainMinHeight,
terrainMaxHeight,
upAxis,
hdt,
flipQuadEdges
);
// Set horizontal scale
const scaleX:number = terrainWidthExtents / (terrainWidth - 1);
const scaleZ:number = terrainDepthExtents / (terrainDepth - 1);
heightFieldShape.setLocalScaling( new Ammo.btVector3(scaleX, 1, scaleZ));
heightFieldShape.setMargin(BABYLON.SceneManager.DefaultHeightFieldMargin);
return heightFieldShape;
}
How do i use the raw Havok API to create a terrain heightfield shape ??? (@3th maybe you can help here)
Second… How do I lock an axis from movement… In ammo i would use setLinearFactor and setAngularFactor … so for rotation i can use setAngularFactor(0,1,0) to lock a capsule upright to it would not tip over… you can only rotate around the Y axis
Third… In Ammo… I was using btKinematicCharacterController as well as btRaycastVehicle with wheel collider support… Is there a character controller and raycast wheeled vehicle support in havok…
It seems a bit strange that we upgraded to a more commercial physics but is does not seem to readily expose some of the basic physics engine stuff we had before in Ammo.
- Kinematic Character Controllers
- Raycast Wheel Vehicle Support
- Terrain Height Field Shapes
These are MAJOR issues for me and my Babylon Toolkit.
Any light you guys can shed on these matter would be sweeeeeeet… Thank you so much
@Pryme8 … Andy what you think ???