Skip to content

fix(MeshHelper): get_triangles on meshes without indices - #381

Open
nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:fix/mesh-without-indices
Open

nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:fix/mesh-without-indices

Conversation

@nichinichisou0609

Copy link
Copy Markdown

MeshHandler.copy_from_mesh copies mesh.m_IndexBuffer only when it is non-empty, so for a mesh without indices self.m_IndexBuffer stays None, and get_triangles stops at assert self.m_IndexBuffer is not None. Exporting such a mesh (mesh.export()) therefore fails with an AssertionError.

Unity serializes meshes like this, for example:

  • a placeholder mesh with vertices but no submeshes (seen with the prefab mesh of a Spine skeleton: 4 vertices, empty index buffer, m_SubMeshes == []);
  • an empty mesh with one submesh whose indexCount is 0.

Changes:

  • get_triangles: when there is no index buffer, return an empty triangle list for each submesh. If a submesh declares indices (indexCount > 0) while the mesh has no index buffer, raise a ValueError instead, since that data is inconsistent. This matches AssetStudio's GetTriangles, which loops over the submeshes of an empty index buffer without output and fails with an index error when a submesh has indices that the buffer does not hold.
  • copy_from_mesh is unchanged, and so are compressed meshes, whose indices come from m_CompressedMesh; the new check only runs when there is no index buffer at all.
  • tests/test_mesh_helper.py covers the three cases on the xinzexi_2_n_tex sample mesh, with its fields changed in memory: no submeshes and no indices (empty result, OBJ export with vertices and no faces), submeshes with indexCount 0, and submeshes with indices but no index buffer (ValueError). All three fail on master with the AssertionError.

This is the index-buffer counterpart of the empty VertexData handling added in #366.

MeshHandler only copies a non-empty index buffer, so for a mesh without
indices m_IndexBuffer stays None and get_triangles failed its first
assertion. Such a mesh (vertices only, e.g. a placeholder mesh, or
submeshes with indexCount 0) now gets an empty triangle list per submesh;
a submesh that has indices while the mesh has no index buffer raises a
ValueError.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant