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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

ClothPhysics/Library/CurrentLayout-default.dwlt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MonoBehaviour:
1919
width: 1920
2020
height: 997
2121
m_ShowMode: 4
22-
m_Title: Project
22+
m_Title: Game
2323
m_RootView: {fileID: 2}
2424
m_MinSize: {x: 875, y: 542}
2525
m_MaxSize: {x: 10000, y: 10000}
@@ -46,7 +46,7 @@ MonoBehaviour:
4646
y: 0
4747
width: 1920
4848
height: 997
49-
m_MinSize: {x: 875, y: 542}
49+
m_MinSize: {x: 875, y: 300}
5050
m_MaxSize: {x: 10000, y: 10000}
5151
m_UseTopView: 1
5252
m_TopViewHeight: 30
@@ -122,7 +122,7 @@ MonoBehaviour:
122122
m_MinSize: {x: 677, y: 492}
123123
m_MaxSize: {x: 14001, y: 14042}
124124
vertical: 0
125-
controlID: 6232
125+
controlID: 18
126126
--- !u!114 &6
127127
MonoBehaviour:
128128
m_ObjectHideFlags: 52
@@ -147,7 +147,7 @@ MonoBehaviour:
147147
m_MinSize: {x: 402, y: 492}
148148
m_MaxSize: {x: 10001, y: 14042}
149149
vertical: 1
150-
controlID: 6233
150+
controlID: 115
151151
--- !u!114 &7
152152
MonoBehaviour:
153153
m_ObjectHideFlags: 52
@@ -172,7 +172,7 @@ MonoBehaviour:
172172
m_MinSize: {x: 402, y: 221}
173173
m_MaxSize: {x: 8002, y: 4021}
174174
vertical: 0
175-
controlID: 6234
175+
controlID: 116
176176
--- !u!114 &8
177177
MonoBehaviour:
178178
m_ObjectHideFlags: 52
@@ -226,7 +226,7 @@ MonoBehaviour:
226226
- {fileID: 16}
227227
- {fileID: 13}
228228
m_Selected: 0
229-
m_LastSelected: 2
229+
m_LastSelected: 1
230230
--- !u!114 &10
231231
MonoBehaviour:
232232
m_ObjectHideFlags: 52
@@ -309,7 +309,7 @@ MonoBehaviour:
309309
m_ViewDataDictionary: {fileID: 0}
310310
m_LockTracker:
311311
m_IsLocked: 0
312-
m_LastSelectedObjectID: -1742
312+
m_LastSelectedObjectID: 18844
313313
--- !u!114 &13
314314
MonoBehaviour:
315315
m_ObjectHideFlags: 52
@@ -424,9 +424,9 @@ MonoBehaviour:
424424
m_PlayAudio: 0
425425
m_AudioPlay: 0
426426
m_Position:
427-
m_Target: {x: 14.964712, y: 19.526031, z: -0.017123222}
427+
m_Target: {x: 11.686105, y: 23.387985, z: 9.061652}
428428
speed: 2
429-
m_Value: {x: 14.964712, y: 19.526031, z: -0.017123222}
429+
m_Value: {x: 11.686105, y: 23.387985, z: 9.061652}
430430
m_RenderMode: 0
431431
m_CameraMode:
432432
drawMode: 0
@@ -473,13 +473,13 @@ MonoBehaviour:
473473
m_GridAxis: 1
474474
m_gridOpacity: 0.5
475475
m_Rotation:
476-
m_Target: {x: -0.0294426, y: -0.97014624, z: 0.18195778, w: -0.15708269}
476+
m_Target: {x: -0.042115994, y: -0.95659995, z: 0.17793354, w: -0.22652927}
477477
speed: 2
478-
m_Value: {x: -0.029172052, y: -0.97046125, z: 0.18201683, w: -0.1556402}
478+
m_Value: {x: -0.04211951, y: -0.9566798, z: 0.1779484, w: -0.2265482}
479479
m_Size:
480480
m_Target: 8.697202
481481
speed: 2
482-
m_Value: 13.160997
482+
m_Value: 8.697202
483483
m_Ortho:
484484
m_Target: 0
485485
speed: 2
@@ -532,9 +532,9 @@ MonoBehaviour:
532532
m_SceneHierarchy:
533533
m_TreeViewState:
534534
scrollPos: {x: 0, y: 0}
535-
m_SelectedIDs:
536-
m_LastClickedID: 0
537-
m_ExpandedIDs: 3cf9ffff1afbffff1efbffff22fbffff26fbffff2afbffff62fbffff6efbffff
535+
m_SelectedIDs: 6cfbffff
536+
m_LastClickedID: -1172
537+
m_ExpandedIDs: f8f6ffff3cf9ffff6efbffff
538538
m_RenameOverlay:
539539
m_UserAcceptedRename: 0
540540
m_Name:
@@ -616,7 +616,7 @@ MonoBehaviour:
616616
m_HSlider: 0
617617
m_VSlider: 0
618618
m_IgnoreScrollWheelUntilClicked: 0
619-
m_EnableMouseInput: 1
619+
m_EnableMouseInput: 0
620620
m_EnableSliderZoomHorizontal: 0
621621
m_EnableSliderZoomVertical: 0
622622
m_UniformScale: 1
@@ -685,22 +685,22 @@ MonoBehaviour:
685685
m_SkipHidden: 0
686686
m_SearchArea: 1
687687
m_Folders:
688-
- Assets/Prefabs
688+
- Assets/Scripts
689689
m_Globs: []
690690
m_OriginalText:
691691
m_ViewMode: 1
692692
m_StartGridSize: 64
693693
m_LastFolders:
694-
- Assets/Prefabs
694+
- Assets/Scripts
695695
m_LastFoldersGridSize: -1
696696
m_LastProjectPath: "D:\\URJC\\TERCER0\\2\xBA CUATRIMESTRE\\Animacion3D\\Cloth-Behaviour-Simulation\\ClothPhysics"
697697
m_LockTracker:
698698
m_IsLocked: 0
699699
m_FolderTreeState:
700700
scrollPos: {x: 0, y: 0}
701-
m_SelectedIDs: a0430000
702-
m_LastClickedID: 17312
703-
m_ExpandedIDs: 000000009a4300009c4300009e430000a0430000a2430000a4430000a6430000a8430000aa430000ac430000ae430000ce43000000ca9a3b
701+
m_SelectedIDs: 9e430000
702+
m_LastClickedID: 17310
703+
m_ExpandedIDs: 000000009a4300009c4300009e430000a0430000a2430000a4430000a6430000a8430000aa430000ac430000ae430000b243000000ca9a3b
704704
m_RenameOverlay:
705705
m_UserAcceptedRename: 0
706706
m_Name:
@@ -841,7 +841,7 @@ MonoBehaviour:
841841
m_ControlHash: -371814159
842842
m_PrefName: Preview_InspectorPreview
843843
m_LastInspectedObjectInstanceID: -1
844-
m_LastVerticalScrollValue: 375
844+
m_LastVerticalScrollValue: 0
845845
m_GlobalObjectId:
846846
m_LockTracker:
847847
m_IsLocked: 0
88 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

