PxSoftBodyExt

Defined in include/extensions/PxSoftBodyExt.h

class PxSoftBodyExt

Utility functions for use with PxSoftBody and subclasses.

Public Static Functions

static void updateMass(PxSoftBody &softBody, const PxReal density, const PxReal maxInvMassRatio, PxVec4 *simPositionsPinned)

Computes the SoftBody’s vertex masses from the provided density and the volume of the tetrahedra.

The buffers affected by this operation can be obtained from the SoftBody using the methods getSimPositionInvMassBufferD() and getSimVelocityBufferD()

The inverse mass is stored in the 4th component (the first three components are x, y, z coordinates) of the simulation mesh’s position buffer.

Parameters
  • softBody[in] The soft body which will get its mass updated

  • density[in] The density to used to calculate the mass from the body’s volume

  • maxInvMassRatio[in] Maximum allowed ratio defined as max(vertexMasses) / min(vertexMasses) where vertexMasses is a list of float values with a mass for every vertex in the simulation mesh

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

static void setMass(PxSoftBody &softBody, const PxReal mass, const PxReal maxInvMassRatio, PxVec4 *simPositionsPinned)

Computes the SoftBody’s vertex masses such that the sum of all masses is equal to the provided mass.

The buffers affected by this operation can be obtained from the SoftBody using the methods getSimPositionInvMassBufferD()) and getSimVelocityBufferD()

The inverse mass is stored in the 4th component (the first three components are x, y, z coordinates) of the simulation mesh’s position buffer.

Parameters
  • softBody[in] The soft body which will get its mass updated

  • mass[in] The SoftBody’s mass

  • maxInvMassRatio[in] Maximum allowed ratio defined as max(vertexMasses) / min(vertexMasses) where vertexMasses is a list of float values with a mass for every vertex in the simulation mesh

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

static void transform(PxSoftBody &softBody, const PxTransform &transform, const PxReal scale, PxVec4 *simPositionsPinned, PxVec4 *simVelocitiesPinned, PxVec4 *collPositionsPinned, PxVec4 *restPositionsPinned)

Transforms a SoftBody.

The buffers affected by this operation can be obtained from the SoftBody using the methods getSimPositionInvMassBufferD() and getSimVelocityBufferD()

Applies a transformation to the simulation mesh’s positions an velocities. Velocities only get rotated and scaled (translation is not applicable to direction vectors). It does not modify the body’s mass. If the method is called multiple times, the transformation will compound with the ones previously applied.

See also

PxSoftBody

Parameters
  • softBody[in] The soft body which is transformed

  • transform[in] The transform to apply

  • scale[in] A scaling factor

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

  • simVelocitiesPinned[in] A pointer to a pinned host memory buffer containing velocities for each vertex of the simulation mesh.

  • collPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the collision mesh.

  • restPositionsPinned[in] A pointer to a pinned host memory buffer containing rest positions of the collision mesh.

static void updateEmbeddedCollisionMesh(PxSoftBody &softBody, PxVec4 *simPositionsPinned, PxVec4 *collPositionsPinned)

Updates the collision mesh’s vertex positions to match the simulation mesh’s transformation and scale.

The buffer affected by this operation can be obtained from the SoftBody using the method getPositionInvMassBufferD()

See also

PxSoftBody

Parameters
  • softBody[in] The soft body which will get its collision mesh vertices updated

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

  • collPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the collision mesh.

static void commit(PxSoftBody &softBody, PxSoftBodyDataFlags flags, PxVec4 *simPositionsPinned, PxVec4 *simVelocitiesPinned, PxVec4 *collPositionsPinned, PxVec4 *restPositionsPinned, CUstream stream = CUstream(0))

Uploads prepared SoftBody data to the GPU.

It ensures that the embedded collision mesh matches the simulation mesh’s transformation and scale.

Deprecated:

Use copyToDevice() instead.

See also

PxSoftBody

Parameters
  • softBody[in] The soft body which will perform the data upload

  • flags[in] Specifies which buffers the data transfer should include

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

  • simVelocitiesPinned[in] A pointer to a pinned host memory buffer containing velocities for each vertex of the simulation mesh.

  • collPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the collision mesh.

  • restPositionsPinned[in] A pointer to a pinned host memory buffer containing rest positions of the collision mesh.

  • stream[in] A cuda stream to perform the copies.

static void copyToDevice(PxSoftBody &softBody, PxSoftBodyDataFlags flags, PxVec4 *simPositionsPinned, PxVec4 *simVelocitiesPinned, PxVec4 *collPositionsPinned, PxVec4 *restPositionsPinned, CUstream stream = CUstream(0))

Uploads prepared SoftBody data to the GPU.

It ensures that the embedded collision mesh matches the simulation mesh’s transformation and scale.

See also

PxSoftBody

Parameters
  • softBody[in] The soft body which will perform the data upload

  • flags[in] Specifies which buffers the data transfer should include

  • simPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the simulation mesh.

  • simVelocitiesPinned[in] A pointer to a pinned host memory buffer containing velocities for each vertex of the simulation mesh.

  • collPositionsPinned[in] A pointer to a pinned host memory buffer containing positions and inverse masses for each vertex of the collision mesh.

  • restPositionsPinned[in] A pointer to a pinned host memory buffer containing rest positions of the collision mesh.

  • stream[in] A cuda stream to perform the copies.

static PxSoftBodyMesh *createSoftBodyMesh(const PxCookingParams &params, const PxSimpleTriangleMesh &surfaceMesh, PxU32 numVoxelsAlongLongestAABBAxis, PxInsertionCallback &insertionCallback, const bool validate = true)

Creates a full SoftBody mesh matching the shape given as input.

Uses a voxel mesh for FEM simulation and a surface-matching mesh for collision detection.

See also

PxSoftBodyMesh

Parameters
  • params[in] Cooking params instance required for mesh processing

  • surfaceMesh[in] Input triangle mesh that represents the surface of the SoftBody

  • numVoxelsAlongLongestAABBAxis[in] The number of voxels along the longest bounding box axis

  • insertionCallback[in] The insertion interface from PxPhysics

  • validate[in] If set to true the input triangle mesh will get analyzed to find possible deficiencies

Returns

SoftBody mesh if cooking was successful, NULL otherwise

static PxSoftBodyMesh *createSoftBodyMeshNoVoxels(const PxCookingParams &params, const PxSimpleTriangleMesh &surfaceMesh, PxInsertionCallback &insertionCallback, PxReal maxWeightRatioInTet = 1.5f, const bool validate = true)

Creates a full SoftBody mesh matching the shape given as input.

Uses the same surface-matching mesh for collision detection and FEM simulation.

See also

PxSoftBodyMesh

Parameters
  • params[in] Cooking params instance required for mesh processing

  • surfaceMesh[in] Input triangle mesh that represents the surface of the SoftBody

  • insertionCallback[in] The insertion interface from PxPhysics

  • maxWeightRatioInTet[in] Upper limit for the ratio of node weights that are adjacent to the same tetrahedron. The closer to one (while remaining larger than one), the more stable the simulation.

  • validate[in] If set to true the input triangle mesh will get analyzed to find possible deficiencies

Returns

SoftBody mesh if cooking was successful, NULL otherwise

static PxSoftBody *createSoftBodyFromMesh(PxSoftBodyMesh *softBodyMesh, const PxTransform &transform, const PxFEMSoftBodyMaterial &material, PxCudaContextManager &cudaContextManager, PxReal density = 100.0f, PxU32 solverIterationCount = 30, const PxFEMParameters &femParams = PxFEMParameters(), PxReal scale = 1.0f)

Creates a SoftBody instance from a SoftBody mesh.

