Rotation fix (I think)
This commit is contained in:
parent
1892a1cdbd
commit
f426237785
|
@ -33,20 +33,17 @@ def gather_animdata(armature: bpy.types.Armature) -> List[Animation]:
|
||||||
anim_data.bone_transforms[armature.parent.name].append(ModelTransform()) #for testing
|
anim_data.bone_transforms[armature.parent.name].append(ModelTransform()) #for testing
|
||||||
|
|
||||||
for bone in armature.pose.bones:
|
for bone in armature.pose.bones:
|
||||||
|
|
||||||
xform = ModelTransform()
|
xform = ModelTransform()
|
||||||
|
xform.translation = convert_vector_space(bone.location)
|
||||||
|
xform.translation.x *= -1.0
|
||||||
vt = convert_vector_space(bone.location);
|
|
||||||
|
|
||||||
xform.translation = Vector((vt.x * -1.0, vt.y, vt.z))
|
|
||||||
xform.rotation = convert_rotation_space(bone.rotation_quaternion)
|
xform.rotation = convert_rotation_space(bone.rotation_quaternion)
|
||||||
|
xform.rotation.x *= -1.0
|
||||||
'''
|
xform.rotation.y *= -1.0
|
||||||
xform.translation = bone.location
|
xform.rotation.z *= -1.0
|
||||||
xform.rotation = bone.rotation_quaternion
|
|
||||||
|
|
||||||
anim_data.bone_transforms[bone.name].append(xform)
|
anim_data.bone_transforms[bone.name].append(xform)
|
||||||
'''
|
|
||||||
|
|
||||||
return [anim_data]
|
return [anim_data]
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,9 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]:
|
||||||
else:
|
else:
|
||||||
obj = uneval_obj
|
obj = uneval_obj
|
||||||
|
|
||||||
|
if uneval_obj.type == "ARMATURE":
|
||||||
|
continue
|
||||||
|
|
||||||
check_for_bad_lod_suffix(obj)
|
check_for_bad_lod_suffix(obj)
|
||||||
|
|
||||||
local_translation, local_rotation, _ = obj.matrix_local.decompose()
|
local_translation, local_rotation, _ = obj.matrix_local.decompose()
|
||||||
|
@ -44,8 +47,13 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]:
|
||||||
model.transform.rotation = convert_rotation_space(local_rotation)
|
model.transform.rotation = convert_rotation_space(local_rotation)
|
||||||
model.transform.translation = convert_vector_space(local_translation)
|
model.transform.translation = convert_vector_space(local_translation)
|
||||||
|
|
||||||
|
print("Adding model: " + model.name)
|
||||||
|
|
||||||
if obj.parent is not None:
|
if obj.parent is not None:
|
||||||
if obj.parent.type == "ARMATURE":
|
if obj.parent.type == "ARMATURE":
|
||||||
|
|
||||||
|
model.parent = "DummyRoot"
|
||||||
|
|
||||||
skeleton = obj.parent
|
skeleton = obj.parent
|
||||||
|
|
||||||
parent_bone_name = obj.parent_bone
|
parent_bone_name = obj.parent_bone
|
||||||
|
@ -85,13 +93,15 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]:
|
||||||
|
|
||||||
model = Model()
|
model = Model()
|
||||||
model.name = bone.name
|
model.name = bone.name
|
||||||
model.model_type = ModelType.NULL
|
model.model_type = ModelType.BONE
|
||||||
model.hidden = False
|
model.hidden = False
|
||||||
|
|
||||||
local_translation, local_rotation, _ = bone.matrix_local.decompose()
|
local_translation, local_rotation, _ = bone.matrix_local.decompose()
|
||||||
model.transform.rotation = convert_rotation_space(local_rotation)
|
model.transform.rotation = convert_rotation_space(local_rotation)
|
||||||
model.transform.translation = convert_vector_space(local_translation)
|
model.transform.translation = convert_vector_space(local_translation)
|
||||||
|
|
||||||
|
print("Adding bone: " + model.name)
|
||||||
|
|
||||||
parent_name = bone.parent
|
parent_name = bone.parent
|
||||||
if parent_name is not None:
|
if parent_name is not None:
|
||||||
model.parent = parent_name
|
model.parent = parent_name
|
||||||
|
@ -104,6 +114,8 @@ def gather_models(apply_modifiers: bool, export_target: str) -> List[Model]:
|
||||||
models_list.append(model)
|
models_list.append(model)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return models_list
|
return models_list
|
||||||
|
|
||||||
def create_parents_set() -> Set[str]:
|
def create_parents_set() -> Set[str]:
|
||||||
|
|
|
@ -72,6 +72,7 @@ def create_scene(generate_triangle_strips: bool, apply_modifiers: bool, export_t
|
||||||
|
|
||||||
|
|
||||||
#now that we've collected all models, we should remap WGHT indices...
|
#now that we've collected all models, we should remap WGHT indices...
|
||||||
|
'''
|
||||||
names_to_indices = {}
|
names_to_indices = {}
|
||||||
for i,model in enumerate(scene.models):
|
for i,model in enumerate(scene.models):
|
||||||
names_to_indices[model.name] = i;
|
names_to_indices[model.name] = i;
|
||||||
|
@ -82,11 +83,12 @@ def create_scene(generate_triangle_strips: bool, apply_modifiers: bool, export_t
|
||||||
for i in range(len(segment.weights)):
|
for i in range(len(segment.weights)):
|
||||||
vgroup_index = segment.weights[i][0]
|
vgroup_index = segment.weights[i][0]
|
||||||
segment.weights[i][0] = names_to_indices[model.vgroups_to_modelnames_map[vgroup_index]]
|
segment.weights[i][0] = names_to_indices[model.vgroups_to_modelnames_map[vgroup_index]]
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
scene.materials = remove_unused_materials(scene.materials, scene.models)
|
scene.materials = remove_unused_materials(scene.materials, scene.models)
|
||||||
|
|
||||||
#scene.anims = gather_animdata(bpy.context.scene.objects["Armature"])
|
scene.anims = gather_animdata(bpy.context.scene.objects["Armature"])
|
||||||
|
|
||||||
return scene
|
return scene
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ def save_scene(output_file, scene: Scene):
|
||||||
with msh2.create_child("MODL") as modl:
|
with msh2.create_child("MODL") as modl:
|
||||||
_write_modl(modl, model, index, material_index, scene)
|
_write_modl(modl, model, index, material_index, scene)
|
||||||
|
|
||||||
#with hedr.create_child("ANM2") as anm2: #simple for now
|
with hedr.create_child("ANM2") as anm2: #simple for now
|
||||||
# for anim in scene.anims:
|
for anim in scene.anims:
|
||||||
# _write_anm2(anm2, anim)
|
_write_anm2(anm2, anim)
|
||||||
|
|
||||||
with hedr.create_child("CL1L"):
|
with hedr.create_child("CL1L"):
|
||||||
pass
|
pass
|
||||||
|
@ -129,12 +129,13 @@ def _write_modl(modl: Writer, model: Model, index: int, material_index: Dict[str
|
||||||
for segment in model.geometry:
|
for segment in model.geometry:
|
||||||
with geom.create_child("SEGM") as segm:
|
with geom.create_child("SEGM") as segm:
|
||||||
_write_segm(segm, segment, material_index)
|
_write_segm(segm, segment, material_index)
|
||||||
|
'''
|
||||||
if model.model_type == ModelType.SKIN:
|
if model.model_type == ModelType.SKIN:
|
||||||
with modl.create_child("ENVL") as envl:
|
with modl.create_child("ENVL") as envl:
|
||||||
envl.write_u32(len(scene.models))
|
envl.write_u32(len(scene.models))
|
||||||
for i in range(len(scene.models)):
|
for i in range(len(scene.models)):
|
||||||
envl.write_u32(i)
|
envl.write_u32(i)
|
||||||
|
'''
|
||||||
|
|
||||||
if model.collisionprimitive is not None:
|
if model.collisionprimitive is not None:
|
||||||
with modl.create_child("SWCI") as swci:
|
with modl.create_child("SWCI") as swci:
|
||||||
|
@ -165,12 +166,14 @@ def _write_segm(segm: Writer, segment: GeometrySegment, material_index: Dict[str
|
||||||
for normal in segment.normals:
|
for normal in segment.normals:
|
||||||
nrml.write_f32(normal.x, normal.y, normal.z)
|
nrml.write_f32(normal.x, normal.y, normal.z)
|
||||||
|
|
||||||
|
'''
|
||||||
if segment.weights is not None:
|
if segment.weights is not None:
|
||||||
with segm.create_child("WGHT") as wght:
|
with segm.create_child("WGHT") as wght:
|
||||||
wght.write_u32(len(segment.weights) / 4)
|
wght.write_u32(len(segment.weights) / 4)
|
||||||
for weight in segment.weights:
|
for weight in segment.weights:
|
||||||
wght.write_u32(weight[0])
|
wght.write_u32(weight[0])
|
||||||
wght.write_f32(weight[1])
|
wght.write_f32(weight[1])
|
||||||
|
'''
|
||||||
|
|
||||||
if segment.colors is not None:
|
if segment.colors is not None:
|
||||||
with segm.create_child("CLRL") as clrl:
|
with segm.create_child("CLRL") as clrl:
|
||||||
|
@ -217,7 +220,7 @@ def _write_anm2(anm2: Writer, anim: Animation):
|
||||||
cycl.write_u32(1)
|
cycl.write_u32(1)
|
||||||
cycl.write_string(anim.name)
|
cycl.write_string(anim.name)
|
||||||
|
|
||||||
for _ in range(63 - len(anim.name)):
|
for _ in range(64 - (len(anim.name) + 1)):
|
||||||
cycl.write_u8(0)
|
cycl.write_u8(0)
|
||||||
|
|
||||||
cycl.write_f32(10.0) #test framerate
|
cycl.write_f32(10.0) #test framerate
|
||||||
|
|
Loading…
Reference in New Issue