ok so i’ve made an importer/exporter for a custom model file format with blender but I am now trying to improve it so that it can import the armature but i’m having problems…
So i have an array of class joints that i’ve read from the file, each joint has a transform/matrix. and a parentbone. I’ve created a new armature and created the bones and linked the parents. Then i tried setting the transform matrix using
bone.transform(matrix, scale=False, roll=False)
but i get just a bones almost in a pile, i’ve tried with and without scale/roll options but same problem.
I’ve been looking through other importers and online but i’m really not sure what to do next.
Any help is much appreciated… here is what i have
#create armature
bpy.ops.object.armature_add()
obj = bpy.context.scene.objects.active
obj.name = "Armature"
arm = obj.data
#make bones
bpy.ops.object.mode_set(mode='EDIT')
for j in joints:
bone = arm.edit_bones.new(j._name)
bone.head = (0,0,0)
bone.tail = (0,0,1)
bpy.context.scene.update()
#make bone parents
for j in joints:
nameparent=None
if j._parentId in indexedJoints:
nameparent = indexedJoints[j._parentId]._name
if nameparent != None:
bone = arm.edit_bones[j._name]
parentbone = arm.edit_bones[nameparent]
bone.parent = parentbone
bone.use_connect = True
bpy.context.scene.update()
#set bone positioning/matrix
for j in joints:
mat = j._transform.getMatrix()
(pos, rot, scale) = mat.decompose()
bone.transform(rot, scale=False, roll=True)
bpy.context.scene.update()
settings head and tail of bones to same coordinate is not a good idea:
bone.head = (0,0,0)
bone.tail = (0,0,1)
Blender may remove them for being in the same spot.
If an armature looks crunched together, the coordinates might be absolute and not relative to each other