Skip to content

Commit 946ca9a

Browse files
committed
Plane collision area fixed and Mass for entire mesh
1 parent 53bbe8f commit 946ca9a

File tree

99 files changed

+746
-1319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+746
-1319
lines changed

ClothPhysics/Assets/Prefabs/SampleWarrior.prefab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,12 +2073,13 @@ MonoBehaviour:
20732073
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
20742074
m_Name:
20752075
m_EditorClassIdentifier:
2076+
m_NodeMass: 0.03
20762077
m_SolvingMethod: 3
20772078
m_TimeStep: 0.02
20782079
m_Substeps: 5
20792080
m_Paused: 0
20802081
m_Gravity: {x: 0, y: -9.81, z: 0}
2081-
m_NodeMass: 0.03
2082+
m_MeshMass: 20
20822083
m_NodeDamping: 1
20832084
m_SpringDamping: 1
20842085
m_TractionStiffness: 40

ClothPhysics/Assets/Scenes/ClothSampleScene.unity

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,13 @@ MonoBehaviour:
594594
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
595595
m_Name:
596596
m_EditorClassIdentifier:
597+
m_NodeMass: 0.03
597598
m_SolvingMethod: 1
598599
m_TimeStep: 0.02
599600
m_Substeps: 5
600601
m_Paused: 1
601602
m_Gravity: {x: 0, y: -9.81, z: 0}
602-
m_NodeMass: 0.03
603+
m_MeshMass: 0
603604
m_NodeDamping: 0.3
604605
m_SpringDamping: 0.3
605606
m_TractionStiffness: 20
@@ -813,6 +814,10 @@ PrefabInstance:
813814
m_Modification:
814815
m_TransformParent: {fileID: 0}
815816
m_Modifications:
817+
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
818+
propertyPath: m_MeshMass
819+
value: 3.6
820+
objectReference: {fileID: 0}
816821
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
817822
propertyPath: m_CollidingMeshes.Array.data[0]
818823
value:
@@ -1122,12 +1127,13 @@ MonoBehaviour:
11221127
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
11231128
m_Name:
11241129
m_EditorClassIdentifier:
1130+
m_NodeMass: 0.03
11251131
m_SolvingMethod: 1
11261132
m_TimeStep: 0.007
11271133
m_Substeps: 1
11281134
m_Paused: 1
11291135
m_Gravity: {x: 0, y: -9.81, z: 0}
1130-
m_NodeMass: 0.03
1136+
m_MeshMass: 0
11311137
m_NodeDamping: 0.3
11321138
m_SpringDamping: 0.3
11331139
m_TractionStiffness: 20
@@ -1289,6 +1295,10 @@ PrefabInstance:
12891295
m_Modification:
12901296
m_TransformParent: {fileID: 0}
12911297
m_Modifications:
1298+
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
1299+
propertyPath: m_MeshMass
1300+
value: 3.6
1301+
objectReference: {fileID: 0}
12921302
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
12931303
propertyPath: m_CollidingMeshes.Array.data[0]
12941304
value:
@@ -1406,6 +1416,10 @@ PrefabInstance:
14061416
propertyPath: Mass
14071417
value: 0.82
14081418
objectReference: {fileID: 0}
1419+
- target: {fileID: 7945908319452971428, guid: c8bb9f24a9ed08541a45b7bc699dacc0, type: 3}
1420+
propertyPath: m_MeshMass
1421+
value: 3.6
1422+
objectReference: {fileID: 0}
14091423
- target: {fileID: 7945908319452971428, guid: c8bb9f24a9ed08541a45b7bc699dacc0, type: 3}
14101424
propertyPath: m_Substeps
14111425
value: 1

ClothPhysics/Assets/Scripts/ClothBehaviour.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class ClothBehaviour : MonoBehaviour
3939

4040
[HideInInspector] private float m_SubTimeStep;
4141

42+
[HideInInspector] public float m_NodeMass;
43+
44+
4245
#endregion
4346

4447

@@ -58,8 +61,8 @@ public class ClothBehaviour : MonoBehaviour
5861

5962
[SerializeField] public Vector3 m_Gravity;
6063

61-
[Tooltip("Controls the mass each vertex weights, not the entire mesh.")]
62-
[SerializeField] [Range(0f, 1f)] public float m_NodeMass;
64+
[Tooltip("Controls the mass of the entire mesh, assuming it will be equally divided into each node.")]
65+
[SerializeField] [Range(0, 50)] public float m_MeshMass;
6366

