How to create fCurve data for armature bones form game enigine data?

Hi all,

Firstly, argh!. How do I change the background colour of the code tags part below? Its hideous. Anyone? If youre a mod and can be bothered, by all means change it for me or ill come back in and edit it. Sorry. (Im a muppet. It looks like its just in the post preview it shows as a white background.)

Secondly, and main actual real problem. :slight_smile:
Ive managed to cobble my brain around creating fCurve data from game engine positions/rotations etc of Mesh, Light and Camera data but Im struggling with the data stuff for armatures… I think?
Heres the code Im using for a point light, for instance…

        for x in range(l.cLCount):
            ob = l.getSceneList()[0].objects[l.cLights[x].name]    
            bpy.context.scene.objects[l.cLights[x].name].matrix_local = ob.worldTransform
            bpy.context.scene.objects[l.cLights[x].name].keyframe_insert(data_path = "location", frame = (l.frameCounter))        
            bpy.context.scene.objects[l.cLights[x].name].keyframe_insert(data_path = "rotation_euler", frame = (l.frameCounter))
            
            bpy.data.lamps[l.cLights[x].name].color = ob.color
            bpy.data.lamps[l.cLights[x].name].keyframe_insert(data_path = "color", frame = (l.frameCounter))
            
            bpy.data.lamps[l.cLights[x].name].energy = ob.energy
            bpy.data.lamps[l.cLights[x].name].keyframe_insert(data_path = "energy", frame = (l.frameCounter))
            
            bpy.data.lamps[l.cLights[x].name].distance = ob.distance
            bpy.data.lamps[l.cLights[x].name].keyframe_insert(data_path = "distance", frame = (l.frameCounter))

I`m sorting object types and storing them in thier own classes. In the above case, l.cLights.

It took me quite a while to figure out what string to put in after the data_path?
Is there a list of data types somewhere I`m just not finding?

This is all something I do as a background hobby so I really struggle with the lingo/syntax.

I think I realise I`m opening up a can of worms with regards to bone orientations and what not.

Here is the code Ive cobbled, and at this point feel could/should work, but doesnt…

        for x in range(l.cACount):
            ob = l.getSceneList()[0].objects[l.cArms[x].name]
            for chan in range(len(ob.channels)):
                bpy.data.armatures[x].bones[chan].matrix_local = ob.channels[chan].channel_matrix
                bpy.data.armatures[x].bones[chan].keyframe_insert(data_path = "rotation_quaternion", frame = (l.frameCounter))

I was hoping to be able to run the script and all the rotational and positional data of the armature, at that point in the game engine, be copied out to the relating fCurves.? I`m able to do this for Mesh, Light and Camera objects. Just not Armatures at the moment.

Any help would be greatly appreciated.

Thanks in advance.
-Daz

It took me quite a while to figure out what string to put in after the data_path?
Is there a list of data types somewhere I`m just not finding?

It can be any property of an object, if it’s a lamp (bpy.data.lamps[#]), see the Object data tab and hover any prop to see the name:

bpy.data.lamps[“Lamp”].use_own_layer

Thanks CoDEmanX. That was simple/obvious/justwhatineeded. :slight_smile:
You`ve just helped me to open up a massive can of worms by the looks of thing.

For anyone interested, here is some code I`ve cobbled so far which creates contorted bones/poses. (of no real use.)

        # l.cACount - int Variable equal to current number of Armatures in scene.        
        # l.cArms - Bespoke class which stores info for my own needs. (name, loc, intention, etc etc)
        for x in range(l.cACount): 
            ob = l.getSceneList()[0].objects[l.cArms[x].name]
            for chan in range(len(ob.channels)):
                bpy.data.armatures[x].bones[chan].matrix_local = ob.channels[chan].channel_matrix               
                bpy.data.objects[l.cArms[x].name].pose.bones[chan].keyframe_insert(data_path = "rotation_euler", frame = l.frameCounter)

I`m assuming, and we all know what that does, if I can track back up through each bones matrix to the parent bone I may be able to make some vaguely useful values?.!?

Thanks again,
-Daz