Skip to content

Commit

Permalink
Merge pull request #1256 from anatawa12/fix-remove-mesh-in-box
Browse files Browse the repository at this point in the history
Remove Mesh in Box broken with Mesh without Bones
  • Loading branch information
anatawa12 authored Oct 13, 2024
2 parents 7e71736 + 34d4fb9 commit 64a05b5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog].

### Fixed
- `InvalidOperationException` with removing all polygon on one material slot `#1255`
- Remove Mesh in Box does not work for meshes without Bones `#1256`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The format is based on [Keep a Changelog].
- maxSquish cannot be configured for mergePB`#1231`
- Avatar Descriptor can be removed by Avatar Optimizer in extreamely rare case `#1242`
- Material property animation with weight 0 layer might be broken with AutoMergeSkinnedMesh `#1248` `#1253`
- Remove Mesh in Box does not work for meshes without Bones `#1256`

### Security

Expand Down
2 changes: 2 additions & 0 deletions Internal/MeshInfo2/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, Func<Transform, Matrix
if (TryGetBlendShape(name, weight, out var posDelta, out _, out _))
position += posDelta;

if (BoneWeights.Count == 0) return position;

// then, apply bones
var matrix = Matrix4x4.zero;
foreach (var (bone, weight) in BoneWeights)
Expand Down
71 changes: 35 additions & 36 deletions Test~/MeshInfo2/MeshInfo2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void RootBoneWithNoneMeshSkinnedMeshRenderer()
[Test]
public void MultiFrameBlendShapeWithPartiallyIdentity()
{
var mesh = BoxMesh();
var mesh = TestUtils.NewCubeMesh();
var deltas = new Vector3[8];
deltas.AsSpan().Fill(new Vector3(1, 2, 3));
mesh.AddBlendShapeFrame("shape", 0, new Vector3[8], null, null);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void MultiFrameBlendShapeWithPartiallyIdentity()
[Test]
public void BlendShapeWithFrameAtZero()
{
var mesh = BoxMesh();
var mesh = TestUtils.NewCubeMesh();
var deltas = new Vector3[8];
deltas.AsSpan().Fill(new Vector3(1, 2, 3));
mesh.AddBlendShapeFrame("shape", 0, deltas, null, null);
Expand All @@ -158,7 +158,7 @@ public void BlendShapeWithFrameAtZero()
[Test]
public void WriteEmptySubMesh()
{
var mesh = BoxMesh();
var mesh = TestUtils.NewCubeMesh();

var go = new GameObject();
var smr = go.AddComponent<SkinnedMeshRenderer>();
Expand All @@ -175,46 +175,45 @@ public void WriteEmptySubMesh()
Assert.That(newMesh.subMeshCount, Is.EqualTo(1));
}

private Mesh BoxMesh()
[Test]
public void ComputeActualPositionWithoutBones()
{
var mesh = new Mesh
var mesh = TestUtils.NewCubeMesh();

var go = new GameObject();
var smr = go.AddComponent<SkinnedMeshRenderer>();
smr.sharedMesh = mesh;

var meshInfo2 = new MeshInfo2(smr);

foreach (var vertex in meshInfo2.Vertices)
{
vertices = new[]
{
new Vector3(-1, -1, -1),
new Vector3(+1, -1, -1),
new Vector3(-1, +1, -1),
new Vector3(+1, +1, -1),
new Vector3(-1, -1, +1),
new Vector3(+1, -1, +1),
new Vector3(-1, +1, +1),
new Vector3(+1, +1, +1),
},
triangles = new[]
{
0, 1, 2,
1, 3, 2,
var position = vertex.ComputeActualPosition(meshInfo2,
t => t.localToWorldMatrix, go.transform.worldToLocalMatrix);

4, 6, 5,
5, 6, 7,
Assert.That(position, Is.EqualTo(vertex.Position));
}
}

0, 4, 1,
[Test]
public void ComputeActualPositionWithBones()
{
var mesh = TestUtils.NewCubeMesh();

1, 4, 5,
1, 5, 3,

3, 5, 7,
3, 7, 2,

2, 7, 6,
2, 6, 0,
},
};
var go = new GameObject();
var smr = go.AddComponent<SkinnedMeshRenderer>();
smr.sharedMesh = mesh;

mesh.subMeshCount = 1;
mesh.SetSubMesh(0, new SubMeshDescriptor(0, mesh.triangles.Length));
var meshInfo2 = new MeshInfo2(smr);
meshInfo2.MakeBoned();

return mesh;
foreach (var vertex in meshInfo2.Vertices)
{
var position = vertex.ComputeActualPosition(meshInfo2,
t => t.localToWorldMatrix, go.transform.worldToLocalMatrix);

Assert.That(position, Is.EqualTo(vertex.Position));
}
}
}
}

0 comments on commit 64a05b5

Please sign in to comment.