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

Relax limits about normals #569

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog].

### Fixed
- AnimatorOverrideController may not be proceed correctly `#567`
- Unclear behaviour if we merged meshes with and normals without that `#569`
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog].
### Fixed
- AnimatorController with Synced can be broken `#564`
- AnimatorOverrideController may not be proceed correctly `#567`
- Unclear behaviour if we merged meshes with and normals without that `#569`
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

### Security

Expand Down
11 changes: 11 additions & 0 deletions Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public override void Process(OptimizerSession session, MeshInfo2 target)
.ToArray();
var sourceMaterials = meshInfos.Select(x => x.SubMeshes.Select(y => y.SharedMaterial).ToArray()).ToArray();

// check normal information.
int hasNormal = 0;
foreach (var meshInfo2 in meshInfos)
hasNormal |= meshInfo2.HasNormals ? 1 : 2;

if (hasNormal == 3)
{
BuildReport.LogFatal("MergeSkinnedMesh:error:mix-normal-existence")?.WithContext(Component);
}

var (subMeshIndexMap, materials) = CreateMergedMaterialsAndSubMeshIndexMapping(sourceMaterials);

var sourceRootBone = target.RootBone;
Expand Down Expand Up @@ -127,6 +137,7 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) =>
target.Bones.AddRange(meshInfo.Bones);

target.HasColor |= meshInfo.HasColor;
target.HasNormals |= meshInfo.HasNormals;
target.HasTangent |= meshInfo.HasTangent;

target.AssertInvariantContract($"processing meshInfo {Target.gameObject.name}");
Expand Down
21 changes: 15 additions & 6 deletions Editor/Processors/SkinnedMeshes/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class MeshInfo2
public readonly List<Bone> Bones = new List<Bone>();

public bool HasColor { get; set; }
public bool HasNormals { get; set; }
public bool HasTangent { get; set; }

public MeshInfo2(SkinnedMeshRenderer renderer)
Expand Down Expand Up @@ -192,7 +193,11 @@ public void ReadStaticMesh([NotNull] Mesh mesh)
for (var i = 0; i < mesh.vertexCount; i++) Vertices.Add(new Vertex());

CopyVertexAttr(mesh.vertices, (x, v) => x.Position = v);
CopyVertexAttr(mesh.normals, (x, v) => x.Normal = v);
if (mesh.GetVertexAttributeDimension(VertexAttribute.Normal) != 0)
{
HasNormals = true;
CopyVertexAttr(mesh.normals, (x, v) => x.Normal = v);
}
if (mesh.GetVertexAttributeDimension(VertexAttribute.Tangent) != 0)
{
HasTangent = true;
Expand Down Expand Up @@ -275,6 +280,7 @@ public void Clear()
BlendShapes.Clear();
Bones.Clear();
HasColor = false;
HasNormals = false;
HasTangent = false;
}

Expand All @@ -301,14 +307,17 @@ public void WriteToMesh(Mesh destMesh)
// Basic Vertex Attributes: vertices, normals
{
var vertices = new Vector3[Vertices.Count];
var normals = new Vector3[Vertices.Count];
for (var i = 0; i < Vertices.Count; i++)
{
vertices[i] = Vertices[i].Position;
normals[i] = Vertices[i].Normal;
}

destMesh.vertices = vertices;
}

// tangents
if (HasNormals)
{
var normals = new Vector3[Vertices.Count];
for (var i = 0; i < Vertices.Count; i++)
normals[i] = Vertices[i].Normal;
destMesh.normals = normals;
}

Expand Down
5 changes: 5 additions & 0 deletions Localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ msgstr "Merge"
msgid "MergeSkinnedMesh:label:Renderers"
msgstr "Renderers:"

msgid "MergeSkinnedMesh:error:mix-normal-existence"
msgstr ""
"Merging mesh with normal and without normal is not supported! "
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
"Please change import setting of Normals to include normals!"
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

# endregion

# region MergeToonLitMaterial
Expand Down
5 changes: 5 additions & 0 deletions Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ msgstr "統合する"
msgid "MergeSkinnedMesh:label:Renderers"
msgstr "レンダラー:"

msgid "MergeSkinnedMesh:error:mix-normal-existence"
msgstr ""
"法線のあるモデルとないモデルを統合するのはサポートされてません! "
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
"法線を含むようにモデルのインポート設定を変更してください!"
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

# endregion

# region MergeToonLitMaterial
Expand Down