FLEX  0.8
Data Structures | Typedefs | Enumerations | Functions
flex.h File Reference

Go to the source code of this file.

Data Structures

struct  FlexParams
 
struct  FlexSDF
 
struct  FlexTimers
 

Typedefs

typedef void(* FlexErrorCallback) (const char *msg, const char *file, int line)
 

Enumerations

enum  FlexRelaxationMode {
  eFlexRelaxationGlobal = 0,
  eFlexRelaxationLocal = 1
}
 
enum  FlexPhase {
  eFlexPhaseGroupMask = 0x00ffffff,
  eFlexPhaseSelfCollide = 1 << 24,
  eFlexPhaseFluid = 1 << 25
}
 
enum  FlexError {
  eFlexErrorNone = 0,
  eFlexErrorWrongVersion = 1,
  eFlexErrorInsufficientGPU = 2
}
 
enum  FlexMemory {
  eFlexMemoryHost = 0,
  eFlexMemoryDevice = 1,
  eFlexMemoryHostAsync = 2,
  eFlexMemoryDeviceAsync = 3
}
 

Functions

FLEX_API int flexMakePhase (int group, int flags)
 
FLEX_API FlexError flexInit (int version=FLEX_VERSION, FlexErrorCallback errorFunc=NULL)
 
FLEX_API void flexShutdown ()
 
FLEX_API int flexGetVersion ()
 
FLEX_API FlexSolver * flexCreateSolver (int maxParticles, int maxDiffuseParticles, unsigned char maxNeighborsPerParticle=96)
 
FLEX_API void flexDestroySolver (FlexSolver *s)
 
FLEX_API void flexUpdateSolver (FlexSolver *s, float dt, int substeps, FlexTimers *timers)
 
FLEX_API void flexSetParams (FlexSolver *s, const FlexParams *params)
 
FLEX_API void flexSetActive (FlexSolver *s, const int *indices, int n, FlexMemory source)
 
FLEX_API void flexGetActive (FlexSolver *s, int *indices, FlexMemory target)
 
FLEX_API int flexGetActiveCount (FlexSolver *s)
 
FLEX_API void flexSetParticles (FlexSolver *s, const float *p, int n, FlexMemory source)
 
FLEX_API void flexGetParticles (FlexSolver *s, float *p, int n, FlexMemory target)
 
FLEX_API void flexGetSmoothParticles (FlexSolver *s, float *p, int n, FlexMemory target)
 
FLEX_API void flexSetVelocities (FlexSolver *s, const float *v, int n, FlexMemory source)
 
FLEX_API void flexGetVelocities (FlexSolver *s, float *v, int n, FlexMemory target)
 
FLEX_API void flexSetPhases (FlexSolver *s, const int *phases, int n, FlexMemory source)
 
FLEX_API void flexGetPhases (FlexSolver *s, int *phases, int n, FlexMemory target)
 
FLEX_API void flexSetSprings (FlexSolver *s, const int *indices, const float *restLengths, const float *stiffness, int numSprings, FlexMemory source)
 
FLEX_API void flexGetSprings (FlexSolver *s, int *indices, float *restLengths, float *stiffness, int numSprings, FlexMemory target)
 
FLEX_API void flexSetRigids (FlexSolver *s, const int *offsets, const int *indices, const float *restPositions, const float *restNormals, const float *stiffness, const float *rotations, int numRigids, FlexMemory source)
 
FLEX_API void flexSetNormals (FlexSolver *s, const float *normals, int n, FlexMemory source)
 
FLEX_API void flexGetNormals (FlexSolver *s, float *normals, int n, FlexMemory target)
 
FLEX_API void flexGetRigidTransforms (FlexSolver *s, float *rotations, float *translations, FlexMemory target)
 
FLEX_API void flexSetConvexes (FlexSolver *s, const float *aabbMin, const float *aabbMax, const int *planeOffsets, const int *planeCounts, const float *planes, const float *positions, const float *rotations, const float *prevPositions, const float *prevRotations, const int *flags, int numConvexes, int numPlanes, FlexMemory source)
 
FLEX_API void flexSetTriangles (FlexSolver *s, const int *indices, const float *vertices, int numTris, int numVertices, float cellSize, FlexMemory source)
 
