Missing Havok Features

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 :slight_smile:

@Pryme8 … Andy what you think ???

I have not done much work with Havok yet and seem to struggle to find documentation on it whenever I google for it.

There is this:

Not sure how much help for you that is though.

I would assume you just need to make the terrain and then do something like this:

const aggregate = new BABYLON.PhysicsAggregate(terrain, BABYLON.PhysicsShapeType.HEIGHTFIELD, { mass: 0, friction: 0.5, restitution: 0.5 }, scene);

I got terrain height map collision working for my export terrain meshes. Not using a heightmap image, instead I create the Float32Array of heights directly from the terrain mesh exported from unity. No precision loss because of encoding the heights to 8 bit image.

But i still need to get a alternative for Ammo.js setLinearFactor and setAngularFactor

And how to handle Kinematic Character Controllers and Raycast Wheeled Vehicles

I’m back from the break :slight_smile:
Here is current state of Havok physics for your concern:

Heightmap terrain shape is in progress. It should be merged by End of Feb, just before 7.0 code freeze

you can do axis lock this way : setAngularFactor for Havok - #3 by Takemura

No ETA for Kinematic Character Controllers and Raycast Wheeled Vehicles yet. It’s something we want to do for quite some time and as usual, prioritizes change.

What about setLinearFactor ?

@carolhmj Do you remember something related to setlinearfactor in Havok API?

There is SetLinearDamping and SetLinearVelocity, but no SetLinearFactor :thinking:

with a damping of 1, it’s like setting a factor of 0, I guess.

EDIT: nope.

Yeah i tried that too… Its really to damping over time… Not like the multiply factor of SetLinearFactor … Luckily the mas properties inertia is multiplay against angular velocity so give me a way to freeze the rotation axis of the physics body as if havok had a setAngularFactor…

But i still need to come up with a way to freeze the linear velocity as well

Yo @Cedric and @carolhmj … Any idea when we are gonna expose vehicle classes for Havok Physics?

2 Likes

Hi @MackeyK24
Sorry, no ETA yet. We are working on planning ATM. Maybe I’ll have more to share :slight_smile: