The following script records poses in the game engine when attached to an “always” Sensor on an armature with a timer property called “time”(it records on the current action so if you try it, create a new action). The script is, however, slow when recording for larger numbers of bones. Is there any way to speed up the script by changing something in the code?
import Blender
from Blender import *
from Blender.Object import Pose
contr = GameLogic.getCurrentController()
gameObj = contr.getOwner()
name = gameObj.getName()[2:]
frame = int(25*gameObj.time)
a=Armature.Get(name)
c=Object.Get(name).getPose()
for B in a.bones.keys():
c.bones[b].insertKey(Object.Get(name), frame, [Object.Pose.ROT,Object.Pose.LOC,Object.Pose.SIZE] )
It’s cool that you figured out how to access Pose bone stuff in the G.E.
I wonder if a “Python actuator” can be constructed to control bone rotations / translations ?
I increased the speed quite a bit by doing a couple of things :
Instead of recording every bone, I only recorded one (for testing purposes)
I moved some of the constants, like “25” to variables.
I also thought it might help if some of the “initialization” code (like “Armature.Get …Object.Get(name) …” were moved to an “init” script that ran only once at the beginning of the game … (I’m not sure how to set that up) … but I doubt that will make a big difference.
The big problem is that the sampling / recording is just not fast enough. Even when I only recorded one bone the playback of the recorded action didn’t work well.
I think a better solution (when using pre-recorded Armature actions), is to just have a script that records the time that an action is triggered, then a final “write results” script would be triggered to create NLA strips for the actions that were triggered.
Tried initializing it, and the success was mixed. However, I think I know what the problem is.
First, for some reason the keys are recorded to all bones, regardless of if the bones were deleted, however this is not the major problem.
The game engine seems to get slowed down over time as the script runs and the number of keys increase. I don’t know why this is, but I am sure it has something to do with the number of existing keys because once the game engine is started again after it slows down, it starts at the same speed, unless the key frames are deleted…
Would it be easier to record directly to IPOs? I won’t pretend to understand the difference (in terms of system resources used) between recording actions (keyframes) vs. recording to IPOs, but it seems like Blender is able to do IPO recording just fine, even for complex physics simulations.