26-04-2019, 06:46 AM
(25-04-2019, 10:49 PM)tsantoro Wrote: Hello.
We're using Obi Cloth in our VR app. There are two pieces of cloth that the user must grab and drop on the floor. So we must check if the controller is within range of a particle to grab the cloth, and if majority of the particles are on the floor.
Previously, we were checking the position of the particles by doing actor.GetParticlePositions().
If I understand correctly, that returns renderable positions, and only works appropriately if you tell the solver of the actor to RequireRenderablePositions? Otherwise those renderable positions don't move if the cloth moves. Then you can call RelinquishRenderablePositions when you're done, and the main reason for that is that renderable positions are a little expensive?
I also discovered an alternative way to do this by calling actor.PullDataFromSolver(ParticleData.POSITIONS), then the actor has a vector3 positions array of all the particles. The documentation referred to this as "normal positions".
Three questions:
- Is that more or less expensive than doing renderable positions?
- If it's less expensive, how often do you have to call PullDataFromSolver()? Every frame?
- And am I on the right track here, or is there a better way we should be checking the position of the particles?
Thank you.
Hi,
In 4.x, Require/Relinquish RenderablePositions does no longer exist, and using renderable positions is not any more expensive than using positions. All per-particle arrays are memory mapped between C++ and C#, so they are always available and reading/writing from/to them incurs no extra cost.
If you're using 3.x, then yes, using renderable positions is a bit more expensive because memory must be copied around, and that's why you need to call require/relinquish when appropriate. Note however, than calling actor.PullDataFromSolver(ParticleData.POSITIONS); is exactly as expensive as calling RequireRenderablePositions(), which instructs the solver to call actor.PullDataFromSolver(ParticleData.RENDERABLE_POSITIONS) internally every frame. If you need to retrieve particle positions from the solver, you can use either method as the cost is essentially the same.
The difference between renderable and "normal" positions, is that renderable positions are iterpolated between physics steps if your solver has "Interpolation" enabled. Otherwise, they're exactly the same.
kind regards,