PDA

View Full Version : animate cal3d bones


krimble
01-09-2008, 05:39 AM
Hi all,

What I have is a cal3d avatar with a peoplemaker morph (for a talking mouth).

The avatar has to perform an animation: lean forward - back the origin - lean backward back to origin - lean left - back to origin - lean right and back to origin.

The bone that I want to rotate is one of the spineBones.

This is the code-part where i'm talking about:

viz.starttimer(TIMER_BODY_MOVEMENT, .03, 1)

def onTimerEvent(id) :
if id == TIMER_BODY_MOVEMENT :
spine02.rotate(10,0,0)

viz.callback(viz.TIMER_EVENT,onTimerEvent)

What's happening now: the bone seems to snap to the new position, with <bone>.setEuler() it's doing the same.

How can I make this a smooth animation?

Thanks!

krimble
01-10-2008, 02:23 AM
Anybody?

Shorter question: How do I animate a cal3d bone. ( not the neckBone )?

Thanks!

farshizzo
01-10-2008, 03:20 PM
I've attached a sample script that creates a custom vizact action that animates a bone. The code at the bottom of the script shows how to use the action. This action will be included in the vizact library in the next release of Vizard. Let me know if anything is unclear.import viz
viz.go()

"""
Code for creating action that animates a bone rotating
"""

_paramval_ = vizact._paramval_
_paramlist_ = vizact._paramlist_
VizCubicQuatInterpolator = vizact.VizCubicQuatInterpolator
VizLinearQuatInterpolator = vizact.VizLinearQuatInterpolator

def boneSpinTo(bone,mode=viz.ABS_PARENT,quat=None,eule r=None,axisAngle=None,speed=None,time=None,p1=None ,p2=None):
bla = viz.ActionData()
bla.bone = bone
bla.mode = mode
bla.speed = speed
bla.time = time
bla.quat = quat
bla.euler = euler
bla.axisAngle = axisAngle
bla.p1 = p1
bla.p2 = p2
bla.actionclass = VizBoneSpintToAction
return bla

class VizBoneSpintToAction(viz.ActionClass):

def begin(self,object):

self.elapsed = 0.0
self.duration = 0.0

#If bone is not a Vizard bone object, assume it is string and get bone from name
bone = _paramval_(self._actiondata_.bone,object)
if isinstance(bone,viz.VizBone):
self.bone = bone
else:
self.bone = object.getBone(bone)

#Make sure bone is valid
if not self.bone:
self.end(object)
return

#Lock the bone for animating
self.bone.lock()

#Get coordinate frame mode for bone rotations
self.mode = _paramval_(self._actiondata_.mode,object)

#Get begin and end rotation
beginQuat = self.bone.getQuat(self.mode)

if self._actiondata_.quat is not None:
self.endQuat = _paramlist_(self._actiondata_.quat,object)
elif self._actiondata_.euler is not None:
self.endQuat = vizmat.EulerToQuat(_paramlist_(self._actiondata_.e uler,object))
elif self._actiondata_.axisAngle is not None:
self.endQuat = vizmat.AxisAngleToQuat(_paramlist_(self._actiondat a_.axisAngle,object))
else:
self.end(object)
return

#Compute whether animation duration is based on time or speed
speed = _paramval_(self._actiondata_.speed,object)
time = _paramval_(self._actiondata_.time,object)

if time is not None:
self.duration = time
elif speed is not None:
self.duration = vizmat.QuatDiff(beginQuat,self.endQuat) / speed

#Make sure duration is valid
if self.duration <= 0.0:
self.bone.setQuat(self.endQuat,self.mode)
self.end(object)
return

#Check if we are using linear or cubic interpolation
p1 = _paramlist_(self._actiondata_.p1,object)
p2 = _paramlist_(self._actiondata_.p2,object)
if p1[0] is not None and p2[0] is not None:
interpolator = VizCubicQuatInterpolator(p1[0],p2[0])
else:
interpolator = VizLinearQuatInterpolator()

