InteractiveComputerGraphics / PositionBasedDynamics

PositionBasedDynamics is a library for the physically-based simulation of rigid bodies, deformable solids and fluids.
MIT License
1.92k stars 362 forks source link

render sdf error #177

Closed linson7017 closed 10 months ago

linson7017 commented 10 months ago

I tried to study how cubic sdf works by rendering sdf while simulating. I found that If rigid was initialized with no translation and scale, i can get a reasonable result. However when i changed the initial position, rotation or scale, i got an unexpected sdf rendering. But the collision detection had no problem. I did not know what happen behind the cubic sdf detection. Without any initialization image With initial position image With initial rotation image

This is my rigid initialization code image

My understanding of sdf rendering is to transform the world pos inside aabb to local pos and draw point with negative sdf value calculated by collision object. Why cubic sdf collision object give an unexpected result! Any one knows why. Thanks! image

linson7017 commented 10 months ago

I found i have made a mistake. I should use the vertex data before initialization when create sdf and use local vertex data when add cubic sdf collision object. image

janbender commented 10 months ago

The reason for this is that the SDF is computed in the reference configuration of the bunny and during runtime each query vertex is transformed to this reference configutation. So the SDF never changes. Moreover, since we use an SDF of a geometry for all instances of this geometry, this has to be in an independent coordinate system. So all bunnies of a scene just share one SDF.