FLEX_API void flexSetFields (FlexSolver *s, const FlexSDF *shapes, int numShapes)
 
FLEX_API void flexSetDynamicTriangles (FlexSolver *s, const int *indices, const float *normals, int numTris, FlexMemory source)
 
FLEX_API void flexGetDynamicTriangles (FlexSolver *s, int *indices, float *normals, int numTris, FlexMemory target)
 
FLEX_API void flexSetInflatables (FlexSolver *s, const int *startTris, const int *numTris, float *restVolumes, float *overPressures, float *constraintScales, int numInflatables, FlexMemory source)
 
FLEX_API void flexGetDensities (FlexSolver *s, float *densities, FlexMemory target)
 
FLEX_API void flexGetAnisotropy (FlexSolver *s, float *q1, float *q2, float *q3, FlexMemory target)
 
FLEX_API int flexGetDiffuseParticles (FlexSolver *s, float *p, float *v, int *indices, FlexMemory target)
 
FLEX_API void flexSetDiffuseParticles (FlexSolver *s, const float *p, const float *v, int n, FlexMemory source)
 
FLEX_API void flexGetContacts (FlexSolver *s, float *planes, int *indices, unsigned char *counts, FlexMemory target)
 
FLEX_API void flexGetBounds (FlexSolver *s, float *lower, float *upper)
 
FLEX_API void * flexAlloc (int size)
 
FLEX_API void flexFree (void *ptr)
 
FLEX_API void flexSetFence ()
 
FLEX_API void flexWaitFence ()
 

Data Structure Documentation

struct FlexParams
Data Fields
int mNumIterations Number of solver iterations to perform per-substep.
float mGravity[3] Constant acceleration applied to all particles.
float mRadius The maximum interaction radius for particles.
float mSolidRestDistance The distance non-fluid particles attempt to maintain from each other, must be in the range (0, radius].
float mFluidRestDistance 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 mDynamicFriction Coefficient of friction used when colliding against shapes.
float mStaticFriction Coefficient of static friction used when colliding against shapes.
float mParticleFriction Coefficient of friction used when colliding particles.
float mRestitution Coefficient of restitution used when colliding against shapes, particle collisions are always inelastic.
float mAdhesion Controls how strongly particles stick to surfaces they hit, default 0.0, range [0.0, +inf].
float mSleepThreshold Particles with a velocity magnitude < this threshold will be considered fixed.
float mMaxVelocity Particle velocity will be clamped to this value at the end of each step.
float mShockPropagation Artificially decrease the mass of particles based on height from a fixed reference point, this makes stacks and piles converge faster.
float mDissipation Damps particle velocity based on how many particle contacts it has.
float mDamping Viscous drag force, applies a force proportional, and opposite to the particle velocity.
float mEnableCCD If true then a second collision detection pass will be executed against triangle meshes to prevent tunneling, usually not necessary, only enable if having tunnelling problems.
float mWind[3] Constant acceleration applied to particles that belong to dynamic triangles, drag needs to be > 0 for wind to affect triangles.
float mDrag Drag force applied to particles belonging to dynamic triangles, proportional to velocity^2*area in the negative velocity direction.
float mLift 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.
bool mFluid If true then particles with phase 0 are considered fluid particles and interact using the position based fluids method.
float mCohesion Control how strongly particles hold each other together, default: 0.025, range [0.0, +inf].
float mSurfaceTension Controls how strongly particles attempt to minimize surface area, default: 0.0, range: [0.0, +inf].
float mViscosity Smoothes particle velocities using XSPH viscosity.
float mVorticityConfinement Increases vorticity by applying rotational forces to particles.
float mAnisotropyScale Control how much anisotropy is present in resulting ellipsoids for rendering, if zero then anisotropy will not be calculated, see flexGetAnisotropy()
float mSmoothing Control the strength of Laplacian smoothing in particles for rendering, if zero then smoothed positions will not be calculated, see flexGetSmoothParticles()
float mSolidPressure Add pressure from solid surfaces to particles.
float mFreeSurfaceDrag Drag force applied to boundary fluid particles.
float mBuoyancy Gravity is scaled by this value for fluid particles.
float mDiffuseThreshold Particles with kinetic energy + divergence above this threshold will spawn new diffuse particles.
float mDiffuseBuoyancy Scales force opposing gravity that diffuse particles receive.
float mDiffuseDrag Scales force diffuse particles receive in direction of neighbor fluid particles.
int mDiffuseBallistic The number of neighbors below which a diffuse particle is considered ballistic.
float mDiffuseSortAxis[3] Diffuse particles will be sorted by depth along this axis if non-zero.
float mPlasticThreshold Particles belonging to rigid shapes that move with a position delta magnitude > threshold will be permanently deformed in the rest pose.
float mPlasticCreep Controls the rate at which particles in the rest pose are deformed for particles passing the deformation threshold.
float mCollisionDistance Distance particles maintain against shapes.
float mParticleCollisionMargin 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 mShapeCollisionMargin Increases the radius used during contact finding against kinematic shapes.
float mPlanes[8][4] Collision planes in the form ax + by + cz + d = 0.
int mNumPlanes Num collision planes.
FlexRelaxationMode mRelaxationMode How the relaxation is applied inside the solver.
float mRelaxationFactor Control the convergence rate of the parallel solver, default: 1, values greater than 1 may lead to instability.
struct FlexSDF