interpolator.init(beginQuat,self.endQuat)
self.interpolate = interpolator.interpolate

def update(self,elapsed,object):

self.elapsed += elapsed
p = self.elapsed / self.duration
if p >= 1.0:
self._overtime_ = self.elapsed - self.duration
self.bone.setQuat(self.endQuat,self.mode)
self.end(object)
return

self.bone.setQuat(self.interpolate(p),self.mode)




model = viz.add('vcc_female.cfg',pos=(0,0,5),euler=(180,0, 0))

lookRight = boneSpinTo('Bip01 Spine1',mode=viz.AVATAR_LOCAL,euler=(45,0,0),speed =90)
lookLeft = boneSpinTo('Bip01 Spine1',mode=viz.AVATAR_LOCAL,euler=(-45,0,0),speed=90)

vizact.onkeydown(viz.KEY_RIGHT,model.runAction,loo kRight,pool=1)
vizact.onkeydown(viz.KEY_LEFT,model.runAction,look Left,pool=1)

krimble
01-11-2008, 04:31 AM
Thanks man!!!

I'll take a look at it as soon i've got the time.

Karla
05-07-2008, 07:51 AM
I noticed that for the Q1 2008 Release of Vizard, vizact.boneSpinTo() is listed as an addition.

vizact.boneSpinTo() action for animating avatar bones

I am running vizard_3.00.2701. I cannot find any additional information about vizact.boneSpinTo() in the Help Documentation.

Can someone please post an example of how to use vizact.boneSpinTo() without including the sample script as posted above? For now I'm using the sample script but more condensed code would be preferable.

Thanks!

~Karla

farshizzo
05-07-2008, 09:40 AM
Here is a short sample:lookLeft = vizact.boneSpinTo('Bip01 Head',mode=viz.AVATAR_LOCAL,euler=(-90,0,0),speed=90)

avatar.runAction(lookLeft)
And here is the documentation for the command:
<vizact>.boneSpinTo(
bone
mode = viz.ABS_PARENT
quat = None # Keyword argument
euler = None # Keyword argument
axisAngle = None # Keyword argument
speed = None # Keyword argument
time = None # Keyword argument
)



bone
An Avatar bone object or the name of a bone.

mode = viz.ABS_PARENT
The transformation mode to apply the rotations with

quat = None
The quaternion rotation to spin to

euler = None
The euler rotation to spin to

axisAngle = None
The Axis-Angle rotation to spin to

speed = None
The speed to spin at in degrees/sec

time = None
The amount of time to spin for

Karla
05-07-2008, 03:07 PM
Thank you!

I was working in a long file, which made troubleshooting more difficult than necessary. I made the following concise example and got it to work. With a more positive resolve, I was able to find my mistakes in the longer file. It's all working now.

Thanks,
Karla


#************************************************* *****************************************
#************************************************* *****************************************
#Trying to use boneSpinTo with avatar in Art Gallery
#Created: May 6th, 2008
#************************************************* *****************************************
#************************************************* *****************************************

import viz
import viztask #For wait time

viz.go()

viz.MainView.setPosition(0,1.72,7.5)
viz.MainView.setEuler(183,0,0)

#Add an avatar
male = viz.add('male.cfg'); male.translate(0.25,0,5.5); male.rotate(0,1,0,-3); male.state(1) #Start in neutral state animation
face1 = male.face('biohead_talk.vzf') #add a face to the avatar

#speed settings for boneSpinTo()
headSpeed = 100

def SpinHeadLeft():
yield viztask.waitTime(2) #Wait 2 seconds
lookleft = vizact.boneSpinTo('skel_Head',mode=viz.AVATAR_LOCA L,euler=(-90,0,0),speed=headSpeed)
male.runAction(lookleft)

viztask.schedule( SpinHeadLeft() )

#************************************************* **********
#Adding a world
#************************************************* **********
room = viz.add('gallery.ive') # Load
room.scale(1,1,1) # scale actual
room.translate(0,0,0) ## position in the world