FLEX  1.2.0
Data Structures | Typedefs | Enumerations | Functions
NvFlex.h File Reference

Go to the source code of this file.

Data Structures

struct  NvFlexParams
 
struct  NvFlexTimers
 
struct  NvFlexSolverCallbackParams
 
struct  NvFlexSolverCallback
 
struct  NvFlexInitDesc
 
struct  NvFlexSolverDesc
 
struct  NvFlexCopyDesc
 
struct  NvFlexSphereGeometry
 
struct  NvFlexCapsuleGeometry
 
struct  NvFlexBoxGeometry
 
struct  NvFlexConvexMeshGeometry
 
struct  NvFlexTriangleMeshGeometry
 
struct  NvFlexSDFGeometry
 
union  NvFlexCollisionGeometry
 
struct  NvFlexDetailTimer
 

Typedefs

typedef struct NvFlexLibrary NvFlexLibrary
 
typedef struct NvFlexSolver NvFlexSolver
 
typedef struct NvFlexBuffer NvFlexBuffer
 
typedef void(* NvFlexErrorCallback) (NvFlexErrorSeverity type, const char *msg, const char *file, int line)
 
typedef unsigned int NvFlexTriangleMeshId
 
typedef unsigned int NvFlexDistanceFieldId
 
typedef unsigned int NvFlexConvexMeshId
 

Enumerations

enum  NvFlexMapFlags {
  eNvFlexMapWait = 0,
  eNvFlexMapDoNotWait = 1
}
 
enum  NvFlexBufferType {
  eNvFlexBufferHost = 0,
  eNvFlexBufferDevice = 1
}
 
enum  NvFlexRelaxationMode {
  eNvFlexRelaxationGlobal = 0,
  eNvFlexRelaxationLocal = 1
}
 
enum  NvFlexPhase {
  eNvFlexPhaseGroupMask = 0x000fffff,
  eNvFlexPhaseFlagsMask = 0x00f00000,
  eNvFlexPhaseShapeChannelMask = 0xff000000,
  eNvFlexPhaseSelfCollide = 1 << 20,
  eNvFlexPhaseSelfCollideFilter = 1 << 21,
  eNvFlexPhaseFluid = 1 << 22,
  eNvFlexPhaseUnused = 1 << 23,
  eNvFlexPhaseShapeChannel0 = 1 << 24,
  eNvFlexPhaseShapeChannel1 = 1 << 25,
  eNvFlexPhaseShapeChannel2 = 1 << 26,
  eNvFlexPhaseShapeChannel3 = 1 << 27,
  eNvFlexPhaseShapeChannel4 = 1 << 28,
  eNvFlexPhaseShapeChannel5 = 1 << 29,
  eNvFlexPhaseShapeChannel6 = 1 << 30,
  eNvFlexPhaseShapeChannel7 = 1 << 31
}
 
enum  NvFlexErrorSeverity {
  eNvFlexLogError = 0,
  eNvFlexLogInfo = 1,
  eNvFlexLogWarning = 2,
  eNvFlexLogDebug = 4,
  eNvFlexLogAll = -1
}
 
enum  NvFlexSolverCallbackStage {
  eNvFlexStageIterationStart,
  eNvFlexStageIterationEnd,
  eNvFlexStageSubstepBegin,
  eNvFlexStageSubstepEnd,
  eNvFlexStageUpdateEnd,
  eNvFlexStageCount
}
 
enum  NvFlexComputeType {
  eNvFlexCUDA,
  eNvFlexD3D11,
  eNvFlexD3D12
}
 
enum  NvFlexFeatureMode {
  eNvFlexFeatureModeDefault = 0,
  eNvFlexFeatureModeSimpleSolids = 1,
  eNvFlexFeatureModeSimpleFluids = 2
}
 
enum  NvFlexCollisionShapeType {
  eNvFlexShapeSphere = 0,
  eNvFlexShapeCapsule = 1,
  eNvFlexShapeBox = 2,
  eNvFlexShapeConvexMesh = 3,
  eNvFlexShapeTriangleMesh = 4,
  eNvFlexShapeSDF = 5
}
 
enum  NvFlexCollisionShapeFlags {
  eNvFlexShapeFlagTypeMask = 0x7,
  eNvFlexShapeFlagDynamic = 0x8,
  eNvFlexShapeFlagTrigger = 0x10,
  eNvFlexShapeFlagReserved = 0xffffff00
}
 

Functions

NV_FLEX_API int NvFlexMakePhaseWithChannels (int group, int particleFlags, int shapeChannels)
 
NV_FLEX_API int NvFlexMakePhase (int group, int particleFlags)
 
NV_FLEX_API NvFlexLibraryNvFlexInit (int version=NV_FLEX_VERSION, NvFlexErrorCallback errorFunc=0, NvFlexInitDesc *desc=0)
 
NV_FLEX_API void NvFlexShutdown (NvFlexLibrary *lib)
 
NV_FLEX_API int NvFlexGetVersion ()
 
NV_FLEX_API void NvFlexSetSolverDescDefaults (NvFlexSolverDesc *desc)
 
NV_FLEX_API NvFlexSolverNvFlexCreateSolver (NvFlexLibrary *lib, const NvFlexSolverDesc *desc)
 
NV_FLEX_API void NvFlexDestroySolver (NvFlexSolver *solver)
 
NV_FLEX_API NvFlexLibraryNvFlexGetSolverLibrary (NvFlexSolver *solver)
 
NV_FLEX_API void NvFlexGetSolverDesc (NvFlexSolver *solver, NvFlexSolverDesc *desc)
 
NV_FLEX_API NvFlexSolverCallback NvFlexRegisterSolverCallback (NvFlexSolver *solver, NvFlexSolverCallback function, NvFlexSolverCallbackStage stage)
 
NV_FLEX_API void NvFlexUpdateSolver (NvFlexSolver *solver, float dt, int substeps, bool enableTimers)
 
NV_FLEX_API void NvFlexSetParams (NvFlexSolver *solver, const NvFlexParams *params)
 
NV_FLEX_API void NvFlexGetParams (NvFlexSolver *solver, NvFlexParams *params)
 
