Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue with custom mesh on physics shape auth #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,33 +171,35 @@ bool GetMeshes(PhysicsShapeAuthoring shape, out List<UnityEngine.Mesh> meshes, o
meshes.Add(shape.CustomMesh);
childrenToShape.Add(float4x4.identity);
}

// Try to get all the meshes in the children
var meshFilters = GetComponentsInChildren<MeshFilter>();

foreach (var meshFilter in meshFilters)
else
{
if (meshFilter != null && meshFilter.sharedMesh != null)
// Try to get all the meshes in the children
var meshFilters = GetComponentsInChildren<MeshFilter>();

foreach (var meshFilter in meshFilters)
{
var shapeAuthoring = GetComponent<PhysicsShapeAuthoring>(meshFilter);
if (shapeAuthoring != null && shapeAuthoring != shape)
{
// Skip this case, since it will be treated independently
continue;
}

meshes.Add(meshFilter.sharedMesh);

// Don't calculate the children to shape if not needed, to avoid approximation that could prevent collider to be shared
if (shape.transform.localToWorldMatrix.Equals(meshFilter.transform.localToWorldMatrix))
childrenToShape.Add(float4x4.identity);
else
if (meshFilter != null && meshFilter.sharedMesh != null)
{
var transform = math.mul(shape.transform.worldToLocalMatrix, meshFilter.transform.localToWorldMatrix);
childrenToShape.Add(transform);
var shapeAuthoring = GetComponent<PhysicsShapeAuthoring>(meshFilter);
if (shapeAuthoring != null && shapeAuthoring != shape)
{
// Skip this case, since it will be treated independently
continue;
}

meshes.Add(meshFilter.sharedMesh);

// Don't calculate the children to shape if not needed, to avoid approximation that could prevent collider to be shared
if (shape.transform.localToWorldMatrix.Equals(meshFilter.transform.localToWorldMatrix))
childrenToShape.Add(float4x4.identity);
else
{
var transform = math.mul(shape.transform.worldToLocalMatrix, meshFilter.transform.localToWorldMatrix);
childrenToShape.Add(transform);
}

DependsOn(meshes.Last());
}

DependsOn(meshes.Last());
}
}

Expand Down