2020-10-30 20:59:54 +00:00
|
|
|
""" Contains functions for extracting a scene from a .msh file"""
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
from itertools import islice
|
|
|
|
from typing import Dict
|
|
|
|
from .msh_scene import Scene
|
|
|
|
from .msh_model import *
|
|
|
|
from .msh_material import *
|
|
|
|
from .msh_utilities import *
|
|
|
|
|
|
|
|
from .crc import *
|
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
from .chunked_file_reader import Reader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Current model position
|
2020-11-29 02:42:27 +00:00
|
|
|
model_counter = 0
|
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
# Used to remap MNDX to the MODL's actual position
|
|
|
|
mndx_remap : Dict[int, int] = {}
|
2020-12-04 08:33:46 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
# How much to print
|
|
|
|
debug_level = 0
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
Debug levels just indicate how much info should be printed.
|
|
|
|
0 = nothing
|
|
|
|
1 = just blurbs about valuable info in the chunks
|
|
|
|
2 = #1 + full chunk structure
|
|
|
|
'''
|
|
|
|
def read_scene(input_file, anim_only=False, debug=0) -> Scene:
|
|
|
|
|
|
|
|
global debug_level
|
|
|
|
debug_level = debug
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
scene = Scene()
|
|
|
|
scene.models = []
|
2020-10-30 20:59:54 +00:00
|
|
|
scene.materials = {}
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-04 08:33:46 +00:00
|
|
|
global mndx_remap
|
|
|
|
mndx_remap = {}
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
global model_counter
|
|
|
|
model_counter = 0
|
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
with Reader(file=input_file, debug=debug_level>0) as head:
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
head.skip_until("HEDR")
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
with head.read_child() as hedr:
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
while hedr.could_have_child():
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
next_header = hedr.peak_next_header()
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
if next_header == "MSH2":
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
with hedr.read_child() as msh2:
|
|
|
|
|
|
|
|
if not anim_only:
|
|
|
|
materials_list = []
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
while (msh2.could_have_child()):
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
next_header = msh2.peak_next_header()
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
if next_header == "SINF":
|
|
|
|
with msh2.read_child() as sinf:
|
|
|
|
pass
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
elif next_header == "MATL":
|
|
|
|
with msh2.read_child() as matl:
|
|
|
|
materials_list += _read_matl_and_get_materials_list(matl)
|
|
|
|
for i,mat in enumerate(materials_list):
|
|
|
|
scene.materials[mat.name] = mat
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
elif next_header == "MODL":
|
|
|
|
with msh2.read_child() as modl:
|
|
|
|
scene.models.append(_read_modl(modl, materials_list))
|
|
|
|
|
|
|
|
else:
|
|
|
|
msh2.skip_bytes(1)
|
2020-11-01 16:48:07 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
elif next_header == "SKL2":
|
|
|
|
with hedr.read_child() as skl2:
|
|
|
|
num_bones = skl2.read_u32()
|
|
|
|
scene.skeleton = [skl2.read_u32(5)[0] for i in range(num_bones)]
|
|
|
|
|
|
|
|
elif next_header == "ANM2":
|
|
|
|
with hedr.read_child() as anm2:
|
|
|
|
scene.animation = _read_anm2(anm2)
|
2020-12-04 08:33:46 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
else:
|
|
|
|
hedr.skip_bytes(1)
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
# Print models in skeleton
|
|
|
|
if scene.skeleton and debug_level > 0:
|
2020-11-22 05:24:20 +00:00
|
|
|
print("Skeleton models: ")
|
|
|
|
for model in scene.models:
|
2020-12-04 08:33:46 +00:00
|
|
|
for i in range(len(scene.skeleton)):
|
2021-01-07 06:25:09 +00:00
|
|
|
if to_crc(model.name) == scene.skeleton[i]:
|
2020-12-04 08:33:46 +00:00
|
|
|
print("\t" + model.name)
|
|
|
|
if model.model_type == ModelType.SKIN:
|
|
|
|
scene.skeleton.pop(i)
|
|
|
|
break
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
'''
|
|
|
|
Iterate through every vertex weight in the scene and
|
|
|
|
change its index to directly reference its bone's index.
|
|
|
|
It will reference the MNDX of its bone's MODL by default.
|
|
|
|
'''
|
2022-01-11 19:02:17 +00:00
|
|
|
|
2020-12-04 08:33:46 +00:00
|
|
|
for model in scene.models:
|
|
|
|
if model.geometry:
|
|
|
|
for seg in model.geometry:
|
|
|
|
if seg.weights:
|
|
|
|
for weight_set in seg.weights:
|
|
|
|
for vweight in weight_set:
|
2022-01-11 19:02:17 +00:00
|
|
|
|
|
|
|
if vweight.bone in mndx_remap:
|
|
|
|
vweight.bone = mndx_remap[vweight.bone]
|
|
|
|
else:
|
|
|
|
vweight.bone = 0
|
|
|
|
|
|
|
|
# So in the new republic boba example, the weights aimed for bone_head instead map to sv_jettrooper...
|
|
|
|
|
|
|
|
|
|
|
|
#for key, val in mndx_remap.items():
|
|
|
|
#if scene.models[val].name == "bone_head" or scene.models[val].name == "sv_jettrooper":
|
|
|
|
#print("Key: {} is mapped to val: {}".format(key, val))
|
|
|
|
#print("Key: {}, val {} is model: {}".format(key, val, scene.models[val].name))
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-10-20 18:28:53 +00:00
|
|
|
return scene
|
|
|
|
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
def _read_matl_and_get_materials_list(matl: Reader) -> List[Material]:
|
|
|
|
materials_list: List[Material] = []
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
num_mats = matl.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_mats):
|
2020-11-01 16:48:07 +00:00
|
|
|
with matl.read_child() as matd:
|
2020-10-20 18:28:53 +00:00
|
|
|
materials_list.append(_read_matd(matd))
|
|
|
|
|
|
|
|
return materials_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _read_matd(matd: Reader) -> Material:
|
|
|
|
|
|
|
|
mat = Material()
|
|
|
|
|
|
|
|
while matd.could_have_child():
|
|
|
|
|
|
|
|
next_header = matd.peak_next_header()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if next_header == "NAME":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as name:
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.name = name.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "DATA":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as data:
|
2020-10-20 18:28:53 +00:00
|
|
|
data.read_f32(4) # Diffuse Color (Seams to get ignored by modelmunge)
|
|
|
|
mat.specular_color = data.read_f32(4)
|
|
|
|
data.read_f32(4) # Ambient Color (Seams to get ignored by modelmunge and Zero(?))
|
|
|
|
data.read_f32() # Specular Exponent/Decay (Gets ignored by RedEngine in SWBFII for all known materials)
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "ATRB":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as atrb:
|
2022-01-15 16:45:38 +00:00
|
|
|
mat.flags = MaterialFlags(atrb.read_u8())
|
2022-01-11 19:02:17 +00:00
|
|
|
mat.rendertype = Rendertype(atrb.read_u8())
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.data = atrb.read_u8(2)
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "TX0D":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as tx0d:
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.texture0 = tx0d.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "TX1D":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as tx1d:
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.texture1 = tx1d.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "TX2D":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as tx2d:
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.texture2 = tx2d.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "TX3D":
|
2020-11-01 16:48:07 +00:00
|
|
|
with matd.read_child() as tx3d:
|
2020-10-20 18:28:53 +00:00
|
|
|
mat.texture3 = tx3d.read_string()
|
|
|
|
|
|
|
|
else:
|
2020-12-04 08:33:46 +00:00
|
|
|
matd.skip_bytes(1)
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
return mat
|
|
|
|
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
def _read_modl(modl: Reader, materials_list: List[Material]) -> Model:
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
model = Model()
|
|
|
|
|
|
|
|
while modl.could_have_child():
|
|
|
|
|
|
|
|
next_header = modl.peak_next_header()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if next_header == "MTYP":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as mtyp:
|
2020-10-30 20:59:54 +00:00
|
|
|
model.model_type = ModelType(mtyp.read_u32())
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "MNDX":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as mndx:
|
2020-12-04 08:33:46 +00:00
|
|
|
index = mndx.read_u32()
|
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
global model_counter
|
2020-12-04 08:33:46 +00:00
|
|
|
global mndx_remap
|
|
|
|
mndx_remap[index] = model_counter
|
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
model_counter += 1
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "NAME":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as name:
|
2020-10-20 18:28:53 +00:00
|
|
|
model.name = name.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "PRNT":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as prnt:
|
2020-10-20 18:28:53 +00:00
|
|
|
model.parent = prnt.read_string()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "FLGS":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as flgs:
|
2020-10-20 18:28:53 +00:00
|
|
|
model.hidden = flgs.read_u32()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "TRAN":
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as tran:
|
2020-10-20 18:28:53 +00:00
|
|
|
model.transform = _read_tran(tran)
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "GEOM":
|
2020-10-20 18:28:53 +00:00
|
|
|
model.geometry = []
|
2020-11-29 02:42:27 +00:00
|
|
|
envelope = []
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as geom:
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
while geom.could_have_child():
|
|
|
|
next_header_geom = geom.peak_next_header()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if next_header_geom == "SEGM":
|
2020-11-01 23:11:26 +00:00
|
|
|
with geom.read_child() as segm:
|
|
|
|
model.geometry.append(_read_segm(segm, materials_list))
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header_geom == "ENVL":
|
2020-11-01 23:11:26 +00:00
|
|
|
with geom.read_child() as envl:
|
|
|
|
num_indicies = envl.read_u32()
|
2020-12-04 08:33:46 +00:00
|
|
|
envelope += [envl.read_u32() for _ in range(num_indicies)]
|
2020-11-01 23:11:26 +00:00
|
|
|
|
2022-01-15 16:45:38 +00:00
|
|
|
elif next_header_geom == "CLTH":
|
|
|
|
with geom.read_child() as clth:
|
|
|
|
pass
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
else:
|
2020-12-04 08:33:46 +00:00
|
|
|
geom.skip_bytes(1)
|
2020-11-29 02:42:27 +00:00
|
|
|
|
|
|
|
for seg in model.geometry:
|
2020-12-04 08:33:46 +00:00
|
|
|
if seg.weights and envelope:
|
2020-11-29 02:42:27 +00:00
|
|
|
for weight_set in seg.weights:
|
2022-01-11 19:02:17 +00:00
|
|
|
for vertex_weight in weight_set:
|
|
|
|
vertex_weight.bone = envelope[vertex_weight.bone]
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "SWCI":
|
2020-10-20 18:28:53 +00:00
|
|
|
prim = CollisionPrimitive()
|
2020-11-01 16:48:07 +00:00
|
|
|
with modl.read_child() as swci:
|
|
|
|
prim.shape = CollisionPrimitiveShape(swci.read_u32())
|
2020-10-20 18:28:53 +00:00
|
|
|
prim.radius = swci.read_f32()
|
|
|
|
prim.height = swci.read_f32()
|
|
|
|
prim.length = swci.read_f32()
|
|
|
|
model.collisionprimitive = prim
|
|
|
|
|
|
|
|
else:
|
2020-12-04 08:33:46 +00:00
|
|
|
modl.skip_bytes(1)
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
global debug_level
|
|
|
|
if debug_level > 0:
|
|
|
|
print(modl.indent + "Read model " + model.name + " of type: " + str(model.model_type)[10:])
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
return model
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _read_tran(tran: Reader) -> ModelTransform:
|
|
|
|
|
|
|
|
xform = ModelTransform()
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
tran.skip_bytes(12) #ignore scale
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
xform.rotation = tran.read_quat()
|
|
|
|
xform.translation = tran.read_vec()
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
global debug_level
|
|
|
|
if debug_level > 0:
|
|
|
|
print(tran.indent + "Rot: {} Loc: {}".format(str(xform.rotation), str(xform.translation)))
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
return xform
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
def _read_segm(segm: Reader, materials_list: List[Material]) -> GeometrySegment:
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
geometry_seg = GeometrySegment()
|
|
|
|
|
|
|
|
while segm.could_have_child():
|
|
|
|
|
|
|
|
next_header = segm.peak_next_header()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if next_header == "MATI":
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as mati:
|
2020-10-30 20:59:54 +00:00
|
|
|
geometry_seg.material_name = materials_list[mati.read_u32()].name
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "POSL":
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as posl:
|
2020-10-20 18:28:53 +00:00
|
|
|
num_positions = posl.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_positions):
|
|
|
|
geometry_seg.positions.append(Vector(posl.read_f32(3)))
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "NRML":
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as nrml:
|
2020-10-20 18:28:53 +00:00
|
|
|
num_normals = nrml.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_positions):
|
|
|
|
geometry_seg.normals.append(Vector(nrml.read_f32(3)))
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "CLRL":
|
2020-10-20 18:28:53 +00:00
|
|
|
geometry_seg.colors = []
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as clrl:
|
2020-10-20 18:28:53 +00:00
|
|
|
num_colors = clrl.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_colors):
|
|
|
|
geometry_seg.colors += unpack_color(clrl.read_u32())
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "UV0L":
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as uv0l:
|
2020-10-20 18:28:53 +00:00
|
|
|
num_texcoords = uv0l.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_texcoords):
|
|
|
|
geometry_seg.texcoords.append(Vector(uv0l.read_f32(2)))
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "NDXL":
|
2022-01-07 18:45:50 +00:00
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as ndxl:
|
2022-01-07 18:45:50 +00:00
|
|
|
pass
|
|
|
|
'''
|
2020-10-20 18:28:53 +00:00
|
|
|
num_polygons = ndxl.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_polygons):
|
|
|
|
polygon = ndxl.read_u16(ndxl.read_u16())
|
|
|
|
geometry_seg.polygons.append(polygon)
|
2022-01-07 18:45:50 +00:00
|
|
|
'''
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "NDXT":
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as ndxt:
|
2020-10-20 18:28:53 +00:00
|
|
|
num_tris = ndxt.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_tris):
|
|
|
|
geometry_seg.triangles.append(ndxt.read_u16(3))
|
2022-01-15 16:45:38 +00:00
|
|
|
|
|
|
|
# There could be major issues with this, so far it hasn't failed but its inelegance irks me
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "STRP":
|
2020-12-04 08:33:46 +00:00
|
|
|
strips : List[List[int]] = []
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
with segm.read_child() as strp:
|
2020-12-04 08:33:46 +00:00
|
|
|
num_indicies = strp.read_u32()
|
|
|
|
|
|
|
|
num_indicies_read = 0
|
|
|
|
|
|
|
|
curr_strip = []
|
|
|
|
previous_flag = False
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-04 08:33:46 +00:00
|
|
|
if num_indicies > 0:
|
|
|
|
index, index1 = strp.read_u16(2)
|
|
|
|
curr_strip = [index & 0x7fff, index1 & 0x7fff]
|
|
|
|
num_indicies_read += 2
|
|
|
|
|
|
|
|
for i in range(num_indicies - 2):
|
|
|
|
index = strp.read_u16(1)
|
|
|
|
|
|
|
|
if index & 0x8000 > 0:
|
|
|
|
index = index & 0x7fff
|
|
|
|
|
|
|
|
if previous_flag:
|
|
|
|
previous_flag = False
|
|
|
|
curr_strip.append(index)
|
|
|
|
strips.append(curr_strip[:-2])
|
|
|
|
curr_strip = curr_strip[-2:]
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
previous_flag = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
previous_flag = False
|
|
|
|
|
|
|
|
curr_strip.append(index)
|
|
|
|
|
|
|
|
geometry_seg.triangle_strips = strips
|
|
|
|
|
|
|
|
#if segm.read_u16 != 0: #trailing 0 bug https://schlechtwetterfront.github.io/ze_filetypes/msh.html#STRP
|
|
|
|
# segm.skip_bytes(-2)
|
2020-10-20 18:28:53 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
elif next_header == "WGHT":
|
2020-11-26 04:10:14 +00:00
|
|
|
with segm.read_child() as wght:
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
geometry_seg.weights = []
|
|
|
|
num_weights = wght.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_weights):
|
|
|
|
weight_set = []
|
|
|
|
for _ in range(4):
|
|
|
|
index = wght.read_u32()
|
|
|
|
value = wght.read_f32()
|
|
|
|
|
|
|
|
if value > 0.000001:
|
2020-12-04 08:33:46 +00:00
|
|
|
weight_set.append(VertexWeight(value,index))
|
2020-11-01 23:11:26 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
geometry_seg.weights.append(weight_set)
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-10-20 18:28:53 +00:00
|
|
|
else:
|
2020-12-04 08:33:46 +00:00
|
|
|
segm.skip_bytes(1)
|
2020-10-20 18:28:53 +00:00
|
|
|
|
|
|
|
return geometry_seg
|
|
|
|
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
def _read_anm2(anm2: Reader) -> Animation:
|
2020-11-01 23:11:26 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
anim = Animation()
|
2020-11-01 23:11:26 +00:00
|
|
|
|
|
|
|
while anm2.could_have_child():
|
|
|
|
|
|
|
|
next_header = anm2.peak_next_header()
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if next_header == "CYCL":
|
2020-11-01 23:11:26 +00:00
|
|
|
with anm2.read_child() as cycl:
|
2022-01-07 18:45:50 +00:00
|
|
|
# Dont even know what CYCL's data does. Tried playing
|
|
|
|
# with the values but didn't change anything in zenasset or ingame...
|
2020-11-01 23:11:26 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
'''
|
|
|
|
num_anims = cycl.read_u32()
|
|
|
|
|
|
|
|
for _ in range(num_anims):
|
|
|
|
cycl.skip_bytes(64)
|
|
|
|
print("CYCL play style {}".format(cycl.read_u32(4)[1]))
|
|
|
|
'''
|
2022-01-07 18:45:50 +00:00
|
|
|
pass
|
2020-12-11 04:47:45 +00:00
|
|
|
|
|
|
|
elif next_header == "KFR3":
|
2020-11-01 23:11:26 +00:00
|
|
|
with anm2.read_child() as kfr3:
|
|
|
|
|
|
|
|
num_bones = kfr3.read_u32()
|
|
|
|
|
2022-01-07 18:45:50 +00:00
|
|
|
bone_crcs = []
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
for _ in range(num_bones):
|
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
bone_crc = kfr3.read_u32()
|
2022-01-07 18:45:50 +00:00
|
|
|
bone_crcs.append(bone_crc)
|
2020-12-05 05:53:59 +00:00
|
|
|
|
|
|
|
frames = ([],[])
|
2020-11-01 23:11:26 +00:00
|
|
|
|
|
|
|
frametype = kfr3.read_u32()
|
|
|
|
|
|
|
|
num_loc_frames = kfr3.read_u32()
|
|
|
|
num_rot_frames = kfr3.read_u32()
|
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
for i in range(num_loc_frames):
|
|
|
|
frames[0].append(TranslationFrame(kfr3.read_u32(), kfr3.read_vec()))
|
|
|
|
|
|
|
|
for i in range(num_rot_frames):
|
|
|
|
frames[1].append(RotationFrame(kfr3.read_u32(), kfr3.read_quat()))
|
|
|
|
|
|
|
|
anim.bone_frames[bone_crc] = frames
|
2022-01-07 18:45:50 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
else:
|
|
|
|
anm2.skip_bytes(1)
|
|
|
|
|
|
|
|
return anim
|
2020-11-01 23:11:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|