Repository navigation
fix(MeshHelper): apply submesh baseVertex to triangle indices - #384
Open
nichinichisou0609 wants to merge 2 commits into
Open
nichinichisou0609 wants to merge 2 commits into
nichinichisou0609 wants to merge 2 commits into
Conversation
nichinichisou0609
marked this pull request as ready for review
October 8, 2026 07:14
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MeshHandler.get_triangles()currently returns indices without applying the submesh'sbaseVertex. For a submesh containing[0, 1, 2]withbaseVertex = 5, it returns(0, 1, 2)instead of(5, 6, 7). Consumers that index the mesh's complete vertex array consequently select the wrong vertices. In the synthetic OBJ case, the face changes fromf 3/3/3 2/2/2 1/1/1tof 8/8/8 7/7/7 6/6/6, preserving the exporter's winding and one-based indices.Unity defines
SubMeshDescriptor.baseVertexas the offset applied to each stored index, including when a 16-bit index buffer addresses a larger mesh.Mesh.GetTrianglesapplies that offset by default. These public APIs establish the expected index arithmetic independently of the implementation.The change adds the submesh's nonzero
baseVertexto each triangle corner after the existing topology conversion. Missing,None, and zero values retain their existing behavior. Applying the offset after triangulation covers triangles, triangle strips, and quads without changing their winding or degenerate-strip handling.The affected path is visible in the base revision:
get_triangles()slices the index buffer and converts topology without addingbaseVertex;MeshExporterconsumes those indices directly when writing OBJ faces. Correcting the helper therefore also corrects exported face references.The triangulation refactor in #335 and empty-index handling in #381 remain intact. Neither applies this stored offset. AssetStudio reads
baseVertex, but its triangulation also leaves it unapplied. The expected results here follow Unity's API contract rather than that exporter's output.The 19 new regression cases construct in-memory
Meshobjects with packed vertex and index buffers. They exerciseMeshHandler.process()and the OBJ exporter without external asset files:firstByte, for 16-bit and 32-bit index buffers.None, and absentbaseVertexfields, and repeated reads without modifying the stored indices.baseVertex = 65536, checking that the resolved indices and OBJ references are not truncated to 16 bits.Validation on Linux x86_64 with CPython 3.9.25 / pytest 8.4.2 and CPython 3.13.16 / pytest 9.1.1. Both the compiled
UnityPyBoostpath and the Python fallback were exercised:417d595ruff checkandruff format --checkThe existing mesh-helper tests retain coverage for empty submeshes and absent index buffers. To reproduce the checks from the repository root after installing
.[tests]and Ruff:This patch changes the returned vertex indices for the topologies already supported by
get_triangles(). It adds no new topology, vertex-format decoder, serialization behavior, or public option. The fixtures exercise index arithmetic and export behavior. Windows/macOS CI and assets built by multiple Unity Editor versions have not been run for this change.