ZE crash fixes
This commit is contained in:
parent
fb072f8d59
commit
20ad9a48d5
|
@ -27,6 +27,7 @@ def extract_anim(armature: bpy.types.Armature) -> Animation:
|
||||||
|
|
||||||
anim.end_index = num_frames - 1
|
anim.end_index = num_frames - 1
|
||||||
|
|
||||||
|
anim.bone_transforms["DummyRoot"] = []
|
||||||
for bone in armature.data.bones:
|
for bone in armature.data.bones:
|
||||||
anim.bone_transforms[bone.name] = []
|
anim.bone_transforms[bone.name] = []
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ def extract_anim(armature: bpy.types.Armature) -> Animation:
|
||||||
frame_time = framerange.x + frame * increment
|
frame_time = framerange.x + frame * increment
|
||||||
bpy.context.scene.frame_set(frame_time)
|
bpy.context.scene.frame_set(frame_time)
|
||||||
|
|
||||||
|
anim.bone_transforms["DummyRoot"].append(ModelTransform())
|
||||||
for bone in armature.pose.bones:
|
for bone in armature.pose.bones:
|
||||||
|
|
||||||
transform = bone.matrix
|
transform = bone.matrix
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Animation:
|
||||||
name: str = "fullanimation"
|
name: str = "fullanimation"
|
||||||
bone_transforms: Dict[str, List[ModelTransform]] = field(default_factory=dict)
|
bone_transforms: Dict[str, List[ModelTransform]] = field(default_factory=dict)
|
||||||
|
|
||||||
framerate: float = 10.0
|
framerate: float = 29.97
|
||||||
start_index : int = 0
|
start_index : int = 0
|
||||||
end_index : int = 0
|
end_index : int = 0
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
|
||||||
|
|
||||||
if obj.type == "ARMATURE":
|
if obj.type == "ARMATURE":
|
||||||
models_list += expand_armature(obj)
|
models_list += expand_armature(obj)
|
||||||
|
continue
|
||||||
|
|
||||||
if skeleton_only:
|
if skeleton_only:
|
||||||
continue
|
continue
|
||||||
|
@ -52,6 +53,9 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
|
||||||
transform = obj.parent.data.bones[obj.parent_bone].matrix_local.inverted() @ transform
|
transform = obj.parent.data.bones[obj.parent_bone].matrix_local.inverted() @ transform
|
||||||
else:
|
else:
|
||||||
if obj.parent is not None:
|
if obj.parent is not None:
|
||||||
|
if obj.parent.type == "ARMATURE":
|
||||||
|
model.parent = obj.parent.parent.name
|
||||||
|
else:
|
||||||
model.parent = obj.parent.name
|
model.parent = obj.parent.name
|
||||||
|
|
||||||
local_translation, local_rotation, _ = transform.decompose()
|
local_translation, local_rotation, _ = transform.decompose()
|
||||||
|
@ -368,7 +372,7 @@ def expand_armature(obj: bpy.types.Object) -> List[Model]:
|
||||||
transform = bone.parent.matrix_local.inverted() @ transform
|
transform = bone.parent.matrix_local.inverted() @ transform
|
||||||
model.parent = bone.parent.name
|
model.parent = bone.parent.name
|
||||||
else:
|
else:
|
||||||
model.parent = obj.name
|
model.parent = "tst_prop"
|
||||||
|
|
||||||
local_translation, local_rotation, _ = transform.decompose()
|
local_translation, local_rotation, _ = transform.decompose()
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ def save_scene(output_file, scene: Scene, is_animated: bool):
|
||||||
|
|
||||||
def _write_sinf(sinf: Writer, scene: Scene):
|
def _write_sinf(sinf: Writer, scene: Scene):
|
||||||
with sinf.create_child("NAME") as name:
|
with sinf.create_child("NAME") as name:
|
||||||
name.write_string(scene.name)
|
name.write_string("spa1_prop_impdoor_rig")
|
||||||
|
|
||||||
with sinf.create_child("FRAM") as fram:
|
with sinf.create_child("FRAM") as fram:
|
||||||
min_index = 0
|
min_index = 0
|
||||||
|
@ -58,8 +58,8 @@ def _write_sinf(sinf: Writer, scene: Scene):
|
||||||
min_index = min([anim.start_index for anim in scene.anims])
|
min_index = min([anim.start_index for anim in scene.anims])
|
||||||
max_index = min([anim.end_index for anim in scene.anims])
|
max_index = min([anim.end_index for anim in scene.anims])
|
||||||
|
|
||||||
fram.write_i32(min_index, max_index)
|
fram.write_i32(0, 1)
|
||||||
fram.write_f32(10.0)
|
fram.write_f32(29.97)
|
||||||
|
|
||||||
with sinf.create_child("BBOX") as bbox:
|
with sinf.create_child("BBOX") as bbox:
|
||||||
aabb = create_scene_aabb(scene)
|
aabb = create_scene_aabb(scene)
|
||||||
|
@ -100,7 +100,7 @@ def _write_matd(matd: Writer, material_name: str, material: Material):
|
||||||
data.write_f32(1.0, 1.0, 1.0, 1.0) # Diffuse Color (Seams to get ignored by modelmunge)
|
data.write_f32(1.0, 1.0, 1.0, 1.0) # Diffuse Color (Seams to get ignored by modelmunge)
|
||||||
data.write_f32(material.specular_color[0], material.specular_color[1],
|
data.write_f32(material.specular_color[0], material.specular_color[1],
|
||||||
material.specular_color[2], 1.0)
|
material.specular_color[2], 1.0)
|
||||||
data.write_f32(0.0, 0.0, 0.0, 1.0) # Ambient Color (Seams to get ignored by modelmunge and Zero(?))
|
data.write_f32(1.0, 1.0, 1.0, 1.0) # Ambient Color (Seams to get ignored by modelmunge and Zero(?))
|
||||||
data.write_f32(50.0) # Specular Exponent/Decay (Gets ignored by RedEngine in SWBFII for all known materials)
|
data.write_f32(50.0) # Specular Exponent/Decay (Gets ignored by RedEngine in SWBFII for all known materials)
|
||||||
with matd.create_child("ATRB") as atrb:
|
with matd.create_child("ATRB") as atrb:
|
||||||
atrb.write_u8(material.flags.value)
|
atrb.write_u8(material.flags.value)
|
||||||
|
@ -135,9 +135,13 @@ def _write_modl(modl: Writer, model: Model, index: int, material_index: Dict[str
|
||||||
with modl.create_child("PRNT") as prnt:
|
with modl.create_child("PRNT") as prnt:
|
||||||
prnt.write_string(model.parent)
|
prnt.write_string(model.parent)
|
||||||
|
|
||||||
if model.hidden:
|
if model.model_type != ModelType.NULL and model.model_type != ModelType.BONE:
|
||||||
|
if model.hidden or "Dummy" in model.name or "hp_" in model.name:
|
||||||
with modl.create_child("FLGS") as flgs:
|
with modl.create_child("FLGS") as flgs:
|
||||||
flgs.write_u32(1)
|
flgs.write_u32(1)
|
||||||
|
for seg in model.geometry:
|
||||||
|
seg.texcoords = None
|
||||||
|
|
||||||
|
|
||||||
with modl.create_child("TRAN") as tran:
|
with modl.create_child("TRAN") as tran:
|
||||||
_write_tran(tran, model.transform)
|
_write_tran(tran, model.transform)
|
||||||
|
@ -198,6 +202,7 @@ def _write_segm(segm: Writer, segment: GeometrySegment, material_index: Dict[str
|
||||||
for color in segment.colors:
|
for color in segment.colors:
|
||||||
clrl.write_u32(pack_color(color))
|
clrl.write_u32(pack_color(color))
|
||||||
|
|
||||||
|
if segment.texcoords is not None:
|
||||||
with segm.create_child("UV0L") as uv0l:
|
with segm.create_child("UV0L") as uv0l:
|
||||||
uv0l.write_u32(len(segment.texcoords))
|
uv0l.write_u32(len(segment.texcoords))
|
||||||
|
|
||||||
|
@ -234,8 +239,6 @@ SKINNING CHUNKS
|
||||||
def _write_wght(wght: Writer, weights: List[List[VertexWeight]]):
|
def _write_wght(wght: Writer, weights: List[List[VertexWeight]]):
|
||||||
wght.write_u32(len(weights))
|
wght.write_u32(len(weights))
|
||||||
|
|
||||||
print("Writing WGHT: ")
|
|
||||||
|
|
||||||
for weight_list in weights:
|
for weight_list in weights:
|
||||||
weight_list += [VertexWeight(0.0, 0)] * 4
|
weight_list += [VertexWeight(0.0, 0)] * 4
|
||||||
weight_list = sorted(weight_list, key=lambda w: w.weight, reverse=True)
|
weight_list = sorted(weight_list, key=lambda w: w.weight, reverse=True)
|
||||||
|
@ -243,24 +246,13 @@ def _write_wght(wght: Writer, weights: List[List[VertexWeight]]):
|
||||||
|
|
||||||
total_weight = max(sum(map(lambda w: w.weight, weight_list)), 1e-5)
|
total_weight = max(sum(map(lambda w: w.weight, weight_list)), 1e-5)
|
||||||
|
|
||||||
print_str = ""
|
|
||||||
|
|
||||||
for weight in weight_list:
|
for weight in weight_list:
|
||||||
|
|
||||||
print_str += "({}, {}) ".format(weight.bone, weight.weight / total_weight)
|
|
||||||
|
|
||||||
wght.write_i32(weight.bone)
|
wght.write_i32(weight.bone)
|
||||||
wght.write_f32(weight.weight / total_weight)
|
wght.write_f32(weight.weight / total_weight)
|
||||||
|
|
||||||
print(" {}".format(print_str))
|
|
||||||
|
|
||||||
def _write_envl(envl: Writer, model: Model, model_index: Dict[str, int]):
|
def _write_envl(envl: Writer, model: Model, model_index: Dict[str, int]):
|
||||||
envl.write_u32(len(model.bone_map))
|
envl.write_u32(len(model.bone_map))
|
||||||
|
|
||||||
print("Writing ENVL: ")
|
|
||||||
|
|
||||||
for bone_name in model.bone_map:
|
for bone_name in model.bone_map:
|
||||||
print(" {:10} Index: {}".format(bone_name, model_index[bone_name]))
|
|
||||||
envl.write_u32(model_index[bone_name])
|
envl.write_u32(model_index[bone_name])
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue