Skip to content

Commit

Permalink
Plane collision area fixed and Mass for entire mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Apr 25, 2022
1 parent 53bbe8f commit 946ca9a
Show file tree
Hide file tree
Showing 99 changed files with 746 additions and 1,319 deletions.
3 changes: 2 additions & 1 deletion ClothPhysics/Assets/Prefabs/SampleWarrior.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -2073,12 +2073,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_NodeMass: 0.03
m_SolvingMethod: 3
m_TimeStep: 0.02
m_Substeps: 5
m_Paused: 0
m_Gravity: {x: 0, y: -9.81, z: 0}
m_NodeMass: 0.03
m_MeshMass: 20
m_NodeDamping: 1
m_SpringDamping: 1
m_TractionStiffness: 40
Expand Down
18 changes: 16 additions & 2 deletions ClothPhysics/Assets/Scenes/ClothSampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_NodeMass: 0.03
m_SolvingMethod: 1
m_TimeStep: 0.02
m_Substeps: 5
m_Paused: 1
m_Gravity: {x: 0, y: -9.81, z: 0}
m_NodeMass: 0.03
m_MeshMass: 0
m_NodeDamping: 0.3
m_SpringDamping: 0.3
m_TractionStiffness: 20
Expand Down Expand Up @@ -813,6 +814,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
propertyPath: m_MeshMass
value: 3.6
objectReference: {fileID: 0}
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
propertyPath: m_CollidingMeshes.Array.data[0]
value:
Expand Down Expand Up @@ -1122,12 +1127,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 64ea09637adbe6041bed55d9f421aca4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_NodeMass: 0.03
m_SolvingMethod: 1
m_TimeStep: 0.007
m_Substeps: 1
m_Paused: 1
m_Gravity: {x: 0, y: -9.81, z: 0}
m_NodeMass: 0.03
m_MeshMass: 0
m_NodeDamping: 0.3
m_SpringDamping: 0.3
m_TractionStiffness: 20
Expand Down Expand Up @@ -1289,6 +1295,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
propertyPath: m_MeshMass
value: 3.6
objectReference: {fileID: 0}
- target: {fileID: 6174403516559788333, guid: 82e3ccf40b371f1488a235d98adcf249, type: 3}
propertyPath: m_CollidingMeshes.Array.data[0]
value:
Expand Down Expand Up @@ -1406,6 +1416,10 @@ PrefabInstance:
propertyPath: Mass
value: 0.82
objectReference: {fileID: 0}
- target: {fileID: 7945908319452971428, guid: c8bb9f24a9ed08541a45b7bc699dacc0, type: 3}
propertyPath: m_MeshMass
value: 3.6
objectReference: {fileID: 0}
- target: {fileID: 7945908319452971428, guid: c8bb9f24a9ed08541a45b7bc699dacc0, type: 3}
propertyPath: m_Substeps
value: 1
Expand Down
22 changes: 13 additions & 9 deletions ClothPhysics/Assets/Scripts/ClothBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class ClothBehaviour : MonoBehaviour

[HideInInspector] private float m_SubTimeStep;

[HideInInspector] public float m_NodeMass;


#endregion


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

[SerializeField] public Vector3 m_Gravity;

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

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

m_NodeMass = 0.03f;
m_MeshMass = 3.63f;

