bvh editing re-target simple script

(gabdab) #1

Hi,
I have made a little script to handle bvh files re-targeting ( sum different bvh actions ).
I m little tired so I am going to be coincise.
You need to set up 2 Armatures ( Armature and Armature.001 ).
This script simply copy location and rotation of every bone of Armature.001 to Armature bones ( this means that Armature coincides with Armature.001 position ).
Every bone of Armature and Armature.001 must have same name .


#!BPY

"""
Name: 'Bones loc-rot copier'
Blender: 244
Group: 'Object'
Tooltip: 'Copy location and rotation constraints applied to every bone of Armature according to Armature.001 bones .'
"""

#-------
# renommer tous les bones d'une armature 
# jm soler, 04/2004 
# Modif par Gabio, 01/2005
#-------
#-------------------
#copy location | copy rotation constraints between armatures-bones
#
#gabdab, 09/2007
#-------------------

import Blender
from Blender import Armature,Object
from Blender.BGL import *
from Blender.Draw import *

from Blender import *

ob = Object.Get('Armature')
target = Object.Get('Armature.001')


scn= Scene.GetCurrent()
arm_ob= scn.objects.active


# Assign the pose animation 
pose = arm_ob.getPose() 
 
act = arm_ob.getAction() 
if not act: # Add a pose action if we dont have one 
    act = Armature.NLA.NewAction() 
    act.setActive(arm_ob) 
      
    xbones=arm_ob.data.bones.values() 
    pbones = pose.bones.values() 
    print xbones 
    print pbones 

pose = ob.getPose()
pose1 = target.getPose()

for bonename in pose.bones.keys():
     bone = pose.bones[bonename]
     bone1=pose1.bones[bonename]
     #for const in bone.constraints:
     #print bone.name #,'=>',const
     print bone.name ,'=>',bone1.name
     bone.constraints.append(Blender.Constraint.Type.COPYLOC)
     const = bone.constraints[len(bone.constraints)-1] #last constraint in the list
     const[Constraint.Settings.TARGET] = target
     const[Constraint.Settings.BONE] = bone1.name

     bone.constraints.append(Blender.Constraint.Type.COPYROT)
     const = bone.constraints[len(bone.constraints)-1] #last constraint in the list
     const[Constraint.Settings.TARGET] = target
     const[Constraint.Settings.BONE] = bone1.name
     


That’s all …
Ask away.
Gab-

0 Likes

(ibkanat) #2

I just tried this… Seems to error out on line 57… None type object has no name. bone1.name.

Am I missing something? I renamed my bvh files bones to be the same as my rig. Except for I had a extra bone in my rigs feet. Could this cause it?

0 Likes

(gabdab) #3

Hi ibkanat,
yes might be… it is very basic.
Just add a bone or delete it when necessary to have the exact number and names of bones in both armatures …
Btw I made the script after your explanation of the process so blame yourself …:evilgrin:
Send me the file if you want so I can check …
You can test it duplicating an armature first.

0 Likes

(gabdab) #4

By the way it would be easier ( and would maybe work fine too ) to copy action ipo for bones …I guess ?

0 Likes

(gabdab) #5

Since parented mesh gets distorted apparently , now it reports Armature head and tail positions…
All info by console no chance to make gui.
Anyone helping out ?


#!BPY

"""
Name: 'Bones loc-rot copier'
Blender: 244
Group: 'Object'
Tooltip: 'Copy location and rotation constraints applied to every bone of Armature according to Armature.001 bones .'
"""

#-------
# renommer tous les bones d'une armature 
# jm soler, 04/2004 
# Modif par Gabio, 01/2005
#-------
#-------------------
#copy location | copy rotation constraints between armatures-bones
#FrankenBlend of snippets inside beware !
#gabdab, 09/2007
#-------------------

import Blender
from Blender import Armature,Object
from Blender.BGL import *
from Blender.Draw import *
from Blender.Mathutils import *
from Blender import *

ob = Object.Get('Armature')
target = Object.Get('Armature.001')


scn= Scene.GetCurrent()
arm_ob= scn.objects.active
#
#if arm_ob.name == 'Armature':
arms = Armature.Get()
for arm in arms.values():
    if arm.name == 'Armature':
        arm.drawType = Armature.STICK #set the draw type
        #arm.makeEditable() #enter editmode
        #print arm.bones.items()
        for bone in arm.bones.values():
                #print bone.matrix['ARMATURESPACE']
                 print bone.parent, bone.name
                 print bone.children, bone.name
                 print bone.options, bone.name
                 print bone.tail, bone.name
                 print bone.head, bone.name


# Assign the pose animation 
pose = arm_ob.getPose() 
 
