create poses using script

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

Moderator: joepal

create poses using script

Postby dugarsumit » Thu May 04, 2017 9:28 am

I want to create different poses using scripting in makehuman. I have written a following dummy script. When I try to run this script I cannot observe any change in the pose of my model. Am I missing something or doing something wrong? Can someone please help me.
Code: Select all
import numpy as np
human = G.app.selectedHuman
skeleton = human.skeleton
bones = skeleton.getBones()
pose = skeleton.getPose()
poseMats = []
matPose = np.identity(4, dtype=np.float32)
for bIdx, bone in enumerate(bones):
    if bone.name == "LeftLeg":
        #bone.rotateRest(matPose)
        poseMats.append(matPose)
    else:
        poseMats.append(bone.matPoseGlobal)
poseMats = np.array(poseMats)
skeleton.setPose(poseMats)
Last edited by dugarsumit on Thu May 04, 2017 9:48 am, edited 1 time in total.
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby joepal » Thu May 04, 2017 9:38 am

In general, MH will not redraw automatically. You need to tell it to.

There are two pertinent calls which might be of interest. You can test both and see if either or both helps.

Code: Select all
import gui3d
import mh

gui3d.app.selectedHuman.applyAllTargets()   # <--- probably not relevant for posing, but doesn't hurt to try
mh.redraw()   # <--- this is probably the one you want


I did not test your code though, so there might be something else missing too.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4465
Joined: Wed Jun 04, 2008 11:20 am

Re: create poses using script

Postby dugarsumit » Thu May 04, 2017 9:50 am

I tried your suggestions but neither of them are working :(
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby joepal » Fri May 05, 2017 8:02 am

Actually, you should probably work with animations (where a pose is a 1 frame animation) rather than overwriting the base data structures directly. Something like:

Code: Select all
from core import G
from bvh import BVH

human = G.app.selectedHuman
skeleton = human.skeleton
bones = skeleton.getBones()

b = BVH()
b.fromSkeleton(skeleton)
anim = b.createAnimationTrack(skeleton, name="test")

for boneNr in range(len(bones)):
    boneName = bones[boneNr].name
    animData = anim.data[boneNr]
    if boneName == "upperarm02.L":
        pass # <--- here "animData" holds info about the rotations for bone "upperarm02.L" and can be modified

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


There are probably more efficient ways to achieve these things, you could try reading the plugins/7_expression_mixer.py (see https://bitbucket.org/MakeHuman/makehum ... ew-default) for an example where poses are created via the UI.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4465
Joined: Wed Jun 04, 2008 11:20 am

Re: create poses using script

Postby dugarsumit » Fri May 05, 2017 11:10 am

Thanks a lot :)
It's working fine and I think it will solve my problem. The only problem is, it working only for default skeleton and not for any other skeleton type.
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

Postby joepal » Fri May 05, 2017 1:26 pm

I think pretty much everything in MH presupposes the default skeleton, and that poses are then interpolated onto a different skeleton if chosen. But don't quote me on this, I haven't studied those parts of the source code in such detail.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4465
Joined: Wed Jun 04, 2008 11:20 am

Re: create poses using script

Postby ShatteredEssence » Mon Jun 12, 2017 12:17 pm

joepal wrote:Actually, you should probably work with animations (where a pose is a 1 frame animation) rather than overwriting the base data structures directly. Something like:

Code: Select all
from core import G
from bvh import BVH

human = G.app.selectedHuman
skeleton = human.skeleton
bones = skeleton.getBones()

b = BVH()
b.fromSkeleton(skeleton)
anim = b.createAnimationTrack(skeleton, name="test")

for boneNr in range(len(bones)):
    boneName = bones[boneNr].name
    animData = anim.data[boneNr]
    if boneName == "upperarm02.L":
        pass # <--- here "animData" holds info about the rotations for bone "upperarm02.L" and can be modified

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


There are probably more efficient ways to achieve these things, you could try reading the plugins/7_expression_mixer.py (see https://bitbucket.org/MakeHuman/makehum ... ew-default) for an example where poses are created via the UI.


Can you pleace be more specific on how do i update animdata, and pass it back to apply changes? thx
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

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

If it helps you can checkout my code here - https://github.com/dugarsumit/pythonCod ... manBlender
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Re: create poses using script

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

Weel, that lookis nice, I'm really new to python, so I'll try to figure out myself how to apply random transform on selected bones only (just name list for example), and dont store each pose in different file. All i want hbasicly is to random specific bones, make render, and repeat again) If toy can give me some tips I will defenetly apritiate it)

thx
ShatteredEssence
 
Posts: 13
Joined: Mon Jun 12, 2017 12:14 pm

Re: create poses using script

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

If I am understanding you correctly, I think you can use my code of generate_poses() method from generatePoses.py file with slight modifications.
dugarsumit
 
Posts: 10
Joined: Thu May 04, 2017 9:12 am

Next

Return to User contributions

Who is online

Users browsing this forum: No registered users and 1 guest