fabmax / physx-js-webidl

Javascript WASM bindings for Nvidia PhysX
MIT License
117 stars 27 forks source link

about raycast #10

Closed lo-th closed 2 years ago

lo-th commented 2 years ago

Hi me again about raycast

standard init for ray is

const rayBuffer = new PhysX.PxRaycastBuffer10()
const rayFlags = new PhysX.PxHitFlags( PhysX._emscripten_enum_PxHitFlagEnum_eDEFAULT() );
const rayFilter = new PhysX.PxQueryFilterData();

after on step let hit = root.scene.raycast( v1, v2, distance, rayBuffer, rayFlags, rayFilter )

hit work is return good true or false but rayBuffer.block not return good position normal and actor ? if you have idea, thank's

fabmax commented 2 years ago

I think with eDEFAULT flags the raycast reports multiple hits instead of a single blocking one (although according to the doc it should not)

You should be able to iterate over the result in a loop (until rayBuffer.getNbAnyHits()) and take the nearest from rayBuffer.getAnyHit(). The results are not ordered by distance, so simply taking the first one might give you a wrong result. Alternatively you can try to play around with the flags but I don't know if that makes a difference.

lo-th commented 2 years ago

yes is perfect many thank's

let r = rayBuffer.getAnyHit()
r.position, r.normal , r.actor are good 

and rayBuffer.getNbAnyHits() return 1 with default