12
$\begingroup$

I need to control an armature using Python so that I can animate a biped model using data from a text file. I've been using this tutorial and some other sources to try and do so, but I can never see any results in the rendered game window.

The code I have thus far is:

import GameLogic

arm = GameLogic.getCurrentController().owner

print(arm.channels['Upperleg.L'].rotation_euler)

arm.channels['Upperleg.L'].rotation_euler = [5, 5, 5]
arm.update()

print(arm.channels['Upperleg.L'].rotation_euler)

In the console, the values for BL_ArmatureChannel.rotation_euler are changing...

<Vector <0.0000, 0.0000, 0.0000>>
<Vector <5.0000, 5.0000, 5.0000>>

...but nothing is happening with the model linked to the armature (not visually at least). If I change BL_ArmatureChannel.rotation_euler to BL_ArmatureChannel.joint_rotation the values being printed in the console don't change at all.

On my armature, I have an "Always" sensor attached to a "Python" controller to execute the script. There are no IK constraints on the armature and no other sensors/controllers/actuators.

Any help on this matter would be greatly appreciated. I have a tight deadline on this project and I can't seem to get this very simple (but necessary) part of it working.

$\endgroup$

3 Answers 3

6
$\begingroup$

I'm afraid dynamically changing the mesh connected to the armature is not possible inside the Blender game engine without implementing it as a new feature in the source code.

All deformations of meshes must either be done vertex by vertex or through actions in the Dope sheet editor.

If you create action logic bricks that correspond to the limb movement you are trying to get to work, you should be able to get limited model deformation movements going. Changing an action actuator's start and end frames is possible when the game engine is running. This gives you some of the control you seek.

$\endgroup$
1
  • 1
    $\begingroup$ I see, thank you for letting me know. That makes sense now, all the tutorials/examples I've seen of BL_ArmatureChannel.joint_rotation() used robot models with non-deforming meshes. I've already switched this project over to Unity, which is capable of script-based mesh deformations via armature rotations, so I'll just stick with that. Thanks again. $\endgroup$ Commented Aug 17, 2013 at 18:41
5
$\begingroup$

I realize I'm a few months late but there are actually several ways to control a mesh deforming armature from within BGE without rewriting the source code. Here's probably the simplest method:

  1. Create an anchor object such as a cube. The size, shape, and location are unimportant.
  2. In pose mode, select the armature you want to use and add the bone constraint "copy rotation", then choose your anchor for the target.

The rest should be pretty self explanatory. As you rotate the anchor (using python or logic bricks) the armature mimics it and deforms the vertex group it's assigned to. If you're using this with something complex, like a humanoid model, then you'll probably want to use a script. If you're uncertain how to do this a good example is the "brik" ragdoll plugin. The source for brik will show you how to easily search for bones in any armature and automatically create, name and assign anchors in just a few lines of code.

$\endgroup$
4
$\begingroup$

I think you just forgot to set the mode as stated in the manual: bge.types.BL_ArmatureChannel

Excerpt: rotation_euler Note: This field is only used if rotation_mode is > 0.

This worked for me (v2.69):

tA.channels['middleBone'].rotation_mode = logic.ROT_MODE_XYZ
tA.channels['middleBone'].rotation_euler = ( 0.5, 0, 0 )
tA.update()
$\endgroup$
1
  • $\begingroup$ This worked for me too, though I have GameLogic.ROT_MODE_XYZ, I assume @user3054986 must have import GameLogic as logic. (I'm psyched I've been looking for this the last few days, thanks!) $\endgroup$ Commented May 19, 2014 at 6:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .