diff --git a/fast64_internal/f3d/f3d_material.py b/fast64_internal/f3d/f3d_material.py index ba513fdc9..27e5363e7 100644 --- a/fast64_internal/f3d/f3d_material.py +++ b/fast64_internal/f3d/f3d_material.py @@ -2161,9 +2161,9 @@ def update_tex_values(self, context): def get_tex_basis_size(f3d_mat: "F3DMaterialProperty"): useDict, tex_dimensions = all_combiner_uses(f3d_mat), [32, 32] if useDict["Texture 0"] and f3d_mat.tex0.is_set: - tex_dimensions = tex0_dimensions = f3d_mat.tex0.get_tex_size() + tex_dimensions = tex0_dimensions = f3d_mat.tex0.tex_size if useDict["Texture 1"] and f3d_mat.tex1.is_set: - tex_dimensions = f3d_mat.tex1.get_tex_size() + tex_dimensions = f3d_mat.tex1.tex_size return tex0_dimensions if f3d_mat.get_uv_basis() == "TEXEL0" else tex_dimensions @@ -2760,7 +2760,7 @@ def update_tex_field_prop(self: Property, context: Context): prop_path = self.path_from_id() tex_property, tex_index = get_tex_prop_from_path(material, prop_path) - tex_size = tex_property.get_tex_size() + tex_size = tex_property.tex_size if tex_size[0] > 0 and tex_size[1] > 0: update_tex_values_field(material, tex_property, tex_size, tex_index) @@ -2775,7 +2775,7 @@ def toggle_auto_prop(self, context: Context): prop_path = self.path_from_id() tex_property, tex_index = get_tex_prop_from_path(material, prop_path) if tex_property.autoprop: - tex_size = tuple([s for s in tex_property.get_tex_size()]) + tex_size = tuple([s for s in tex_property.tex_size]) if tex_size[0] > 0 and tex_size[1] > 0: update_tex_values_field(material, tex_property, tex_size, tex_index) @@ -2910,7 +2910,8 @@ def is_ci(self): def is_set(self): return self.tex_set and (self.use_tex_reference or self.tex is not None) - def get_tex_size(self) -> list[int]: + @property + def tex_size(self) -> list[int]: if self.tex or self.use_tex_reference: if self.tex is not None: return list(self.tex.size) @@ -2918,6 +2919,10 @@ def get_tex_size(self) -> list[int]: return list(self.tex_reference_size) return [0, 0] + @property + def word_usage(self): + return getTmemWordUsage(self.tex_format, *self.tex_size) + @property def format_type(self): return texFormatOf[self.tex_format][len("G_IM_FMT_") :] diff --git a/fast64_internal/f3d/glTF/f3d_gltf.py b/fast64_internal/f3d/glTF/f3d_gltf.py index f0bf864f4..a789b9b3c 100644 --- a/fast64_internal/f3d/glTF/f3d_gltf.py +++ b/fast64_internal/f3d/glTF/f3d_gltf.py @@ -19,7 +19,6 @@ all_combiner_uses, get_color_info_from_tex, getTmemMax, - getTmemWordUsage, link_if_none_exist, remove_first_link_if_exists, rendermode_presets_checks, @@ -85,7 +84,7 @@ def large_tex_checks(obj: Object, mesh: Mesh): continue f3d_mat: F3DMaterialProperty = mat.f3d_mat use_dict = all_combiner_uses(f3d_mat) - textures = [] + textures: list[TextureProperty] = [] if use_dict["Texture 0"] and f3d_mat.tex0.tex_set: textures.append(f3d_mat.tex0) if use_dict["Texture 1"] and f3d_mat.tex1.tex_set: @@ -95,14 +94,8 @@ def large_tex_checks(obj: Object, mesh: Mesh): continue texture = textures[0] - tex_sizes = [tex.get_tex_size() for tex in textures] - tmem = sum( - getTmemWordUsage(tex.tex_format, *size) - for tex, size in zip( - textures, - tex_sizes, - ) - ) + tex_sizes = [tex.tex_size for tex in textures] + tmem = sum(tex.word_usage for tex in textures) tmem_size = 256 if texture.is_ci else 512 if tmem <= tmem_size: continue # Can fit in TMEM without large mode, so skip @@ -204,17 +197,15 @@ def get_tmem_usage(width, height, texels_per_word=texels_per_word): def multitex_checks(raise_large_multitex: bool, f3d_mat: F3DMaterialProperty): - tex0, tex1 = f3d_mat.tex0, f3d_mat.tex1 + tex0: TextureProperty = f3d_mat.tex0 + tex1: TextureProperty = f3d_mat.tex1 both_reference = tex0.use_tex_reference and tex1.use_tex_reference - both_ci8 = tex0.tex_format == tex1.tex_format == "CI8" same_reference = both_reference and tex0.tex_reference == tex1.tex_reference same_textures = same_reference or (not both_reference and tex0.tex == tex1.tex) + both_ci8 = tex0.tex_format == tex1.tex_format == "CI8" - tex0_size, tex1_size = tex0.get_tex_size(), tex1.get_tex_size() - tex0_tmem, tex1_tmem = ( - getTmemWordUsage(tex0.tex_format, *tex0_size), - getTmemWordUsage(tex1.tex_format, *tex1_size), - ) + tex0_size, tex1_size = tex0.tex_size, tex1.tex_size + tex0_tmem, tex1_tmem = tex0.word_usage, tex1.word_usage tmem = tex0_tmem if same_textures else tex0_tmem + tex1_tmem tmem_size = 256 if tex0.is_ci and tex1.is_ci else 512 @@ -252,10 +243,7 @@ def multitex_checks(raise_large_multitex: bool, f3d_mat: F3DMaterialProperty): if tex0.use_tex_reference != tex1.use_tex_reference and both_ci8: # TODO: If flipbook is ever implemented, check if the reference is set by the flipbook # Theoretically possible if there was an option to have half the palette for each - raise PluginError( - "Can't have two CI8 textures where only one is a reference; " - "no way to assign the palette." # pylint: disable=line-too-long - ) + raise PluginError("Can't have two CI8 textures where only one is a reference; no way to assign the palette.") if both_reference and both_ci8 and not same_pal_reference: raise PluginError("Can't have two CI8 textures with different palette references.") @@ -431,8 +419,8 @@ def f3d_to_gltf2_texture( source = get_gltf_image_from_blender_image(img.name, export_settings) if self.settings.raise_texture_limits and f3d_tex.tex_set: - tex_size = f3d_tex.get_tex_size() - tmem_usage = getTmemWordUsage(f3d_tex.tex_format, *tex_size) * 8 + tex_size = f3d_tex.tex_size + tmem_usage = f3d_tex.word_usage tmem_max = getTmemMax(f3d_tex.tex_format) if f3d_mat.use_large_textures and tex_size[0] > 1024 or tex_size[1] > 1024: @@ -497,7 +485,7 @@ def to_offset(low: float, tex_size: int): return trunc_10_2(low) * (1.0 / tex_size) transform_data = {} - size = f3d_tex.get_tex_size() + size = f3d_tex.tex_size if size != [0, 0]: offset = [to_offset(f3d_tex.S.low, size[0]), to_offset(f3d_tex.T.low, size[1])] if offset != [0.0, 0.0]: @@ -928,6 +916,7 @@ def modify_f3d_nodes_for_export(use: bool): link_if_none_exist(mat, vertex_color.outputs["Alpha"], bsdf.inputs["Alpha"]) link_if_none_exist(mat, bsdf.outputs["BSDF"], material_output.inputs["Surface"]) + def gather_mesh_hook(blender_mesh: Mesh, *args): """HACK: Runs right before the actual gather_mesh func in the addon, we need to join col and alpha""" print("F3D glTF: Applying alpha")