class MAGES::MeshDeformations::SpringMassParticle¶
Overview¶
class SpringMassParticle
{
public:
// classes
class AffectedVertex;
// fields
int particleId = -1;
GameObject gameObject;
Transform gameObjectTransform;
Transform parent;
Rigidbody rigidbody;
Collider collider;
ConfigurableJoint centerConnection;
SerializableDictionary ownedConnectingJoints = new SerializableDictionary();
SerializableDictionary notOwnedConnectingJoints = new SerializableDictionary();
List m_ParticleBoneWeights = new List(MAX_BONE_AFFECTIONS);
List affectedVertices = new List();
// properties
Vector3 AnchorPosition;
Vector3 LocalAnchorPosition;
Quaternion AnchorRotation;
Quaternion LocalAnchorRotation;
Matrix4x4 Bindpose;
bool Gravity;
float Mass;
float MassScale;
float AngularDrag;
Vector3 Position;
Quaternion Rotation;
float Scale;
float Spring;
float Damper;
float Tolerance;
float MaxDistanceFromAnchor;
// methods
SpringMassParticle(
int particleId,
Vector3 localAnchorPosition,
Quaternion localAnchorRotation,
Vector3 localScale,
Transform parent,
Rigidbody center
);
SpringMassParticle(
int particleId,
Vector3 localAnchorPosition,
Quaternion localAnchorRotation,
Vector3 localScale,
in Transform[] originalBones,
in Matrix4x4[] originalBindposes,
List boneWeights,
Transform parent,
Rigidbody center
);
bool TryConnectParticle(SpringMassParticle connectTo);
bool TryDisconnectParticle(SpringMassParticle disconnectFrom);
bool IsConnectedTo(SpringMassParticle particle);
void Recenter();
void CalculateAffectedVerticesAndWeights(
in Vector3[] vertices,
in float maxWeightAffectionDistance,
in AnimationCurve weightCurve
);
void CalculateParticleBoneAffection(
in Unity.Collections.NativeArray originalBonesPerVertex,
in Unity.Collections.NativeArray originalBoneWeights
);
void Destroy(in SerializableDictionary particles);
void SkinAnchorPositionAndUpdateSprings(
in Transform[] originalBones,
in Matrix4x4[] originalBindposes,
in SerializableDictionary particles
);
void CalculateAndAddNewAffectedVerticesAndWeights(
in Vector3[] vertices,
in int newVerticesStartIndex,
in float maxWeightAffectionDistance,
in AnimationCurve weightCurve
);
override int GetHashCode();
override bool Equals(object obj);
};
Detailed Documentation¶
Fields¶
int particleId = -1
Note: All transformation are local and based to parent transform.
Properties¶
Vector3 AnchorPosition
Anchor Position in world Coords.
Methods¶
SpringMassParticle(
int particleId,
Vector3 localAnchorPosition,
Quaternion localAnchorRotation,
Vector3 localScale,
Transform parent,
Rigidbody center
)
Creates a static physics particle. It does not connect the particle or skin it.
Parameters:
particleId |
|
localAnchorPosition |
|
localAnchorRotation |
|
localScale |
|
parent |
|
center |
SpringMassParticle(
int particleId,
Vector3 localAnchorPosition,
Quaternion localAnchorRotation,
Vector3 localScale,
in Transform[] originalBones,
in Matrix4x4[] originalBindposes,
List boneWeights,
Transform parent,
Rigidbody center
)
Creates a skinned physics particle. It does not connect the particle or skin it.
Parameters:
particleId |
|
localAnchorPosition |
|
localAnchorRotation |
|
localScale |
|
originalBones |
The bones of original mesh |
originalBindposes |
The bindposes of the original mesh |
boneWeights |
Boneweights for the created particle |
parent |
|
center |
bool TryConnectParticle(SpringMassParticle connectTo)
Tries to connect a particle with other using spring joint.
Parameters:
connectTo |
The particle to connect to |
Returns:
False if already connected, true otherwise
bool TryDisconnectParticle(SpringMassParticle disconnectFrom)
Tries to disconnect a particle with other if connected with a springjoint.
Parameters:
disconnectFrom |
The particle to disconnect from |
particles |
A list of all the particles |
Returns:
False if particles were not connected, true if it got disconnected
bool IsConnectedTo(SpringMassParticle particle)
Are two particles connected?
Parameters:
particle |
The particle to check if this particle is connected to with a spring |
Returns:
True if connected, false otherwise
void Recenter()
Transforms the particle to the Anchor position.
void CalculateAffectedVerticesAndWeights(
in Vector3[] vertices,
in float maxWeightAffectionDistance,
in AnimationCurve weightCurve
)
Calculates affected vertices and their weights.
Parameters:
vertices |
|
maxWeightAffectionDistance |
|
weightCurve |
void CalculateParticleBoneAffection(
in Unity.Collections.NativeArray originalBonesPerVertex,
in Unity.Collections.NativeArray originalBoneWeights
)
After the Calculation of Affected Vertices and weights.
void Destroy(in SerializableDictionaryparticles)
Destroys this particle.
Parameters:
particles |
The particles of the softbody |
void SkinAnchorPositionAndUpdateSprings(
in Transform[] originalBones,
in Matrix4x4[] originalBindposes,
in SerializableDictionary particles
)
Calculates the new position of the particle based on its boneweights and also ajusts spring lengths.
void CalculateAndAddNewAffectedVerticesAndWeights(
in Vector3[] vertices,
in int newVerticesStartIndex,
in float maxWeightAffectionDistance,
in AnimationCurve weightCurve
)
Calculates.
Parameters:
vertices |
|
newVerticesStartIndex |
|
maxWeightAffectionDistance |
|
weightCurve |