Skip to content

Fix de-indexed head LOD import and safe vertex overwrite - #6

Open
Puderzo wants to merge 1 commit into
AlexP0:masterfrom
Puderzo:fix-head-lod-external-overwrite
Open

Fix de-indexed head LOD import and safe vertex overwrite#6
Puderzo wants to merge 1 commit into
AlexP0:masterfrom
Puderzo:fix-head-lod-external-overwrite

Conversation

@Puderzo

@Puderzo Puderzo commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

PR: Fix de-indexed head LOD import and safe overwrite for external vertex buffers

Summary

This PR improves support for Star Wars Outlaws head meshes that use external type-12 vertex data, especially head LODs that are stored as de-indexed triangle lists.

Some head LODs, such as head_mesh_LOD1 and head_mesh_LOD2, are stored with vertex_count == index_count == triangle_count * 3. When imported directly, Blender creates one isolated vertex per triangle corner. This makes the mesh appear to have more vertices than higher-detail LODs, prevents normal smooth shading from working properly, and makes the mesh difficult to edit safely.

This PR detects those de-indexed LODs during import, merges identical positions into shared Blender topology for editing, and preserves the original source vertex-buffer order so Overwrite Vertices can write the edited positions back safely.

Why this is needed

Head meshes appear to use a special type-12 layout with external vertex data referenced by data_y_offset.

For example, tested head meshes showed patterns like:

  • head_mesh_LOD0
    • Indexed topology
    • External type-12 vertex data
    • data_y_offset used for vertex positions
  • head_mesh_LOD1
    • De-indexed triangle-list topology
    • Raw vertex count equals index count
    • Blender vertex count equals loop count before this fix
    • Smooth shading does not work correctly before this fix

Before this change, imported de-indexed LODs behaved like triangle soups in Blender. Even if the visible LOD was lower detail than LOD0, the raw Blender vertex count could appear much higher because every triangle corner was imported as a separate vertex.

Also, full export is currently unsafe for LODs using external type-12 vertex data, because the current full export path rebuilds the normal mesh stream but does not relocate or update the external data_y_offset vertex buffer. This can leave the header pointing to invalid or missing data and causes re-import failures.

What changed

Import

  • Detects de-indexed LODs where:

    vertex_count == index_count == triangle_count * 3
    
  • Merges identical vertex positions into shared Blender topology.

  • Preserves UVs as per-corner loop data.

  • Preserves a source vertex index per Blender face corner using a custom mesh attribute:

    SWOMT_source_vertex_index
    
  • Remaps bone weights so deduplicated Blender vertices receive valid weights from their original source vertices.

  • Skips custom normal import when normals_stride == 0, avoiding bogus custom normals from a non-existent normal stream.

Overwrite Vertices

  • Adds safe overwrite support for external type-12 vertex buffers.
  • For indexed external LODs, positions are written in normal vertex order.
  • For de-indexed external LODs, positions are written back in original source vertex-buffer order using SWOMT_source_vertex_index.
  • This allows the original .mmb structure and offsets to remain intact.

Export safety

  • Blocks full Export for LODs using data_y_offset.
  • Directs users to use Overwrite Vertices instead.
  • This avoids corrupting files by rebuilding the normal mesh stream while leaving external type-12 offset references invalid.

UI

  • Raw de-indexed-looking LOD counts are labelled with a raw suffix.
  • This makes it clearer that the displayed count may represent raw triangle-corner entries rather than editable Blender topology vertices.

Tested workflows

Tested with head mesh assets using external type-12 vertex data.

head_mesh_LOD1

Verified:

Import -> Overwrite Vertices -> Re-import

Result:

  • LOD imports as shared Blender topology.
  • Smooth shading works in Blender.
  • Overwrite Vertices writes back in correct source vertex-buffer order.
  • Re-import produces the expected shape instead of exploded geometry.

head_mesh_LOD0

Verified:

Import -> Overwrite Vertices -> Re-import

Result:

  • Indexed external vertex buffer overwrites correctly.
  • Re-import works after overwrite.

Known limitation

This PR does not implement full export support for external type-12 vertex data.

Full export for these LODs would require relocating or rebuilding the external vertex data blocks and updating all related offsets, including data_y_offset and related type-12 metadata. Until that is implemented, Overwrite Vertices is the safe supported workflow for these LODs.

Recommended workflow for affected head LODs

  1. Import the LOD.
  2. Edit vertex positions in Blender.
  3. Use Overwrite Vertices.
  4. Reload and re-import the .mmb to verify the result.

Do not use full Export for LODs that use external type-12 vertex data.

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