Skip to content

Commit

Permalink
fix outline mesh generation for some models, fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
ScanMountGoat committed Jul 29, 2024
1 parent 3c62e19 commit 2c80faf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## unreleased
### Fixed
* Fixed an issue where exporting would fail if an image texture did not use the expected naming convention.
* Fixed an issue where some models would not correctly generate outline meshes for all relevant meshes.

## 0.11.0 - 2024-07-26
### Added
Expand Down
38 changes: 22 additions & 16 deletions xenoblade_blender/export_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,21 @@ def export_mesh_inner(

# TODO: report a warning if this fails.
if has_outlines is not None and original_mesh_index is not None:
# Find the outline material for this material.
# Use the original index in case the name is new.
outline_material_index = None
for i, material in enumerate(root.models.materials):
# TODO: How to handle materials with the same name?
if material.name == root.models.materials[material_index].name + "_outline":
outline_material_index = i
break
original_mesh = original_meshes[original_mesh_index]

# Find the original outline mesh.
# TODO: Find a way to generate outline meshes instead.
# Find the original outline mesh and its outline material.
# TODO: Find a way to generate outline meshes and materials instead.
original_outline_mesh = None
outline_material_index = None
for i, mesh in enumerate(original_meshes):
if mesh.material_index == outline_material_index:
# Outlines use the same vertex data but a different material.
if (
mesh.vertex_buffer_index == original_mesh.vertex_buffer_index
and mesh.index_buffer_index == original_mesh.index_buffer_index
and original_materials[mesh.material_index].name.endswith("_outline")
):
original_outline_mesh = mesh
outline_material_index = mesh.material_index
break

if original_outline_mesh is not None and outline_material_index is not None:
Expand All @@ -503,11 +503,17 @@ def export_mesh_inner(
# xc3_model will fill in missing required attributes with default values.
# TODO: Raise an error if the color data is missing?
# TODO: How to handle the alpha for outline width?
outline_attributes = [
xc3_model_py.vertex.AttributeData(
xc3_model_py.vertex.AttributeType.Normal, normals
),
]
outline_attributes = []

# Buffers with morphs should omit the normals to work properly in game.
# The normals are already provided by the morph attributes.
if len(morph_targets) == 0:
outline_attributes.append(
xc3_model_py.vertex.AttributeData(
xc3_model_py.vertex.AttributeType.Normal, normals
)
)

for color_attribute in mesh_data.color_attributes:
if color_attribute.name == "OutlineVertexColor":
attribute = export_color_attribute(
Expand Down

0 comments on commit 2c80faf

Please sign in to comment.