m_NodeDamping = 0.3f;
m_SpringDamping = 0.3f;
Expand Down Expand Up @@ -149,23 +152,23 @@ public enum WindPrecission
private void LowResSetup()
{
m_TimeStep = 0.02f; m_Paused = true;
m_TractionStiffness = 20f; m_FlexionStiffness = 15f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_TractionStiffness = 20f; m_FlexionStiffness = 15f; m_MeshMass = 3.6f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_SolvingMethod = Solver.Simplectic;
m_WindSolverPrecission = WindPrecission.High;
}
[ContextMenu("Medium Res Mesh Setup")]
private void MedResSetup()
{
m_TimeStep = 0.01f; m_Substeps = 2; m_Paused = true;
m_TractionStiffness = 50f; m_FlexionStiffness = 30f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_TractionStiffness = 50f; m_FlexionStiffness = 30f; m_MeshMass = 20f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_SolvingMethod = Solver.Simplectic;
m_WindSolverPrecission = WindPrecission.Medium;
}
[ContextMenu("High Res Mesh Setup")]
private void HighResSetup()
{
m_TimeStep = 0.007f; m_Substeps = 1; m_Paused = true;
m_TractionStiffness = 100f; m_FlexionStiffness = 80f; m_NodeMass = 0.03f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_TractionStiffness = 100f; m_FlexionStiffness = 80f; m_MeshMass = 50f; m_NodeDamping = 0.3f; m_SpringDamping = 0.3f;
m_SolvingMethod = Solver.Simplectic;
m_WindSolverPrecission = WindPrecission.Low;
}
Expand All @@ -183,7 +186,7 @@ public void Start()

m_Nodes = new List<Node>();


m_NodeMass = m_MeshMass / m_Vertices.Length;

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

m_NodeMass = m_MeshMass / m_Vertices.Length;
m_SubTimeStep = m_TimeStep / m_Substeps;

CheckWindObjects();
Expand Down Expand Up @@ -741,8 +745,8 @@ public int isColliding(GameObject obj, float offset)
else if (obj.GetComponent<MeshCollider>() != null)
{
MeshCollider collider = obj.GetComponent<MeshCollider>();
float xExtension = collider.bounds.extents.x;
float zExtension = collider.bounds.extents.z;
float xExtension = collider.sharedMesh.bounds.extents.x;
float zExtension = collider.sharedMesh.bounds.extents.z;
Vector3 nodeLocalPos = obj.transform.InverseTransformPoint(m_Pos);
if (nodeLocalPos.y <= 0f + offset && nodeLocalPos.y >= -1.0f && Mathf.Abs(nodeLocalPos.z) <= zExtension && Mathf.Abs(nodeLocalPos.x) <= xExtension) return 2;
}
Expand Down
1 change: 1 addition & 0 deletions ClothPhysics/Assets/Scripts/Editor/ClothBehaviorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


