View Single Post
  #6  
Old 02-13-2009, 11:32 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
When you specify a center, it will be set in the nodes local coordinate system. You will need to convert the pivot point from the models coordinate frame to the muscles local coordinate frame before setting the center. Here is a sample script that shows how to accomplish this:
Code:
import viz
viz.go()

#Add model
model = viz.add('all_centered.lwo')
bb = model.getBoundingSphere()

#Add environment
import vizshape
vizshape.addGrid(color=[0.2]*3)
viz.clearcolor(viz.GRAY)

#Setup camera navigation
import vizcam
cam = vizcam.PivotNavigate()
cam.setCenter(bb.center)
cam.setDistance(bb.radius*2)

#Rotation pivot point in models reference frame
PIVOT = [.0695,.0346,.7674]

#Display rotation pivot point as a green ball
anchor = vizshape.addSphere(radius=0.1,parent=model,color=viz.GREEN,pos=PIVOT)

#Get handle to muscle
muscle = model.getChild('005')

#Convert pivot point from model coordinate frame to local coordinate frame of muscle
localMatrix = muscle.getMatrix(viz.ABS_GLOBAL) * model.getMatrix(viz.ABS_GLOBAL).inverse()
muscle.setCenter(localMatrix * viz.Vector(PIVOT))

#Spin muscle
muscle.addAction(vizact.spin(1,0,0,90,viz.FOREVER))
Reply With Quote