Signed distance field collision shape, note that only cubic fields are currently supported (mWidth=mHeight=mDepth)

Data Fields
float mLower[3] Shape AABB lower bounds in world space.
float mUpper[3] Shape AABB upper bounds in world space.
float mInvEdgeLength[3] 1/(mUpper-mLower)
unsigned int mWidth Field x dimension in voxels.
unsigned int mHeight Field y dimension in voxels.
unsigned int mDepth Field z dimension in voxels.
const float * mField SDF voxel data, must be mWidth*mHeight*mDepth in length.
struct FlexTimers

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

Data Fields
float mPredict Time spent in prediction.
float mCreateCellIndices Time spent creating grid indices.
float mSortCellIndices Time spent sorting grid indices.
float mCreateGrid Time spent creating grid.
float mReorder Time spent reordering particles.
float mCollideParticles Time spent finding particle neighbors.
float mCollideConvexes Time spent colliding convex shapes.
float mCollideTriangles Time spent colliding triangle shapes.
float mCollideFields Time spent colliding signed distance field shapes.
float mCalculateDensity Time spent calculating fluid density.
float mSolveDensities Time spent solving density constraints.
float mSolveVelocities Time spent solving velocity constraints.
float mSolveShapes Time spent solving rigid body constraints.
float mSolveSprings Time spent solving distance constraints.
float mSolveContacts Time spent solving contact constraints.
float mSolveInflatables Time spent solving pressure constraints.
float mCalculateAnisotropy Time spent calculating particle anisotropy for fluid.
float mUpdateDiffuse Time spent updating diffuse particles.
float mUpdateTriangles Time spent updating dynamic triangles.
float mUpdateNormals Time spent updating vertex normals.
float mFinalize Time spent finalizing state.
float mUpdateBounds Time spent updating particle bounds.
float mTotal Sum of all timers above.

Typedef Documentation

typedef void(* FlexErrorCallback) (const char *msg, const char *file, int line)

Error reporting callback.

Enumeration Type Documentation

Simulation parameters for a solver

Enumerator
eFlexRelaxationGlobal 

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

eFlexRelaxationLocal 

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.

enum FlexPhase

Flags that control the a particle's behavior and grouping

Enumerator
eFlexPhaseGroupMask 

Low 24 bits represent the particle group for controlling collisions.

eFlexPhaseSelfCollide 

Flag specifying whether this particle will interact with particles of the same group.

eFlexPhaseFluid 

Flag specifying whether this particle will generate fluid density constraints for its overlapping neighbors.

enum FlexError

Flex error types

Enumerator
eFlexErrorNone 

The API call returned with no errors.

eFlexErrorWrongVersion 

The header version does not match the library binary.

eFlexErrorInsufficientGPU 

The GPU associated with the calling thread does not meet requirements. An SM3.0 GPU or above is required.

enum FlexMemory

Designates a memory space for getting/settings data to/from

Enumerator
eFlexMemoryHost 

Host (CPU) memory.

eFlexMemoryDevice 

Device (GPU) memory.

eFlexMemoryHostAsync 

