2020-10-30 20:59:54 +00:00
|
|
|
""" Gathers the Blender objects from the current scene and returns them as a list of
|
|
|
|
Model objects. """
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
import bmesh
|
|
|
|
import math
|
|
|
|
from enum import Enum
|
|
|
|
from typing import List, Set, Dict, Tuple
|
|
|
|
from itertools import zip_longest
|
|
|
|
from .msh_scene import Scene
|
|
|
|
from .msh_model import *
|
|
|
|
from .msh_model_utilities import *
|
|
|
|
from .msh_utilities import *
|
|
|
|
from .msh_model_gather import *
|
2020-11-01 16:48:07 +00:00
|
|
|
from .crc import *
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
import os
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
|
2020-12-06 09:11:12 +00:00
|
|
|
def extract_and_apply_anim(filename, scene):
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
arma = bpy.context.view_layer.objects.active
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if arma.type != 'ARMATURE':
|
|
|
|
raise Exception("Select an armature to attach the imported animation to!")
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if scene.animation is None:
|
|
|
|
raise Exception("No animation found in msh file!")
|
|
|
|
|
|
|
|
else:
|
|
|
|
head, tail = os.path.split(filename)
|
|
|
|
anim_name = tail.split(".")[0]
|
|
|
|
action = bpy.data.actions.new(anim_name)
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if not arma.animation_data:
|
|
|
|
arma.animation_data_create()
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-06 05:19:58 +00:00
|
|
|
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
bone_bind_poses = {}
|
|
|
|
bone_stack_mats = {}
|
|
|
|
|
|
|
|
'''
|
|
|
|
for bone in arma.data.bones:
|
|
|
|
local_mat = bone.matrix_local
|
|
|
|
if bone.parent:
|
|
|
|
local_mat = bone.parent.matrix_local.inverted() @ local_mat
|
|
|
|
bone_bind_poses[bone.name] = local_mat
|
|
|
|
'''
|
|
|
|
|
|
|
|
for bone in arma.data.bones:
|
|
|
|
bone_obj = bpy.data.objects[bone.name]
|
|
|
|
bone_obj_parent = bone_obj.parent
|
|
|
|
|
|
|
|
bind_mat = bone_obj.matrix_local
|
|
|
|
stack_mat = Matrix.Identity(4)
|
|
|
|
|
|
|
|
|
|
|
|
while(True):
|
|
|
|
if bone_obj_parent is None or bone_obj_parent.name in arma.data.bones:
|
|
|
|
break
|
|
|
|
bind_mat = bone_obj_parent.matrix_local @ bind_mat
|
|
|
|
stack_mat = bone_obj_parent.matrix_local @ stack_mat
|
|
|
|
bone_obj_parent = bone_obj_parent.parent
|
|
|
|
|
|
|
|
bone_bind_poses[bone.name] = bind_mat.inverted() @ stack_mat
|
2020-12-06 05:19:58 +00:00
|
|
|
|
2020-12-06 09:11:12 +00:00
|
|
|
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
for bone in arma.pose.bones:
|
|
|
|
if crc(bone.name) in scene.animation.bone_frames:
|
|
|
|
#print("Inserting anim data for bone: {}".format(bone.name))
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
bind_mat = bone_bind_poses[bone.name]
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
translation_frames, rotation_frames = scene.animation.bone_frames[crc(bone.name)]
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
loc_data_path = "pose.bones[\"{}\"].location".format(bone.name)
|
|
|
|
rot_data_path = "pose.bones[\"{}\"].rotation_quaternion".format(bone.name)
|
2020-12-06 05:19:58 +00:00
|
|
|
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
fcurve_rot_w = action.fcurves.new(rot_data_path, index=0)
|
|
|
|
fcurve_rot_x = action.fcurves.new(rot_data_path, index=1)
|
|
|
|
fcurve_rot_y = action.fcurves.new(rot_data_path, index=2)
|
|
|
|
fcurve_rot_z = action.fcurves.new(rot_data_path, index=3)
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
for frame in rotation_frames:
|
|
|
|
i = frame.index
|
|
|
|
q = (bind_mat @ convert_rotation_space(frame.rotation).to_matrix().to_4x4()).to_quaternion()
|
2020-12-06 05:19:58 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
fcurve_rot_w.keyframe_points.insert(i,q.w)
|
|
|
|
fcurve_rot_x.keyframe_points.insert(i,q.x)
|
|
|
|
fcurve_rot_y.keyframe_points.insert(i,q.y)
|
|
|
|
fcurve_rot_z.keyframe_points.insert(i,q.z)
|
2020-12-06 09:11:12 +00:00
|
|
|
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
fcurve_loc_x = action.fcurves.new(loc_data_path, index=0)
|
|
|
|
fcurve_loc_y = action.fcurves.new(loc_data_path, index=1)
|
|
|
|
fcurve_loc_z = action.fcurves.new(loc_data_path, index=2)
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
for frame in translation_frames:
|
|
|
|
i = frame.index
|
|
|
|
t = (bind_mat @ Matrix.Translation(convert_vector_space(frame.translation))).translation
|
2020-12-06 09:11:12 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
fcurve_loc_x.keyframe_points.insert(i,t.x)
|
|
|
|
fcurve_loc_y.keyframe_points.insert(i,t.y)
|
|
|
|
fcurve_loc_z.keyframe_points.insert(i,t.z)
|
|
|
|
|
|
|
|
arma.animation_data.action = action
|
2020-12-04 06:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
def parent_object_to_bone(obj, armature, bone_name):
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
worldmat = obj.matrix_world
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
obj.parent = None
|
|
|
|
obj.parent = armature
|
|
|
|
obj.parent_type = 'BONE'
|
|
|
|
obj.parent_bone = bone_name
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
obj.matrix_basis = Matrix()
|
|
|
|
obj.matrix_parent_inverse = Matrix()
|
2020-12-04 06:22:58 +00:00
|
|
|
|
2020-12-05 05:53:59 +00:00
|
|
|
obj.matrix_world = worldmat
|
2020-12-04 06:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
def refined_skeleton_to_armature(refined_skeleton : List[Model], model_map):
|
|
|
|
|
|
|
|
armature = bpy.data.armatures.new("skeleton")
|
|
|
|
armature_obj = bpy.data.objects.new("skeleton", armature)
|
|
|
|
|
|
|
|
bpy.context.view_layer.active_layer_collection.collection.objects.link(armature_obj)
|
|
|
|
armature_obj.select_set(True)
|
|
|
|
|
|
|
|
bpy.context.view_layer.objects.active = armature_obj
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
|
|
|
|
for bone in refined_skeleton:
|
|
|
|
|
|
|
|
edit_bone = armature.edit_bones.new(bone.name)
|
|
|
|
|
|
|
|
if bone.parent:
|
|
|
|
edit_bone.parent = armature.edit_bones[bone.parent]
|
|
|
|
|
2020-12-06 05:19:58 +00:00
|
|
|
bone_obj = model_map[bone.name]
|
|
|
|
|
|
|
|
#edit_bone.head = bone_obj.matrix_world.translation
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-12-06 05:19:58 +00:00
|
|
|
edit_bone.matrix = bone_obj.matrix_world
|
|
|
|
edit_bone.tail = bone_obj.matrix_world @ Vector((0.0,1.0,0.0))
|
|
|
|
#edit_bone.length = 1
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
2020-11-26 04:10:14 +00:00
|
|
|
bone_children = [b for b in get_model_children(bone, refined_skeleton)]
|
|
|
|
|
2020-12-06 05:19:58 +00:00
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
if bone_children:
|
2020-11-22 05:24:20 +00:00
|
|
|
edit_bone.tail = Vector((-0.00001,0.0,0.0))
|
2020-11-26 04:10:14 +00:00
|
|
|
for bone_child in bone_children:
|
|
|
|
edit_bone.tail += model_map[bone_child.name].matrix_world.translation
|
2020-11-22 05:24:20 +00:00
|
|
|
edit_bone.tail = edit_bone.tail / len(bone_children)
|
2020-11-26 04:10:14 +00:00
|
|
|
else:
|
|
|
|
edit_bone.tail = model_map[bone.name].matrix_world @ Vector((-0.2,0.0,0.0))
|
2020-12-06 05:19:58 +00:00
|
|
|
'''
|
2020-11-26 04:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='OBJECT')
|
|
|
|
armature_obj.select_set(True)
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
return armature_obj
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_refined_skeleton(scene: Scene):
|
|
|
|
|
|
|
|
model_dict = {}
|
|
|
|
skeleton_models = []
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
for model in scene.models:
|
|
|
|
model_dict[model.name] = model
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
if model.geometry:
|
|
|
|
for seg in model.geometry:
|
|
|
|
if seg.weights:
|
|
|
|
for weight_set in seg.weights:
|
|
|
|
for weight in weight_set:
|
2020-12-04 08:33:46 +00:00
|
|
|
model_weighted_to = scene.models[weight.bone]
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
if crc(model_weighted_to.name) not in scene.skeleton:
|
|
|
|
scene.skeleton.append(crc(model_weighted_to.name))
|
|
|
|
|
|
|
|
for model in scene.models:
|
2020-11-26 04:10:14 +00:00
|
|
|
if crc(model.name) in scene.skeleton:
|
|
|
|
skeleton_models.append(model)
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
refined_skeleton_models = []
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
'''
|
|
|
|
for bone in skeleton_models:
|
|
|
|
|
|
|
|
if bone.parent:
|
|
|
|
if
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
for bone in skeleton_models:
|
|
|
|
|
|
|
|
if bone.parent:
|
|
|
|
|
|
|
|
curr_ancestor = model_dict[bone.parent]
|
|
|
|
stacked_transform = model_transform_to_matrix(bone.transform)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
if crc(curr_ancestor.name) in scene.skeleton or curr_ancestor.name == scene.models[0].name:
|
2020-11-26 04:10:14 +00:00
|
|
|
new_model = Model()
|
|
|
|
new_model.name = bone.name
|
2020-11-22 05:24:20 +00:00
|
|
|
print("Adding {} to refined skeleton...".format(bone.name))
|
|
|
|
new_model.parent = curr_ancestor.name if curr_ancestor.name != scene.models[0].name else ""
|
2020-11-26 04:10:14 +00:00
|
|
|
|
|
|
|
loc, rot, _ = stacked_transform.decompose()
|
|
|
|
|
|
|
|
new_model.transform.rotation = rot
|
|
|
|
new_model.transform.translation = loc
|
|
|
|
|
|
|
|
refined_skeleton_models.append(new_model)
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
curr_ancestor = model_dict[curr_ancestor.parent]
|
|
|
|
stacked_transform = model_transform_to_matrix(curr_ancestor.transform) @ stacked_transform
|
2020-12-11 04:47:45 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
return sort_by_parent(refined_skeleton_models)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
def extract_models(scene: Scene, materials_map):
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
model_map = {}
|
|
|
|
|
2020-11-01 16:48:07 +00:00
|
|
|
for model in sort_by_parent(scene.models):
|
2020-11-01 23:11:26 +00:00
|
|
|
new_obj = None
|
|
|
|
|
|
|
|
if model.model_type == ModelType.STATIC or model.model_type == ModelType.SKIN:
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
new_mesh = bpy.data.meshes.new(model.name)
|
|
|
|
verts = []
|
|
|
|
faces = []
|
|
|
|
offset = 0
|
|
|
|
|
|
|
|
mat_name = ""
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
full_texcoords = []
|
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
weights_offsets = {}
|
|
|
|
|
2020-12-06 05:19:58 +00:00
|
|
|
if model.geometry:
|
2020-12-11 04:47:45 +00:00
|
|
|
for i,seg in enumerate(model.geometry):
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if i == 0:
|
|
|
|
mat_name = seg.material_name
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
verts += [tuple(convert_vector_space(v)) for v in seg.positions]
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if seg.weights:
|
|
|
|
weights_offsets[offset] = seg.weights
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if seg.texcoords is not None:
|
|
|
|
full_texcoords += seg.texcoords
|
|
|
|
else:
|
|
|
|
full_texcoords += [(0.0,0.0) for _ in range(len(seg.positions))]
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
if seg.triangles:
|
|
|
|
faces += [tuple([ind + offset for ind in tri]) for tri in seg.triangles]
|
|
|
|
else:
|
|
|
|
for strip in seg.triangle_strips:
|
|
|
|
for i in range(len(strip) - 2):
|
|
|
|
face = tuple([offset + strip[j] for j in range(i,i+3)])
|
|
|
|
faces.append(face)
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
offset += len(seg.positions)
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
new_mesh.from_pydata(verts, [], faces)
|
|
|
|
new_mesh.update()
|
|
|
|
new_mesh.validate()
|
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
if full_texcoords:
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
edit_mesh = bmesh.new()
|
|
|
|
edit_mesh.from_mesh(new_mesh)
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
uvlayer = edit_mesh.loops.layers.uv.verify()
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
for edit_mesh_face in edit_mesh.faces:
|
|
|
|
mesh_face = faces[edit_mesh_face.index]
|
2020-10-30 20:59:54 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
for i,loop in enumerate(edit_mesh_face.loops):
|
|
|
|
|
|
|
|
texcoord = full_texcoords[mesh_face[i]]
|
|
|
|
loop[uvlayer].uv = tuple([texcoord.x, texcoord.y])
|
|
|
|
|
|
|
|
edit_mesh.to_mesh(new_mesh)
|
|
|
|
edit_mesh.free()
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
new_obj = bpy.data.objects.new(new_mesh.name, new_mesh)
|
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
vertex_groups_indicies = {}
|
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
for offset in weights_offsets:
|
|
|
|
for i, weight_set in enumerate(weights_offsets[offset]):
|
|
|
|
for weight in weight_set:
|
2020-12-04 08:33:46 +00:00
|
|
|
index = weight.bone
|
2020-11-29 02:42:27 +00:00
|
|
|
|
|
|
|
if index not in vertex_groups_indicies:
|
|
|
|
model_name = scene.models[index].name
|
|
|
|
vertex_groups_indicies[index] = new_obj.vertex_groups.new(name=model_name)
|
|
|
|
|
2020-12-04 08:33:46 +00:00
|
|
|
vertex_groups_indicies[index].add([offset + i], weight.weight, 'ADD')
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
'''
|
|
|
|
Assign Materials - will do per segment later...
|
|
|
|
'''
|
|
|
|
if mat_name:
|
|
|
|
material = materials_map[mat_name]
|
|
|
|
|
|
|
|
if new_obj.data.materials:
|
|
|
|
new_obj.data.materials[0] = material
|
|
|
|
else:
|
|
|
|
new_obj.data.materials.append(material)
|
2020-11-01 16:48:07 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
new_obj = bpy.data.objects.new(model.name, None)
|
|
|
|
new_obj.empty_display_size = 1
|
|
|
|
new_obj.empty_display_type = 'PLAIN_AXES'
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
model_map[model.name] = new_obj
|
|
|
|
|
|
|
|
if model.parent:
|
|
|
|
new_obj.parent = model_map[model.parent]
|
|
|
|
|
|
|
|
new_obj.location = convert_vector_space(model.transform.translation)
|
|
|
|
new_obj.rotation_mode = "QUATERNION"
|
|
|
|
new_obj.rotation_quaternion = convert_rotation_space(model.transform.rotation)
|
|
|
|
|
|
|
|
bpy.context.collection.objects.link(new_obj)
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
return model_map
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
def extract_materials(folder_path: str, scene: Scene) -> Dict[str,bpy.types.Material]:
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
extracted_materials = {}
|
|
|
|
|
|
|
|
for material_name in scene.materials.keys():
|
|
|
|
|
|
|
|
new_mat = bpy.data.materials.new(name=material_name)
|
|
|
|
new_mat.use_nodes = True
|
|
|
|
bsdf = new_mat.node_tree.nodes["Principled BSDF"]
|
2020-11-01 23:11:26 +00:00
|
|
|
|
|
|
|
tex_path_def = os.path.join(folder_path, scene.materials[material_name].texture0)
|
|
|
|
tex_path_alt = os.path.join(folder_path, "PC", scene.materials[material_name].texture0)
|
|
|
|
|
|
|
|
tex_path = tex_path_def if os.path.exists(tex_path_def) else tex_path_alt
|
|
|
|
|
|
|
|
if os.path.exists(tex_path):
|
|
|
|
texImage = new_mat.node_tree.nodes.new('ShaderNodeTexImage')
|
|
|
|
texImage.image = bpy.data.images.load(tex_path)
|
|
|
|
new_mat.node_tree.links.new(bsdf.inputs['Base Color'], texImage.outputs['Color'])
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
extracted_materials[material_name] = new_mat
|
|
|
|
|
|
|
|
return extracted_materials
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
def extract_scene(filepath: str, scene: Scene):
|
|
|
|
|
|
|
|
folder = os.path.join(os.path.dirname(filepath),"")
|
2020-11-22 05:24:20 +00:00
|
|
|
matmap = extract_materials(folder, scene)
|
|
|
|
|
|
|
|
model_map = extract_models(scene, matmap)
|
|
|
|
|
|
|
|
skel = extract_refined_skeleton(scene)
|
|
|
|
armature = refined_skeleton_to_armature(skel, model_map)
|
|
|
|
|
2020-12-11 04:47:45 +00:00
|
|
|
|
|
|
|
for bone in armature.data.bones:
|
|
|
|
bone_local = bone.matrix_local
|
|
|
|
if bone.parent:
|
|
|
|
bone_local = bone.parent.matrix_local.inverted() @ bone_local
|
|
|
|
|
|
|
|
bone_obj_local = bpy.data.objects[bone.name].matrix_local
|
|
|
|
obj_loc, obj_rot, _ = bone_obj_local.decompose()
|
|
|
|
|
|
|
|
loc, rot, _ = bone_local.decompose()
|
|
|
|
|
|
|
|
locdiff = obj_loc - loc
|
|
|
|
quatdiff = obj_rot - rot
|
|
|
|
|
|
|
|
if quatdiff.magnitude > .01:
|
|
|
|
print("Big quat diff here")
|
|
|
|
print("\t{}: obj quat: {} bone quat: {}".format(bone.name, quat_to_str(obj_rot), quat_to_str(rot)))
|
|
|
|
|
|
|
|
|
|
|
|
#if locdiff.magnitude > .01:
|
|
|
|
# print("Big loc diff here")
|
|
|
|
# print("\t{}: obj loc: {} bone loc: {}".format(bone.name, vec_to_str(obj_loc), vec_to_str(loc)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-04 08:33:46 +00:00
|
|
|
reparent_obj = None
|
2020-11-22 05:24:20 +00:00
|
|
|
for model in scene.models:
|
|
|
|
if model.model_type == ModelType.SKIN:
|
|
|
|
|
|
|
|
if model.parent:
|
|
|
|
reparent_obj = model_map[model.parent]
|
|
|
|
|
|
|
|
skin_obj = model_map[model.name]
|
|
|
|
skin_obj.select_set(True)
|
|
|
|
armature.select_set(True)
|
|
|
|
bpy.context.view_layer.objects.active = armature
|
|
|
|
|
|
|
|
bpy.ops.object.parent_clear(type='CLEAR')
|
|
|
|
bpy.ops.object.parent_set(type='ARMATURE')
|
|
|
|
|
|
|
|
skin_obj.select_set(False)
|
|
|
|
armature.select_set(False)
|
|
|
|
bpy.context.view_layer.objects.active = None
|
|
|
|
|
2020-12-04 06:22:58 +00:00
|
|
|
if armature is not None:
|
|
|
|
for bone in armature.data.bones:
|
|
|
|
for model in scene.models:
|
2020-12-11 04:47:45 +00:00
|
|
|
if model.parent in armature.data.bones and model.model_type != ModelType.NULL:
|
|
|
|
pass#parent_object_to_bone(model_map[model.name], armature, model.parent)
|
2020-12-04 06:22:58 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
if reparent_obj is not None and armature.name != reparent_obj.name:
|
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
armature.select_set(True)
|
|
|
|
reparent_obj.select_set(True)
|
|
|
|
bpy.context.view_layer.objects.active = reparent_obj
|
|
|
|
bpy.ops.object.parent_set(type='OBJECT')
|
|
|
|
|
|
|
|
armature.select_set(False)
|
|
|
|
reparent_obj.select_set(False)
|
|
|
|
bpy.context.view_layer.objects.active = None
|
2020-12-11 04:47:45 +00:00
|
|
|
'''
|
2020-11-22 05:24:20 +00:00
|
|
|
|
|
|
|
for model in scene.models:
|
|
|
|
if model.name in bpy.data.objects:
|
2020-12-04 08:33:46 +00:00
|
|
|
obj = bpy.data.objects[model.name]
|
2020-12-11 04:47:45 +00:00
|
|
|
if get_is_model_hidden(obj) and len(obj.children) == 0 and model.model_type != ModelType.NULL:
|
2020-12-04 08:33:46 +00:00
|
|
|
obj.hide_set(True)
|
2020-12-11 04:47:45 +00:00
|
|
|
|
2020-11-22 05:24:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-01 23:11:26 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2020-11-29 02:42:27 +00:00
|
|
|
|
2020-11-26 04:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-30 20:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|