create poses using script

This forum is aimed at user contributions, in the form of assets, side projects, code patches and similar.

Moderator: joepal

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 2:44 pm

Indeed, I cut the code to like this

Code: Select all
import animation
import random
from core import G
from bvh import BVH
import matrix as m

def generate_poses(human, human_name):
    from bvh import BVH
    import matrix as m
    skeleton=human.skeleton
    bones=skeleton.getBones()
    b=BVH()
    b.fromSkeleton(skeleton, None, False)
    anim=b.createAnimationTrack(skeleton, name=human_name)
    rotmatrix=m.rotx(30)
    change=rotmatrix[:5, :2]
    for boneNr in range(len(bones)):
        boneName=bones[boneNr].name
        animData=anim.data[boneNr]
        if boneName == "upperarm02.L":
            anim.data[boneNr]=change

    human.addAnimation(anim)
    human.setActiveAnimation(anim.name)
    human.refreshPose()
    return human


Well, it runs, but I can't see any differences
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby dugarsumit » Mon Jun 12, 2017 2:50 pm

Right. I am afraid you will need to code that part yourself. It won't be tough :)
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 3:04 pm

dugarsumit wrote:Right. I am afraid you will need to code that part yourself. It won't be tough :)

Yeah. Just point me what part? Random? How do i correctly call this funcrion, lets say wo random for now.
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby dugarsumit » Mon Jun 12, 2017 3:12 pm

variable named 'change' that contains rotation matrix defines the change that will happen to the bone. You just need to pass random matrix values into this variable. (Y)
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 4:16 pm

I'am confused.

rotmatrix=m.rotx(30) - here you assig to rotmatrix some kind of matrix, what 30 stands for?

change=rotmatrix[:3, :4] here you take first 3 lines and gets first 4 rows of that lines?

Can't seem to find anything in api reference
http://www.makehumancommunity.org/api/s ... tml?q=rotx
Are there any descent documentations?
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby dugarsumit » Mon Jun 12, 2017 4:47 pm

There is no documentation as far as I remember. I had to struggle a lot when I was figuring out this.
rotmatrix=m.rotx(30) : It means 30 degree rotation around x-axis
change=rotmatrix[:3, :4] : It's a python syntax which means pick first 3 rows and first 4 columns.
Hope this helps :)
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 5:03 pm

dugarsumit wrote:There is no documentation as far as I remember. I had to struggle a lot when I was figuring out this.
rotmatrix=m.rotx(30) : It means 30 degree rotation around x-axis
change=rotmatrix[:3, :4] : It's a python syntax which means pick first 3 rows and first 4 columns.
Hope this helps :)

It does helped ) In a way. Maybe you can clarefy for me pivots of the bones transformation.

In attachment below from 3d app I have a finger rotated by a degree.

I have a code for this like
Code: Select all
import animation
import random
from core import G
from bvh import BVH
import matrix as m

Meanwhile in attachment from debug skeleton i see that X pyvot is set correctly, and adding rotx offset should have bended the finger normaly towards inner part of the hand.

def generate_poses(human):
    from bvh import BVH
    import matrix as m
    skeleton=human.skeleton
    bones=skeleton.getBones()
    b=BVH()
    b.fromSkeleton(skeleton, None, False)
    anim=b.createAnimationTrack(skeleton, name="Tst")
    rotmatrixx=m.rotx(50)
    rotmatrixy=m.roty(0)
    rotmatrixz=m.rotz(0)
    rotmatrix=rotmatrixx*rotmatrixy*rotmatrixz
    change=rotmatrix[:3, :4]
    for boneNr in range(len(bones)):
        boneName=bones[boneNr].name
        animData=anim.data[boneNr]
        if boneName == "finger2-1.R":
            anim.data[boneNr]=change

    human.addAnimation(anim)
    human.setActiveAnimation(anim.name)
    human.refreshPose()
    return human

human = G.app.selectedHuman
human=generate_poses(human)


And the result is wierd, bone kinda rotated oddly.
Attachments
python_2017-06-12_20-08-55.png
python_2017-06-12_20-05-14.png
modo_2017-06-12_20-02-04.png
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 5:39 pm

I guess the key to pivots is

def rotate(a, xyz):
x, y, z = normalize(xyz)
s, c = _sincos(a)
nc = 1 - c
return np.matrix([[x*x*nc + c, x*y*nc - z*s, x*z*nc + y*s, 0],
[y*x*nc + z*s, y*y*nc + c, y*z*nc - x*s, 0],
[x*z*nc - y*s, y*z*nc + x*s, z*z*nc + c, 0],
[ 0, 0, 0, 1]])

But I cant seem to get it working propperly. Have you used this one?
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 7:05 pm

Well. After a few hours of hamering my head agains keyboard i must state: I have comletly no ide how to use local pivots of the bones, shown in debug skeleton.
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

Postby dugarsumit » Tue Jun 13, 2017 5:34 am

I am afraid I don't have any idea about that pivot thing you are talking about. :(
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

PreviousNext

Return to User contributions

Who is online

Users browsing this forum: No registered users and 1 guest

cron