fabmax / physx-jni

Java JNI bindings for Nvidia PhysX
MIT License
94 stars 9 forks source link

PxRenderBuffer array fields aren't mapped properly #70

Open dustContributor opened 5 months ago

dustContributor commented 5 months ago

Hi! I was researching how to implement a debug visualization using the official docs:

https://nvidia-omniverse.github.io/PhysX/physx/5.4.0/docs/DebugVisualization.html

const PxRenderBuffer& rb = scene->getRenderBuffer();

for(PxU32 i=0; i < rb.getNbPoints(); i++)
{
    const PxDebugPoint& point = rb.getPoints()[i];
    // render the point
}

for(PxU32 i=0; i < rb.getNbLines(); i++)
{
    const PxDebugLine& line = rb.getLines()[i];
    // render the line
}

It seems the array fields for points, lines, etc in PxRenderBuffer are mapped to a single element with no way to index into them.

https://github.com/fabmax/physx-jni/blob/77bb9e5175594e86f1bbb4504c8f4a8ec02298b6/physx-jni/src/main/webidl/common/PxDebugDrawer.idl#L32

I think PxDebugLine.arrayGet for example can be used to work around this:

PxRenderBuffer renderBuffer = physxScene.getRenderBuffer();
int pointsLength = renderBuffer.getNbPoints();
int pointsBaseAddress = renderBuffer.getPoints().getAddress();
for (int p = 0; p < pointsLength; ++p) {
    PxDebugPoint point = PxDebugPoint.arrayGet(pointsBaseAddress, p);
}

But I believe it should be exposed like the getAnyHit(index) accessor from PxSweepResult https://github.com/fabmax/physx-jni/blob/77bb9e5175594e86f1bbb4504c8f4a8ec02298b6/physx-jni/src/main/webidl/physics/PxSceneQuery.idl#L224

Where you do

int hitsLength = sweepResult.getNbAnyHits();
for (int h = 0; h < hitsLength; ++h) {
    PxSweepHit hit = sweepResult.getAnyHit(h);
}
fabmax commented 1 week ago

I was just browsing through the open issues and found this one... (for some reason I wasn't watching this repo for a while and didn't get notifications on new issues 😄)

Yeah the way the PxRenderBuffer (and also a lot of the other PhysX classes) works is a bit unfortunate, because it only returns a raw pointer for the get*() functions and my code generator currently isn't smart enough to generate array accessors for these.

The various PxHitResult classes work better than this because I implemented them myself: WebIdlBindings.h

I guess it would be possible to add an annotation to the idl file and improve the code generator for this case but I'm also trying to keep it in line with the emscripten / WASM version of this library and with emscripten this isn't possible as far as I know. On the other hand I already do a few things differently than emscipten and it would make things easier in a lot of places, so I might actually do this one day.