Host (CPU) memory asynchronous, when used with a flexGet/flexSet method the memory transfer will be asynchronous and should be synchronized with flexWaitFence()

eFlexMemoryDeviceAsync 

Device (GPU) memory asynchronous, when used with a flexGet/flexSet method the memory transfer will be asynchronous and should be synchronized with flexWaitFence()

Function Documentation

FLEX_API int flexMakePhase ( int  group,
int  flags 
)
inline

Generate a bit set for the particle phase, the group should be an integer < 2^24, and the flags should be a combination of FlexPhase enum values

FLEX_API FlexError flexInit ( int  version = FLEX_VERSION,
FlexErrorCallback  errorFunc = NULL 
)

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

Note
Flex uses the calling thread's CUDA context for all operations so users should make sure the same context is used for all API calls (this should be the case if just using the default runtime context).
FLEX_API void flexShutdown ( )

Shutdown library, users should manually destroy any previously created solvers to ensure memory is freed before calling this method.

FLEX_API int flexGetVersion ( )

Get library version number

FLEX_API FlexSolver* flexCreateSolver ( int  maxParticles,
int  maxDiffuseParticles,
unsigned char  maxNeighborsPerParticle = 96 
)

Create a new particle solver

Parameters
[in]maxParticlesMaximum number of simulation particles possible for this solver
[in]maxDiffuseParticlesMaximum number of diffuse (non-simulation) particles possible for this solver
[in]maxNeighborsPerParticleMaximum number of neighbors per particle possible for this solver
FLEX_API void flexDestroySolver ( FlexSolver *  s)

Delete a particle solver

FLEX_API void flexUpdateSolver ( FlexSolver *  s,
float  dt,
int  substeps,
FlexTimers timers 
)

Move particle solver forward in time

Parameters
[in]sA 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
[out]timersIf non-NULL this struct will be filled out with profiling information for the step, note that profiling can substantially slow down overal performance so this param should only be non-NULL in non-release builds
FLEX_API void flexSetParams ( FlexSolver *  s,
const FlexParams params 
)

Update solver paramters

Parameters
[in]sA valid solver
[in]paramsParameters structure in host memory, see FlexParams
FLEX_API void flexSetActive ( FlexSolver *  s,
const int *  indices,
int  n,
FlexMemory  source 
)

Set the active particles indices in the solver

Parameters
[in]sA valid solver
[in]indicesHolds the indices of particles that have been made active
[in]nNumber of particles to allocate
[in]sourceThe memory space of the indices
FLEX_API void flexGetActive ( FlexSolver *  s,
int *  indices,
FlexMemory  target 
)

Return the active particle indices

Parameters
[in]sA valid solver
[out]indicesAn array of indices at least activeCount in length
[in]targetThe memory space of the destination buffer
FLEX_API int flexGetActiveCount ( FlexSolver *  s)

Return the number of active particles in the solver

Parameters
[in]sA valid solver
Returns
The number of active particles in the solver
FLEX_API void flexSetParticles ( FlexSolver *  s,
const float *  p,
int  n,
FlexMemory  source 
)

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

Parameters
[in]sA valid solver
[in]pPointer to an array of particle data, should be 4*n in length
[in]nThe number of particles to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetParticles ( FlexSolver *  s,
float *  p,
int  n,
FlexMemory  target 
)

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

Parameters
[in]sA valid solver
[out]pPointer to an array of 4*n floats that will be filled out with the particle data, can be either a host or device pointer
[in]nThe number of particles to get, must be less than max particles passed to flexCreateSolver
[in]targetThe memory space of the destination buffer
FLEX_API void flexGetSmoothParticles ( FlexSolver *  s,
float *  p,
int  n,
FlexMemory  target 
)

Get the Laplacian smoothed particle positions for rendering, see FlexParams::mSmoothing

Parameters
[in]sA valid solver
[out]pPointer to an array of 4*n floats that will be filled out with the data, can be either a host or device pointer
[in]nThe number of smooth particles to return
[in]targetThe memory space of the destination buffer
FLEX_API void flexSetVelocities ( FlexSolver *  s,
const float *  v,
int  n,
FlexMemory  source 
)

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

Parameters
[in]sA valid solver
[in]vPointer to an array of 3*n floats
[in]nThe number of velocities to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetVelocities ( FlexSolver *  s,
float *  v,
int  n,
FlexMemory  target 
)

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

