Skip to content

Commit

Permalink
Merge pull request #142 from 2024FALL-SWPP/bugfix/softbody_revisit
Browse files Browse the repository at this point in the history
fix: complex collider
  • Loading branch information
integraldx authored Dec 21, 2024
2 parents 5279ead + c67a234 commit 04e5822
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
45 changes: 23 additions & 22 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,28 +660,29 @@ private void CreateLockingObject()

public void FixJoint()
{
if (_hullMesh == null)
{
_hullMesh = new Mesh();
_hullMesh.MarkDynamic();
_lockingMeshCollider.sharedMesh = _hullMesh;
}

_hullMesh.SetVertices(WritableVertices);
_hullMesh.SetTriangles(WritableTris, 0);
_hullMesh.SetNormals(WritableNormals);

var simp = new MeshSimplifier();
simp.Initialize(_hullMesh);
simp.SimplifyMesh(0.3f);

_hullMesh.SetTriangles(simp.GetSubMeshTriangles(0), 0);
_hullMesh.SetVertices(simp.Vertices);
_hullMesh.RecalculateBounds();
_hullMesh.MarkModified();

Physics.BakeMesh(_hullMesh.GetInstanceID(), true);

// if (_hullMesh == null)
// {
// _hullMesh = new Mesh();
// _hullMesh.MarkDynamic();
// _lockingMeshCollider.sharedMesh = _hullMesh;
// }
//
// _hullMesh.SetVertices(WritableVertices);
// _hullMesh.SetTriangles(WritableTris, 0);
// _hullMesh.SetNormals(WritableNormals);
//
// var simp = new MeshSimplifier();
// simp.Initialize(_hullMesh);
// simp.SimplifyMesh(0.3f);
//
// _hullMesh.SetTriangles(simp.GetSubMeshTriangles(0), 0);
// _hullMesh.SetVertices(simp.Vertices);
// _hullMesh.RecalculateBounds();
// _hullMesh.MarkModified();
//
// Physics.BakeMesh(_hullMesh.GetInstanceID(), true);

_lockingMeshCollider.sharedMesh = _writableMesh;
_lockingMeshCollider.convex = true;
_lockingMeshCollider.hasModifiableContacts = true;

Expand Down
3 changes: 2 additions & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ PlayerSettings:
16:9: 1
Others: 0
bundleVersion: 0.1.0
preloadedAssets: []
preloadedAssets:
- {fileID: 11400000, guid: 232ef4def277d7d4cadf1d6d055ba9bb, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
Expand Down

0 comments on commit 04e5822

Please sign in to comment.