NVIDIA-Omniverse / PhysX

NVIDIA PhysX SDK
BSD 3-Clause "New" or "Revised" License
2.54k stars 361 forks source link

Position Based Dynamics: Set Particle Position and Velocity #238

Closed ErlerPhilipp closed 8 months ago

ErlerPhilipp commented 8 months ago

Library and Version

Physx 5.3.1

Operating System

Windows 10

Issue

The documentation for PBD lacks some information: How can I set the position and velocity of a particle? A snippet for a particle emitter would be great.

Context: I'm trying to implement a water gun. It should select unused or hidden fluid particles and teleport them to the emitter.

I tried modifying the array returned by PxParticleBuffer::getNbActiveParticles() but it raises an error. I guess that this array is not meant to be written into, maybe related to CUDA memory allocation and syncing.

preist-nvidia commented 8 months ago

Hi @ErlerPhilipp,

Please check the documentation again a bit lower where the particle buffer and its update flags are discussed. This is how you can update positions and velocities from a buffer, and how you can implement your watergun by either creating and adding new particle buffers to the system, or, better, creating all particles initially but park them somewhere invisible and then teleport them to the emitter location.

Hope this helps, Philipp

Internal tracking: PX-4771

ErlerPhilipp commented 8 months ago

Hi @preist-nvidia,

yes, thanks. I don't know how I missed this. Maybe, I thought that was only for initialization.

Related question: Is there a way to directly interact with the particle buffer from a custom CUDA kernel, without the detour through host memory? Would I need to run my kernel in the PhysX CUDA context or could this safely work between 2 contexts?

preist-nvidia commented 8 months ago

Hi @ErlerPhilipp - yes of course you can interact with the buffers from your own CUDA code.

We think it'll be easier to work with a single CUDA context (either use the PhysX one or create the PhysX context with your own); but it should also be possible to work with two contexts.

Philipp

ErlerPhilipp commented 8 months ago

All right. Thanks!