Parameters
[in]sA valid solver
[out]vPointer to an array of 3*n floats that will be filled out with the data, can be either a host or device pointer
[in]nThe number of velocities to get
[in]targetThe memory space of the destination buffer
FLEX_API void flexSetPhases ( FlexSolver *  s,
const int *  phases,
int  n,
FlexMemory  source 
)

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 FlexParams::mFluid is set.

Parameters
[in]sA valid solver
[in]phasesPointer to an array of n integers containing the phases
[in]nThe number of phases to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetPhases ( FlexSolver *  s,
int *  phases,
int  n,
FlexMemory  target 
)

Get the particle phase ids

Parameters
[in]sA valid solver
[out]phasesPointer to an array of n integers that will be filled with the phase data, can be either a host or device pointer
[in]nThe number of phases to get
[in]targetThe memory space of the destination buffer
FLEX_API void flexSetSprings ( FlexSolver *  s,
const int *  indices,
const float *  restLengths,
const float *  stiffness,
int  numSprings,
FlexMemory  source 
)

Set spring constraints for the solver. Each spring consists of two particle indices stored consecutively, a rest-length, and a stiffness value.

Parameters
[in]sA valid solver
[in]indicesPointer to the spring indices array, should be 2*numSprings length, 2 indices per-spring
[in]restLengthsPointer to an array 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
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetSprings ( FlexSolver *  s,
int *  indices,
float *  restLengths,
float *  stiffness,
int  numSprings,
FlexMemory  target 
)

Get the spring constraints for the solver

Parameters
[in]sA valid solver
[out]indicesPointer to the spring indices array, should be 2*numSprings length, 2 indices per-spring
[out]restLengthsPointer to an array 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
[in]targetThe memory space of the destination buffers
FLEX_API void flexSetRigids ( FlexSolver *  s,
const int *  offsets,
const int *  indices,
const float *  restPositions,
const float *  restNormals,
const float *  stiffness,
const float *  rotations,
int  numRigids,
FlexMemory  source 
)

Set rigid body constraints for the solver.

Note
A particle should not belong to more than one rigid body at a time.
Parameters
[in]sA valid solver
[in]offsetsPointer to an array 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 an array 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 an array of local space positions relative to the rigid's center of mass (average position), this should be at least 4*numIndices in length in the format x,y,z,w
[in]restNormalsPointer to an array 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 it's shape
[in]stiffnessPointer to an array of rigid stiffness coefficents, should be numRigids in length, valid values in range [0, 1]
[in]rotationsPointer to an array of 3x3 rotation matrices (9*numRigids in length)
[in]numRigidsThe number of rigid bodies to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexSetNormals ( FlexSolver *  s,
const float *  normals,
int  n,
FlexMemory  source 
)

Set per-particle normals to the solver, these will be overwritten after each simulation step

Parameters
[in]sA valid solver
[in]normalsPointer to an array of normals, should be 4*n in length
[in]nThe number of normals to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetNormals ( FlexSolver *  s,
float *  normals,
int  n,
FlexMemory  target 
)

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

Parameters
[in]sA valid solver
[out]normalsPointer to an array of normals, should be 4*n in length
[in]nThe number of normals to get
[in]targetThe memory space of the destination buffer
FLEX_API void flexGetRigidTransforms ( FlexSolver *  s,
float *  rotations,
float *  translations,
FlexMemory  target 
)

Get the rotation matrices for the rigid bodies in the solver

Parameters
[in]sA valid solver
[out]rotationsPointer to an array of 3x3 rotation matrices to hold the rigid rotations, should be 9*numRigids floats in length
[out]translationsPointer to an array of vectors to hold the rigid translations, should be 3*numRigids floats in length
[in]targetThe memory space of the destination buffer
FLEX_API void flexSetConvexes ( FlexSolver *  s,
const float *  aabbMin,
const float *  aabbMax,
const int *  planeOffsets,
const int *  planeCounts,
const float *  planes,
const float *  positions,
const float *  rotations,
const float *  prevPositions,
const float *  prevRotations,
const int *  flags,
int  numConvexes,
int  numPlanes,
FlexMemory  source 
)

