fabmax / physx-jni

Java JNI bindings for Nvidia PhysX
MIT License
85 stars 8 forks source link

Constraint Break is not passing in an array in Java (PhysX 4.0) #48

Closed haubna closed 1 year ago

haubna commented 1 year ago

onConstraintBreak should pass an array (described here https://gameworksdocs.nvidia.com/PhysX/4.0/documentation/PhysXGuide/Manual/Joints.html).

class MySimulationEventCallback
{
    void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count)
    {
        for(PxU32 i=0; i<count; i++)
        {
            PxJoint* joint = reinterpret_cast<PxJoint*>(constraints[i].externalReference);
            ...
        }
    }
}

But it passes only one value that can't be iterated. Maybe a similar solution to PxContactPair (PxContactPair pair = TypeHelpers.getContactPairAt(pairs, i);) would be feasible.

public void onConstraintBreak(PxConstraintInfo constraints, int count) {
}
fabmax commented 1 year ago

Same here: would be possible, but I'm not going to do it for PhysX 4 😃

With the PhysX 5 bindings these raw-pointer based arrays can be iterated out-of-the-box in Java (passing an actual array would still be much cleaner, but is difficult to generate):

public void onConstraintBreak(PxConstraintInfo constraints, int count) {
    for (int i = 0; i < count; i++) {
        PxConstraintInfo info = PxConstraintInfo.arrayGet(constraints.getAddress(), i);
    }
}
haubna commented 1 year ago

Perfect, thanks! :D