FLEX  0.8
Data Structures | Enumerations | Functions
flexExt.h File Reference

Go to the source code of this file.

Data Structures

struct  FlexExtAsset
 
struct  FlexExtInstance
 
struct  FlexExtForceField
 

Enumerations

enum  FlexForceExtMode {
  eFlexExtModeForce = 0,
  eFlexExtModeImpulse = 1,
  eFlexExtModeVelocityChange = 2
}
 

Functions

FLEX_API int flexExtCreateWeldedMeshIndices (const float *vertices, int numVertices, int *uniqueVerts, int *originalToUniqueMap, float threshold)
 
FLEX_API FlexExtAssetflexExtCreateClothFromMesh (const float *particles, int numVertices, const int *indices, int numTriangles, float stretchStiffness, float bendStiffness, float tetherStiffness, float tetherGive, float pressure)
 
FLEX_API FlexExtAssetflexExtCreateRigidFromMesh (const float *vertices, int numVertices, const int *indices, int numTriangleIndices, float radius)
 
FLEX_API void flexExtDestroyAsset (FlexExtAsset *asset)
 
FLEX_API FlexExtContainer * flexExtCreateContainer (FlexSolver *solver, int maxParticles)
 
FLEX_API void flexExtDestroyContainer (FlexExtContainer *container)
 
FLEX_API int flexExtAllocParticles (FlexExtContainer *container, int n, int *indices)
 
FLEX_API void flexExtFreeParticles (FlexExtContainer *container, int n, const int *indices)
 
FLEX_API int flexExtGetActiveList (FlexExtContainer *container, int *indices)
 
FLEX_API FlexExtInstanceflexExtCreateInstance (FlexExtContainer *container, const FlexExtAsset *asset, const float *transform, float vx, float vy, float vz, int phase, float invMassScale)
 
FLEX_API void flexExtDestroyInstance (FlexExtContainer *container, const FlexExtInstance *instance)
 
FLEX_API void flexExtGetParticleData (FlexExtContainer *container, float **particles, float **velocities, int **phases, float **normals)
 
FLEX_API void flexExtGetTriangleData (FlexExtContainer *container, int **indices, float **normals)
 
FLEX_API void flexExtGetRigidData (FlexExtContainer *container, float **rotations, float **positions)
 
FLEX_API void flexExtTickContainer (FlexExtContainer *container, float dt, int numSubsteps, FlexTimers *timers=NULL)
 
FLEX_API void flexExtPushToDevice (FlexExtContainer *container)
 
FLEX_API void flexExtPullFromDevice (FlexExtContainer *container)
 
FLEX_API void flexExtSetForceFields (FlexExtContainer *container, const FlexExtForceField *forceFields, int numForceFields, FlexMemory source)
 
FLEX_API void flexExtApplyForceFields (FlexExtContainer *container, float dt)
 

Data Structure Documentation

struct FlexExtAsset

Represents a group of particles and constraints, each asset can be instanced into a simulation using flexExtCreateInstance

Data Fields
float * mParticles Local space particle positions, x,y,z,1/mass.
int mNumParticles Number of particles.
int * mSpringIndices Spring indices.
float * mSpringCoefficients Spring coefficients.
float * mSpringRestLengths Spring rest-lengths.
int mNumSprings Number of springs.
float mRigidStiffness Rigid body constraint stiffness.
float mRigidCenter[3] Local space center of mass of the particles.
int * mTriangleIndices Indexed triangle mesh for clothing.
int mNumTriangles Number of triangles.
bool mInflatable Whether an inflatable constraint should be added.
float mInflatableVolume The rest volume for the inflatable constraint.
float mInflatablePressure How much over the rest volume the inflatable should attempt to maintain.
float mInflatableStiffness How stiff the inflatable is.
struct FlexExtInstance

Represents an instance of a FlexAsset in a container

Data Fields
int * mParticleIndices Simulation particle indices.
int mNumParticles Number of simulation particles.
int mTriangleIndex Index in the container's triangle array.
int mRigidIndex Index in the container's rigid body constraints array.
int mInflatableIndex Index in the container's inflatables array.
const FlexExtAsset * mAsset Source asset used to create this instance.
void * mUserData User data pointer.
struct FlexExtForceField

Force field data, currently just supports radial fields

Data Fields
float mPosition[3] Center of force field.
float mRadius Radius of the force field.
float mStrength Strength of the force field.
FlexForceExtMode mMode Mode of field application.
bool mLinearFalloff Linear or no falloff.