Set the convex collision shapes for the solver, the convex data is specified in structure of array (SOA) format.

Parameters
[in]sA valid solver
[in]aabbMinPoint to an array of lower AABB coordinates for each convex in world space, should be 4*numConvexes in length in x,y,z,* format
[in]aabbMaxPointer to an array of upper AABB coordinates for each convex in world space, should be 4*numConvexes in length in x,y,z,* format
[in]planeOffsetsPointer to an array of start offsets into the planes array for each convex, should be numConvexes in length
[in]planeCountsPointer to an array of counts representing the number of planes belonging to each convex, should be numConvexes in length
[in]planesPointer to an array of planes defining the convex shapes in ax + by + cz + d = 0 form, planes are specified in a local coordinate solver, should be 4*numPlanes in length
[in]positionsPointer to an array of translations for each convex in world space, should be 4*numConvexes in length
[in]rotationsPointer to an an array of rotations for each convex stored as quaternion, should be 4*numConvexes in length
[in]prevPositionsPointer to an array of translations for each convex at the start of the time step, should be 4*numConvexes in length
[in]prevRotationsPointer to an an array of rotations for each convex stored as a quaternion at the start of the time step, should be 4*numConvexes in length
[in]flagsWhether the convex is considered static (0), or dynamic (1), collisions with static shapes are prioritized over dynamic ones
[in]numConvexesThe number of convexes
[in]numPlanesThe total number of planes for all convexes
[in]sourceThe memory space of the source buffer
FLEX_API void flexSetTriangles ( FlexSolver *  s,
const int *  indices,
const float *  vertices,
int  numTris,
int  numVertices,
float  cellSize,
FlexMemory  source 
)

Set the triangle mesh collision data for the solver, triangles are treated as two-sided and collided using a continuous collison detection method to prevent tunnelling

Parameters
[in]sA valid solver
[in]indicesPointer to an array of triangle vertex indices, should be 3*numTris in length
[in]verticesPointer to an array of vertex positions in world space, should be 3*numPositions in length
[in]numTrisThe number of triangles
[in]numVerticesThe number of mesh vertices
[in]cellSizeThe size of grid cell used for broad phase collision culling, should be set relative to particle radius, e.g. 2*radius
[in]sourceThe memory space of the source buffer
FLEX_API void flexSetFields ( FlexSolver *  s,
const FlexSDF shapes,
int  numShapes 
)

Set the signed distance field collision shapes, see FlexSDF.

Parameters
[in]sA valid solver
[in]shapesPointer to an array of signed distance field shapes
[in]numShapesThe number of shapes
FLEX_API void flexSetDynamicTriangles ( FlexSolver *  s,
const int *  indices,
const float *  normals,
int  numTris,
FlexMemory  source 
)

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

Parameters
[in]sA valid solver
[in]indicesPointer to an array of triangle indices into the particles array, should be 3*numTris in length
[in]normalsPointer to an array of triangle normals, should be 3*numTris in length, can be NULL
[in]numTrisThe number of dynamic triangles
[in]sourceThe memory space of the source buffers
FLEX_API void flexGetDynamicTriangles ( FlexSolver *  s,
int *  indices,
float *  normals,
int  numTris,
FlexMemory  target 
)

Get the dynamic triangle indices and normals.

Parameters
[in]sA valid solver
[out]indicesPointer to an array of triangle indices into the particles array, should be 3*numTris in length, if NULL indices will not be returned
[out]normalsPointer to an array of triangle normals, should be 3*numTris in length, if NULL normals will be not be returned
[in]numTrisThe number of dynamic triangles
[in]targetThe memory space of the destination arrays
FLEX_API void flexSetInflatables ( FlexSolver *  s,
const int *  startTris,
const int *  numTris,
float *  restVolumes,
float *  overPressures,
float *  constraintScales,
int  numInflatables,
FlexMemory  source 
)

Set inflatable shapes, an inflatable is a range of dynamic triangles 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]sA valid solver
[in]startTrisPointer to an array of offsets into the solver's dynamic triangles for each inflatable, should be numInflatables in length
[in]numTrisPointer to an array of triangle counts for each inflatable, should be numInflatablesin length
[in]restVolumesPointer to an array of rest volumes for the inflatables, should be numInflatables in length
[in]overPressuresPointer to an array 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 an array 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
[in]sourceThe memory space of the source buffers
FLEX_API void flexGetDensities ( FlexSolver *  s,
float *  densities,
FlexMemory  target 
)