act = arm_ob.getAction() 
if not act: # Add a pose action if we dont have one 
    act = Armature.NLA.NewAction() 
    act.setActive(arm_ob) 
      

xbones=arm_ob.data.bones.values() 
pbones = pose.bones.values() 
#print xbones 
#print pbones 

pose = ob.getPose()
pose1 = target.getPose()

for bonename in pose.bones.keys():
     bone = pose.bones[bonename]
     bone1=pose1.bones[bonename]
     #for const in bone.constraints:
     #print bone.name #,'=>',const
     #print bone.name ,'=>',bone1.name
     bone.constraints.append(Blender.Constraint.Type.COPYLOC)
     const = bone.constraints[len(bone.constraints)-1] #last constraint in the list
     const[Constraint.Settings.TARGET] = target
     const[Constraint.Settings.BONE] = bone1.name

     bone.constraints.append(Blender.Constraint.Type.COPYROT)
     const = bone.constraints[len(bone.constraints)-1] #last constraint in the list
     const[Constraint.Settings.TARGET] = target
     const[Constraint.Settings.BONE] = bone1.name


0 Likes

(ibkanat) #6

Hey thanks for this. Sorry I am not the best at explaining things. I think that there is some work being done on auto rigging that would be great.

Really what I found easiest was to delete my rig and just use the bvh files. But that really doesnt slove any problems. This script is a good start. But I wonder if it is easier than like you said just coping the actions or adding constraints. I am still trying to get a easy and quick work flow. Right now it seems that animating by hand might be quicker.

I was wondering how hard it would be to create a gui for maybe constraints in python?
The work flow would be

  1. You have your rigged character
  2. You import a bvh rig
  3. You scale it to fit your rig.
  4. Run the script and have it find the links between the closest bones. Similar to heat weight except for bone matching. This might be what the Devs are working on
    Maybe using envelopes to assign the links. Just one of those crazy thoughts.
0 Likes

(gabdab) #7

This post script might be related to what you mentioned , or not ?

http://blenderartists.org/forum/showthread.php?t=67129&highlight=rcruiz+constraint.

By hand workflow sound fine , it depends on how many characters and animations you need.
What do you mean by ‘find the links between the closest bones …’ ? I don’t know what ‘heat weight’ is :slight_smile:
It should not be too difficoult to have an armature match another …
I will look into some exporters ( smd , md5… ) .
I am trying to hypnotize the python …

0 Likes

(gabdab) #8

…also the old script for Blender 2.37 by jbperin:
http://blenderartists.org/forum/showthread.php?t=39635
works really good for importing more bvh to the same armature …

0 Likes

(ibkanat) #9

Hey thanks for the links to the scripts I will check them out. Here is a link for the heat weight it is already in the svn(graphicall.org builds). blender.org - Skinning
What I was thinking is a script that would have a gui to create constraint links based on distance. Probably it is a bit far fetched cause heat weight is in the trunk and it would need to run interactively. Thanks for the links. Maybe there would be a way to write a script that would bring up the bone hierarchy and give a person the ability to make links between bones.

I guess I need to learn python it doesnt look that hard.

0 Likes

(gabdab) #10

I suggest you go on with Python since you have nice ideas.
I am a bit out of Blender at the moment, I need to get a better grip to Python .
Nice stuff coming to Blender , heat weight rules !:slight_smile:
By ‘making links’ I guess you refer to one of the armature related functions but can’t figure out which one yet .

Gab_

Blender 2.44 API
http://www.zoo-logique.org/3D.Blender/scripts_python/API/Armature-module.html

0 Likes

(gabdab) #11

I figured that the editing position of armature influences final action performance.
If you set ipo action of Armature_0_Bone to Armature_1_Bone the eventual different performance is due to edit pose of Armature.
How do I overcome that ?
The calculation should involve quaternions and else,

(Not sure if ARMATURESPACE and BONESPACE could influence this and how.)

0 Likes

(ibkanat) #12

Thats why retargeting with constraints is ideal. If you leave you character rig and bvh alone and just use copy location and copy rotation it should ideally copy the action. It is just a bit of a pain to do that with lots of bones.

I am not too concerned about this at the moment… Because I know people are working on it.

Yes placement of a bvh rig in your character is key to it moving the way it should. I have had some pretty funny perfomances. Honestly I have gotten close but not close enough. I hoped that using my own rig retargeted with a bvh rig would give me the performace I wanted. I wonder if its the build I am using or what I cant seem to get empties to import. Empties I believe are the way to go they drive the character bones much better… You dont even have to retarget all the bones and you can set a influence.

0 Likes

(gabdab) #13

Problem is that such constraint is absent right now.
It should apply armatures rest position differences to action ipos .

0 Likes