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

chore: do not add bone for boneless mesh renderer #694

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog].

### Fixed
- proxy animation can be modified `#678`
- complex shader with SkinnedMeshRenderer without Bones Brokebn `#694`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog].
- Improve support of newer Unity versions `#608`
- Improve support of projects without VRCSDK `#609` `#625` `#627`
- Prefab blinks when we see editor of PrefabSafeSet of prefab asset `#645` `#664`
- complex shader with SkinnedMeshRenderer without Bones Brokebn `#694`

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void Process(BuildContext context, MeshInfo2 target)
.ToArray();

foreach (var meshInfo2 in meshInfos) meshInfo2.FlattenMultiPassRendering("Merge Skinned Mesh");
foreach (var meshInfo2 in meshInfos) meshInfo2.MakeBoned();

var sourceMaterials = meshInfos.Select(x => x.SubMeshes.Select(y => (y.Topology, y.SharedMaterial)).ToArray()).ToArray();
Profiler.EndSample();
Expand Down
19 changes: 9 additions & 10 deletions Editor/Processors/SkinnedMeshes/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes
{
internal class MeshInfo2
{
public readonly Renderer SourceRenderer;
public Transform RootBone;
[NotNull] public readonly Renderer SourceRenderer;
[NotNull] public Transform RootBone;
public Bounds Bounds;
public readonly List<Vertex> Vertices = new List<Vertex>(0);

Expand All @@ -46,10 +46,6 @@ public MeshInfo2(SkinnedMeshRenderer renderer)
if (mesh)
ReadSkinnedMesh(mesh);

// if there's no bones: add one fake bone
if (Bones.Count == 0)
SetIdentityBone(renderer.rootBone ? renderer.rootBone : renderer.transform);

Bounds = renderer.localBounds;
RootBone = renderer.rootBone ? renderer.rootBone : renderer.transform;

Expand Down Expand Up @@ -80,8 +76,6 @@ public MeshInfo2(MeshRenderer renderer)
if (mesh)
ReadStaticMesh(mesh);

SetIdentityBone(renderer.transform);

if (mesh)
Bounds = mesh.bounds;
RootBone = renderer.transform;
Expand Down Expand Up @@ -131,9 +125,14 @@ public void AssertInvariantContract(string context)
$"{context}: some SubMesh has invalid bone weights");
}

private void SetIdentityBone(Transform transform)
/// <summary>
/// Makes all vertices in this MeshInfo2 boned.
/// </summary>
public void MakeBoned()
{
Bones.Add(new Bone(Matrix4x4.identity, transform));
if (Bones.Count != 0) return;

Bones.Add(new Bone(Matrix4x4.identity, RootBone));

foreach (var vertex in Vertices)
vertex.BoneWeights.Add((Bones[0], 1f));
Expand Down