6467
[Tooltip("Higher values means more reduction in vertex movement.")]
6568
[SerializeField] [Range(0f, 5f)] public float m_NodeDamping;
@@ -111,7 +114,7 @@ public ClothBehaviour()
111114
m_TractionStiffness = 20f;
112115
m_FlexionStiffness = 15f;
113116

114-
m_NodeMass = 0.03f;
117+
m_MeshMass = 3.63f;
115118

116119
m_NodeDamping = 0.3f;
117120
m_SpringDamping = 0.3f;
@@ -149,23 +152,23 @@ public enum WindPrecission
149152
private void LowResSetup()
150153
{
151154
m_TimeStep = 0.02f; m_Paused = true;
152-
m_TractionStiffness = 20f; m_FlexionStiffness = 15f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
155+
m_TractionStiffness = 20f; m_FlexionStiffness = 15f; m_MeshMass = 3.6f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
153156
m_SolvingMethod = Solver.Simplectic;
154157
m_WindSolverPrecission = WindPrecission.High;
155158
}
156159
[ContextMenu("Medium Res Mesh Setup")]
157160
private void MedResSetup()
158161
{
159162
m_TimeStep = 0.01f; m_Substeps = 2; m_Paused = true;
160-
m_TractionStiffness = 50f; m_FlexionStiffness = 30f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
163+
m_TractionStiffness = 50f; m_FlexionStiffness = 30f; m_MeshMass = 20f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
161164
m_SolvingMethod = Solver.Simplectic;
162165
m_WindSolverPrecission = WindPrecission.Medium;
163166
}
164167
[ContextMenu("High Res Mesh Setup")]
165168
private void HighResSetup()
166169
{
167170
m_TimeStep = 0.007f; m_Substeps = 1; m_Paused = true;
168-
m_TractionStiffness = 100f; m_FlexionStiffness = 80f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
171+
m_TractionStiffness = 100f; m_FlexionStiffness = 80f; m_MeshMass = 50f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
169172
m_SolvingMethod = Solver.Simplectic;
170173
m_WindSolverPrecission = WindPrecission.Low;
171174
}
@@ -183,7 +186,7 @@ public void Start()
183186

184187
m_Nodes = new List<Node>();
185188

186-
189+
m_NodeMass = m_MeshMass / m_Vertices.Length;
187190

188191
for (int i = 0; i < m_Mesh.vertexCount; i++)
189192
{
@@ -244,6 +247,7 @@ public void Update()
244247
if (Input.GetKeyUp(KeyCode.P))
245248
this.m_Paused = !this.m_Paused;
246249

250+
m_NodeMass = m_MeshMass / m_Vertices.Length;
247251
m_SubTimeStep = m_TimeStep / m_Substeps;
248252

249253
CheckWindObjects();
@@ -741,8 +745,8 @@ public int isColliding(GameObject obj, float offset)
741745
else if (obj.GetComponent<MeshCollider>() != null)
742746
{
743747
MeshCollider collider = obj.GetComponent<MeshCollider>();
744-
float xExtension = collider.bounds.extents.x;
745-
float zExtension = collider.bounds.extents.z;
748+
float xExtension = collider.sharedMesh.bounds.extents.x;
749+
float zExtension = collider.sharedMesh.bounds.extents.z;
746750
Vector3 nodeLocalPos = obj.transform.InverseTransformPoint(m_Pos);
747751
if (nodeLocalPos.y <= 0f + offset && nodeLocalPos.y >= -1.0f && Mathf.Abs(nodeLocalPos.z) <= zExtension && Mathf.Abs(nodeLocalPos.x) <= xExtension) return 2;
748752
}

ClothPhysics/Assets/Scripts/Editor/ClothBehaviorEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
[CustomEditor(typeof(ClothBehaviour))]
8+
[CanEditMultipleObjects]
89
public class ClothBehaviorEditor : Editor
910
{
1011
public override void OnInspectorGUI()

ClothPhysics/Library/ArtifactDB

0 Bytes
Binary file not shown.
Binary file not shown.
-35.1 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

ClothPhysics/Library/Artifacts/e6/e64b1de174520e5c90828c3d77c0ee01 renamed to ClothPhysics/Library/Artifacts/19/1950da6f4e5e41e194489833182f3ed2

35.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)