FLEX  0.8
flex.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2013-2015 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef FLEX_H
30 #define FLEX_H
31 
33 #if _WIN32
34 #define FLEX_API __declspec(dllexport)
35 #else
36 #define FLEX_API
37 #endif
38 
39 // least 2 significant digits define minor version, eg: 10 -> version 0.10
40 #define FLEX_VERSION 26
41 
43 
44 extern "C" {
45 
49 struct FlexSolver;
50 
55 {
58 };
59 
60 struct FlexParams
61 {
63 
64  float mGravity[3];
65  float mRadius;
68 
69  // common params
73  float mRestitution;
74  float mAdhesion;
76  float mMaxVelocity;
78  float mDissipation;
79  float mDamping;
80  float mEnableCCD;
81 
82  // cloth params
83  float mWind[3];
84  float mDrag;
85  float mLift;
86 
87  // fluid params
88  bool mFluid;
89  float mCohesion;
91  float mViscosity;
94  float mSmoothing;
97  float mBuoyancy;
98 
99  // diffuse params
102  float mDiffuseDrag;
104  float mDiffuseSortAxis[3];
105 
106  // rigid params
109 
110  // collision params
114 
115  float mPlanes[8][4];
117 
120 };
121 
126 {
127  eFlexPhaseGroupMask = 0x00ffffff,
128 
130  eFlexPhaseFluid = 1 << 25,
131 };
132 
136 FLEX_API inline int flexMakePhase(int group, int flags) { return (group & eFlexPhaseGroupMask) | flags; }
137 
141 struct FlexSDF
142 {
143  float mLower[3];
144  float mUpper[3];
145  float mInvEdgeLength[3];
146 
147  unsigned int mWidth;
148  unsigned int mHeight;
149  unsigned int mDepth;
150 
151  const float* mField;
152 };
153 
154 
159 {
160  float mPredict;
163  float mCreateGrid;
164  float mReorder;
172  float mSolveShapes;
180  float mFinalize;
182  float mTotal;
183 };
184 
185 
190 {
193 
196 
200 };
201 
202 
207 {
210 
213 
219 
225 };
226 
230 typedef void (*FlexErrorCallback)(const char* msg, const char* file, int line);
231 
239 FLEX_API FlexError flexInit(int version=FLEX_VERSION, FlexErrorCallback errorFunc=NULL);
240 
245 FLEX_API void flexShutdown();
246 
250 FLEX_API int flexGetVersion();
251 
259 FLEX_API FlexSolver* flexCreateSolver(int maxParticles, int maxDiffuseParticles, unsigned char maxNeighborsPerParticle = 96);
263 FLEX_API void flexDestroySolver(FlexSolver* s);
264 
273 FLEX_API void flexUpdateSolver(FlexSolver* s, float dt, int substeps, FlexTimers* timers);
274 
281 FLEX_API void flexSetParams(FlexSolver* s, const FlexParams* params);
282 
291 FLEX_API void flexSetActive(FlexSolver* s, const int* indices, int n, FlexMemory source);
292 
300 FLEX_API void flexGetActive(FlexSolver* s, int* indices, FlexMemory target);
301 
308 FLEX_API int flexGetActiveCount(FlexSolver* s);
309 
318 FLEX_API void flexSetParticles(FlexSolver* s, const float* p, int n, FlexMemory source);
327 FLEX_API void flexGetParticles(FlexSolver* s, float* p, int n, FlexMemory target);
328 
337 FLEX_API void flexGetSmoothParticles(FlexSolver* s, float* p, int n, FlexMemory target);
338 
347 FLEX_API void flexSetVelocities(FlexSolver* s, const float* v, int n, FlexMemory source);
356 FLEX_API void flexGetVelocities(FlexSolver* s, float* v, int n, FlexMemory target);
357 
374 FLEX_API void flexSetPhases(FlexSolver* s, const int* phases, int n, FlexMemory source);
383 FLEX_API void flexGetPhases(FlexSolver* s, int* phases, int n, FlexMemory target);
384 
396 FLEX_API void flexSetSprings(FlexSolver* s, const int* indices, const float* restLengths, const float* stiffness, int numSprings, FlexMemory source);
407 FLEX_API void flexGetSprings(FlexSolver* s, int* indices, float* restLengths, float* stiffness, int numSprings, FlexMemory target);
408 
423 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);
424 
433 FLEX_API void flexSetNormals(FlexSolver* s, const float* normals, int n, FlexMemory source);
434 
443 FLEX_API void flexGetNormals(FlexSolver* s, float* normals, int n, FlexMemory target);
444 
453 FLEX_API void flexGetRigidTransforms(FlexSolver* s, float* rotations, float* translations, FlexMemory target);
454 
474 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);
486 FLEX_API void flexSetTriangles(FlexSolver* s, const int* indices, const float* vertices, int numTris, int numVertices, float cellSize, FlexMemory source);
494 FLEX_API void flexSetFields(FlexSolver* s, const FlexSDF* shapes, int numShapes);
495 
506 FLEX_API void flexSetDynamicTriangles(FlexSolver* s, const int* indices, const float* normals, int numTris, FlexMemory source);
516 FLEX_API void flexGetDynamicTriangles(FlexSolver* s, int* indices, float* normals, int numTris, FlexMemory target);
517 
532 FLEX_API void flexSetInflatables(FlexSolver* s, const int* startTris, const int* numTris, float* restVolumes, float* overPressures, float* constraintScales, int numInflatables, FlexMemory source);
533 
541 FLEX_API void flexGetDensities(FlexSolver* s, float* densities, FlexMemory target);
556 FLEX_API void flexGetAnisotropy(FlexSolver* s, float* q1, float* q2, float* q3, FlexMemory target);
567 FLEX_API int flexGetDiffuseParticles(FlexSolver* s, float* p, float* v, int* indices, FlexMemory target);
578 FLEX_API void flexSetDiffuseParticles(FlexSolver* s, const float* p, const float* v, int n, FlexMemory source);
579 
589 FLEX_API void flexGetContacts(FlexSolver* s, float* planes, int* indices, unsigned char* counts, FlexMemory target);
590 
598 FLEX_API void flexGetBounds(FlexSolver* s, float* lower, float* upper);
599 
610 FLEX_API void* flexAlloc(int size);
611 
617 FLEX_API void flexFree(void* ptr);
618 
643 FLEX_API void flexSetFence();
644 
650 FLEX_API void flexWaitFence();
651 
653 
657 FLEX_API void flexSetDebug(FlexSolver* s, bool enable);
658 FLEX_API void flexGetConvexGrid(FlexSolver* s, int* grid, float* lower, float* upper, int* axis);
659 FLEX_API void flexGetStaticTriangleGrid(FlexSolver* s, int* counts, float* lower, float* cellEdge);
660 FLEX_API void flexStartRecord(FlexSolver* s, const char* file);
661 FLEX_API void flexStopRecord(FlexSolver* s);
662 
664 
665 } // extern "C"
666 
667 #endif // FLEX_H
float mSleepThreshold
Particles with a velocity magnitude < this threshold will be considered fixed.
Definition: flex.h:75
float mUpdateNormals
Time spent updating vertex normals.
Definition: flex.h:179
FlexPhase
Definition: flex.h:125
void(* FlexErrorCallback)(const char *msg, const char *file, int line)
Definition: flex.h:230
unsigned int mDepth
Field z dimension in voxels.
Definition: flex.h:149
float mCohesion
Control how strongly particles hold each other together, default: 0.025, range [0.0, +inf].
Definition: flex.h:89
FLEX_API void flexGetNormals(FlexSolver *s, float *normals, int n, FlexMemory target)
float mBuoyancy
Gravity is scaled by this value for fluid particles.
Definition: flex.h:97
FLEX_API void flexGetSmoothParticles(FlexSolver *s, float *p, int n, FlexMemory target)
float mStaticFriction
Coefficient of static friction used when colliding against shapes.
Definition: flex.h:71
float mSolveVelocities
Time spent solving velocity constraints.
Definition: flex.h:171
float mSolidRestDistance
The distance non-fluid particles attempt to maintain from each other, must be in the range (0...
Definition: flex.h:66
FLEX_API void flexGetSprings(FlexSolver *s, int *indices, float *restLengths, float *stiffness, int numSprings, FlexMemory target)
FLEX_API int flexGetVersion()
float mRelaxationFactor
Control the convergence rate of the parallel solver, default: 1, values greater than 1 may lead to in...
Definition: flex.h:119
Definition: flex.h:158
int mDiffuseBallistic
The number of neighbors below which a diffuse particle is considered ballistic.
Definition: flex.h:103
float mMaxVelocity
Particle velocity will be clamped to this value at the end of each step.
Definition: flex.h:76
float mAdhesion
Controls how strongly particles stick to surfaces they hit, default 0.0, range [0.0, +inf].
Definition: flex.h:74
FLEX_API FlexError flexInit(int version=FLEX_VERSION, FlexErrorCallback errorFunc=NULL)
int mNumIterations
Number of solver iterations to perform per-substep.
Definition: flex.h:62
float mCollideFields
Time spent colliding signed distance field shapes.
Definition: flex.h:168
float mCreateGrid
Time spent creating grid.
Definition: flex.h:163
FLEX_API void flexSetActive(FlexSolver *s, const int *indices, int n, FlexMemory source)
FLEX_API void flexGetParticles(FlexSolver *s, float *p, int n, FlexMemory target)
float mGravity[3]
Constant acceleration applied to all particles.
Definition: flex.h:64
FlexRelaxationMode mRelaxationMode
How the relaxation is applied inside the solver.
Definition: flex.h:118
FLEX_API void flexGetBounds(FlexSolver *s, float *lower, float *upper)
float mCalculateDensity
Time spent calculating fluid density.
Definition: flex.h:169
float mCreateCellIndices
Time spent creating grid indices.
Definition: flex.h:161
FLEX_API void flexWaitFence()
float mPlasticThreshold
Particles belonging to rigid shapes that move with a position delta magnitude > threshold will be per...
Definition: flex.h:107
FLEX_API void flexSetNormals(FlexSolver *s, const float *normals, int n, FlexMemory source)
The GPU associated with the calling thread does not meet requirements. An SM3.0 GPU or above is requi...
Definition: flex.h:199
float mDamping
Viscous drag force, applies a force proportional, and opposite to the particle velocity.
Definition: flex.h:79
The relaxation factor is a fixed multiplier on each constraint's delta divided by the particle's cons...
Definition: flex.h:57
float mPlanes[8][4]
Collision planes in the form ax + by + cz + d = 0.
Definition: flex.h:115
float mCollideParticles
Time spent finding particle neighbors.
Definition: flex.h:165
float mDrag
Drag force applied to particles belonging to dynamic triangles, proportional to velocity^2*area in th...
Definition: flex.h:84
float mAnisotropyScale
Control how much anisotropy is present in resulting ellipsoids for rendering, if zero then anisotropy...
Definition: flex.h:93
FLEX_API void flexSetFields(FlexSolver *s, const FlexSDF *shapes, int numShapes)
float mUpper[3]
Shape AABB upper bounds in world space.
Definition: flex.h:144
float mSolveDensities
Time spent solving density constraints.
Definition: flex.h:170
Device (GPU) memory asynchronous, when used with a flexGet/flexSet method the memory transfer will be...
Definition: flex.h:224
float mDiffuseSortAxis[3]
Diffuse particles will be sorted by depth along this axis if non-zero.
Definition: flex.h:104
float mDiffuseBuoyancy
Scales force opposing gravity that diffuse particles receive.
Definition: flex.h:101
float mSurfaceTension
Controls how strongly particles attempt to minimize surface area, default: 0.0, range: [0...
Definition: flex.h:90
float mLift
Lift force applied to particles belonging to dynamic triangles, proportional to velocity^2*area in th...
Definition: flex.h:85
float mInvEdgeLength[3]
1/(mUpper-mLower)
Definition: flex.h:145
float mSolidPressure
Add pressure from solid surfaces to particles.
Definition: flex.h:95
float mLower[3]
Shape AABB lower bounds in world space.
Definition: flex.h:143
float mShockPropagation
Artificially decrease the mass of particles based on height from a fixed reference point...
Definition: flex.h:77
The header version does not match the library binary.
Definition: flex.h:195
unsigned int mHeight
Field y dimension in voxels.
Definition: flex.h:148
float mSolveShapes
Time spent solving rigid body constraints.
Definition: flex.h:172
float mPlasticCreep
Controls the rate at which particles in the rest pose are deformed for particles passing the deformat...
Definition: flex.h:108
float mFinalize
Time spent finalizing state.
Definition: flex.h:180
float mDiffuseThreshold
Particles with kinetic energy + divergence above this threshold will spawn new diffuse particles...
Definition: flex.h:100
FlexRelaxationMode
Definition: flex.h:54
Device (GPU) memory.
Definition: flex.h:212
float mReorder
Time spent reordering particles.
Definition: flex.h:164
float mCollisionDistance
Distance particles maintain against shapes.
Definition: flex.h:111
FLEX_API void flexGetContacts(FlexSolver *s, float *planes, int *indices, unsigned char *counts, FlexMemory target)
FlexMemory
Definition: flex.h:206
Definition: flex.h:141
float mViscosity
Smoothes particle velocities using XSPH viscosity.
Definition: flex.h:91
FLEX_API void flexSetSprings(FlexSolver *s, const int *indices, const float *restLengths, const float *stiffness, int numSprings, FlexMemory source)
FLEX_API void flexGetDynamicTriangles(FlexSolver *s, int *indices, float *normals, int numTris, FlexMemory target)
FLEX_API void flexSetPhases(FlexSolver *s, const int *phases, int n, FlexMemory source)
FLEX_API void flexSetDynamicTriangles(FlexSolver *s, const int *indices, const float *normals, int numTris, FlexMemory source)
Flag specifying whether this particle will generate fluid density constraints for its overlapping nei...
Definition: flex.h:130
float mTotal
Sum of all timers above.
Definition: flex.h:182
Host (CPU) memory asynchronous, when used with a flexGet/flexSet method the memory transfer will be a...
Definition: flex.h:218
float mFluidRestDistance
The distance fluid particles are spaced at the rest density, must be in the range (0...
Definition: flex.h:67
FLEX_API void flexSetDiffuseParticles(FlexSolver *s, const float *p, const float *v, int n, FlexMemory source)
FLEX_API void flexGetRigidTransforms(FlexSolver *s, float *rotations, float *translations, FlexMemory target)
FLEX_API int flexGetActiveCount(FlexSolver *s)
bool mFluid
If true then particles with phase 0 are considered fluid particles and interact using the position ba...
Definition: flex.h:88
float mCollideTriangles
Time spent colliding triangle shapes.
Definition: flex.h:167
float mCollideConvexes
Time spent colliding convex shapes.
Definition: flex.h:166
Definition: flex.h:60
float mRestitution
Coefficient of restitution used when colliding against shapes, particle collisions are always inelast...
Definition: flex.h:73
float mSolveContacts
Time spent solving contact constraints.
Definition: flex.h:174
Host (CPU) memory.
Definition: flex.h:209
float mUpdateBounds
Time spent updating particle bounds.
Definition: flex.h:181
FLEX_API void flexSetParams(FlexSolver *s, const FlexParams *params)
FLEX_API void flexSetInflatables(FlexSolver *s, const int *startTris, const int *numTris, float *restVolumes, float *overPressures, float *constraintScales, int numInflatables, FlexMemory source)
FlexError
Definition: flex.h:189
float mCalculateAnisotropy
Time spent calculating particle anisotropy for fluid.
Definition: flex.h:176
float mUpdateDiffuse
Time spent updating diffuse particles.
Definition: flex.h:177
FLEX_API int flexGetDiffuseParticles(FlexSolver *s, float *p, float *v, int *indices, FlexMemory target)
unsigned int mWidth
Field x dimension in voxels.
Definition: flex.h:147
float mPredict
Time spent in prediction.
Definition: flex.h:160
FLEX_API void flexSetFence()
float mShapeCollisionMargin
Increases the radius used during contact finding against kinematic shapes.
Definition: flex.h:113
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)
float mVorticityConfinement
Increases vorticity by applying rotational forces to particles.
Definition: flex.h:92
float mFreeSurfaceDrag
Drag force applied to boundary fluid particles.
Definition: flex.h:96
float mWind[3]
Constant acceleration applied to particles that belong to dynamic triangles, drag needs to be > 0 for...
Definition: flex.h:83
FLEX_API int flexMakePhase(int group, int flags)
Definition: flex.h:136
FLEX_API void flexSetParticles(FlexSolver *s, const float *p, int n, FlexMemory source)
float mSmoothing
Control the strength of Laplacian smoothing in particles for rendering, if zero then smoothed positio...
Definition: flex.h:94
FLEX_API void * flexAlloc(int size)
FLEX_API void flexGetActive(FlexSolver *s, int *indices, FlexMemory target)
FLEX_API void flexGetVelocities(FlexSolver *s, float *v, int n, FlexMemory target)
FLEX_API void flexUpdateSolver(FlexSolver *s, float dt, int substeps, FlexTimers *timers)
const float * mField
SDF voxel data, must be mWidth*mHeight*mDepth in length.
Definition: flex.h:151
The relaxation factor is a fixed multiplier on each constraint's position delta.
Definition: flex.h:56
FLEX_API void flexSetTriangles(FlexSolver *s, const int *indices, const float *vertices, int numTris, int numVertices, float cellSize, FlexMemory source)
FLEX_API FlexSolver * flexCreateSolver(int maxParticles, int maxDiffuseParticles, unsigned char maxNeighborsPerParticle=96)
The API call returned with no errors.
Definition: flex.h:192
FLEX_API void flexFree(void *ptr)
float mDiffuseDrag
Scales force diffuse particles receive in direction of neighbor fluid particles.
Definition: flex.h:102
Flag specifying whether this particle will interact with particles of the same group.
Definition: flex.h:129
float mSolveInflatables
Time spent solving pressure constraints.
Definition: flex.h:175
float mDissipation
Damps particle velocity based on how many particle contacts it has.
Definition: flex.h:78
int mNumPlanes
Num collision planes.
Definition: flex.h:116
FLEX_API void flexSetVelocities(FlexSolver *s, const float *v, int n, FlexMemory source)
float mUpdateTriangles
Time spent updating dynamic triangles.
Definition: flex.h:178
float mRadius
The maximum interaction radius for particles.
Definition: flex.h:65
FLEX_API void flexGetPhases(FlexSolver *s, int *phases, int n, FlexMemory target)
float mSortCellIndices
Time spent sorting grid indices.
Definition: flex.h:162
FLEX_API void flexGetAnisotropy(FlexSolver *s, float *q1, float *q2, float *q3, FlexMemory target)
FLEX_API void flexShutdown()
Low 24 bits represent the particle group for controlling collisions.
Definition: flex.h:127
FLEX_API void flexDestroySolver(FlexSolver *s)
float mSolveSprings
Time spent solving distance constraints.
Definition: flex.h:173
float mEnableCCD
If true then a second collision detection pass will be executed against triangle meshes to prevent tu...
Definition: flex.h:80
FLEX_API void flexGetDensities(FlexSolver *s, float *densities, FlexMemory target)
float mDynamicFriction
Coefficient of friction used when colliding against shapes.
Definition: flex.h:70
float mParticleFriction
Coefficient of friction used when colliding particles.
Definition: flex.h:72
float mParticleCollisionMargin
Increases the radius used during neighbor finding, this is useful if particles are expected to move s...
Definition: flex.h:112
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)