NV_FLEX_API void NvFlexSetActive (NvFlexSolver *solver, NvFlexBuffer *indices, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetActive (NvFlexSolver *solver, NvFlexBuffer *indices, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetActiveCount (NvFlexSolver *solver, int n)
 
NV_FLEX_API int NvFlexGetActiveCount (NvFlexSolver *solver)
 
NV_FLEX_API void NvFlexSetParticles (NvFlexSolver *solver, NvFlexBuffer *p, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetParticles (NvFlexSolver *solver, NvFlexBuffer *p, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetRestParticles (NvFlexSolver *solver, NvFlexBuffer *p, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetRestParticles (NvFlexSolver *solver, NvFlexBuffer *p, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetSmoothParticles (NvFlexSolver *solver, NvFlexBuffer *p, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetVelocities (NvFlexSolver *solver, NvFlexBuffer *v, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetVelocities (NvFlexSolver *solver, NvFlexBuffer *v, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetPhases (NvFlexSolver *solver, NvFlexBuffer *phases, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetPhases (NvFlexSolver *solver, NvFlexBuffer *phases, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetNormals (NvFlexSolver *solver, NvFlexBuffer *normals, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetNormals (NvFlexSolver *solver, NvFlexBuffer *normals, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexSetSprings (NvFlexSolver *solver, NvFlexBuffer *indices, NvFlexBuffer *restLengths, NvFlexBuffer *stiffness, int numSprings)
 
NV_FLEX_API void NvFlexGetSprings (NvFlexSolver *solver, NvFlexBuffer *indices, NvFlexBuffer *restLengths, NvFlexBuffer *stiffness, int numSprings)
 
NV_FLEX_API void NvFlexSetRigids (NvFlexSolver *solver, NvFlexBuffer *offsets, NvFlexBuffer *indices, NvFlexBuffer *restPositions, NvFlexBuffer *restNormals, NvFlexBuffer *stiffness, NvFlexBuffer *thresholds, NvFlexBuffer *creeps, NvFlexBuffer *rotations, NvFlexBuffer *translations, int numRigids, int numIndices)
 
NV_FLEX_API void NvFlexGetRigids (NvFlexSolver *solver, NvFlexBuffer *offsets, NvFlexBuffer *indices, NvFlexBuffer *restPositions, NvFlexBuffer *restNormals, NvFlexBuffer *stiffness, NvFlexBuffer *thresholds, NvFlexBuffer *creeps, NvFlexBuffer *rotations, NvFlexBuffer *translations)
 
NV_FLEX_API NvFlexTriangleMeshId NvFlexCreateTriangleMesh (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexDestroyTriangleMesh (NvFlexLibrary *lib, NvFlexTriangleMeshId mesh)
 
NV_FLEX_API void NvFlexUpdateTriangleMesh (NvFlexLibrary *lib, NvFlexTriangleMeshId mesh, NvFlexBuffer *vertices, NvFlexBuffer *indices, int numVertices, int numTriangles, const float *lower, const float *upper)
 
NV_FLEX_API void NvFlexGetTriangleMeshBounds (NvFlexLibrary *lib, const NvFlexTriangleMeshId mesh, float *lower, float *upper)
 
NV_FLEX_API NvFlexDistanceFieldId NvFlexCreateDistanceField (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexDestroyDistanceField (NvFlexLibrary *lib, NvFlexDistanceFieldId sdf)
 
NV_FLEX_API void NvFlexUpdateDistanceField (NvFlexLibrary *lib, NvFlexDistanceFieldId sdf, int dimx, int dimy, int dimz, NvFlexBuffer *field)
 
NV_FLEX_API NvFlexConvexMeshId NvFlexCreateConvexMesh (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexDestroyConvexMesh (NvFlexLibrary *lib, NvFlexConvexMeshId convex)
 
NV_FLEX_API void NvFlexUpdateConvexMesh (NvFlexLibrary *lib, NvFlexConvexMeshId convex, NvFlexBuffer *planes, int numPlanes, const float *lower, const float *upper)
 
NV_FLEX_API void NvFlexGetConvexMeshBounds (NvFlexLibrary *lib, NvFlexConvexMeshId mesh, float *lower, float *upper)
 
NV_FLEX_API int NvFlexMakeShapeFlagsWithChannels (NvFlexCollisionShapeType type, bool dynamic, int shapeChannels)
 
NV_FLEX_API int NvFlexMakeShapeFlags (NvFlexCollisionShapeType type, bool dynamic)
 
NV_FLEX_API void NvFlexSetShapes (NvFlexSolver *solver, NvFlexBuffer *geometry, NvFlexBuffer *shapePositions, NvFlexBuffer *shapeRotations, NvFlexBuffer *shapePrevPositions, NvFlexBuffer *shapePrevRotations, NvFlexBuffer *shapeFlags, int numShapes)
 
NV_FLEX_API void NvFlexSetDynamicTriangles (NvFlexSolver *solver, NvFlexBuffer *indices, NvFlexBuffer *normals, int numTris)
 
NV_FLEX_API void NvFlexGetDynamicTriangles (NvFlexSolver *solver, NvFlexBuffer *indices, NvFlexBuffer *normals, int numTris)
 
NV_FLEX_API void NvFlexSetInflatables (NvFlexSolver *solver, NvFlexBuffer *startTris, NvFlexBuffer *numTris, NvFlexBuffer *restVolumes, NvFlexBuffer *overPressures, NvFlexBuffer *constraintScales, int numInflatables)
 
NV_FLEX_API void NvFlexGetDensities (NvFlexSolver *solver, NvFlexBuffer *densities, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetAnisotropy (NvFlexSolver *solver, NvFlexBuffer *q1, NvFlexBuffer *q2, NvFlexBuffer *q3, const NvFlexCopyDesc *desc)
 
NV_FLEX_API void NvFlexGetDiffuseParticles (NvFlexSolver *solver, NvFlexBuffer *p, NvFlexBuffer *v, NvFlexBuffer *count)
 
NV_FLEX_API void NvFlexSetDiffuseParticles (NvFlexSolver *solver, NvFlexBuffer *p, NvFlexBuffer *v, int n)
 
NV_FLEX_API void NvFlexGetContacts (NvFlexSolver *solver, NvFlexBuffer *planes, NvFlexBuffer *velocities, NvFlexBuffer *indices, NvFlexBuffer *counts)
 
NV_FLEX_API void NvFlexGetNeighbors (NvFlexSolver *solver, NvFlexBuffer *neighbors, NvFlexBuffer *counts, NvFlexBuffer *remap)
 
NV_FLEX_API void NvFlexGetBounds (NvFlexSolver *solver, NvFlexBuffer *lower, NvFlexBuffer *upper)
 
NV_FLEX_API float NvFlexGetDeviceLatency (NvFlexSolver *solver, unsigned long long *begin, unsigned long long *end, unsigned long long *frequency)
 
NV_FLEX_API void NvFlexGetTimers (NvFlexSolver *solver, NvFlexTimers *timers)
 
NV_FLEX_API int NvFlexGetDetailTimers (NvFlexSolver *solver, NvFlexDetailTimer **timers)
 
NV_FLEX_API NvFlexBufferNvFlexAllocBuffer (NvFlexLibrary *lib, int elementCount, int elementByteStride, NvFlexBufferType type)
 
NV_FLEX_API void NvFlexFreeBuffer (NvFlexBuffer *buf)
 
NV_FLEX_API void * NvFlexMap (NvFlexBuffer *buffer, int flags)
 
NV_FLEX_API void NvFlexUnmap (NvFlexBuffer *buffer)
 
NV_FLEX_API NvFlexBufferNvFlexRegisterOGLBuffer (NvFlexLibrary *lib, int buf, int elementCount, int elementByteStride)
 
NV_FLEX_API void NvFlexUnregisterOGLBuffer (NvFlexBuffer *buf)
 
NV_FLEX_API NvFlexBufferNvFlexRegisterD3DBuffer (NvFlexLibrary *lib, void *buffer, int elementCount, int elementByteStride)
 
NV_FLEX_API void NvFlexUnregisterD3DBuffer (NvFlexBuffer *buf)
 
NV_FLEX_API void NvFlexAcquireContext (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexRestoreContext (NvFlexLibrary *lib)
 
NV_FLEX_API const char * NvFlexGetDeviceName (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexGetDeviceAndContext (NvFlexLibrary *lib, void **device, void **context)
 
NV_FLEX_API void NvFlexFlush (NvFlexLibrary *lib)
 
NV_FLEX_API void NvFlexWait (NvFlexLibrary *lib)
 

Detailed Description

The main include file for the core Flex solver.


Data Structure Documentation

struct NvFlexParams

Simulation parameters for a solver

Data Fields
int numIterations Number of solver iterations to perform per-substep.
float gravity[3] Constant acceleration applied to all particles.
float radius The maximum interaction radius for particles.
float solidRestDistance The distance non-fluid particles attempt to maintain from each other, must be in the range (0, radius].
float fluidRestDistance The distance fluid particles are spaced at the rest density, must be in the range (0, radius], for fluids this should generally be 50-70% of mRadius, for rigids this can simply be the same as the particle radius.
float dynamicFriction Coefficient of friction used when colliding against shapes.
float staticFriction Coefficient of static friction used when colliding against shapes.
float particleFriction Coefficient of friction used when colliding particles.
float restitution Coefficient of restitution used when colliding against shapes, particle collisions are always inelastic.
float adhesion Controls how strongly particles stick to surfaces they hit, default 0.0, range [0.0, +inf].
float sleepThreshold Particles with a velocity magnitude < this threshold will be considered fixed.
float maxSpeed The magnitude of particle velocity will be clamped to this value at the end of each step.
float maxAcceleration The magnitude of particle acceleration will be clamped to this value at the end of each step (limits max velocity change per-second), useful to avoid popping due to large interpenetrations.
float shockPropagation Artificially decrease the mass of particles based on height from a fixed reference point, this makes stacks and piles converge faster.
float dissipation Damps particle velocity based on how many particle contacts it has.
float damping Viscous drag force, applies a force proportional, and opposite to the particle velocity.
float wind[3] Constant acceleration applied to particles that belong to dynamic triangles, drag needs to be > 0 for wind to affect triangles.
float drag Drag force applied to particles belonging to dynamic triangles, proportional to velocity^2*area in the negative velocity direction.
float lift Lift force applied to particles belonging to dynamic triangles, proportional to velocity^2*area in the direction perpendicular to velocity and (if possible), parallel to the plane normal.
float cohesion Control how strongly particles hold each other together, default: 0.025, range [0.0, +inf].
float surfaceTension Controls how strongly particles attempt to minimize surface area, default: 0.0, range: [0.0, +inf].
float viscosity Smoothes particle velocities using XSPH viscosity.
float vorticityConfinement Increases vorticity by applying rotational forces to particles.
float anisotropyScale Control how much anisotropy is present in resulting ellipsoids for rendering, if zero then anisotropy will not be calculated, see NvFlexGetAnisotropy()
float anisotropyMin Clamp the anisotropy scale to this fraction of the radius.
float anisotropyMax Clamp the anisotropy scale to this fraction of the radius.
float smoothing Control the strength of Laplacian smoothing in particles for rendering, if zero then smoothed positions will not be calculated, see NvFlexGetSmoothParticles()
float solidPressure Add pressure from solid surfaces to particles.
float freeSurfaceDrag Drag force applied to boundary fluid particles.
float buoyancy Gravity is scaled by this value for fluid particles.
float diffuseThreshold Particles with kinetic energy + divergence above this threshold will spawn new diffuse particles.
float diffuseBuoyancy Scales force opposing gravity that diffuse particles receive.
float diffuseDrag Scales force diffuse particles receive in direction of neighbor fluid particles.
int diffuseBallistic The number of neighbors below which a diffuse particle is considered ballistic.
float diffuseLifetime Time in seconds that a diffuse particle will live for after being spawned, particles will be spawned with a random lifetime in the range [0, diffuseLifetime].
float collisionDistance Distance particles maintain against shapes, note that for robust collision against triangle meshes this distance should be greater than zero.
float particleCollisionMargin Increases the radius used during neighbor finding, this is useful if particles are expected to move significantly during a single step to ensure contacts aren't missed on subsequent iterations.
float shapeCollisionMargin Increases the radius used during contact finding against kinematic shapes.
float planes[8][4] Collision planes in the form ax + by + cz + d = 0.
int numPlanes Num collision planes.
NvFlexRelaxationMode relaxationMode How the relaxation is applied inside the solver.
float relaxationFactor Control the convergence rate of the parallel solver, default: 1, values greater than 1 may lead to instability.
struct NvFlexTimers

Time spent in each section of the solver update, times in GPU seconds, see NvFlexUpdateSolver()

Data Fields
float predict Time spent in prediction.
float createCellIndices Time spent creating grid indices.
float sortCellIndices Time spent sorting grid indices.
float createGrid Time spent creating grid.
float reorder Time spent reordering particles.
float collideParticles Time spent finding particle neighbors.
float collideShapes Time spent colliding convex shapes.
float collideTriangles Time spent colliding triangle shapes.
float collideFields Time spent colliding signed distance field shapes.
float calculateDensity Time spent calculating fluid density.
float solveDensities Time spent solving density constraints.
float solveVelocities Time spent solving velocity constraints.
float solveShapes Time spent solving rigid body constraints.
float solveSprings Time spent solving distance constraints.
float solveContacts Time spent solving contact constraints.
float solveInflatables Time spent solving pressure constraints.
float applyDeltas Time spent adding position deltas to particles.
float calculateAnisotropy Time spent calculating particle anisotropy for fluid.
float updateDiffuse Time spent updating diffuse particles.
float updateTriangles Time spent updating dynamic triangles.
float updateNormals Time spent updating vertex normals.
float finalize Time spent finalizing state.
float updateBounds Time spent updating particle bounds.
float total Sum of all timers above.
struct NvFlexSolverCallbackParams

Structure containing pointers to the internal solver data that is passed to each registered solver callback

Remarks
Pointers to internal data are only valid for the lifetime of the callback and should not be stored. However, it is safe to launch kernels and memory transfers using the device pointers.
Because Flex re-orders particle data internally for performance, the particle data in the callback is not in the same order as it was provided to the API. The callback provides arrays which map original particle indices to sorted positions and vice-versa.
Particle positions may be modified during any callback, but velocity modifications should only occur during the eNvFlexStageUpdateEnd stage, otherwise any velocity changes will be discarded.
Data Fields
NvFlexSolver * solver Pointer to the solver that the callback is registered to.
void * userData Pointer to the user data provided to NvFlexRegisterSolverCallback()
float * particles Device pointer to the active particle basic data in the form x,y,z,1/m.
float * velocities Device pointer to the active particle velocity data in the form x,y,z,w (last component is not used)
int * phases Device pointer to the active particle phase data.
int numActive The number of active particles returned, the callback data only return pointers to active particle data, this is the same as NvFlexGetActiveCount()
float dt The per-update time-step, this is the value passed to NvFlexUpdateSolver()
const int * originalToSortedMap Device pointer that maps the sorted callback data to the original position given by SetParticles()
const int * sortedToOriginalMap Device pointer that maps the original particle index to the index in the callback data structure.
struct NvFlexInitDesc

Descriptor used to initialize Flex

Data Fields
int deviceIndex The GPU device index that should be used, if there is already a CUDA context on the calling thread then this parameter will be ignored and the active CUDA context used. Otherwise a new context will be created using the suggested device ordinal.
bool enableExtensions Enable or disable NVIDIA/AMD extensions in DirectX, can lead to improved performance.
void * renderDevice Direct3D device to use for simulation, if none is specified a new device and context will be created.
void * renderContext Direct3D context that the app is using for rendering. In DirectX 12 this should be a ID3D12CommandQueue pointer.
void * computeContext Direct3D context to use for simulation, if none is specified a new context will be created, in DirectX 12 this should be a pointer to the ID3D12CommandQueue where compute operations will take place.
bool useComputeQueue If true, run Flex on a D3D12 compute queue, or vendor specific D3D11 compute queue. This allows compute and graphics to run in parallel on some GPUs.
NvFlexComputeType computeType Set to eNvFlexD3D11 if DirectX 11 should be used, eNvFlexD3D12 for DirectX 12, this must match the libraries used to link the application.
struct NvFlexSolverDesc

Describes the creation time parameters for the solver

Data Fields
NvFlexFeatureMode featureMode Control which features are enabled.
int maxParticles Maximum number of regular particles in the solver.
int maxDiffuseParticles Maximum number of diffuse particles in the solver.
int maxNeighborsPerParticle Maximum number of neighbors per-particle, for solids this can be around 32, for fluids up to 128 may be necessary depending on smoothing radius.
struct NvFlexCopyDesc

Describes a source and destination buffer region for performing a copy operation.

Data Fields
int srcOffset
int dstOffset
int elementCount
struct NvFlexSphereGeometry

A basic sphere shape with origin at the center of the sphere and radius

Data Fields
float radius
struct NvFlexCapsuleGeometry

A collision capsule extends along the x-axis with its local origin at the center of the capsule

Data Fields
float radius
float halfHeight
struct NvFlexBoxGeometry

A simple box with interior [-halfHeight, +halfHeight] along each dimension

Data Fields
float halfExtents[3]
struct NvFlexConvexMeshGeometry

A convex mesh instance with non-uniform scale

Data Fields
float scale[3]
NvFlexConvexMeshId mesh
struct NvFlexTriangleMeshGeometry

A scaled triangle mesh instance with non-uniform scale

Data Fields
float scale[3] The scale of the object from local space to world space.
NvFlexTriangleMeshId mesh A triangle mesh pointer created by NvFlexCreateTriangleMesh()
struct NvFlexSDFGeometry

A scaled signed distance field instance, the local origin of the SDF is at corner of the field corresponding to the first voxel. The field is mapped to the local space volume [0, 1] in each dimension.

Data Fields
float scale Uniform scale of SDF, this corresponds to the world space width of the shape.
NvFlexDistanceFieldId field A signed distance field pointer created by NvFlexCreateDistanceField()
union NvFlexCollisionGeometry

This union allows collision geometry to be sent to Flex as a flat array of 16-byte data structures, the shape flags array specifies the type for each shape, see NvFlexSetShapes().

Data Fields
NvFlexSphereGeometry sphere
NvFlexCapsuleGeometry capsule
NvFlexBoxGeometry box
NvFlexConvexMeshGeometry convexMesh
NvFlexTriangleMeshGeometry triMesh
NvFlexSDFGeometry sdf
struct NvFlexDetailTimer

Holds the execution time for a specfic shader

Data Fields
char * name
float time

Typedef Documentation

typedef struct NvFlexLibrary NvFlexLibrary

Opaque type representing a library that can create FlexSolvers, FlexTriangleMeshes, and NvFlexBuffers

typedef struct NvFlexSolver NvFlexSolver

Opaque type representing a collection of particles and constraints

typedef struct NvFlexBuffer NvFlexBuffer

Opaque type representing a data buffer, type and contents depends on usage, see NvFlexAllocBuffer()

typedef void(* NvFlexErrorCallback) (NvFlexErrorSeverity type, const char *msg, const char *file, int line)

Function pointer type for error reporting callbacks

typedef unsigned int NvFlexTriangleMeshId

An opaque type representing a static triangle mesh in the solver

typedef unsigned int NvFlexDistanceFieldId

An opaque type representing a signed distance field collision shape in the solver.

typedef unsigned int NvFlexConvexMeshId

An opaque type representing a convex mesh collision shape in the solver. Convex mesh shapes may consist of up to 64 planes of the form a*x + b*y + c*z + d = 0, particles will be constrained to the outside of the shape.

Enumeration Type Documentation

Controls behavior of NvFlexMap()

Enumerator
eNvFlexMapWait 

Calling thread will be blocked until buffer is ready for access, default.

eNvFlexMapDoNotWait 

Calling thread will check if buffer is ready for access, if not ready then the method will return NULL immediately.

Controls memory space of a NvFlexBuffer, see NvFlexAllocBuffer()

Enumerator
eNvFlexBufferHost 

A host mappable buffer, pinned memory on CUDA, staging buffer on DX.

eNvFlexBufferDevice 

A device memory buffer, mapping this on CUDA will return a device memory pointer, and will return a buffer pointer on DX.

Controls the relaxation method used by the solver to ensure convergence

Enumerator
eNvFlexRelaxationGlobal 

The relaxation factor is a fixed multiplier on each constraint's position delta.

eNvFlexRelaxationLocal 

The relaxation factor is a fixed multiplier on each constraint's delta divided by the particle's constraint count, convergence will be slower but more reliable.

Flags that control a particle's behavior and grouping, use NvFlexMakePhase() to construct a valid 32bit phase identifier

Enumerator
eNvFlexPhaseGroupMask 

Bits [ 0, 19] represent the particle group for controlling collisions.

eNvFlexPhaseFlagsMask 

Bits [20, 23] hold flags about how the particle behave.

eNvFlexPhaseShapeChannelMask 

Bits [24, 31] hold flags representing what shape collision channels particles will collide with, see NvFlexMakeShapeFlags()

eNvFlexPhaseSelfCollide 

If set this particle will interact with particles of the same group.

eNvFlexPhaseSelfCollideFilter 

If set this particle will ignore collisions with particles closer than the radius in the rest pose, this flag should not be specified unless valid rest positions have been specified using NvFlexSetRestParticles()

eNvFlexPhaseFluid 

If set this particle will generate fluid density constraints for its overlapping neighbors.

eNvFlexPhaseUnused 

Reserved.

eNvFlexPhaseShapeChannel0 

Particle will collide with shapes with channel 0 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel1 

Particle will collide with shapes with channel 1 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel2 

Particle will collide with shapes with channel 2 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel3 

Particle will collide with shapes with channel 3 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel4 

Particle will collide with shapes with channel 4 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel5 

Particle will collide with shapes with channel 5 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel6 

Particle will collide with shapes with channel 6 set (see NvFlexMakeShapeFlags())

eNvFlexPhaseShapeChannel7 

Particle will collide with shapes with channel 7 set (see NvFlexMakeShapeFlags())

Flex error return codes

Enumerator
eNvFlexLogError 

Error messages.

eNvFlexLogInfo 

Information messages.

eNvFlexLogWarning 

Warning messages.

eNvFlexLogDebug 

Used only in debug version of dll.

eNvFlexLogAll 

All log types.

Defines the set of stages at which callbacks may be registered

Enumerator
eNvFlexStageIterationStart 

Called at the beginning of each constraint iteration.

eNvFlexStageIterationEnd 

Called at the end of each constraint iteration.

eNvFlexStageSubstepBegin 

Called at the beginning of each substep after the prediction step has been completed.

eNvFlexStageSubstepEnd 

Called at the end of each substep after the velocity has been updated by the constraints.

eNvFlexStageUpdateEnd 

Called at the end of solver update after the final substep has completed.

eNvFlexStageCount 

Number of stages.

Defines the different compute backends that Flex can use

Enumerator
eNvFlexCUDA 

Use CUDA compute for Flex, the application must link against the CUDA libraries.

eNvFlexD3D11 

Use DirectX 11 compute for Flex, the application must link against the D3D libraries.

eNvFlexD3D12 

Use DirectX 12 compute for Flex, the application must link against the D3D libraries.

Controls which features are enabled, choosing a simple option will disable features and can lead to better performance and reduced memory usage

Enumerator
eNvFlexFeatureModeDefault 

All features enabled.

eNvFlexFeatureModeSimpleSolids 

Simple per-particle collision (no per-particle SDF normals, no fluids)

eNvFlexFeatureModeSimpleFluids 

Simple single phase fluid-only particles (no solids)

Enumerator
eNvFlexShapeSphere 

A sphere shape, see FlexSphereGeometry.

eNvFlexShapeCapsule 

A capsule shape, see FlexCapsuleGeometry.

eNvFlexShapeBox 

A box shape, see FlexBoxGeometry.

eNvFlexShapeConvexMesh 

A convex mesh shape, see FlexConvexMeshGeometry.

eNvFlexShapeTriangleMesh 

A triangle mesh shape, see FlexTriangleMeshGeometry.

eNvFlexShapeSDF 

A signed distance field shape, see FlexSDFGeometry.

Enumerator
eNvFlexShapeFlagTypeMask 

Lower 3 bits holds the type of the collision shape given by the NvFlexCollisionShapeType enum.

eNvFlexShapeFlagDynamic 

Indicates the shape is dynamic and should have lower priority over static collision shapes.

eNvFlexShapeFlagTrigger 

Indicates that the shape is a trigger volume, this means it will not perform any collision response, but will be reported in the contacts array (see NvFlexGetContacts())

eNvFlexShapeFlagReserved 

Function Documentation

NV_FLEX_API int NvFlexMakePhaseWithChannels ( int  group,
int  particleFlags,
int  shapeChannels 
)
inline

Generate a bit set for the particle phase, this is a helper method to simply combine the group id and bit flags into a single integer.

Parameters
[in]groupThe index of the group for this particle, should be an integer < 2^20
[in]particleFlagsA combination of the phase flags which should be a combination of eNvFlexPhaseSelfCollide, eNvFlexPhaseSelfCollideFilter, and eNvFlexPhaseFluid
[in]shapeChannelsA combination of eNvFlexPhaseShapeChannel* flags that control which shapes will be collided against, particles will only collide against shapes that share at least one set channel, see NvFlexMakeShapeFlagsWithChannels()
NV_FLEX_API int NvFlexMakePhase ( int  group,
int  particleFlags 
)
inline

Deprecated helper method to generates a phase with all shape channels set

NV_FLEX_API NvFlexLibrary* NvFlexInit ( int  version = NV_FLEX_VERSION,
NvFlexErrorCallback  errorFunc = 0,
NvFlexInitDesc desc = 0 
)

Initialize library, should be called before any other API function.

Parameters
[in]versionThe version number the app is expecting, should almost always be NV_FLEX_VERSION
[in]errorFuncThe callback used for reporting errors.
[in]descThe NvFlexInitDesc struct defining the device ordinal, D3D device/context and the type of D3D compute being used
Returns
A pointer to a library instance that can be used to allocate shared object such as triangle meshes, buffers, etc
NV_FLEX_API void NvFlexShutdown ( NvFlexLibrary lib)

Shutdown library, users should manually destroy any previously created solvers to ensure memory is freed before calling this method. If a new CUDA context was created during NvFlexInit() then it will be destroyed.

Parameters
[in]libThe library intance to use
NV_FLEX_API int NvFlexGetVersion ( )

Get library version number

NV_FLEX_API void NvFlexSetSolverDescDefaults ( NvFlexSolverDesc desc)

Initialize the solver desc to its default values

Parameters
[in]descPointer to a description structure that will be initialized to default values
NV_FLEX_API NvFlexSolver* NvFlexCreateSolver ( NvFlexLibrary lib,
const NvFlexSolverDesc desc 
)

Create a new particle solver

Parameters
[in]libThe library instance to use
[in]descPointer to a solver description structure used to create the solver
NV_FLEX_API void NvFlexDestroySolver ( NvFlexSolver solver)

Delete a particle solver

Parameters
[in]solverA valid solver pointer created from NvFlexCreateSolver()
NV_FLEX_API NvFlexLibrary* NvFlexGetSolverLibrary ( NvFlexSolver solver)

Return the library associated with a solver

Parameters
[in]solverA valid solver created with NvFlexCreateSolver()
Returns
A library pointer
NV_FLEX_API void NvFlexGetSolverDesc ( NvFlexSolver solver,
NvFlexSolverDesc desc 
)

Return the solver desc that was used to create a solver

Parameters
[in]solverPointer to a valid Flex solver
[in]descPointer to a desc structure
NV_FLEX_API NvFlexSolverCallback NvFlexRegisterSolverCallback ( NvFlexSolver solver,
NvFlexSolverCallback  function,
NvFlexSolverCallbackStage  stage 
)

Registers a callback for a solver stage, the callback will be invoked from the same thread that calls NvFlexUpdateSolver().

Parameters
[in]solverA valid solver
[in]functionA pointer to a function that will be called during the solver update
[in]stageThe stage of the update at which the callback function will be called
Returns
The previously registered callback for this slot, this allows multiple users to chain callbacks together
NV_FLEX_API void NvFlexUpdateSolver ( NvFlexSolver solver,
float  dt,
int  substeps,
bool  enableTimers 
)

Integrate particle solver forward in time. Below is an example of how to step Flex in the context of a simple game loop:

NvFlexSolver* solver = NvFlexCreateSolver(library);
NvFlexBuffer* particleBuffer = NvFlexAllocBuffer(library, n, sizeof(Vec4), eNvFlexBufferHost);
NvFlexBuffer* velocityBuffer = NvFlexAllocBuffer(library, n, sizeof(Vec4), eNvFlexBufferHost);
NvFlexBuffer* phaseBuffer = NvFlexAllocBuffer(library, n, sizeof(int), eNvFlexBufferHost);
while(!done)
{
// map buffers for reading / writing
float4* particles = (float4*)NvFlexMap(particles, eNvFlexMapWait);
float3* velocities = (float3*)NvFlexMap(velocities, eNvFlexMapWait);
int* phases = (int*)NvFlexMap(phases, eNvFlexMapWait);
// spawn (user method)
SpawnParticles(particles, velocities, phases);
// render (user method)
RenderParticles(particles, velocities, phases);
// unmap buffers
NvFlexUnmap(particleBuffer);
NvFlexUnmap(velocityBuffer);
NvFlexUnmap(phaseBuffer);
// write to device (async)
NvFlexSetParticles(particleBuffer, n);
NvFlexSetVelocities(velocityBuffer, n);
NvFlexSetPhases(phaseBuffer, n);
// tick
NvFlexUpdateSolver(solver, dt, 1, NULL);
// read back (async)
NvFlexGetParticles(particleBuffer, n);
NvFlexGetVelocities(velocityBuffer, n);
NvFlexGetPhases(phaseBuffer, n);
}
NvFlexFreeBuffer(particleBuffer);
NvFlexFreeBuffer(velocityBuffer);
NvFlexFreeBuffer(phaseBuffer);
NvFlexShutdown(library);
Parameters
[in]solverA valid solver
[in]dtTime to integrate the solver forward in time by
[in]substepsThe time dt will be divided into the number of sub-steps given by this parameter
[in]enableTimersWhether to enable per-kernel timers for profiling. Note that profiling can substantially slow down overall performance so this param should only be true in non-release builds
NV_FLEX_API void NvFlexSetParams ( NvFlexSolver solver,
const NvFlexParams params 
)

Update solver paramters

Parameters
[in]solverA valid solver
[in]paramsParameters structure in host memory, see NvFlexParams
NV_FLEX_API void NvFlexGetParams ( NvFlexSolver solver,
NvFlexParams params 
)

Retrieve solver paramters, default values will be set at solver creation time

Parameters
[in]solverA valid solver
[out]paramsParameters structure in host memory, see NvFlexParams
NV_FLEX_API void NvFlexSetActive ( NvFlexSolver solver,
NvFlexBuffer indices,
const NvFlexCopyDesc desc 
)

Set the active particles indices in the solver

Parameters
[in]solverA valid solver
[in]indicesHolds the indices of particles that have been made active
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetActive ( NvFlexSolver solver,
NvFlexBuffer indices,
const NvFlexCopyDesc desc 
)

Return the active particle indices

Parameters
[in]solverA valid solver
[out]indicesa buffer of indices at least activeCount in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetActiveCount ( NvFlexSolver solver,
int  n 
)

Set the total number of active particles

Parameters
[in]solverA valid solver
[in]nThe number of active particles, the first n indices in the active particles array will be used as the active count
NV_FLEX_API int NvFlexGetActiveCount ( NvFlexSolver solver)

Return the number of active particles in the solver

Parameters
[in]solverA valid solver
Returns
The number of active particles in the solver
NV_FLEX_API void NvFlexSetParticles ( NvFlexSolver solver,
NvFlexBuffer p,
const NvFlexCopyDesc desc 
)

Set the particles state of the solver, a particle consists of 4 floating point numbers, its x,y,z position followed by its inverse mass (1/m)

Parameters
[in]solverA valid solver
[in]pPointer to a buffer of particle data, should be 4*n in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetParticles ( NvFlexSolver solver,
NvFlexBuffer p,
const NvFlexCopyDesc desc 
)

Get the particles state of the solver, a particle consists of 4 floating point numbers, its x,y,z position followed by its inverse mass (1/m)

Parameters
[in]solverA valid solver
[out]pPointer to a buffer of 4*n floats that will be filled out with the particle data, can be either a host or device pointer
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetRestParticles ( NvFlexSolver solver,
NvFlexBuffer p,
const NvFlexCopyDesc desc 
)

Set the particle positions in their rest state, if eNvFlexPhaseSelfCollideFilter is set on the particle's phase attribute then particles that overlap in the rest state will not generate collisions with each other

Parameters
[in]solverA valid solver
[in]pPointer to a buffer of particle data, should be 4*n in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetRestParticles ( NvFlexSolver solver,
NvFlexBuffer p,
const NvFlexCopyDesc desc 
)

Get the particle positions in their rest state

Parameters
[in]solverA valid solver
[in]pPointer to a buffer of particle data, should be 4*n in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetSmoothParticles ( NvFlexSolver solver,
NvFlexBuffer p,
const NvFlexCopyDesc desc 
)

Get the Laplacian smoothed particle positions for rendering, see NvFlexParams::smoothing

Parameters
[in]solverA valid solver
[out]pPointer to a buffer of 4*n floats that will be filled out with the data, can be either a host or device pointer
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetVelocities ( NvFlexSolver solver,
NvFlexBuffer v,
const NvFlexCopyDesc desc 
)

Set the particle velocities, each velocity is a 3-tuple of x,y,z floating point values

Parameters
[in]solverA valid solver
[in]vPointer to a buffer of 3*n floats
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetVelocities ( NvFlexSolver solver,
NvFlexBuffer v,
const NvFlexCopyDesc desc 
)

Get the particle velocities, each velocity is a 3-tuple of x,y,z floating point values

Parameters
[in]solverA valid solver
[out]vPointer to a buffer of 3*n floats that will be filled out with the data, can be either a host or device pointer
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetPhases ( NvFlexSolver solver,
NvFlexBuffer phases,
const NvFlexCopyDesc desc 
)

Set the particles phase id array, each particle has an associated phase id which controls how it interacts with other particles. Particles with phase 0 interact with all other phase types.

Particles with a non-zero phase id only interact with particles whose phase differs from theirs. This is useful, for example, to stop particles belonging to a single rigid shape from interacting with each other.

Phase 0 is used to indicate fluid particles when NvFlexParams::mFluid is set.

Parameters
[in]solverA valid solver
[in]phasesPointer to a buffer of n integers containing the phases
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetPhases ( NvFlexSolver solver,
NvFlexBuffer phases,
const NvFlexCopyDesc desc 
)

Get the particle phase ids

Parameters
[in]solverA valid solver
[out]phasesPointer to a buffer of n integers that will be filled with the phase data, can be either a host or device pointer
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetNormals ( NvFlexSolver solver,
NvFlexBuffer normals,
const NvFlexCopyDesc desc 
)

Set per-particle normals to the solver, these will be overwritten after each simulation step, but can be used to initialize the normals to valid values

Parameters
[in]solverA valid solver
[in]normalsPointer to a buffer of normals, should be 4*n in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexGetNormals ( NvFlexSolver solver,
NvFlexBuffer normals,
const NvFlexCopyDesc desc 
)

Get per-particle normals from the solver, these are the world-space normals computed during surface tension, cloth, and rigid body calculations

Parameters
[in]solverA valid solver
[out]normalsPointer to a buffer of normals, should be 4*n in length
[in]descDescribes the copy region, if NULL the solver will try to access the entire buffer (maxParticles length)
NV_FLEX_API void NvFlexSetSprings ( NvFlexSolver solver,
NvFlexBuffer indices,
NvFlexBuffer restLengths,
NvFlexBuffer stiffness,
int  numSprings 
)

Set distance constraints for the solver. Each distance constraint consists of two particle indices stored consecutively, a rest-length, and a stiffness value. These are not springs in the traditional sense, but behave somewhat like a traditional spring when lowering the stiffness coefficient.

Parameters
[in]solverA valid solver
[in]indicesPointer to the spring indices array, should be 2*numSprings length, 2 indices per-spring
[in]restLengthsPointer to a buffer of rest lengths, should be numSprings length
[in]stiffnessPointer to the spring stiffness coefficents, should be numSprings in length, a negative stiffness value represents a tether constraint
[in]numSpringsThe number of springs to set
NV_FLEX_API void NvFlexGetSprings ( NvFlexSolver solver,
NvFlexBuffer indices,
NvFlexBuffer restLengths,
NvFlexBuffer stiffness,
int  numSprings 
)

Get the distance constraints from the solver

Parameters
[in]solverA valid solver
[out]indicesPointer to the spring indices array, should be 2*numSprings length, 2 indices per-spring
[out]restLengthsPointer to a buffer of rest lengths, should be numSprings length
[out]stiffnessPointer to the spring stiffness coefficents, should be numSprings in length, a negative stiffness value represents a unilateral tether constraint (only resists stretching, not compression), valid range [-1, 1]
[in]numSpringsThe number of springs to get
NV_FLEX_API void NvFlexSetRigids ( NvFlexSolver solver,
NvFlexBuffer offsets,
NvFlexBuffer indices,
NvFlexBuffer restPositions,
NvFlexBuffer restNormals,
NvFlexBuffer stiffness,
NvFlexBuffer thresholds,
NvFlexBuffer creeps,
NvFlexBuffer rotations,
NvFlexBuffer translations,
int  numRigids,
int  numIndices 
)

Set rigid body constraints for the solver.

Note
A particle should not belong to more than one rigid body at a time.
Parameters
[in]solverA valid solver
[in]offsetsPointer to a buffer of start offsets for a rigid in the indices array, should be numRigids+1 in length, the first entry must be 0
[in]indicesPointer to a buffer of indices for the rigid bodies, the indices for the jth rigid body start at indices[offsets[j]] and run to indices[offsets[j+1]] exclusive
[in]restPositionsPointer to a buffer of local space positions relative to the rigid's center of mass (average position), this should be at least 3*numIndices in length in the format x,y,z
[in]restNormalsPointer to a buffer of local space normals, this should be at least 4*numIndices in length in the format x,y,z,w where w is the (negative) signed distance of the particle inside its shape
[in]stiffnessPointer to a buffer of rigid stiffness coefficents, should be numRigids in length, valid values in range [0, 1]
[in]thresholdsPointer to a buffer of plastic deformation threshold coefficients, should be numRigids in length
[in]creepsPointer to a buffer of plastic deformation creep coefficients, should be numRigids in length, valid values in range [0, 1]
[in]rotationsPointer to a buffer of quaternions (4*numRigids in length)
[in]translationsPointer to a buffer of translations of the center of mass (3*numRigids in length)
[in]numRigidsThe number of rigid bodies to set
[in]numIndicesThe number of indices in the indices array
NV_FLEX_API void NvFlexGetRigids ( NvFlexSolver solver,
NvFlexBuffer offsets,
NvFlexBuffer indices,
NvFlexBuffer restPositions,
NvFlexBuffer restNormals,
NvFlexBuffer stiffness,
NvFlexBuffer thresholds,
NvFlexBuffer creeps,
NvFlexBuffer rotations,
NvFlexBuffer translations 
)

Retrive the rigid body shape matching constraints and transforms, if any buffer pointers are NULL then they will be ignored This method supersedes the previous NvFlexGetRigidTransforms method and can be used to retrieve modified rest positions from plastic deformation.

Parameters
[in]solverA valid solver
[in]offsetsPointer to a buffer of start offsets for a rigid in the indices array, should be numRigids+1 in length, the first entry must be 0
[in]indicesPointer to a buffer of indices for the rigid bodies, the indices for the jth rigid body start at indices[offsets[j]] and run to indices[offsets[j+1]] exclusive
[in]restPositionsPointer to a buffer of local space positions relative to the rigid's center of mass (average position), this should be at least 3*numIndices in length in the format x,y,z
[in]restNormalsPointer to a buffer of local space normals, this should be at least 4*numIndices in length in the format x,y,z,w where w is the (negative) signed distance of the particle inside its shape
[in]stiffnessPointer to a buffer of rigid stiffness coefficents, should be numRigids in length, valid values in range [0, 1]
[in]thresholdsPointer to a buffer of plastic deformation threshold coefficients, should be numRigids in length
[in]creepsPointer to a buffer of plastic deformation creep coefficients, should be numRigids in length, valid values in range [0, 1]
[in]rotationsPointer to a buffer of quaternions (4*numRigids in length with the imaginary elements in the x,y,z components)
[in]translationsPointer to a buffer of translations of the center of mass (3*numRigids in length)
NV_FLEX_API NvFlexTriangleMeshId NvFlexCreateTriangleMesh ( NvFlexLibrary lib)

Create triangle mesh geometry, note that meshes may be used by multiple solvers if desired

Parameters
[in]libThe library instance to use
Returns
A pointer to a triangle mesh object
NV_FLEX_API void NvFlexDestroyTriangleMesh ( NvFlexLibrary lib,
NvFlexTriangleMeshId  mesh 
)

Destroy a triangle mesh created with NvFlexCreateTriangleMesh()

Parameters
[in]libThe library instance to use
[in]meshA triangle mesh created with NvFlexCreateTriangleMesh()
NV_FLEX_API void NvFlexUpdateTriangleMesh ( NvFlexLibrary lib,
NvFlexTriangleMeshId  mesh,
NvFlexBuffer vertices,
NvFlexBuffer indices,
int  numVertices,
int  numTriangles,
const float *  lower,
const float *  upper 
)

Specifies the triangle mesh geometry (vertices and indices), this method will cause any internal data structures (e.g.: bounding volume hierarchies) to be rebuilt.

Parameters
[in]libThe library instance to use
[in]meshA triangle mesh created with NvFlexCreateTriangleMesh()
[in]verticesPointer to a buffer of float3 vertex positions
[in]indicesPointer to a buffer of triangle indices, should be length numTriangles*3
[in]numVerticesThe number of vertices in the vertices array
[in]numTrianglesThe number of triangles in the mesh
[in]lowerA pointer to a float3 vector holding the lower spatial bounds of the mesh
[in]upperA pointer to a float3 vector holding the upper spatial bounds of the mesh
NV_FLEX_API void NvFlexGetTriangleMeshBounds ( NvFlexLibrary lib,
const NvFlexTriangleMeshId  mesh,
float *  lower,
float *  upper 
)

Retrieve the local space bounds of the mesh, these are the same values specified to NvFlexUpdateTriangleMesh()

Parameters
[in]libThe library instance to use
[in]meshPointer to a triangle mesh object
[out]lowerPointer to a buffer of 3 floats that the lower mesh bounds will be written to
[out]upperPointer to a buffer of 3 floats that the upper mesh bounds will be written to
NV_FLEX_API NvFlexDistanceFieldId NvFlexCreateDistanceField ( NvFlexLibrary lib)

Create a signed distance field collision shape, see NvFlexDistanceFieldId for details.

Parameters
[in]libThe library instance to use
Returns
A pointer to a signed distance field object
NV_FLEX_API void NvFlexDestroyDistanceField ( NvFlexLibrary lib,
NvFlexDistanceFieldId  sdf 
)

Destroy a signed distance field

Parameters
[in]libThe library instance to use
[in]sdfA signed distance field created with NvFlexCreateDistanceField()
NV_FLEX_API void NvFlexUpdateDistanceField ( NvFlexLibrary lib,
NvFlexDistanceFieldId  sdf,
int  dimx,
int  dimy,
int  dimz,
NvFlexBuffer field 
)

Update the signed distance field volume data, this method will upload the field data to a 3D texture on the GPU

Parameters
[in]libThe library instance to use
[in]sdfA signed distance field created with NvFlexCreateDistanceField()
[in]dimxThe x-dimension of the volume data in voxels
[in]dimyThe y-dimension of the volume data in voxels
[in]dimzThe z-dimension of the volume data in voxels
[in]fieldThe volume data stored such that the voxel at the x,y,z coordinate is addressed as field[z*dimx*dimy + y*dimx + x]
NV_FLEX_API NvFlexConvexMeshId NvFlexCreateConvexMesh ( NvFlexLibrary lib)

Create a convex mesh collision shape, see NvFlexConvexMeshId for details.

Parameters
[in]libThe library instance to use
Returns
A pointer to a signed distance field object
NV_FLEX_API void NvFlexDestroyConvexMesh ( NvFlexLibrary lib,
NvFlexConvexMeshId  convex 
)

Destroy a convex mesh

Parameters
[in]libThe library instance to use
[in]convexA a convex mesh created with NvFlexCreateConvexMesh()
NV_FLEX_API void NvFlexUpdateConvexMesh ( NvFlexLibrary lib,
NvFlexConvexMeshId  convex,
NvFlexBuffer planes,
int  numPlanes,
const float *  lower,
const float *  upper 
)

Update the convex mesh geometry

Parameters
[in]libThe library instance to use
[in]convexA valid convex mesh shape created from NvFlexCreateConvexMesh()
[in]planesAn array of planes, each plane consists of 4 floats in the form a*x + b*y + c*z + d = 0
[in]numPlanesThe number of planes in the convex, must be less than 64 planes per-convex
[in]lowerThe local space lower bound of the convex shape
[in]upperThe local space upper bound of the convex shape
NV_FLEX_API void NvFlexGetConvexMeshBounds ( NvFlexLibrary lib,
NvFlexConvexMeshId  mesh,
float *  lower,
float *  upper 
)

Retrieve the local space bounds of the mesh, these are the same values specified to NvFlexUpdateConvexMesh()

Parameters
[in]libThe library instance to use
[in]meshPointer to a convex mesh object
[out]lowerPointer to a buffer of 3 floats that the lower mesh bounds will be written to
[out]upperPointer to a buffer of 3 floats that the upper mesh bounds will be written to
NV_FLEX_API int NvFlexMakeShapeFlagsWithChannels ( NvFlexCollisionShapeType  type,
bool  dynamic,
int  shapeChannels 
)
inline

Helper function to combine shape type, flags, and phase/shape collision channels into a 32bit value

Parameters
[in]typeThe type of the shape, see NvFlexCollisionShapeType
[in]dynamicSee eNvFlexShapeFlagDynamic
[in]shapeChannelsA combination of the eNvFlexPhaseShapeChannel* flags, collisions will only be processed between a particle and a shape if a channel is set on both the particle and shape, see NvFlexMakePhaseWithChannels()
NV_FLEX_API int NvFlexMakeShapeFlags ( NvFlexCollisionShapeType  type,
bool  dynamic 
)
inline

Deprecrated helper method that creates shape flags that by default have all collision channels enabled

NV_FLEX_API void NvFlexSetShapes ( NvFlexSolver solver,
NvFlexBuffer geometry,
NvFlexBuffer shapePositions,
NvFlexBuffer shapeRotations,
NvFlexBuffer shapePrevPositions,
NvFlexBuffer shapePrevRotations,
NvFlexBuffer shapeFlags,
int  numShapes 
)

Set the collision shapes for the solver

Parameters
[in]solverA valid solver
[in]geometryPointer to a buffer of NvFlexCollisionGeometry entries, the type of each shape determines how many entries it has in the array
[in]shapePositionsPointer to a buffer of translations for each shape in world space, should be 4*numShapes in length
[in]shapeRotationsPointer to an a buffer of rotations for each shape stored as quaternion, should be 4*numShapes in length
[in]shapePrevPositionsPointer to a buffer of translations for each shape at the start of the time step, should be 4*numShapes in length
[in]shapePrevRotationsPointer to an a buffer of rotations for each shape stored as a quaternion at the start of the time step, should be 4*numShapees in length
[in]shapeFlagsThe type and behavior of the shape, NvFlexCollisionShapeFlags for more detail
[in]numShapesThe number of shapes
NV_FLEX_API void NvFlexSetDynamicTriangles ( NvFlexSolver solver,
NvFlexBuffer indices,
NvFlexBuffer normals,
int  numTris 
)

Set dynamic triangles mesh indices, typically used for cloth. Flex will calculate normals and apply wind and drag effects to connected particles. See NvFlexParams::drag, NvFlexParams::wind.

Parameters
[in]solverA valid solver
[in]indicesPointer to a buffer of triangle indices into the particles array, should be 3*numTris in length
[in]normalsPointer to a buffer of triangle normals, should be 3*numTris in length, can be NULL
[in]numTrisThe number of dynamic triangles s
NV_FLEX_API void NvFlexGetDynamicTriangles ( NvFlexSolver solver,
NvFlexBuffer indices,
NvFlexBuffer normals,
int  numTris 
)

Get the dynamic triangle indices and normals.

Parameters
[in]solverA valid solver
[out]indicesPointer to a buffer of triangle indices into the particles array, should be 3*numTris in length, if NULL indices will not be returned
[out]normalsPointer to a buffer of triangle normals, should be 3*numTris in length, if NULL normals will be not be returned
[in]numTrisThe number of dynamic triangles
NV_FLEX_API void NvFlexSetInflatables ( NvFlexSolver solver,
NvFlexBuffer startTris,
NvFlexBuffer numTris,
NvFlexBuffer restVolumes,
NvFlexBuffer overPressures,
NvFlexBuffer constraintScales,
int  numInflatables 
)

Set inflatable shapes, an inflatable is a range of dynamic triangles (wound CCW) that represent a closed mesh. Each inflatable has a given rest volume, constraint scale (roughly equivalent to stiffness), and "over pressure" that controls how much the shape is inflated.

Parameters
[in]solverA valid solver
[in]startTrisPointer to a buffer of offsets into the solver's dynamic triangles for each inflatable, should be numInflatables in length
[in]numTrisPointer to a buffer of triangle counts for each inflatable, should be numInflatablesin length
[in]restVolumesPointer to a buffer of rest volumes for the inflatables, should be numInflatables in length
[in]overPressuresPointer to a buffer of floats specifying the pressures for each inflatable, a value of 1.0 means the rest volume, > 1.0 means over-inflated, and < 1.0 means under-inflated, should be numInflatables in length
[in]constraintScalesPointer to a buffer of scaling factors for the constraint, this is roughly equivalent to stiffness but includes a constraint scaling factor from position-based dynamics, see helper code for details, should be numInflatables in length
[in]numInflatablesNumber of inflatables to set
NV_FLEX_API void NvFlexGetDensities ( NvFlexSolver solver,
NvFlexBuffer densities,
const NvFlexCopyDesc desc 
)

Get the density values for fluid particles

Parameters
[in]solverA valid solver
[out]densitiesPointer to a buffer of floats, should be maxParticles in length, density values are normalized between [0, 1] where 1 represents the rest density
[in]descPointer to a descriptor specifying the contents to read back
NV_FLEX_API void NvFlexGetAnisotropy ( NvFlexSolver solver,
NvFlexBuffer q1,
NvFlexBuffer q2,
NvFlexBuffer q3,
const NvFlexCopyDesc desc 
)

Get the anisotropy of fluid particles, the particle distribution for a particle is represented by 3 orthogonal vectors. Each 3-vector has unit length with the variance along that axis packed into the w component, i.e.: x,y,z,lambda.

The anisotropy defines an oriented ellipsoid in worldspace that can be used for rendering or surface extraction.

Parameters
[in]solverA valid solver
[out]q1Pointer to a buffer of floats that receive the first basis vector and scale, should be 4*maxParticles in length
[out]q2Pointer to a buffer of floats that receive the second basis vector and scale, should be 4*maxParticles in length
[out]q3Pointer to a buffer of floats that receive the third basis vector and scale, should be 4*maxParticles in length
[in]descPointer to a descriptor specifying the contents to read back
NV_FLEX_API void NvFlexGetDiffuseParticles ( NvFlexSolver solver,
NvFlexBuffer p,
NvFlexBuffer v,
NvFlexBuffer count 
)

Get the state of the diffuse particles. Diffuse particles are passively advected by the fluid velocity field.

Parameters
[in]solverA valid solver
[out]pPointer to a buffer of floats, should be 4*maxParticles in length, the w component represents the particles lifetime with 1 representing a new particle, and 0 representing an inactive particle
[out]vPointer to a buffer of floats, should be 4*maxParticles in length, the w component is not used
[out]countPointer to a buffer of a single int that holds the current particle count (this may be updated by the GPU which is why it is passed back in a buffer)
NV_FLEX_API void NvFlexSetDiffuseParticles ( NvFlexSolver solver,
NvFlexBuffer p,
NvFlexBuffer v,
int  n 
)

Set the state of the diffuse particles. Diffuse particles are passively advected by the fluid velocity field.

Parameters
[in]solverA valid solver
[in]pPointer to a buffer of floats, should be 4*n in length, the w component represents the particles lifetime with 1 representing a new particle, and 0 representing an inactive particle
[in]vPointer to a buffer of floats, should be 4*n in length, the w component is not used
[in]nThe number of active diffuse particles
NV_FLEX_API void NvFlexGetContacts ( NvFlexSolver solver,
NvFlexBuffer planes,
NvFlexBuffer velocities,
NvFlexBuffer indices,
NvFlexBuffer counts 
)

Get the particle contact planes. Note this will only include contacts that were active on the last substep of an update, and will include all contact planes generated within NvFlexParams::shapeCollisionMargin.

Parameters
[in]solverA valid solver
[out]planesPointer to a destination buffer containing the contact planes for the particle, each particle can have up to 6 contact planes so this buffer should be 4*6*maxParticles floats in length
[out]velocitiesPointer to a destination buffer containing the velocity of the contact point on the shape in world space, the index of the shape (corresponding to the shape in NvFlexSetShapes() is stored in the w component), each particle can have up to 6 contact planes so this buffer should be 4*6*maxParticles floats in length
[out]indicesPointer to a buffer of indices into the contacts buffer, the first contact plane for the i'th particle is given by planes[indices[i]*sizeof(float)*4*6] and subsequent contact planes for that particle are stored sequentially, this array should be maxParticles in length
[out]countsPointer to a buffer of contact counts for each particle (will be <= 6), this buffer should be maxParticles in length
NV_FLEX_API void NvFlexGetNeighbors ( NvFlexSolver solver,
NvFlexBuffer neighbors,
NvFlexBuffer counts,
NvFlexBuffer remap 
)

Get the particle neighbor lists, these are stored in a strided format, and can be iterated in the following manner:

NvFlexGetNeighbors(solver, neighborsBuffer, countsBuffer, indicesBuffer);
int* neighbors = (int*)NvFlexMap(neighborsBuffer, 0);
int* counts = (int*)NvFlexMap(countsBuffer, 0);
int* remap = (int*)NvFlexMap(remapBuffer, 0);
// neighbors are stored in a strided format so that the first neighbor
// of each particle is stored sequentially, then the second, and so on
int stride = maxParticles;
for (int i=0; i < maxParticles; ++i)
{
// find offset in the neighbors buffer
int offset = remap[i];
int count = counts[offset];
for (int c=0; c < count; ++c)
{
int neighbor = remap[neighbors[c*stride + offset]];
printf("Particle %d's neighbor %d is particle %d\n", i, c, neighbor);
}
}
NvFlexUnmap(neighborsBuffer);
NvFlexUnmap(countsBuffer);
NvFlexUnmap(remapBuffer);
Parameters
[in]solverA valid solver
[out]neighborsPointer to a destination buffer containing the the neighbors for all particles, this should be maxParticles*maxParticleNeighbors ints (passed to NvFlexInit() in length)
[out]countsPointer to a buffer of neighbor counts per-particle, should be maxParticles ints in length
[out]remapPointer to a buffer of indices, because Flex internally re-orders particles these are used to map from an API particle index to it internal index
Note
Neighbors are only valid after a call to NvFlexUpdateSolver() has completed, the returned neighbors correspond to the last substep of the last update
NV_FLEX_API void NvFlexGetBounds ( NvFlexSolver solver,
NvFlexBuffer lower,
NvFlexBuffer upper 
)

Get the world space AABB of all particles in the solver, note that the bounds are calculated during the update (see NvFlexUpdateSolver()) so only become valid after an update has been performed. The returned bounds represent bounds of the particles in their predicted positions before the constraint solve.

Parameters
[in]solverA valid solver
[out]lowerPointer to a buffer of 3 floats to receive the lower bounds
[out]upperPointer to a buffer of 3 floats to receive the upper bounds
NV_FLEX_API float NvFlexGetDeviceLatency ( NvFlexSolver solver,
unsigned long long *  begin,
unsigned long long *  end,
unsigned long long *  frequency 
)
Parameters
[in]solverA valid solver
[out]beginOptional pointer to a 64 bit unsigned to receive the value of the GPU clock when Flex update began (in cycles)
[out]endOptional pointer to a 64 bit unsigned to receive the value of the GPU clock when Flex update ended (in cycles)
[out]frequencyOptional pointer to a 64 bit unsigned to receive the frequency of the clock used to measure begin and end
Returns
The time in seconds between the first and last GPU operations executed by the last NvFlexUpdateSolver.
Note
This method causes the CPU to wait until the GPU has finished any outstanding work. To avoid blocking the calling thread it should be called after work has completed, e.g.: directly after a NvFlexMap().
NV_FLEX_API void NvFlexGetTimers ( NvFlexSolver solver,
NvFlexTimers timers 
)

Fetch high-level GPU timers.

Parameters
[in]solverThe solver instance to use
[out]timersA struct containing the GPU latency of each stage in the physics pipeline.
Note
This method causes the CPU to wait until the GPU has finished any outstanding work. To avoid blocking the calling thread it should be called after work has completed, e.g.: directly after a NvFlexMap(). To capture there timers you must pass true for enableTimers in NvFlexUpdateSolver()
NV_FLEX_API int NvFlexGetDetailTimers ( NvFlexSolver solver,
NvFlexDetailTimer **  timers 
)

Fetch per-shader GPU timers.

Parameters
[in]solverThe solver instance to use
[out]timersAn array of NvFlexDetailTimer structures, each representing a unique shader.
Returns
The number of detail timers in the timers array
Note
This method causes the CPU to wait until the GPU has finished any outstanding work. To avoid blocking the calling thread it should be called after work has completed, e.g.: directly after a NvFlexMap(). To capture there timers you must pass true for enableTimers in NvFlexUpdateSolver() Timers are valid until the next call to NvFlexGetDetailTimers
NV_FLEX_API NvFlexBuffer* NvFlexAllocBuffer ( NvFlexLibrary lib,
int  elementCount,
int  elementByteStride,
NvFlexBufferType  type 
)

Allocate a Flex buffer. Buffers are used to pass data to the API in an efficient manner.

Parameters
[in]libThe library instance to use
[in]elementCountThe number of elements in the buffer
[in]elementByteStrideThe size of each element in bytes
[in]typeThe type of buffer to allocate, can be either host memory or device memory
Returns
A pointer to a NvFlexBuffer
NV_FLEX_API void NvFlexFreeBuffer ( NvFlexBuffer buf)

Free a Flex buffer

Parameters
[in]bufA buffer to free, must be allocated with NvFlexAllocBuffer()
NV_FLEX_API void* NvFlexMap ( NvFlexBuffer buffer,
int  flags 
)

Maps a buffer for reading and writing. When the buffer is created with NvFlexBufferType::eHost, then the returned pointer will be a host memory address that can be read/written. Mapping a buffer implicitly synchronizes with the GPU to ensure that any reads or writes from the buffer (e.g.: from the NvFlexGet*() or NvFlexSet*() methods) have completed.

Parameters
[in]bufferA buffer allocated with NvFlexAllocBuffer()
[in]flagsHints to Flex how the buffer is to be accessed, typically this should be eNvFlexMapWait (0)
Returns
A pointer to the mapped memory
NV_FLEX_API void NvFlexUnmap ( NvFlexBuffer buffer)

Unmaps a buffer that was mapped through NvFlexMap(), note that buffers must be unmapped before they can be passed to a NvFlexGet*() or NvFlexSet*() method

Parameters
[in]bufferA valid buffer allocated through NvFlexAllocBuffer()
NV_FLEX_API NvFlexBuffer* NvFlexRegisterOGLBuffer ( NvFlexLibrary lib,
int  buf,
int  elementCount,
int  elementByteStride 
)

Registers an OpenGL buffer to Flex which can be used to copy directly into a graphics resource. Example usage is below

GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW)
NvFlexBuffer* vboBuffer = NvFlexRegisterOGLBuffer(lib, vbo, n, sizeof(float)*4);
// simulate
...
// copy directly from Flex into render buffer
NvFlexGetParticles(vboBuffer, n);
// render
...
Parameters
[in]libThe library instance to use
[in]bufAn OpenGL buffer identifier
[in]elementCountThe number of elements in the buffer
[in]elementByteStridethe size of each element in bytes
Returns
A valid NvFlexBuffer pointer that may be used with NvFlexGet*() methods to populate the render buffer using direct GPU-GPU copies
NV_FLEX_API void NvFlexUnregisterOGLBuffer ( NvFlexBuffer buf)

Unregister a NvFlexBuffer allocated through NvFlexRegisterOGLBuffer()

Parameters
[in]bufA valid buffer
NV_FLEX_API NvFlexBuffer* NvFlexRegisterD3DBuffer ( NvFlexLibrary lib,
void *  buffer,
int  elementCount,
int  elementByteStride 
)

Registers a Direct3D buffer to Flex which can be used to copy directly into a graphics resource

Parameters
[in]libThe library instance to use
[in]bufferA pointer to either an ID3D11Buffer or ID3D12Resource object
[in]elementCountThe number of elements in the buffer
[in]elementByteStridethe size of each element in bytes
Returns
A valid NvFlexBuffer pointer that may be used with NvFlexGet*() methods to populate the render buffer using direct GPU-GPU copies
NV_FLEX_API void NvFlexUnregisterD3DBuffer ( NvFlexBuffer buf)

Unregister a NvFlexBuffer allocated through NvFlexRegistereD3DBuffer()

Parameters
[in]bufA valid buffer
NV_FLEX_API void NvFlexAcquireContext ( NvFlexLibrary lib)

Ensures that the CUDA context the library was initialized with is present on the current thread

Parameters
[in]libThe library instance to use
NV_FLEX_API void NvFlexRestoreContext ( NvFlexLibrary lib)

Restores the CUDA context (if any) that was present on the last call to NvFlexAcquireContext() Note: the acquire/restore pair of calls must come from the same thread

NV_FLEX_API const char* NvFlexGetDeviceName ( NvFlexLibrary lib)

Returns a null-terminated string with the compute device name

Parameters
[in]libThe library instance to use
NV_FLEX_API void NvFlexGetDeviceAndContext ( NvFlexLibrary lib,
void **  device,
void **  context 
)

Retrieve the device and context for the the library. On CUDA the context pointer will be filled with a pointer to a CUcontext structure On D3D the device and context pointers will be filled with pointers to a NvFlex::Device, and NvFlex::Context wrapper

Parameters
[in]libPointer to a valid library returned from NvFlexInit()
[out]devicePointer to a device pointer, see description
[out]contextPointer to a context pointer, see description
NV_FLEX_API void NvFlexFlush ( NvFlexLibrary lib)

Force a pipeline flush to ensure any queued work is submitted to the GPU

Parameters
[in]libThe library instance to use
NV_FLEX_API void NvFlexWait ( NvFlexLibrary lib)