Skip to content

fix(MeshHelper): apply submesh baseVertex to triangle indices - #384

Open
nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:codex/mesh-base-vertex
Open

nichinichisou0609 wants to merge 1 commit into
K0lb3:masterfrom
nichinichisou0609:codex/mesh-base-vertex

Conversation

@nichinichisou0609

@nichinichisou0609 nichinichisou0609 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

MeshHandler.get_triangles() returns the stored indices without applying the submesh's baseVertex. For a submesh with indices [0, 1, 2] and baseVertex = 5 it returns (0, 1, 2) instead of (5, 6, 7), so anything indexing the mesh's full vertex array (the OBJ exporter included) picks the wrong vertices.

Unity defines SubMeshDescriptor.baseVertex as an offset added to every index (which is also how a 16-bit index buffer can address a larger mesh), and Mesh.GetTriangles applies it by default.

The offset is added after the existing topology conversion, so triangles, strips and quads keep their winding. A missing, None or zero baseVertex behaves as before.

@nichinichisou0609
nichinichisou0609 marked this pull request as ready for review October 8, 2026 07:14
Comment thread tests/test_mesh_base_vertex.py Outdated
@@ -0,0 +1,177 @@
import struct

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the other PR,
I prefer real assets for the test cases of the Unity object handling functions,
instead of engineered tests, as such tests will always just work for the implemented code.
Ofc they protect against potential future breakage, but don't really provide any real value otherwise,
and instead add a relatively big maintenance cost.

@K0lb3

K0lb3 commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Besides the test, looks good, and seems to be correct.
(Double checked against the Unity docs)

@nichinichisou0609

nichinichisou0609 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for checking it against the docs! Removed the test file and rebased on master, so it's just the change in MeshHelper now.

If a sample helps: the zip has a tiny AssetBundle with one mesh whose second submesh uses baseVertex = 4, built from an empty Unity 2022.3 project (build script included). Use it or not, whatever works for you.

unitypy-384-samples.zip

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.

2 participants