Parameters
  • softBodyMesh[in] The SoftBody mesh

  • transform[in] The transform that defines initial position and orientation of the SoftBody

  • material[in] The material

  • cudaContextManager[in] A cuda context manager

  • density[in] The density used to compute the mass properties

  • solverIterationCount[in] The number of iterations the solver should apply during simulation

  • femParams[in] Additional parameters to specify e. g. damping

  • scale[in] The scaling of the SoftBody

Returns

SoftBody instance

static PxSoftBody *createSoftBodyBox(const PxTransform &transform, const PxVec3 &boxDimensions, const PxFEMSoftBodyMaterial &material, PxCudaContextManager &cudaContextManager, PxReal maxEdgeLength = -1.0f, PxReal density = 100.0f, PxU32 solverIterationCount = 30, const PxFEMParameters &femParams = PxFEMParameters(), PxU32 numVoxelsAlongLongestAABBAxis = 10, PxReal scale = 1.0f)

Creates a SoftBody instance with a box shape.

Parameters
  • transform[in] The transform that defines initial position and orientation of the SoftBody

  • boxDimensions[in] The dimensions (side lengths) of the box shape

  • material[in] The material

  • cudaContextManager[in] A cuda context manager

  • maxEdgeLength[in] The maximal length of a triangle edge. Subdivision will get applied until the edge length criteria is matched. -1 means no subdivision is applied.

  • density[in] The density used to compute the mass properties

  • solverIterationCount[in] The number of iterations the solver should apply during simulation

  • femParams[in] Additional parameters to specify e. g. damping

  • numVoxelsAlongLongestAABBAxis[in] The number of voxels to use for the simulation mesh along the longest bounding box dimension

  • scale[in] The scaling of the SoftBody

Returns

SoftBody instance

static void allocateAndInitializeHostMirror(PxSoftBody &softBody, PxCudaContextManager *cudaContextManager, PxVec4 *&simPositionInvMassPinned, PxVec4 *&simVelocityPinned, PxVec4 *&collPositionInvMassPinned, PxVec4 *&restPositionPinned)

allocates and initializes pinned host memory buffers from an actor with shape.

See also

PxSoftBody

Parameters
  • softBody[in] A PxSoftBody that has a valid shape attached to it.

  • cudaContextManager[in] The PxCudaContextManager of the scene this soft body will be simulated in

  • simPositionInvMassPinned[in] A reference to a pointer for the return value of the simPositionInvMassPinned buffer, will be set by this function.

  • simVelocityPinned[in] A reference to a pointer for the return value of the simVelocityPinned buffer, will be set by this function.

  • collPositionInvMassPinned[in] A reference to a pointer for the return value of the collPositionInvMassPinned buffer, will be set by this function.

  • restPositionPinned[in] A reference to a pointer for the return value of the restPositionPinned buffer, will be set by this function.

static void relaxSoftBodyMesh(const PxVec4 *verticesOriginal, PxVec4 *verticesDeformed, PxU32 nbVertices, const PxU32 *tetrahedra, PxU32 nbTetraheda, const bool *vertexIsFixed = NULL, PxU32 numIterations = 200)

Given a set of points and a set of tetrahedra, it finds the equilibrium state of the softbody.

Every input point is either fixed or can move freely.

Parameters
  • verticesOriginal[in] Mesh vertex positions in undeformed original state.

  • verticesDeformed[in] Mesh vertex positions in new deformed state. Only fixed vertices must have their final location, all other locations will get updated by the method.

  • nbVertices[in] The number of vertices.

  • tetrahedra[in] The tetrahedra.

  • nbTetraheda[in] The number of tetrahedra.

  • vertexIsFixed[in] Optional input that specifies which vertex is fixed and which one can move to relax the tension. If not provided, vertices from verticesOriginal which have a .w value of 0 will be considered fixed.

  • numIterations[in] The number of stress relaxation iterations to run.