| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | |
| 14 | #ifndef PX_PARTICLESYSTEM_NXPARTICLEREADDATA |
| 15 | #define PX_PARTICLESYSTEM_NXPARTICLEREADDATA |
| 16 | /** \addtogroup particles |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "foundation/PxStrideIterator.h" |
| 21 | #include "PxLockedData.h" |
| 22 | #include "foundation/PxFlags.h" |
| 23 | #include "PxParticleFlag.h" |
| 24 | |
| 25 | #ifndef PX_DOXYGEN |
| 26 | namespace physx |
| 27 | { |
| 28 | #endif |
| 29 | |
| 30 | /** |
| 31 | Flags to configure PxParticleBase simulation output that can be read by the application. |
| 32 | Disabling unneeded buffers saves memory and improves performance. |
| 33 | */ |
| 34 | struct PxParticleReadDataFlag |
| 35 | { |
| 36 | enum Enum |
| 37 | { |
| 38 | /** |
| 39 | Enables reading particle positions from the SDK. |
| 40 | @see PxParticleReadData.positionBuffer |
| 41 | */ |
| 42 | ePOSITION_BUFFER = (1<<0), |
| 43 | |
| 44 | /** |
| 45 | Enables reading particle velocities from the SDK. |
| 46 | @see PxParticleReadData.velocityBuffer |
| 47 | */ |
| 48 | eVELOCITY_BUFFER = (1<<1), |
| 49 | |
| 50 | /** |
| 51 | Enables reading per particle rest offsets from the SDK. |
| 52 | Per particle rest offsets are never changed by the simulation. |
| 53 | This option may only be used on particle systems that have |
| 54 | PxParticleBaseFlag.ePER_PARTICLE_REST_OFFSET enabled. |
| 55 | @see PxParticleBaseFlag.ePER_PARTICLE_REST_OFFSET |
| 56 | */ |
| 57 | eREST_OFFSET_BUFFER = (1<<2), |
| 58 | |
| 59 | /** |
| 60 | Enables reading particle flags from the SDK. |
| 61 | @see PxParticleReadData.flagsBuffer |
| 62 | */ |
| 63 | eFLAGS_BUFFER = (1<<3), |
| 64 | |
| 65 | /** |
| 66 | Enables reading particle collision normals from the SDK. |
| 67 | @see PxParticleReadData.collisionNormalBuffer |
| 68 | */ |
| 69 | eCOLLISION_NORMAL_BUFFER = (1<<4), |
| 70 | |
| 71 | /** |
| 72 | Enables reading particle collision velocities from the SDK. |
| 73 | @see PxParticleReadData.collisionVelocity |
| 74 | */ |
| 75 | eCOLLISION_VELOCITY_BUFFER = (1<<5), |
| 76 | |
| 77 | /** |
| 78 | Enables reading particle densities from the SDK. (PxParticleFluid only) |
| 79 | @see PxParticleFluidReadData.densityBuffer |
| 80 | */ |
| 81 | eDENSITY_BUFFER = (1<<6) |
| 82 | }; |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | \brief collection of set bits defined in PxParticleReadDataFlag. |
| 87 | |
| 88 | @see PxParticleReadDataFlag |
| 89 | */ |
| 90 | typedef PxFlags<PxParticleReadDataFlag::Enum,PxU16> PxParticleReadDataFlags; |
| 91 | PX_FLAGS_OPERATORS(PxParticleReadDataFlag::Enum,PxU16) |
| 92 | |
| 93 | /** |
| 94 | \brief collection of set bits defined in PxParticleFlag. |
| 95 | |
| 96 | @see PxParticleFlag |
| 97 | */ |
| 98 | typedef PxFlags<PxParticleFlag::Enum,PxU16> PxParticleFlags; |
| 99 | PX_FLAGS_OPERATORS(PxParticleFlag::Enum,PxU16) |
| 100 | |
| 101 | /** |
| 102 | \brief Data layout descriptor for reading particle data from the SDK. |
| 103 | |
| 104 | PxParticleReadData is used to retrieve information about simulated particles. It can be accessed by calling PxParticleBase.lockParticleReadData(). |
| 105 | |
| 106 | Each particle is described by its position, velocity, a set of (PxParticleFlag) flags and information on collisions (collision normal). |
| 107 | The particle buffers are sparse, i.e. occupied particle indices will have PxParticleFlag.eVALID set in the corresponding entry of |
| 108 | PxParticleReadData.flagsBuffer. Alternatively valid particles can be identified with the bitmap PxParticleReadData.validParticleBitmap. |
| 109 | If (and only if) the index range of valid particles PxParticleReadData.validParticleRange is greater 0, i.e. any particles are present, |
| 110 | data can be read from the particle buffers. Additionally individual particle buffers can only be read if the corresponding |
| 111 | PxParticleReadDataFlag in particleReadDataFlags is set. |
| 112 | |
| 113 | The particle data buffer are defined in the range [0, PxParticleReadData.validParticleRange-1]. |
| 114 | The bitmap words are defined in the range [0, (PxParticleReadData.validParticleRange-1) >> 5]. |
| 115 | |
| 116 | @see PxParticleBase::lockParticleReadData() |
| 117 | */ |
| 118 | class PxParticleReadData : public PxLockedData |
| 119 | { |
| 120 | public: |
| 121 | |
| 122 | /** |
| 123 | \brief Number of particles (only including particles with PxParticleFlag.eVALID set). |
| 124 | */ |
| 125 | PxU32 nbValidParticles; |
| 126 | |
| 127 | /** |
| 128 | \brief Index after the last valid particle (PxParticleFlag.eVALID set). Its 0 if there are no valid particles. |
| 129 | */ |
| 130 | PxU32 validParticleRange; |
| 131 | |
| 132 | /** |
| 133 | \brief Bitmap marking valid particle indices. The bitmap is defined between [0, (PxParticleReadData.validParticleRange-1) >> 5]. |
| 134 | \note Might be NULL if PxParticleReadData.validParticleRange == 0. |
| 135 | */ |
| 136 | const PxU32* validParticleBitmap; |
| 137 | |
| 138 | /** |
| 139 | \brief Particle position data. |
| 140 | */ |
| 141 | PxStrideIterator<const PxVec3> positionBuffer; |
| 142 | |
| 143 | /** |
| 144 | \brief Particle velocity data. |
| 145 | */ |
| 146 | PxStrideIterator<const PxVec3> velocityBuffer; |
| 147 | |
| 148 | /** |
| 149 | \brief Particle rest offset data. |
| 150 | */ |
| 151 | PxStrideIterator<const PxF32> restOffsetBuffer; |
| 152 | |
| 153 | /** |
| 154 | \brief Particle flags. |
| 155 | */ |
| 156 | PxStrideIterator<const PxParticleFlags> flagsBuffer; |
| 157 | |
| 158 | /** |
| 159 | \brief Collision normals of colliding particles. |
| 160 | The collision normal buffer is only guaranteed to be valid after the particle |
| 161 | system has been simulated. Otherwise collisionNormalBuffer.ptr() is NULL. This also |
| 162 | applies to particle systems that are not assigned to a scene. |
| 163 | */ |
| 164 | PxStrideIterator<const PxVec3> collisionNormalBuffer; |
| 165 | |
| 166 | /** |
| 167 | \brief Velocities of particles relative to shapes they collide with. |
| 168 | The collision velocity buffer is only guaranteed to be valid after the particle |
| 169 | system has been simulated. Otherwise collisionVelocityBuffer.ptr() is NULL. This also |
| 170 | applies to particle systems that are not assigned to a scene. |
| 171 | The collision velocity is identical to the particle velocity if the particle is not colliding. |
| 172 | */ |
| 173 | PxStrideIterator<const PxVec3> collisionVelocityBuffer; |
| 174 | |
| 175 | /** |
| 176 | \brief Returns PxDataAccessFlag::eREADABLE, since PxParticleReadData is read only data |
| 177 | @see PxLockedData |
| 178 | */ |
| 179 | virtual PxDataAccessFlags getDataAccessFlags() = 0; |
| 180 | |
| 181 | /** |
| 182 | \brief Unlocks the data. |
| 183 | @see PxLockedData |
| 184 | */ |
| 185 | virtual void unlock() = 0; |
| 186 | |
| 187 | /** |
| 188 | \brief virtual destructor |
| 189 | */ |
| 190 | virtual ~PxParticleReadData() {} |
| 191 | |
| 192 | }; |
| 193 | |
| 194 | #ifndef PX_DOXYGEN |
| 195 | } // namespace physx |
| 196 | #endif |
| 197 | |
| 198 | /** @} */ |
| 199 | #endif |
| 200 | |