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

Mesh broken with many vertices #87

Merged
merged 3 commits into from
Mar 30, 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
2 changes: 2 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Mesh is broken if more than 65536 vertices are exists `#87`
- Because we didn't check for vertices count and index format, vertex index can be overflow before.

### Security

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The format is based on [Keep a Changelog].
- This can be problem with FreezeBlendShape.
- Assertion does not work well `#85`
- This can make invalid mesh
- Mesh is broken if more than 65536 vertices are exists `#87`
- Because we didn't check for vertices count and index format, vertex index can be overflow before.

### Security

Expand Down
27 changes: 17 additions & 10 deletions Editor/MergeSkinnedMeshWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ private void OnGUI()
_mesh = (Mesh)EditorGUILayout.ObjectField(_mesh, typeof(Mesh), true);
if (_mesh != null)
{
//PrintInfo(nameof(_mesh.indexFormat), _mesh.indexFormat);
//PrintInfo(nameof(_mesh.vertexBufferCount), _mesh.vertexBufferCount);
//PrintInfo(nameof(_mesh.blendShapeCount), _mesh.blendShapeCount);
SelectableLabelField(nameof(_mesh.indexFormat), _mesh.indexFormat);
SelectableLabelField(nameof(_mesh.vertexBufferCount), _mesh.vertexBufferCount);
SelectableLabelField(nameof(_mesh.blendShapeCount), _mesh.blendShapeCount);
PrintInfo(nameof(_mesh.bindposes), _mesh.bindposes);
//PrintInfo(nameof(_mesh.isReadable), _mesh.isReadable);
//PrintInfo(nameof(_mesh.canAccess), _mesh.canAccess); internal
Expand All @@ -37,23 +37,30 @@ private void OnGUI()
//PrintInfo(nameof(_mesh.vertexAttributeCount), _mesh.vertexAttributeCount);
PrintInfo(nameof(_mesh.triangles), _mesh.triangles);
PrintInfo(nameof(_mesh.boneWeights), _mesh.boneWeights);
EditorGUILayout.LabelField("BlendShape count", _mesh.blendShapeCount.ToString());
EditorGUILayout.LabelField("All Weights", _mesh.GetAllBoneWeights().Length.ToString());
EditorGUILayout.LabelField("BonesPerVertex", _mesh.GetBonesPerVertex().Length.ToString());
EditorGUILayout.LabelField("subMeshCount", _mesh.subMeshCount.ToString());
SelectableLabelField("BlendShape count", _mesh.blendShapeCount);
SelectableLabelField("All Weights", _mesh.GetAllBoneWeights().Length);
SelectableLabelField("BonesPerVertex", _mesh.GetBonesPerVertex().Length);
SelectableLabelField("subMeshCount", _mesh.subMeshCount);
for (var i = 0; i < _mesh.subMeshCount; i++)
EditorGUILayout.LabelField($"subMesh #{i}", _mesh.GetSubMesh(i).ToString());
SelectableLabelField($"subMesh #{i}", _mesh.GetSubMesh(i));
var attributes = _mesh.GetVertexAttributes();
for (var i = 0; i < attributes.Length; i++)
{
EditorGUILayout.LabelField($"attr #{i}", attributes[i].ToString());
SelectableLabelField($"attr #{i}", attributes[i]);
}
}
}

private void SelectableLabelField<T>(string label, T value)
{
var fullRect = EditorGUILayout.GetControlRect(true);
var elementRect = EditorGUI.PrefixLabel(fullRect, new GUIContent(label));
EditorGUI.SelectableLabel(elementRect, value.ToString());
}

private void PrintInfo<T>(string prop, T[] array)
{
EditorGUILayout.LabelField(prop, array == null ? "null" : array.Length.ToString());
SelectableLabelField(prop, array == null ? "null" : array.Length.ToString());
}

[MenuItem("Tools/Avatar Optimizer/Test GUI")]
Expand Down
1 change: 1 addition & 0 deletions Editor/Processors/SkinnedMeshes/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public void WriteToMesh(Mesh destMesh)
triangles[trianglesIndex++] = vertexIndices[triangle];
}

destMesh.indexFormat = triangles.Length <= ushort.MaxValue ? IndexFormat.UInt16 : IndexFormat.UInt32;
destMesh.triangles = triangles;
destMesh.subMeshCount = SubMeshes.Count;
for (var i = 0; i < SubMeshes.Count; i++)
Expand Down