Get the density values for fluid particles

Parameters
[in]sA valid solver
[out]densitiesPointer to an array of floats, should be maxParticles in length, density values are normalized between [0, 1] where 1 represents the rest density
[in]targetThe memory space of the destination arrays
FLEX_API void flexGetAnisotropy ( FlexSolver *  s,
float *  q1,
float *  q2,
float *  q3,
FlexMemory  target 
)

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]sA valid solver
[out]q1Pointer to an array of floats that receive the first basis vector and scale, should be 4*maxParticles in length
[out]q2Pointer to an array of floats that receive the second basis vector and scale, should be 4*maxParticles in length
[out]q3Pointer to an array of floats that receive the third basis vector and scale, should be 4*maxParticles in length
[in]targetThe memory space of the destination arrays
FLEX_API int flexGetDiffuseParticles ( FlexSolver *  s,
float *  p,
float *  v,
int *  indices,
FlexMemory  target 
)

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

Parameters
[in]sA valid solver
[out]pPointer to an array 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 an array of floats, should be 4*maxParticles in length, the w component is not used
[out]indicesPointer to an array of ints that specify particle indices in depth sorted order, should be maxParticles in length, see FlexParams::mDiffuseSortDir
[in]targetThe memory space of the destination arrays
FLEX_API void flexSetDiffuseParticles ( FlexSolver *  s,
const float *  p,
const float *  v,
int  n,
FlexMemory  source 
)

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

Parameters
[in]sA valid solver
[in]pPointer to an array 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 an array of floats, should be 4*n in length, the w component is not used
[in]nNumber of diffuse particles to set
[in]sourceThe memory space of the source buffer
FLEX_API void flexGetContacts ( FlexSolver *  s,
float *  planes,
int *  indices,
unsigned char *  counts,
FlexMemory  target 
)

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 FlexParam::mShapeCollisionMargin.

Parameters
[in]sA valid solver
[out]planesPointer to a destination buffer containing the contact planes for the particle, each particle can have up to 4 contact planes so this buffer should be 16*maxParticles in length
[out]indicesPointer to an array of indices into the contacts buffer, the contact planes for the i'th particle are given by planes[indices[i]], should be maxParticles in length
[out]countsPointer to an array of contact counts for each particle (will be < 4), this buffer should be maxParticles in length
[in]targetThe memory space of the target buffers
FLEX_API void flexGetBounds ( FlexSolver *  s,
float *  lower,
float *  upper 
)

Get the world space AABB of all particles in the solver.

Parameters
[in]sA valid solver
[out]lowerPointer to an array of 3 floats to receive the lower bounds
[out]upperPointer to an array of 3 floats to receive the upper bounds
FLEX_API void* flexAlloc ( int  size)

Allocates size bytes of memory from the optimal memory pool. Using this function is optional, but when passed to flexGet/flexSet methods it may result in significantly faster transfers, memory used with async transfers should be allocated by this method to ensure optimal performance. For CUDA implementations this method will return pinned host memory from cudaMallocHost().

Parameters
[in]sizeThe number of bytes to alloc
Returns
pointer to the allocated memory
FLEX_API void flexFree ( void *  ptr)

Free memory allocated through flexAlloc

Parameters
[in]ptrPointer returned from flexAlloc
FLEX_API void flexSetFence ( )

Sets a fence that can be used to synchronize the calling thread with any outstanding GPU work, typically used with async transfers to ensure any flexGet/flexSet calls have completed.

// update solver
flexUpdateSolver(solver, dt, iterations, NULL);
// read back state
flexGetParticles(solver, &particles, n, eFlexMemoryHostAsync);
flexGetVelocities(solver, &velocities, n, eFlexMemoryHostAsync);
flexGetDensities(solver, &densities, n, eFlexMemoryHostAsync);
// insert fence
// perform asynchronous CPU work
// wait for queued work to finish
FLEX_API void flexWaitFence ( )

Wait's for the work scheduled before the last call to flexSetFence() to complete If flexSetFence() has not yet been called then this is function returns immediately