@ -26,6 +26,17 @@ else:
l . reverse ( )
l . reverse ( )
return l
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 ) :
def convert_model ( geo_model , mesh_data , obj , scale ) :
#Convert the geo_model into a GeoMesh.
#Convert the geo_model into a GeoMesh.
geomesh = geo_model . saveToGeoMesh ( )
geomesh = geo_model . saveToGeoMesh ( )
@ -82,9 +93,10 @@ def convert_model(geo_model, mesh_data, obj, scale):
#todo: attempt to load textures/images
#todo: attempt to load textures/images
def getBonePositionBody ( bone ) :
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 :
if bone . parent is None :
p = bone . tail
p = bone . head
print ( " root: %s : %s ( %s ) " % ( bone , p , bone . head ) )
print ( " root: %s : %s ( %s ) " % ( bone , p , bone . tail ) )
return p
return p
else :
else :
p = bone . tail + getBonePositionBody ( bone . parent )
p = bone . tail + getBonePositionBody ( bone . parent )
@ -142,13 +154,21 @@ def load(operator, context, scale = 1.0, filepath = "", global_matrix = None, us
if bone_name is None :
if bone_name is None :
#No bones, don't attach.
#No bones, don't attach.
pass
pass
elif bone_name in armature . bones :
bone_pos = getBonePosition ( armature , bone_name )
obj . matrix_world = mathutils . Matrix . Translation ( bone_pos )
obj . modifiers . new ( name = ' Armature ' , type = ' ARMATURE ' )
obj . modifiers [ ' Armature ' ] . object = armature_obj
else :
else :
print ( " Bone ' %s ' not found in armature ' %s ' , skipping. " % ( bone_name , armature ) )
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 ( arm_pos + bone_pos )
obj . modifiers . new ( name = ' Armature ' , type = ' ARMATURE ' )
obj . modifiers [ ' Armature ' ] . object = armature_obj
else :
print ( " Bone ' %s ' not found in armature ' %s ' , skipping. " % ( bone_name , armature ) )
obj . select_set ( True )
obj . select_set ( True )
pass
pass
pass
pass