Enumeration Type Documentation

Controls the way that force fields affect particles

Enumerator
eFlexExtModeForce 

Apply field value as a force.

eFlexExtModeImpulse 

Apply field value as an impulse.

eFlexExtModeVelocityChange 

Apply field value as a velocity change.

Function Documentation

FLEX_API int flexExtCreateWeldedMeshIndices ( const float *  vertices,
int  numVertices,
int *  uniqueVerts,
int *  originalToUniqueMap,
float  threshold 
)

Create an index buffer of unique vertices in the mesh

Parameters
[in]verticesA pointer to an array of float3 positions
[in]numVerticesThe number of vertices in the mesh
[out]uniqueVertsA list of unique mesh vertex indices, should be numVertices in length (worst case all verts are unique)
[out]originalToUniqueMapMapping from the original vertex index to the unique vertex index, should be numVertices in length
[in]thresholdThe distance below which two vertices are considered duplicates
Returns
The number of unique vertices in the mesh
FLEX_API FlexExtAsset* flexExtCreateClothFromMesh ( const float *  particles,
int  numVertices,
const int *  indices,
int  numTriangles,
float  stretchStiffness,
float  bendStiffness,
float  tetherStiffness,
float  tetherGive,
float  pressure 
)

Create a cloth asset consisting of stretch and bend distance constraints given an indexed triangle mesh. Stretch constraints will be placed along triangle edges, while bending constraints are placed over two edges.

Parameters
[in]particlesPositions and masses of the particles in the format [x, y, z, 1/m]
[in]numVerticesThe number of particles
[in]indicesThe triangle indices, these should be 'welded' using flexExtCreateWeldedMeshIndices() first
[in]numTrianglesThe number of triangles
[in]stretchStiffnessThe stiffness coefficient for stretch constraints
[in]bendStiffnessThe stiffness coefficient used for bending constraints
[in]tetherStiffnessIf > 0.0f then the function will create tether's attached to particles with zero inverse mass. These are unilateral, long-range attachments, which can greatly reduce stretching even at low iteration counts.
[in]tetherGiveBecause tether constraints are so effective at reducing stiffness, it can be useful to allow a small amount of extension before the constraint activates.
[in]pressureIf > 0.0f then a volume (pressure) constraint will also be added to the asset, the rest volume and stiffness will be automatically computed by this function
Returns
A pointer to an asset structure holding the particles and constraints
FLEX_API FlexExtAsset* flexExtCreateRigidFromMesh ( const float *  vertices,
int  numVertices,
const int *  indices,
int  numTriangleIndices,
float  radius 
)

Create a rigid body asset from a closed triangle mesh. The mesh is first voxelized at a spacing specified by the radius, and particles are placed at occupied voxels.

Parameters
[in]verticesVertices of the triangle mesh
[in]numVerticesThe number of vertices
[in]indicesThe triangle indices
[in]numTriangleIndicesThe number of triangles indices (triangles*3)
[in]radiusThe spacing used for voxelization, note that the number of voxels grows proportional to the inverse cube of radius, currently this method limits construction to resolutions < 64^3
Returns
A pointer to an asset structure holding the particles and constraints
FLEX_API void flexExtDestroyAsset ( FlexExtAsset asset)

Frees all memory associated with an asset created by one of the creation methods param[in] asset The asset to destroy.

FLEX_API FlexExtContainer* flexExtCreateContainer ( FlexSolver *  solver,
int  maxParticles 
)

Creates a wrapper object around a Flex solver that can hold assets / instances

Parameters
[in]solverThe solver to wrap
[in]maxParticlesThe maximum number of particles to manage
Returns
A pointer to the new container
FLEX_API void flexExtDestroyContainer ( FlexExtContainer *  container)

Frees all memory associated with a container

Parameters
[in]containerThe container to destroy
FLEX_API int flexExtAllocParticles ( FlexExtContainer *  container,
int  n,
int *  indices 
)

Allocates particles in the container.

Parameters
[in]containerThe container to allocate out of
[in]nThe number of particles to allocate
[out]indicesAn n-length array of ints that will store the indices to the allocated particles
FLEX_API void flexExtFreeParticles ( FlexExtContainer *  container,
int  n,
const int *  indices 
)

Free allocated particles

Parameters
[in]containerThe container to free from
[in]nThe number of particles to free
[in]indicesThe indices of the particles to free
FLEX_API int flexExtGetActiveList ( FlexExtContainer *  container,
int *  indices 
)

