diff --git a/.gitignore b/.gitignore index be87d6a..8016114 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ pyproject.toml uv.lock .python-version TODO.md +.idea/ \ No newline at end of file diff --git a/migoto/exporter.py b/migoto/exporter.py index 5d8393e..f337338 100644 --- a/migoto/exporter.py +++ b/migoto/exporter.py @@ -47,15 +47,18 @@ class TextureData: @dataclass class Part: + name: str fullname: str objects: list[SubObj] textures: list[TextureData] first_index: int vertex_count: int = 0 + index_count: int = 0 @dataclass class Component: + name: str fullname: str parts: list[Part] root_vs: str @@ -167,6 +170,7 @@ def __post_init__(self) -> None: for component in self.hash_data: current_name: str = f"{self.mod_name}{component['component_name']}" component_entry: Component = Component( + name=component['component_name'], fullname=current_name, parts=[], root_vs=component.get("root_vs", ""), @@ -229,12 +233,25 @@ def __post_init__(self) -> None: self.obj_from_col(obj, None, objects) else: self.obj_from_col(obj, collection[0], objects) + index_count: int = 0 + if len(objects) > 0: + index_count = objects[0].obj.get("3DMigoto:IndexCount", 0) + else: + try: + index_count = component["object_index_counts"][j] if "object_index_counts" in component else 0 + except IndexError: + self.operator.report( + {"WARNING"}, + f"Index count for part {part_name} not found in hash.json. Defaulting to 0.", + ) component_entry.parts.append( Part( fullname=part_name, + name=part, objects=objects, textures=textures, first_index=component["object_indexes"][j], + index_count=index_count, ) ) self.mod_file.components.append(component_entry) @@ -336,11 +353,12 @@ def generate_buffers(self) -> None: layout=data_model.buffers_format["IB"] ) ib_offset: int = 0 - for t in part.textures: - tex_name = part.fullname + t.name + t.extension - self.files_to_copy[self.dump_path / tex_name] = ( - self.destination / tex_name - ) + if (component.draw_vb != "" and part.vertex_count > 0) or (component.draw_vb == "" and component.position_vb == ""): + for t in part.textures: + tex_name = part.fullname + t.name + t.extension + self.files_to_copy[self.dump_path / tex_name] = ( + self.destination / tex_name + ) if component.draw_vb == "": continue for entry in part.objects: @@ -386,20 +404,21 @@ def generate_buffers(self) -> None: if self.outline_optimization: self.optimize_outlines(out_buffers, component_ib) if component.blend_vb != "": - self.files_to_write[ - self.destination / (component.fullname + "Position.buf") - ] = out_buffers["Position"].data - self.files_to_write[ - self.destination / (component.fullname + "Blend.buf") - ] = out_buffers["Blend"].data - self.files_to_write[ - self.destination / (component.fullname + "Texcoord.buf") - ] = out_buffers["TexCoord"].data - component.strides = { - k.lower(): v.stride - for k, v in data_model.buffers_format.items() - if k != "IB" - } + if any([part.vertex_count for part in component.parts]): + self.files_to_write[ + self.destination / (component.fullname + "Position.buf") + ] = out_buffers["Position"].data + self.files_to_write[ + self.destination / (component.fullname + "Blend.buf") + ] = out_buffers["Blend"].data + self.files_to_write[ + self.destination / (component.fullname + "Texcoord.buf") + ] = out_buffers["TexCoord"].data + component.strides = { + k.lower(): v.stride + for k, v in data_model.buffers_format.items() + if k != "IB" + } continue self.files_to_write[self.destination / (component.fullname + ".buf")] = ( out_buffers["Position"].data @@ -494,6 +513,11 @@ def generate_ini( credit=self.credit, game=self.game, character_name=self.mod_name, + apply_modifiers=self.apply_modifiers, + copy_textures=self.copy_textures, + ignore_duplicate_textures=self.ignore_duplicate_textures, + no_ramps=self.no_ramps, + write_buffers=self.write_buffers ) ) ini_file.clean_up_indentation() diff --git a/migoto/import_ops.py b/migoto/import_ops.py index ba50ac9..5599d56 100644 --- a/migoto/import_ops.py +++ b/migoto/import_ops.py @@ -526,6 +526,7 @@ def import_3dmigoto_vb_ib( obj["3DMigoto:Topology"] = vb.topology for raw_vb in vb.vbs: obj["3DMigoto:VB%iStride" % raw_vb.idx] = raw_vb.stride + obj["3DMigoto:VertexCount"] = vb.vertex_count obj["3DMigoto:FirstVertex"] = vb.first # Record these import options so the exporter can set them to match by # default. Might also consider adding them to the .fmt file so reimporting @@ -546,6 +547,7 @@ def import_3dmigoto_vb_ib( # Attach the index buffer layout to the object for later exporting. obj["3DMigoto:IBFormat"] = ib.format obj["3DMigoto:FirstIndex"] = ib.first + obj["3DMigoto:IndexCount"] = ib.index_count elif vb.topology == "trianglelist": import_faces_from_vb_trianglelist(mesh, vb, flip_winding) elif vb.topology == "trianglestrip": diff --git a/templates/Zenless Zone Zero.ini.j2 b/templates/Zenless Zone Zero.ini.j2 index 87b6afc..83ea662 100644 --- a/templates/Zenless Zone Zero.ini.j2 +++ b/templates/Zenless Zone Zero.ini.j2 @@ -34,18 +34,18 @@ {% block overridesbuffers %} {% for component in mod_file.components if component.draw_vb != "" and component.blend_vb != "" and component.vertex_count > 0 %} - [TextureOverride{{ component.fullname }}Blend] - hash = {{ component.blend_vb }} - handling = skip - vb2 = Resource{{ component.fullname }}Blend - if DRAW_TYPE == 1 - vb0 = Resource{{ component.fullname }}Position - draw = {{ component.vertex_count }}, 0 - {% if credit != "" %} - - $active = 1 - {% endif %} - endif + [TextureOverride{{ component.fullname }}Blend] + hash = {{ component.blend_vb }} + handling = skip + vb2 = Resource{{ component.fullname }}Blend + if DRAW_TYPE == 1 + vb0 = Resource{{ component.fullname }}Position + draw = {{ component.vertex_count }}, 0 + {% if credit != "" %} + + $active = 1 + {% endif %} + endif [TextureOverride{{ component.fullname }}Texcoord] hash = {{ component.texcoord_vb }} @@ -69,38 +69,52 @@ {% endblock %} {% block overridesibs %} - {% for component in mod_file.components if component.draw_vb != "" %} - [TextureOverride{{component.fullname}}IB] - hash = {{ component.ib }} - handling = skip - - {% for part in component.parts if part.vertex_count > 0 %} + {% for component in mod_file.components if component.draw_vb != "" %} + {% for part in component.parts %} [TextureOverride{{ part.fullname }}] hash = {{ component.ib }} match_first_index = {{ part.first_index }} - ib = Resource{{ part.fullname }}IB - {% for texture in part.textures %} - Resource\ZZMI\{{ texture.name }} = ref Resource{{ part.fullname }}{{ texture.name }} - {% endfor %} - run = CommandList\ZZMI\SetTextures - {% for entry in part.objects if entry.vertex_count > 0 %} - {% if loop.previtem and loop.previtem.collection_name != entry.collection_name %} - ; {{ entry.collection_name }} + {% if part.index_count > 0 %} + match_index_count = {{part.index_count}} + {% endif %} + handling = skip + {% if part.vertex_count > 0 %} + ib = Resource{{ part.fullname }}IB + {% if part.textures|length > 0%} + {% for texture in part.textures %} + Resource\ZZMI\{{ texture.name }} = ref Resource{{ part.fullname }}{{ texture.name }} + {% endfor %} + run = CommandList\ZZMI\SetTextures {% endif %} - ; {{ entry.name }} ({{ entry.vertex_count }}) - drawindexed = {{ entry.index_count}}, {{ entry.index_offset }}, 0 - {% endfor %} + {% for entry in part.objects if entry.vertex_count > 0 %} + {% if loop.previtem and loop.previtem.collection_name != entry.collection_name %} + ; {{ entry.collection_name }} + {% endif %} + ; {{ entry.name }} ({{ entry.vertex_count }}) + drawindexed = {{ entry.index_count}}, {{ entry.index_offset }}, 0 + {% endfor %} + {% endif %} {% endfor %} {% endfor %} - {% for component in mod_file.components if component.draw_vb == "" %} + {% for component in mod_file.components if component.draw_vb == "" and component.position_vb == "" %} + {% set count = component.parts | selectattr('textures') | list | length %} {% for part in component.parts %} - {% for texture in part.textures %} - [TextureOverride{{part.fullname}}{{ texture.name }}] - hash = {{ texture.hash }} - this = Resource{{part.fullname}}{{ texture.name }} + {% if part.textures|length > 0 %} + [TextureOverride{{ part.fullname }}] + hash = {{component.ib}} + {% if count > 1 %} + match_first_index = {{ part.first_index }} + {% if part.index_count > 0 %} + match_index_count = {{part.index_count}} + {% endif %} + {% endif %} + {% for texture in part.textures %} + Resource\ZZMI\{{ texture.name }} = ref Resource{{ part.fullname }}{{ texture.name }} + {% endfor %} + run = CommandList\ZZMI\SetTextures - {% endfor %} + {%endif%} {% endfor %} {% endfor %} {% endblock %} @@ -123,7 +137,7 @@ stride = {{ component.strides.texcoord }} filename = {{ component.fullname }}Texcoord.buf {% endif %} - + {% for part in component.parts %} [Resource{{ part.fullname }}IB] type = Buffer @@ -139,7 +153,7 @@ stride = {{ component.strides.position }} filename = {{ component.fullname }}.buf {% endif %} - + {% for part in component.parts %} [Resource{{ part.fullname }}IB] type = Buffer @@ -152,7 +166,7 @@ {% block resourcetextures %} {% for component in mod_file.components %} - {% for part in component.parts %} + {% for part in component.parts if (component.draw_vb != "" and part.vertex_count > 0) or (component.draw_vb == "" and component.position_vb == "") %} {% for texture in part.textures %} [Resource{{ part.fullname }}{{ texture.name }}] filename = {{ part.fullname }}{{ texture.name }}{{ texture.extension }}