From c2ae91966b48bedbc7d6366016dd4b53e6162be7 Mon Sep 17 00:00:00 2001 From: Lila Date: Fri, 20 Sep 2024 17:47:44 +0100 Subject: [PATCH] finish fixing up text and curves --- fast64_internal/f3d/f3d_writer.py | 4 +++- fast64_internal/f3d/glTF/f3d_gltf.py | 36 +++++++++++++--------------- gltf_extension.py | 14 +++++++++++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/fast64_internal/f3d/f3d_writer.py b/fast64_internal/f3d/f3d_writer.py index cb00af839..ef2c348d4 100644 --- a/fast64_internal/f3d/f3d_writer.py +++ b/fast64_internal/f3d/f3d_writer.py @@ -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" diff --git a/fast64_internal/f3d/glTF/f3d_gltf.py b/fast64_internal/f3d/glTF/f3d_gltf.py index c80c672d0..5d81692f2 100644 --- a/fast64_internal/f3d/glTF/f3d_gltf.py +++ b/fast64_internal/f3d/glTF/f3d_gltf.py @@ -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 @@ -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 @@ -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": { @@ -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( diff --git a/gltf_extension.py b/gltf_extension.py index 970af5284..179423ccf 100644 --- a/gltf_extension.py +++ b/gltf_extension.py @@ -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",