[CustomEditor(typeof(ClothBehaviour))]
[CanEditMultipleObjects]
public class ClothBehaviorEditor : Editor
{
public override void OnInspectorGUI()
Expand Down
Binary file modified ClothPhysics/Library/ArtifactDB
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.
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.
44 changes: 22 additions & 22 deletions ClothPhysics/Library/CurrentLayout-default.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MonoBehaviour:
width: 1920
height: 997
m_ShowMode: 4
m_Title: Project
m_Title: Game
m_RootView: {fileID: 2}
m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000}
Expand All @@ -46,7 +46,7 @@ MonoBehaviour:
y: 0
width: 1920
height: 997
m_MinSize: {x: 875, y: 542}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1
m_TopViewHeight: 30
Expand Down Expand Up @@ -122,7 +122,7 @@ MonoBehaviour:
m_MinSize: {x: 677, y: 492}
m_MaxSize: {x: 14001, y: 14042}
vertical: 0
controlID: 6232
controlID: 18
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -147,7 +147,7 @@ MonoBehaviour:
m_MinSize: {x: 402, y: 492}
m_MaxSize: {x: 10001, y: 14042}
vertical: 1
controlID: 6233
controlID: 115
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -172,7 +172,7 @@ MonoBehaviour:
m_MinSize: {x: 402, y: 221}
m_MaxSize: {x: 8002, y: 4021}
vertical: 0
controlID: 6234
controlID: 116
--- !u!114 &8
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -226,7 +226,7 @@ MonoBehaviour:
- {fileID: 16}
- {fileID: 13}
m_Selected: 0
m_LastSelected: 2
m_LastSelected: 1
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -309,7 +309,7 @@ MonoBehaviour:
m_ViewDataDictionary: {fileID: 0}
m_LockTracker:
m_IsLocked: 0
m_LastSelectedObjectID: -1742
m_LastSelectedObjectID: 18844
--- !u!114 &13
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -424,9 +424,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 14.964712, y: 19.526031, z: -0.017123222}
m_Target: {x: 11.686105, y: 23.387985, z: 9.061652}
speed: 2
m_Value: {x: 14.964712, y: 19.526031, z: -0.017123222}
m_Value: {x: 11.686105, y: 23.387985, z: 9.061652}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
Expand Down Expand Up @@ -473,13 +473,13 @@ MonoBehaviour:
m_GridAxis: 1
m_gridOpacity: 0.5
m_Rotation:
m_Target: {x: -0.0294426, y: -0.97014624, z: 0.18195778, w: -0.15708269}
m_Target: {x: -0.042115994, y: -0.95659995, z: 0.17793354, w: -0.22652927}
speed: 2
m_Value: {x: -0.029172052, y: -0.97046125, z: 0.18201683, w: -0.1556402}
m_Value: {x: -0.04211951, y: -0.9566798, z: 0.1779484, w: -0.2265482}
m_Size:
m_Target: 8.697202
speed: 2
m_Value: 13.160997
m_Value: 8.697202
m_Ortho:
m_Target: 0
speed: 2
Expand Down Expand Up @@ -532,9 +532,9 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 3cf9ffff1afbffff1efbffff22fbffff26fbffff2afbffff62fbffff6efbffff
m_SelectedIDs: 6cfbffff
m_LastClickedID: -1172
m_ExpandedIDs: f8f6ffff3cf9ffff6efbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -616,7 +616,7 @@ MonoBehaviour:
m_HSlider: 0
m_VSlider: 0
m_IgnoreScrollWheelUntilClicked: 0
m_EnableMouseInput: 1
m_EnableMouseInput: 0
m_EnableSliderZoomHorizontal: 0
m_EnableSliderZoomVertical: 0
m_UniformScale: 1
Expand Down Expand Up @@ -685,22 +685,22 @@ MonoBehaviour:
m_SkipHidden: 0
m_SearchArea: 1
m_Folders:
- Assets/Prefabs
- Assets/Scripts
m_Globs: []
m_OriginalText:
m_ViewMode: 1
m_StartGridSize: 64
m_LastFolders:
- Assets/Prefabs
- Assets/Scripts
m_LastFoldersGridSize: -1
m_LastProjectPath: "D:\\URJC\\TERCER0\\2\xBA CUATRIMESTRE\\Animacion3D\\Cloth-Behaviour-Simulation\\ClothPhysics"
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: a0430000
m_LastClickedID: 17312
m_ExpandedIDs: 000000009a4300009c4300009e430000a0430000a2430000a4430000a6430000a8430000aa430000ac430000ae430000ce43000000ca9a3b
m_SelectedIDs: 9e430000
m_LastClickedID: 17310
m_ExpandedIDs: 000000009a4300009c4300009e430000a0430000a2430000a4430000a6430000a8430000aa430000ac430000ae430000b243000000ca9a3b
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -841,7 +841,7 @@ MonoBehaviour:
m_ControlHash: -371814159
m_PrefName: Preview_InspectorPreview
m_LastInspectedObjectInstanceID: -1
m_LastVerticalScrollValue: 375
m_LastVerticalScrollValue: 0
m_GlobalObjectId:
m_LockTracker:
m_IsLocked: 0
Expand Down
Binary file modified ClothPhysics/Library/SceneVisibilityState.asset
Binary file not shown.
Binary file modified ClothPhysics/Library/ScriptAssemblies/Assembly-CSharp-Editor.dll
Binary file not shown.
Binary file modified ClothPhysics/Library/ScriptAssemblies/Assembly-CSharp.dll
Binary file not shown.
Binary file modified ClothPhysics/Library/ShaderCache/EditorEncounteredVariants
Binary file not shown.
Binary file modified ClothPhysics/Library/SourceAssetDB
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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}
{"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}
Original file line number Diff line number Diff line change
@@ -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}
{"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}
Loading

0 comments on commit 946ca9a

Please sign in to comment.