class MAGES::MeshDeformations::DynamicSoftbodyActor¶
Overview¶
A dynamic softbody actor. More…
class DynamicSoftbodyActor: public MAGES::MeshDeformations::BasePhysicsActor { public: // structs struct AccumulateParticleNormalsJob; struct BuildFaceAdjacencyJob; struct ClearCountersJob; struct FindResidualDistanceConstraintsJob; struct InitializeParticleToVertexMappingJob; struct RecreateFlatMeshJob; struct RecreateSmoothMeshJob; struct RemoveNeighborsFromDifferentSubMeshesJob; struct RemoveResidualDistanceConstraintsJob; struct RemoveVolumeConstraintsWithLimitedNumberOfNeighbors; struct ScatterVertexNormalsJob; struct SubMeshIndexData; struct UpdateKinematicParticlesJob; struct UpdateMeshJob; // classes class SubMeshIndexDatas; // properties override SimulationMesh SharedSimulationMesh; uint Layer; bool UpdateKinematicParticles; bool SmoothShading; UvStorageMode UvStorage; System.Collections.Generic.IReadOnlyListTetCornerUVs; WedgeCoords WedgeCoords; bool UseSeparateInteriorMaterial; System.Collections.Generic.IReadOnlyList TetFaceIsInterior; bool GenerateFacesInPhysicsMaterialBoundaries; bool RemoveResidualDistanceConstraints; bool RemoveVolumeConstraintsWithLimitedNeighbors; int MinNeighborsBeforeVolumeConstraintsRemoval; // methods WedgeCoordsAssignmentResult SetWedgeCoords(WedgeCoords coords); virtual override void AddToPhysicsWorld(); virtual override void RemoveFromPhysicsWorld(); DynamicSoftbodySnapshot Save(); void Load(DynamicSoftbodySnapshot snapshot); void CutSplit(Disc cuttingDisc); void CutRemove(Disc cuttingDisc); void GenerateUVMapsFromMesh(Mesh mesh); bool GenerateWedgeUVsFromMesh(Mesh mesh, int[] sidecarKeys); bool ImportTetCornerUVs(float2[] importedTetCornerUVs); int[] CopyVertexToTetCornerMap(); void GenerateUVMapsFromMesh2(Mesh mesh); static Vector3 ComputeBarycentric(Vector3 p, Vector3 a, Vector3 b, Vector3 c); static Vector3 ClosestPointOnTriangle( Vector3 p, Vector3 a, Vector3 b, Vector3 c ); };
Inherited Members¶
public:
// properties
PhysicsWorld PhysicsWorld;
SimulationMesh SharedSimulationMesh;
SimulationMesh SimulationMesh;
IReadOnlyList StaticParticles;
bool IsPartOfPhysicsWorld;
UnityEvent<PhysicsWorld> AddedToPhysicsWorld;
UnityEvent<PhysicsWorld> RemovedFromPhysicsWorld;
// methods
bool IsParticleStatic(int particleIndex);
void SetStaticParticles(IEnumerable particleIndices);
virtual void AddToPhysicsWorld();
virtual void RemoveFromPhysicsWorld();
Detailed Documentation¶
A dynamic softbody actor.
The dynamic softbody, creates the render mesh dyanamically based on the current volume constraints of the simulation mesh.<br> This allows us to cut the softbody based on forces and the render mesh to be automatically updated.
Properties¶
uint Layer
Gets or sets the layer used for collision filtering.
bool UpdateKinematicParticles
Gets or sets a value indicating whether to update the kinematic particles position when this actor’s transform is updated.
bool SmoothShading
Gets or sets a value indicating whether to generate smooth or flat shading for the render mesh.
UvStorageMode UvStorage
Gets or sets how UVs are stored/read when reconstructing the render mesh. Changing this rebuilds the editor visualization and flags the runtime visible mesh for reconstruction.
System.Collections.Generic.IReadOnlyListTetCornerUVs
Gets the per-face-corner UVs (indexed vc*12 + faceSlot*3 + cornerInFace; see WedgeUvLayout). Read-only view of the serialized backing array; primarily for tests and tooling.
WedgeCoords WedgeCoords
Gets the WedgeCoords asset currently assigned as the per-wedge UV authoring source, or null. The asset is baked into tetCornerUVs on assignment; runtime cutting / Save / Load keep operating on that baked working copy, not on the asset.
bool UseSeparateInteriorMaterial
Gets or sets a value indicating whether faces exposed by cutting are routed into a dedicated interior submesh (an extra material slot, index PhysicsMaterials count) so the cut cross-section can use a separate “inside” material. The original outer surface keeps its normal submesh(es). Assign the interior material to the last slot of the MeshRenderer.
System.Collections.Generic.IReadOnlyListTetFaceIsInterior
Gets the per-tet-face interior flags (indexed vc*4 + faceSlot). Read-only view of the serialized backing array; primarily for tests and tooling.
bool GenerateFacesInPhysicsMaterialBoundaries
Gets or sets a value indicating whether to generate faces (triangles) in the boundaries of the physics material.
bool RemoveResidualDistanceConstraints
Gets or sets a value indicating whether should remove residual distance constraints after a tear.
bool RemoveVolumeConstraintsWithLimitedNeighbors
Gets or sets a value indicating whether after the simulation mesh has been modified, the volume constraints with limited number of neighbors should be removed.
int MinNeighborsBeforeVolumeConstraintsRemoval
Gets or sets the minimum number of neighbors before volume constraints removal.
Methods¶
WedgeCoordsAssignmentResult SetWedgeCoords(WedgeCoords coords)
Assigns (or clears) the per-wedge UV authoring source. On assignment the asset’s payload is baked into the serialized tetCornerUVs (reusing ImportTetCornerUVs), storage is set to UvStorageMode.PerWedge, and the reference is kept. Clearing to null reverts storage to UvStorageMode.PerParticle and clears tetCornerUVs.
Parameters:
coords |
The asset to assign, or |
Returns:
The outcome (see WedgeCoordsAssignmentResult). On any rejection result the actor’s state and the stored reference are left untouched.
virtual override void AddToPhysicsWorld()
Override this function to add the simulation mesh to the physics world.
virtual override void RemoveFromPhysicsWorld()
Override this function to remove the simulation mesh from the physics world.
DynamicSoftbodySnapshot Save()
Captures the actor’s current simulation state into a self-contained, immutable snapshot.
The API is stateless: the returned snapshot owns deep copies of the data and the actor keeps no reference to it. Undo/redo stacking is the caller’s responsibility.
While the actor is part of a physics world the live runtime slices are captured (the current, post-cut topology). Otherwise the design-time BasePhysicsActor.SharedSimulationMesh arrays (the pristine baseline) are captured. In both cases particle positions are set to the rest positions, velocities are zeroed and Particle.Kinematic is derived from a zero inverse mass; transient solver state and physics materials are not captured.
Returns:
The captured snapshot, or null if there is no simulation data to capture.
void Load(DynamicSoftbodySnapshot snapshot)
Restores the actor to a previously captured snapshot, discarding the actor’s current simulation state (e.g. undoing a cut).
This is a runtime-only operation: the actor must already be part of a physics world. The current simulation mesh is removed and a rebuilt instance is re-added through the command queue, so the effect lands on the next physics step. The re-add uses float4x4.identity so the snapshot’s world-space rest positions reproduce exactly. Once the add is applied the snapshot’s per-particle and per-constraint enabled flags are re-applied (the add path force-enables everything) and the visible mesh is reconstructed.
Parameters:
snapshot |
The snapshot to restore. Must originate from Save on this actor. |
void CutSplit(Disc cuttingDisc)
Cut the mesh with a disc by splitting intersected tetrahedra. Only allowed to be called from the PhysicsUpdate Event.
Parameters:
cuttingDisc |
The disc based on which to cut. |
void CutRemove(Disc cuttingDisc)
Cut the mesh with a disc by removing intersected tetrahedra. Only allowed to be called from the PhysicsUpdate Event.
Parameters:
cuttingDisc |
The disc based on which to cut. |
void GenerateUVMapsFromMesh(Mesh mesh)
Uses the mesh for generating UV Maps.
Parameters:
mesh |
The mesh to use UV maps from. |
bool GenerateWedgeUVsFromMesh(Mesh mesh, int[] sidecarKeys)
Assigns per-tet-corner (per-wedge) UVs from an imported mesh using an index-aligned sidecarKeys map (one wedge key per mesh vertex, produced by the OBJ / .uvmap export). This is the round-trip path that preserves authored UV seams: each mesh vertex writes its UV0 into tetCornerUVs[sidecarKeys[i]], so two tetrahedra sharing a particle can carry distinct UVs. Sets UvStorage to UvStorageMode.PerWedge.
Parameters:
mesh |
The mesh whose UV channel 0 supplies the wedge UVs. Vertex order must match the export that produced sidecarKeys. |
sidecarKeys |
The wedge key ( |
Returns:
true if the assignment succeeded; false on a guard failure (in which case tetCornerUVs is left unchanged).
bool ImportTetCornerUVs(float2[] importedTetCornerUVs)
Imports per-face-corner UVs directly (layout vc*12 + faceSlot*3 + cornerInFace; see WedgeUvLayout), e.g. from a .tetuv sidecar produced by the Bake UVs window. Switches storage to UvStorageMode.PerWedge and rebuilds the render / preview mesh.
Parameters:
importedTetCornerUVs |
The per-face-corner UVs to import. Its length must equal the shared simulation mesh’s volume-constraint count * 12 (the sidecar’s stamp validation guarantees this when the file matches the mesh). |
Returns:
true when the UVs were imported; false on a null argument, a missing simulation mesh, or a size mismatch (no partial write).
int[] CopyVertexToTetCornerMap()
Copies the per-output-vertex wedge keys (vc*4 + localCorner) aligned to the current render mesh’s vertex order. Used by the OBJ exporter to write the .uvmap sidecar. Prefers the live runtime map (play mode); falls back to the keys captured from the last flat editor-visualization build (edit mode). Returns an empty array when no flat build has produced keys.
Returns:
The wedge keys in render-mesh vertex order.
void GenerateUVMapsFromMesh2(Mesh mesh)
Uses the mesh for generating UV Maps.
Parameters:
mesh |
The mesh to use UV maps from. |