[Robotics] Python control of armature in the GE
Benoit Bolsee
benoit.bolsee at online.be
Mon Sep 14 21:58:57 CEST 2009
You can read armatures (all poseChannel and bone fields that matters in
the GE) and you can write pose channels (only position/orientation
though).
The detailed documentation on this API in the BPY_GE directory that you
will find in the builds. Open the index.html in your browser and select
the BL_ArmatureObject, BL_ArmatureChannel, BL_ArmatureBone classes on
the left panel: you will find all the properties that you can read or
write in the GE.
Here is an example on how you can get access to the pose channels in a
Python controller in the GE:
cont = GameLogic.getCurrentController()
# get reference to armature object
arm = cont.owner
# list of pose channels for all bones
channels = arm.channels
# access by bone name
pose=channels['Bone']
# read current joint rotation
print (pose.joint_rotation)
# set joint rotation for next frame
pose.joint_rotation = [0.0, 0.0, 0.1]
# you can also set euler angle
# pose.euler_rotation = [x,y,z]
# you can get rest pose information from the bone
bone = pose.bone
# all properties are read-only
print (bone.bone.mat)
# make sure the pose gets updated on next graphic frame
arm.update()
The above code shows the path of references:
GameLogic.getCurrentController().owner.channels["<bone_name>"].<pose
properties>
GameLogic.getCurrentController().owner.channels["<bone_name>"].bone.<bon
e properties>
There is also a path for constraints:
GameLogic.getCurrentController().owner.constraints["<bone_name>:<constra
int_name>"].<constraint properties>
Thanks for confirming that the build works on a recent Ubuntu distro, I
have upgrade mine for a long time.
/benoit
-----Original Message-----
From: robotics-bounces at blender.org [mailto:robotics-bounces at blender.org]
On Behalf Of Florian Lier
Sent: lundi 14 septembre 2009 18:18
To: Blender and Robotics
Subject: Re: [Robotics] Python control of armature in the GE
Hey all,
for claryfication ... I can read write armatures in the GE now?!
This is what I understood from the last mails :)
My goal is to write a time triggered script which manipulates the
armature.
Benoit - if so, can you provide us with some sample code?
BTW: You build works fine on Ubuntu (32Bit) ) 9.04
Cheers, Florian
Benoit Bolsee wrote:
Blender 2.5 needs Python 3.1 indeed (at least the GE).
Regarding Blender module, yes it's gone, you need to switch to the new
RNA and operator API.
You have the documentation (still partial) here :
http://www.graphicall.org/ftp/ideasman42/html/bpy-module.html
The principle is that you get reference to the data block you want to
manipulate from the context
(http://www.graphicall.org/ftp/ideasman42/html/bpy.types.Context-class.h
tml): you start from the main and dig through it.
Afaik it's not available in the GE yet.
So in the GE you must stick with GE API only, which hasn't changed.
You will noticed that I implemented proxy classes in the GE to bone,
pose channel, and armatures. So you don't need bpy for that.
I hope this news are not too disappointing ;-)
Regards,
Benoit
-----Original Message-----
From: robotics-bounces at blender.org
[mailto:robotics-bounces at blender.org] On Behalf Of Markus Mehrwald
Sent: vendredi 11 septembre 2009 16:04
To: Blender and Robotics
Subject: Re: [Robotics] Python control of armature in the GE
Hi Benoit,
I figured out some other problems now. I got Blender to compile only
with Pyhton 3.1 but now I cannot use my scripts anymore with
the error:
Traceback (most recent call last):
File "Steuerung.py", line 4, in <module>
ImportError: No module named Blender
Do you know what this could be or is there already a
documentation for 2.5?
Thanks,
Markus
Benoit Bolsee schrieb:
I fixed CMake in the itasc branch. Sorry for the delay.
/benoit
-----Original Message-----
From: robotics-bounces at blender.org
[mailto:robotics-bounces at blender.org] On Behalf Of Markus Mehrwald
Sent: vendredi 11 septembre 2009 11:21
To: Blender and Robotics
Subject: Re: [Robotics] Python control of armature in the GE
Hi,
I just managed it to compile the branch with the ikplugin. For some
reasons I was not able to compile because of a few errors. I
think its
just some little changes in the CMake files. First of all the
BIK_api.h
was not found. I did it quick and dirty by copying the full
path in the
files where it is needed. The second thing was that obviously
the libs
bf_ikplugin and bf_ITASC are not in the list of libs to link
against. Maybe you did not update the CMakeList or was it a
problem of my computer?
Regards,
Markus
Benoit Bolsee schrieb:
Hi,
I have added support for controlling armatures through
Python in the
GE.
This is provided through the new proxy class
BL_ArmatureChannel that
corresponds to the pose channel structure. Most attributes match
directly the Blender bPoseChannel structure but I added a
'joint_rotation' attribute that gives direct access to
joint angles. You
can use this attribute to set the joint angles from
external data or
your own calculation and the armature will move according
to it. If the
armature is controlled by IK, you can read the joint angles
computed by
the algorithm. Full details is provided in the BPY documentation
included in the packages below. Download them if you want
to know more
about it.
Other fix in this build is correct matrix operation with
MathUtils:
http://lists.blender.org/pipermail/bf-blender-cvs/2009-Septemb
er/022245.html
For those who want to experiment, I made two builds on graphicall:
Linux:
http://graphicall.org/builds/builds/showbuild.>
php?action=show&id=1082
<http://graphicall.org/builds/builds/showbuild.php?action=show
&id=1082>
Windows:
http://graphicall.org/builds/builds/showbuild.>
php?action=show&id=1080
<http://graphicall.org/builds/builds/showbuild>
<http://graphicall.org/builds/builds/showbuild>
.php?action=show&id=1080
If your system is not in this list, you can check out the itasc
branch and compile. For those interested in the
implementation, look
at the BL_ArmatureChannel.cpp module in
source/gameengine/converter.
If
you
have some ideas to extend the API, you are welcome to make your own
additions and send me the diff, I will review and commit
them to SVN.
The itasc branch will be merged with 2.5 in the coming
days, it would
be
nice to get some feedback before I start the merge.
/benoit.
---------------------------------------------------------------------
-
--
_______________________________________________
Robotics mailing list
Robotics at blender.org
http://lists.blender.org/mailman/listinfo/robotics
_______________________________________________
Robotics mailing list
Robotics at blender.org
http://lists.blender.org/mailman/listinfo/robotics
_______________________________________________
Robotics mailing list
Robotics at blender.org
http://lists.blender.org/mailman/listinfo/robotics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/robotics/attachments/20090914/fd029fcc/attachment-0001.htm
More information about the Robotics
mailing list