Skip to content

Commit

Permalink
plugin - cleanup lod counts for meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Nov 12, 2023
1 parent 717ef47 commit b52e64a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
12 changes: 6 additions & 6 deletions generated/formats/ms2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def update_buffer_2_bytes(self):
# update LodInfo
logging.debug(f"Updating lod vertex counts")
for lod in model.lods:
lod.vertex_count = sum(wrapper.mesh.vertex_count for wrapper in lod.meshes)
lod.tri_index_count = sum(wrapper.mesh.tri_index_count for wrapper in lod.meshes)
lod.vertex_count = sum(ob.mesh.vertex_count for ob in lod.objects)
lod.tri_index_count = sum(ob.mesh.tri_index_count for ob in lod.objects)
# modify buffer size
for buffer_info in self.buffer_infos:
# get bytes from IO obj, pad, and update size in BufferInfo
Expand Down Expand Up @@ -421,15 +421,13 @@ def lookup_material(self):
for lod_index, lod in enumerate(model_info.model.lods):
# logging.debug(f"Mapping LOD{lod_index}")
lod.objects = model_info.model.objects[lod.first_object_index:lod.last_object_index]
# todo - investigate how duplicate meshes are handled for the lod's vertex count0
lod.meshes = tuple(model_info.model.meshes[obj.mesh_index] for obj in lod.objects)
for obj in lod.objects:
try:
material = model_info.model.materials[obj.material_index]
material.name = self.buffer_0.names[material.name_index]
obj.mesh = model_info.model.meshes[obj.mesh_index].mesh
obj.material = material
flag = int(obj.mesh.flag) if hasattr(obj.mesh, "flag") else None
# flag = int(obj.mesh.flag) if hasattr(obj.mesh, "flag") else None
# logging.debug(
# f"Mesh: {obj.mesh_index} Material: {material.name} Blend Mode: {material.blend_mode} "
# f"Lod: {obj.mesh.poweroftwo} Flag: {flag}")
Expand Down Expand Up @@ -488,7 +486,9 @@ def clear(self):
# m.load("C:/Users/arnfi/Desktop/rhinoblack_female_.ms2", read_editable=True, dump=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/ContentPDLC5/Buildings/ModularStructures/LAG_NaturalWaterPool_Malta_Walls/LAG_NaturalWaterPool_Malta_Walls/models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/ContentPDLC5/Buildings/ModularStructures/LAG_NaturalWaterPool_Malta/LAG_NaturalWaterPool_Malta/models.ms2", read_editable=True)
m.load("C:\Program Files (x86)\Steam\steamapps\common\Jurassic World Evolution 2\Win64\ovldata\walker_export\Content0\Buildings\Shared\Props\CharacterScale\CharacterScale\models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/Content0/Buildings/Shared/Props/CharacterScale/CharacterScale/models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Planet Zoo/win64/ovldata/walker_export/Content0/Animals/Aardvarks/Aardvark/Aardvark_Female/Aardvark_Female/aardvark_female_.ms2", read_editable=True)
m.load("C:/Program Files (x86)/Steam/steamapps/common/Planet Zoo/win64/ovldata/walker_export/Content0/Animals/Big_Cats/Bengal_Tiger/Bengal_Tiger_Male/Bengal_Tiger_Male/bengal_tiger_male_.ms2", read_editable=True)
# for i, bone_info in enumerate(m.models_reader.bone_infos):
# for bi, bone in enumerate(bone_info.bones):
# print(bi, bone.name)
Expand Down
4 changes: 2 additions & 2 deletions generated/formats/ms2/compounds/LodInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def __init__(self, context, arg=0, template=None, set_default=True):
# not included in interval (python style indexing)
self.last_object_index = name_type_map['Ushort'](self.context, 0, None)

# vertex count of lod, sum of all vertex counts that are attached to this lod; rendered count, including duped models
# sum for objects in lod, duplicated meshes count
self.vertex_count = name_type_map['Uint'](self.context, 0, None)

# number of index entries in the triangle index list; (not: number of triangles, byte count of tri buffer); rendered count, including duped models
# sum for objects in lod, duplicated meshes count
self.tri_index_count = name_type_map['Uint'](self.context, 0, None)
if set_default:
self.set_defaults()
Expand Down
4 changes: 2 additions & 2 deletions generated/formats/ms2/ms2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
<add name="first_object_index_1" type="ushort" until="13"/>
<add name="first_object_index_2" type="ushort" until="13"/>
<add name="last object index" type="ushort" >not included in interval (python style indexing)</add>
<add name="vertex count" type="uint" since="32" until="51">vertex count of lod, sum of all vertex counts that are attached to this lod; rendered count, including duped models</add>
<add name="tri_index_count" type="uint" since="32" until="51" >number of index entries in the triangle index list; (not: number of triangles, byte count of tri buffer); rendered count, including duped models</add>
<add name="vertex count" type="uint" since="32" until="51">sum for objects in lod, duplicated meshes count</add>
<add name="tri_index_count" type="uint" since="32" until="51" >sum for objects in lod, duplicated meshes count</add>
</compound>

