Help! Script to create Armature

Hello! I don’t know where to ask this, so I will ask here…

On the official Elder Scrolls:Oblivion forum we’re trying to get Blender export into Oblivion working via the new kludge in the Nifskope utility.

However, one thing we still lack is a clean skeleton to rig to in Blender!

I have attempted to create a distributable one by clearing out the uninterpretable Havok data from the bethesda skeleton. nif and importing it , and it does import… but not as an armature! It just imports as a lot of objects. Proper rotation, proper position, and they seem linked to eachother… they’re just not an armature!

What my hope is, is that this is not such an uncommon thing that someone will know how a script can be authored to take the data in either of the two .nif files I have created ( I can save as .blend too if it will help) and translate this data into IK/Armature rather than just generic linked objects!

It would be a great help if anyone was able to do this. or able to put my foot in the right direction…

I have uploaded two .nif files to FileFactory, CleanedSkeleton.nif is ONLY the ninodes, clanedskeleton2.nif is the skeleton as it comes from Bethesda with only havok removed, and the transformcontrollers et cetera left in.

Link is here, please take a look if you have the ability to fulfill my request.

http://www.filefactory.com/?4933d3

I managed to import the cleanedskeleton.nif into blender.

I noticed that there was a script in the animation menu to convert empties to an armature and tried that.

However I got a python script error.
I had to change line 386 on the script from:
thebone = thepose.bones[bonename]
to:
thebone=Blender.Armature.Editbone()
armData.bones[‘bone1’] = thebone
because of latest changes to the py api.
Also this script was initially made to convert bvh animations to armature animations. So I had to insert an ipo for all the objects, before running the script.

The script ran but still had some error, but the armature was created.

The armature was there but the transforms(positioning) were not there but I saved and re-opened the file and the transforms appeared.

Here is a zip file of the blend.

Good luck with this. I am interested in seeing new skinned meshes created with Blender in Oblivion.

You need to put the armature into editmode to edit the bone data. When your done you need to call update() on the armature to save the changes. You should take a look at the API documentation.

actually, copying over shape data which referenced the bones let blender import it as armature. No problems now ^^

Converts a dict to an armature - works with current CVS

from Blender import Scene, Armature, Object, Mathutils

def dict2armatre(armDict):
    '''Utility function that converts a dictionary to an armature
    the armDict dictionary is a nested dictionary of items described below.
    
    Each item is is a list formatted as follows.
    [childrenDict, start, end, Bone=None]
    * childrenDict is the child of the armDict.
    * start and end are vectors representing the armature space locations of the bones rest position.
    * Bone, starts off as None, but the 4th slot will havea bone added into it once the armature is created
    
    Dictionary keys are all strings that are used to name the bones.
    the example below shows 3 bones
    armdct= {'hip':[{'knee':[{}, (0,0,1), (0,0,2), None]}, (0,0,0), (0,0,1), None], 'vehicle':[{}, (1,0,0), (2,0,0), None]}
    ..hip
    ....knee
    ..vehicle '''
    
    def item2bone(name, data, selfdata, parentdata):
        bone= selfdata[3]= Armature.Editbone()
        bone.name= name
        data.bones[bone.name]= bone
        bone.head= Mathutils.Vector(selfdata[1])
        bone.tail= Mathutils.Vector(selfdata[2])
        
        if parentdata:
            bone.parent= parentdata[3]
        
        for childname, childdata in selfdata[0].iteritems():
            # Make bones recursivly
            item2bone(childname, data, childdata, selfdata)
    
    armOb= Object.New('Armature')
    armData= Armature.Armature('myArmature')
    armOb.link(armData)
    armData.makeEditable()
    
    for childname, rootbonedata in armDict.iteritems():
        item2bone(childname, armData, rootbonedata, None)
    
    armData.update()
    return armOb

if __name__ == '__main__':
    v=Mathutils.Vector
    armdct= {'hip':[{'knee':[{}, v(0,0,1), v(0,0,2), None]}, v(0,0,0), v(0,0,1), None], 'vehicle':[{}, v(1,0,0), v(2,0,0), None]}
    ob= dict2armatre(armdct)
    scn= Scene.GetCurrent()
    scn.link(ob)
    

Spiffy! Actually we got blender to import as armature just by adding geometry data to the skeleton .nif that referenced the bones.