Pose module and Action.setActive problem, any workarounds?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
jsgreenawalt
Posts: 0
Joined: Sun Jan 08, 2006 6:27 am

Pose module and Action.setActive problem, any workarounds?

Post by jsgreenawalt »

Hello all. I've been working on converting the Torque exporter for blender to use the new pose module. The code is largely complete and working except for one little problem. Calling Action.setActive() to cycle through the available actions is corrupting the user count on the actions, causing permanent data loss. I've submitted a bug report for this issue here: http://projects.blender.org/tracker/ind ... 9&atid=125

Hopefully this will be resolved soon. I've tried everything I can think of but cannot seem to come up with a workaround that prevents the problem. Does anyone know of an alternative means to cycle through the actions? Or some way to prevent the actions from being destroyed by setActive()?

amoghvc
Posts: 0
Joined: Tue Feb 21, 2006 7:49 am
Contact:

Post by amoghvc »

Can I have a look at the code that you have written to cycle through the actions. I need a similar thing as well and I will certainly take a look into your code to see if I can come up with something.

jsgreenawalt
Posts: 0
Joined: Sun Jan 08, 2006 6:27 am

Post by jsgreenawalt »

I did come up with a workaround for this problem. It's pretty ugly, but it's the only solution I can see until the bug is fixed. I'll post a condensed version.

Note that this is copied and pasted together from several different functions, so there may be some bits missing. Think of it as pseudo-code ;)

Code: Select all

import Blender
from Blender import *

arm = Blender.Object.Get('Armature')
armData = arm.getData()


# cycle through each Blender action
for act in Blender.Armature.NLA.GetActions().values():
	# set the current action as active.
	act.setActive(arm)
	# Need to cycle through ALL bones and reset the transforms.
	# This has the same effect as clearing rotation, tranlation, and scale
	# by hand before playing the animation in Blender.
	tempPose = armOb.getPose()
	for bonename in armData.bones.keys():
		# reset the bone's transforms
		tempPose.bones[bonename].quat = bMath.Quaternion().identity()
		tempPose.bones[bonename].size = bMath.Vector(1.0, 1.0, 1.0)
		tempPose.bones[bonename].loc = bMath.Vector(0.0, 0.0, 0.0)
	# update the pose.
	tempPose.update()
	# Update the scene's state.
	scene.update(1)
	# now we cycle through each frame of the current action
	for frame in range(1, numFrames):
		# Set the current frame in blender
		context.currentFrame(frame)
		# Update the scene's state.
		scene.update(1)
		# now get the pose
		pose = arm.getPose()
		# Add code here to cycle through the pose bones 
		# and get what you need.
		

# Now for the workaround.  Before the script exits, we'll create our own action and set
# it active.  This will shield the user's actions from being destroyed by Blender.
act = None
try:
	# if fake action already exists reuse it.
	act = Blender.Armature.NLA.GetActions()["DTSEXPFAKEACT"]
except:
	# if it doesn't exist, create it.
	act = Blender.Armature.NLA.NewAction("DTSEXPFAKEACT")
act.setActive(arm)
You can download the full DTS exporter code here: http://projects.blender.org/frs/?group_id=95 (you'll want the "Torque DTS Exporter 0.91RC2" version under test builds). Most of the relevant code can be found in the DtsShape_Blender.py file.

amoghvc
Posts: 0
Joined: Tue Feb 21, 2006 7:49 am
Contact:

Post by amoghvc »

jsgreenawalt, thanks for posting that here. I can see some stuff i didn't know existed.

What I am trying to do is write a DirectX .X file exporter. I have come to the point where I need to get the Animation Action IPO for skinned exported to the file. I think your code snippet will be helpful to me.

If I have any questions, I hope I can bug you :P

Amogh
Last edited by amoghvc on Thu Feb 23, 2006 9:52 am, edited 1 time in total.

jsgreenawalt
Posts: 0
Joined: Sun Jan 08, 2006 6:27 am

Post by jsgreenawalt »

On a side note, it would be nice to have some way of determining through the API which action is linked with which objects. The Torque DTS exporter for blender supports the export of multiple armatures. Currenly I have to set each action active on every armature in order to be sure that I've covered all the bases. That causes the actions to become linked to every armature, but strangely enough, the user count for the actions does not increase. The behavior of Action.setActive() is truely bizzare.

amoghvc
Posts: 0
Joined: Tue Feb 21, 2006 7:49 am
Contact:

Post by amoghvc »

I agree and I was unable to find any documentation for the Action object. I looked hard. Maybe I didn't look hard enough ?

jsgreenawalt
Posts: 0
Joined: Sun Jan 08, 2006 6:27 am

Post by jsgreenawalt »

Look under the NLA module in the 2.41 docs: http://download.blender.org/documentati ... pi.tar.bz2. The Action object should be listed there.

amoghvc
Posts: 0
Joined: Tue Feb 21, 2006 7:49 am
Contact:

Post by amoghvc »

Pure Genius !! How can I pay homage to you ? :D

amoghvc
Posts: 0
Joined: Tue Feb 21, 2006 7:49 am
Contact:

Post by amoghvc »

jsgreenawalt, one more thing. If I have to go through the pose matrices for different poses, will adding "Blender.Set ('curframe', frameNumber)" to your code allow me to iterate through all the poses available at the different key frames ?

EDIT : Got the answer, My mistake . . . :oops:

LetterRip
Posts: 0
Joined: Thu Mar 25, 2004 7:03 am

Post by LetterRip »

Hi, did you post to the bug tracker? If not would be a good idea to do so, link to the bug tracker is on the left.

LetterRip

jsgreenawalt
Posts: 0
Joined: Sun Jan 08, 2006 6:27 am

Post by jsgreenawalt »

Yep, I linked to the bug report in the first post. As far as the user count not increasing, I didn't submit a bug report for that because it doesn't really seem to be causing any problems. it's just wierd ;) It might even be by design, since there isn't any way to tell which actions and armatures are already linked prior to calling setActive.

Post Reply