ClothPhysics/Library/SourceAssetDB

0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"m_ScrollY":968.0,"m_ExpandedPrefabGameObjectFileIDs":[4726982129777914958,1793219166972479350,1343704396112024852,7598264871304661165,32490656706741259,7605477600268506858,2343120425918575219,8983248898323846052,5730052557671801478,3968678280495872520,8171921479927036837,6521183026559124835,6045746584795018026,3470280650096550961,5706715038726354635,7802779332203002994,5795919301665273318,1473002259879849371,5258212573227245316,3186154623383745181,7406980316823925800,8351361309175429454,8554682143331634600,1874798905707986781,7864671622969286018,6301643757899507847,186432924366475993,7356120364027179783,3038400437354134895,7139498776320300740,7948424689445685289,7800402116217091529,235812824276320059,7629313182187030808,7632428492392069215,6374772166074600571,2080309830577147747,2976763538700752412,6942069096373566326,6559122059958697876,2924947039739672768,1142152216139859826,444624946857401529,5151406461615110287,4744080403367995115,6896437480312719029,5334658195516161303,1845354775806305978,4083898261284909573,5789883725611063238,6092774160319542087,6070752316274865709,3521061738916400679,6433707218267847018,1791735107598917686,7006256221044920402,6334829850000653455,220619424095091815,8762306872487107823,6760663898027671553,3119201861333200642,2759501666071804968,5695394238467027335,4080037266440605259,9212728441686358556,1568079412127858377,7817078055990358377,1742424884223929376,3205213869281447648,4035370856202412212,1757902253388209644,3602382300821691293,291813469379992995,6618887678447395269],"m_LastClickedFileID":4726982129773849875}
1+
{"m_ScrollY":968.0,"m_ExpandedPrefabGameObjectFileIDs":[4726982129777914958,1793219166972479350,1343704396112024852,7598264871304661165,32490656706741259,7605477600268506858,2343120425918575219,8983248898323846052,5730052557671801478,3968678280495872520,8171921479927036837,6521183026559124835,6045746584795018026,3470280650096550961,5706715038726354635,7802779332203002994,5795919301665273318,1473002259879849371,5258212573227245316,3186154623383745181,7406980316823925800,8351361309175429454,8554682143331634600,1874798905707986781,7864671622969286018,6301643757899507847,186432924366475993,7356120364027179783,3038400437354134895,7139498776320300740,7948424689445685289,7800402116217091529,235812824276320059,7629313182187030808,7632428492392069215,6374772166074600571,2080309830577147747,2976763538700752412,6942069096373566326,6559122059958697876,2924947039739672768,1142152216139859826,444624946857401529,5151406461615110287,4744080403367995115,6896437480312719029,5334658195516161303,1845354775806305978,4083898261284909573,5789883725611063238,6092774160319542087,6070752316274865709,3521061738916400679,6433707218267847018,1791735107598917686,7006256221044920402,6334829850000653455,220619424095091815,8762306872487107823,6760663898027671553,3119201861333200642,2759501666071804968,5695394238467027335,4080037266440605259,9212728441686358556,1568079412127858377,7817078055990358377,1742424884223929376,3205213869281447648,4035370856202412212,1757902253388209644,3602382300821691293,291813469379992995,6618887678447395269],"m_LastClickedFileID":0}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"cameraMode":{"drawMode":0,"name":"Shaded","section":"Shading Mode"},"sceneLighting":true,"audioPlay":false,"sceneViewState":{"m_AlwaysRefresh":false,"showFog":true,"showSkybox":true,"showFlares":true,"showImageEffects":true,"showParticleSystems":true,"showVisualEffectGraphs":true,"m_FxEnabled":true},"in2DMode":false,"pivot":{"x":14.964712142944336,"y":19.526031494140626,"z":-0.01712322235107422},"rotation":{"x":-0.029442600905895234,"y":-0.9701462388038635,"z":0.18195778131484986,"w":-0.1570826917886734},"size":8.6972017288208,"orthographic":false}
1+
{"cameraMode":{"drawMode":0,"name":"Shaded","section":"Shading Mode"},"sceneLighting":true,"audioPlay":false,"sceneViewState":{"m_AlwaysRefresh":false,"showFog":true,"showSkybox":true,"showFlares":true,"showImageEffects":true,"showParticleSystems":true,"showVisualEffectGraphs":true,"m_FxEnabled":true},"in2DMode":false,"pivot":{"x":11.686104774475098,"y":23.387985229492189,"z":9.061652183532715},"rotation":{"x":-0.04211599379777908,"y":-0.9565999507904053,"z":0.17793354392051698,"w":-0.22652927041053773},"size":8.6972017288208,"orthographic":false}

0 commit comments

Comments
 (0)