Now gets the bone to position the model to from the model's name. Now also adds the armature's position to final model's position, making it line up better.

master
TigerKat 4 years ago
parent 545f6f203d
commit ada937ce82

@ -2,7 +2,7 @@
bl_info = {
"name": "City of Heroes (.geo)",
"author": "TigerKat",
"version": (0, 2, 3),
"version": (0, 2, 4),
"blender": (2, 80, 0),
"location": "File > Import/Export,",
"description": "City of Heroes (.geo)",

@ -26,6 +26,17 @@ else:
l.reverse()
return l
def extractRootBoneFromName(name):
if name.startswith("GEO_"):
name = name[4:]
if name.startswith("N_"):
name = name[2:]
bone = name.split("_")[0]
if bone in BONES_LOOKUP:
return bone
else:
return None
def convert_model(geo_model, mesh_data, obj, scale):
#Convert the geo_model into a GeoMesh.
geomesh = geo_model.saveToGeoMesh()
@ -82,9 +93,10 @@ def convert_model(geo_model, mesh_data, obj, scale):
#todo: attempt to load textures/images
def getBonePositionBody(bone):
#todo: fix this: Presently assumes that the head to tail will always be the same direction and length.
if bone.parent is None:
p = bone.tail
print("root: %s: %s (%s)" % (bone, p, bone.head))
p = bone.head
print("root: %s: %s (%s)" % (bone, p, bone.tail))
return p
else:
p = bone.tail + getBonePositionBody(bone.parent)
@ -142,9 +154,17 @@ def load(operator, context, scale = 1.0, filepath = "", global_matrix = None, us
if bone_name is None:
#No bones, don't attach.
pass
else:
preferred_bone_name = extractRootBoneFromName(model_name)
arm_pos = armature_obj.matrix_world.translation
if preferred_bone_name is not None:
bone_pos = getBonePosition(armature, preferred_bone_name)
obj.matrix_world = mathutils.Matrix.Translation(arm_pos + bone_pos)
obj.modifiers.new(name = 'Armature', type = 'ARMATURE')
obj.modifiers['Armature'].object = armature_obj
elif bone_name in armature.bones:
bone_pos = getBonePosition(armature, bone_name)
obj.matrix_world = mathutils.Matrix.Translation(bone_pos)
obj.matrix_world = mathutils.Matrix.Translation(arm_pos + bone_pos)
obj.modifiers.new(name = 'Armature', type = 'ARMATURE')
obj.modifiers['Armature'].object = armature_obj
else:

Loading…
Cancel
Save