ammo.js icon indicating copy to clipboard operation
ammo.js copied to clipboard

Possible to make custom btVehicleRaycaster?

Open dlannan opened this issue 5 years ago • 2 comments

I have been trying a number of ways to override the "castRay" method in this and passing the structure into the vehicle setup. I haven't yet had any success, and Im a little puzzled. It 'seems' like it should work, but I haven't yet checked the internals of Bullet to see how this might be getting called. Any thoughts or assistance would be great. Im working on a high speed terrain/road lookup to reduce the need for any raycasting at all, and this is working very well. I just cant get the lookup data into the raycast structure..

dlannan avatar Jun 30 '19 13:06 dlannan

It seems there may be a need to extend the idl for this to work. I'll make an attempt to do this, to see if I can solve this.

dlannan avatar Jul 01 '19 00:07 dlannan

Ok. I have figured it out.. but Im not sure its an ideal solution (seems quite stable).

var customRayCaster = function(from, to, resultptr ) {

    from = Ammo.wrapPointer(from, Ammo.btVector3);
    to = Ammo.wrapPointer(to, Ammo.btVector3);
    result = Ammo.wrapPointer(resultptr, Ammo.btVehicleRaycasterResult);
    return groundBody.ptr;
}

Raycasting code or lookups here. Make sure you return a valid rigid body in the scene (a fake ground works fine). The other important structure to fill out is the raycaster results structure. Id recommend just setting its properties.

This seems kind of nasty, but its just overriding the virtual function. So its quite safe.

        var defaultRaycaster = new Ammo.btDefaultVehicleRaycaster(Physics.physicsWorld);
        Ammo.customizeVTable( defaultRaycaster, [{
            original: Ammo.btDefaultVehicleRaycaster.prototype.castRay,
            replacement: customRayCaster
        }]);

        Physics.vehicle = new Ammo.btRaycastVehicle(tuning, body, defaultRaycaster );

Let me know if there is a better way. For the time being this has made the lookups for the wheels very fast.

dlannan avatar Jul 02 '19 13:07 dlannan