Skip to content

Commit

Permalink
finish fixing up text and curves
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 20, 2024
1 parent 9f53d80 commit c2ae919
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
4 changes: 3 additions & 1 deletion fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def check_face_materials(
" Assign the faces to a valid slot."
f" (0-indexed: slot {material_index}, aka the {material_index+1}th slot)."
)
material = material_slots[material_index].material
material = material_slots[material_index]
if isinstance(material, bpy.types.MaterialSlot):
material = material.material
if material is None:
raise PluginError(
f"Mesh object {obj_name} has faces"
Expand Down
36 changes: 16 additions & 20 deletions fast64_internal/f3d/glTF/f3d_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def uvmap_check(mesh: Mesh):
raise PluginError('Object with F3D materials does not have a "UVMap" uvmap layer.')


def large_tex_checks(obj: Object, mesh: Mesh):
def large_tex_checks(materials: list[Material], mesh: Mesh):
"""
See TileLoad.initWithFace for the usual exporter version of this function
This strips out any exporting and focous on just error checking
Expand Down Expand Up @@ -166,10 +166,14 @@ def get_tmem_usage(width, height, texels_per_word=texels_per_word):
raise PluginError('Cannot do large texture checks without a "UVMap" uvmap layer.')
uv_data = mesh.uv_layers["UVMap"].data
for face in mesh.loop_triangles:
mat_name = obj.material_slots[face.material_index].material.name
material = materials[face.material_index]
if material is None:
continue
mat_name: str = material.name
large_props = large_props_dict.get(mat_name)
if large_props is None:
continue

dimensions = large_props["dimensions"]
face_uvs = [UVtoSTLarge(None, loop_index, uv_data, dimensions) for loop_index in face.loops]
sl, sh, tl, th = 1000000, -1, 1000000, -1
Expand Down Expand Up @@ -600,26 +604,27 @@ def gather_material_hook(self, gltf2_material, blender_material: Material, expor
if not f3d_mat.rdp_settings.g_lighting:
self.append_extension(gltf2_material, "KHR_materials_unlit")

def gather_mesh_hook(self, gltf2_mesh, blender_mesh, blender_object, _export_settings: dict):
# TODO: Check if there is no issues with text and curves
def gather_mesh_hook(
self, gltf2_mesh, blender_mesh, _blender_object, _vertex_groups, _modifiers, materials, _export_settings
):
if self.settings.raise_bad_mat_slot:
material_slots = blender_object.material_slots
if len(blender_mesh.materials) == 0 or len(material_slots) == 0:
if len(blender_mesh.materials) == 0 or len(materials) == 0:
raise PluginError("Object does not have any materials.")
check_face_materials(
blender_object.name,
material_slots,
gltf2_mesh.name,
materials,
blender_mesh.polygons,
self.settings.raise_non_f3d_mat,
)
if self.settings.raise_no_uvmap:
uvmap_check(blender_mesh)
if self.settings.raise_large_tex:
large_tex_checks(blender_object, blender_mesh)
large_tex_checks(materials, blender_mesh)

if not self.gbi.F3D_OLD_GBI and not blender_object.use_f3d_culling:
def gather_node_hook(self, gltf2_node, blender_object, _export_settings: dict):
if gltf2_node.mesh and not self.gbi.F3D_OLD_GBI and not blender_object.use_f3d_culling:
self.append_extension(
gltf2_mesh,
gltf2_node.mesh,
MESH_EXTENSION_NAME,
{
"extensions": {
Expand All @@ -632,15 +637,6 @@ def gather_mesh_hook(self, gltf2_mesh, blender_mesh, blender_object, _export_set
},
)

def gather_node_hook(self, gltf2_node, blender_object, _export_settings: dict):
if gltf2_node.mesh: # HACK: gather_mesh_hook is broken in 3.2, no blender object included
self.gather_mesh_hook(
gltf2_node.mesh,
blender_object.data,
blender_object,
_export_settings,
)

# Importing

def gather_import_material_after_hook(
Expand Down
14 changes: 14 additions & 0 deletions gltf_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ def gather_node_hook(self, gltf2_node, blender_object, export_settings):
export_settings,
)

def gather_mesh_hook(self, gltf2_mesh, blender_mesh, blender_object, vertex_groups, modifiers, *last_args):
materials, export_settings = last_args[-2:] # 3.2
self.call_hooks(
"gather_mesh_hook",
'Mesh "{args[1].name}"',
gltf2_mesh,
blender_mesh,
blender_object,
vertex_groups,
modifiers,
materials,
export_settings,
)

def gather_material_hook(self, gltf2_material, blender_material, export_settings):
self.call_hooks(
"gather_material_hook",
Expand Down

0 comments on commit c2ae919

Please sign in to comment.