Retrives the indices of all active particles

Parameters
[in]containerThe container to free from
[out]indicesReturns the number of active particles
Returns
The number of active particles
FLEX_API FlexExtInstance* flexExtCreateInstance ( FlexExtContainer *  container,
const FlexExtAsset asset,
const float *  transform,
float  vx,
float  vy,
float  vz,
int  phase,
float  invMassScale 
)

Creates an instance of an asset, the container will internally store a reference to the asset so it should remain valid for the instance lifetime. This method will allocate particles for the asset, assign their initial positions, velocity and phase.

Parameters
[in]containerThe container to spawn into
[in]assetThe asset to be spawned
[in]transformA pointer to a 4x4 column major, column vector transform that specifies the initial world space configuration of the particles
[in]vxThe velocity of the particles along the x axis
[in]vyThe velocity of the particles along the y axis
[in]vzThe velocity of the particles along the z axis
[in]phaseThe phase used for the particles
[in]invMassScaleA factor applied to the per particle inverse mass
Returns
A pointer to the instance of the asset
FLEX_API void flexExtDestroyInstance ( FlexExtContainer *  container,
const FlexExtInstance instance 
)

Destoy an instance of an asset

Parameters
[in]containerThe container the instance belongs to
[in]instanceThe instance to destroy
FLEX_API void flexExtGetParticleData ( FlexExtContainer *  container,
float **  particles,
float **  velocities,
int **  phases,
float **  normals 
)

Returns pointers to the internal data stored by the container. These are host-memory pointers, and will remain valid until the container is destroyed. They can be used to read and write particle data, but only after suitable synchronization. See flexExtTickContainer() for details.

Parameters
containerThe container whose data should be accessed
particlesReceives a pointer to the particle position / mass data
velocitiesReceives a pointer to the particle velocity data
phasesReceives a pointer to the particle phase data
normalsReceives a pointer to the particle normal data with 16 byte stride in format [nx, ny, nz, nw]
FLEX_API void flexExtGetTriangleData ( FlexExtContainer *  container,
int **  indices,
float **  normals 
)

Access triangle constraint data, see flexExtGetParticleData() for notes on ownership.

Parameters
containerThe container to retrive from
indicesReceives a pointer to the array of triangle index data
normalsReceives a pointer to an array of triangle normal data stored with 16 byte stride, i.e.: [nx, ny, nz]
FLEX_API void flexExtGetRigidData ( FlexExtContainer *  container,
float **  rotations,
float **  positions 
)

Access rigid body constraint data, see flexExtGetParticleData() for notes on ownership.

Parameters
containerThe container to retrive from
rotationsReceives a pointer to the array 3x3 rotation matrix data
positionsReceives a pointer to an array of rigid body translations in [x, y, z] format
FLEX_API void flexExtTickContainer ( FlexExtContainer *  container,
float  dt,
int  numSubsteps,
FlexTimers timers = NULL 
)

Updates the container, applies force fields, steps the solver forward in time, updates the host with the results synchronously. This is a helper function which performs a synchronous update using the following flow.

// async update GPU data
// update solver
flexUpdateSolver(container, dt, iterations);
// async read data back to CPU
// insert and wait on fence
// read / write particle data on CPU
flexExtGetParticleData(container, particles, velocities, phases, normals);
Parameters
[in]containerThe container to update
[in]dtThe time-step in seconds
[in]numSubstepsThe number of substeps to perform
[in]timersPointer to a Flex profiling structure, see flexUpdateSolver()
FLEX_API void flexExtPushToDevice ( FlexExtContainer *  container)

Updates the device asynchronously, transfers any particle and constraint changes to the flex solver, expected to be called in the following sequence: flexExtPushToDevice, [flexExtApplyForceFields,] flexUpdateSolver, flexExtPullFromDevice, flexSynchronize

Parameters
[in]containerThe container to update
FLEX_API void flexExtPullFromDevice ( FlexExtContainer *  container)

Updates the host asynchronously, transfers particle and constraint data back to he host, expected to be called in the following sequence: flexExtPushToDevice, [flexExtApplyForceFields,] flexUpdateSolver, flexExtPullFromDevice, flexSynchronize

Parameters
[in]containerThe container to update
FLEX_API void flexExtSetForceFields ( FlexExtContainer *  container,
const FlexExtForceField forceFields,
int  numForceFields,
FlexMemory  source 
)
FLEX_API void flexExtApplyForceFields ( FlexExtContainer *  container,
float  dt 
)