<compound name="Object">
Expand Down
11 changes: 5 additions & 6 deletions plugin/export_ms2.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def save(filepath='', backup_original=True, apply_transforms=False, update_rig=F
m_lod = LodInfo(ms2.context)
m_lod.distance = math.pow(30 + 15 * lod_i, 2)
m_lod.first_object_index = len(model_info.model.objects)
m_lod.meshes = []
m_lod.objects = []
m_lod.stream_index = stream_index
model_info.model.lods.append(m_lod)
Expand Down Expand Up @@ -193,11 +192,11 @@ def save(filepath='', backup_original=True, apply_transforms=False, update_rig=F
m_ob.material_index = b_materials.index(b_mat)

model_info.model.objects.append(m_ob)
wrapper = model_info.model.meshes[m_ob.mesh_index]
m_lod.meshes.append(wrapper)
if wrapper.context.version >= 52:
mesh = model_info.model.meshes[m_ob.mesh_index].mesh
m_ob.mesh = mesh
if mesh.context.version >= 52:
logging.debug(f"Setting chunk material indices")
for tri_chunk in wrapper.mesh.tri_chunks:
for tri_chunk in mesh.tri_chunks:
tri_chunk.material_index = m_ob.material_index
m_lod.objects.append(m_ob)
m_lod.last_object_index = len(model_info.model.objects)
Expand All @@ -207,9 +206,9 @@ def save(filepath='', backup_original=True, apply_transforms=False, update_rig=F
# reset to original state
for coll, state in zip(view_collections, view_states):
coll.exclude = state
print(ms2)
# write ms2, backup should have been created earlier
ms2.save(filepath)
print(ms2)
if found_scenes:
messages.add(f"Finished MS2 export in {time.time() - start_time:.2f} seconds")
else:
Expand Down
12 changes: 6 additions & 6 deletions source/formats/ms2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def update_buffer_2_bytes(self):
# update LodInfo
logging.debug(f"Updating lod vertex counts")
for lod in model.lods:
lod.vertex_count = sum(wrapper.mesh.vertex_count for wrapper in lod.meshes)
lod.tri_index_count = sum(wrapper.mesh.tri_index_count for wrapper in lod.meshes)
lod.vertex_count = sum(ob.mesh.vertex_count for ob in lod.objects)
lod.tri_index_count = sum(ob.mesh.tri_index_count for ob in lod.objects)
# modify buffer size
for buffer_info in self.buffer_infos:
# get bytes from IO obj, pad, and update size in BufferInfo
Expand Down Expand Up @@ -420,15 +420,13 @@ def lookup_material(self):
for lod_index, lod in enumerate(model_info.model.lods):
# logging.debug(f"Mapping LOD{lod_index}")
lod.objects = model_info.model.objects[lod.first_object_index:lod.last_object_index]
# todo - investigate how duplicate meshes are handled for the lod's vertex count0
lod.meshes = tuple(model_info.model.meshes[obj.mesh_index] for obj in lod.objects)
for obj in lod.objects:
try:
material = model_info.model.materials[obj.material_index]
material.name = self.buffer_0.names[material.name_index]
obj.mesh = model_info.model.meshes[obj.mesh_index].mesh
obj.material = material
flag = int(obj.mesh.flag) if hasattr(obj.mesh, "flag") else None
# flag = int(obj.mesh.flag) if hasattr(obj.mesh, "flag") else None
# logging.debug(
# f"Mesh: {obj.mesh_index} Material: {material.name} Blend Mode: {material.blend_mode} "
# f"Lod: {obj.mesh.poweroftwo} Flag: {flag}")
Expand Down Expand Up @@ -487,7 +485,9 @@ def clear(self):
# m.load("C:/Users/arnfi/Desktop/rhinoblack_female_.ms2", read_editable=True, dump=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/ContentPDLC5/Buildings/ModularStructures/LAG_NaturalWaterPool_Malta_Walls/LAG_NaturalWaterPool_Malta_Walls/models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/ContentPDLC5/Buildings/ModularStructures/LAG_NaturalWaterPool_Malta/LAG_NaturalWaterPool_Malta/models.ms2", read_editable=True)
m.load("C:\Program Files (x86)\Steam\steamapps\common\Jurassic World Evolution 2\Win64\ovldata\walker_export\Content0\Buildings\Shared\Props\CharacterScale\CharacterScale\models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Jurassic World Evolution 2/Win64/ovldata/walker_export/Content0/Buildings/Shared/Props/CharacterScale/CharacterScale/models.ms2", read_editable=True)
# m.load("C:/Program Files (x86)/Steam/steamapps/common/Planet Zoo/win64/ovldata/walker_export/Content0/Animals/Aardvarks/Aardvark/Aardvark_Female/Aardvark_Female/aardvark_female_.ms2", read_editable=True)
m.load("C:/Program Files (x86)/Steam/steamapps/common/Planet Zoo/win64/ovldata/walker_export/Content0/Animals/Big_Cats/Bengal_Tiger/Bengal_Tiger_Male/Bengal_Tiger_Male/bengal_tiger_male_.ms2", read_editable=True)
# for i, bone_info in enumerate(m.models_reader.bone_infos):
# for bi, bone in enumerate(bone_info.bones):
# print(bi, bone.name)
Expand Down
4 changes: 2 additions & 2 deletions source/formats/ms2/ms2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
<add name="first_object_index_1" type="ushort" until="13"/>
<add name="first_object_index_2" type="ushort" until="13"/>
<add name="last object index" type="ushort" >not included in interval (python style indexing)</add>
<add name="vertex count" type="uint" since="32" until="51">vertex count of lod, sum of all vertex counts that are attached to this lod; rendered count, including duped models</add>
<add name="tri_index_count" type="uint" since="32" until="51" >number of index entries in the triangle index list; (not: number of triangles, byte count of tri buffer); rendered count, including duped models</add>
<add name="vertex count" type="uint" since="32" until="51">sum for objects in lod, duplicated meshes count</add>
<add name="tri_index_count" type="uint" since="32" until="51" >sum for objects in lod, duplicated meshes count</add>
</compound>

<compound name="Object">
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e7bf8fa17 - Sat Nov 11 16:36:33 2023 +0100
717ef471e - Sat Nov 11 21:59:08 2023 +0100

0 comments on commit b52e64a

Please sign in to comment.