View Single Post
  #5  
Old 08-31-2006, 12:22 PM
Elizabeth S Elizabeth S is offline
Member
 
Join Date: Aug 2006
Posts: 11
Re: Models not showing up

Thanks for all your responses.
When I initially had the wheels as children of the car body, I could not get them to spin around the right pivot point. This is the reason I import them separately into my Vizard script. Is there a way to easily fix this problem.
Also, here is a trimmed-down script that I'm running....sorry for the length.

import viz
import math

viz.go()

def playAnimations():

#Add car and its wheels
Car = viz.add('Car.obj')
Car.scale(0.305,0.305,0.305)
Car.visible(viz.OFF)
CarwheelRF = viz.add('Carwheel2.obj')
CarwheelRF.scale(0.305,0.305,0.305)
CarwheelRF.translate(-0.92,0.35,1.09)
CarwheelRF.visible(viz.OFF)
CarwheelLF = viz.add('Carwheel2.obj')
CarwheelLF.scale(0.305,0.305,0.305)
CarwheelLF.translate(-2.379,0.35,1.09)
CarwheelLF.rotate(0,-1,0,180)
CarwheelLF.visible(viz.OFF)
CarwheelRB = viz.add('Carwheel2.obj')
CarwheelRB.scale(0.305,0.305,0.305)
CarwheelRB.translate(-0.92,0.35,3.45)
CarwheelRB.visible(viz.OFF)
CarwheelLB = viz.add('Carwheel2.obj')
CarwheelLB.scale(0.305,0.305,0.305)
CarwheelLB.translate(-2.379,0.35,3.45)
CarwheelLB.rotate(0,-1,0,180)
CarwheelLB.visible(viz.OFF)

#Initialize animation paths
CarpathBody = viz.add(viz.ANIMATION_PATH)
CarpathRWF = viz.add(viz.ANIMATION_PATH)
CarpathLWF = viz.add(viz.ANIMATION_PATH)
CarpathRWB = viz.add(viz.ANIMATION_PATH)
CarpathLWB = viz.add(viz.ANIMATION_PATH)
Paths = [CarpathBody,CarpathRWF,CarpathLWF,CarpathRWB,Carpa thLWB]

#Initializing velocity and ttc arrays and using them to find distances
velocity = [10,15,20,25,30]
ttc = [2,2.25,2.5,2.75,3,3.25,3.5,3.75,4,4.25,4.5,4.75,5, 5.25,5.5,5.75,6,6.25,6.5,
6.75,7,7.25,7.5,7.75,8,8.25,8.5,8.75,9,9.25,9.5,9. 75,10]
ttc1 = 5
velocity1 = 4
distance = velocity[velocity1-1]*ttc[ttc1-1]*0.44704
distance2 = 0

#Setting positions of car and its wheels for the animation paths -
#Alternating starting and ending distances for each model in this order:
#Car body, Right wheel front, Left wheel front, Right wheel back,
#Left wheel back
Positions = [ [0,0,distance],[0,0,distance2],
[-0.92,0.35,1.09+distance],[-0.92,0.35,1.09+distance2],
[-2.379,0.35,1.09+distance],[-2.379,0.35,1.09+distance2],
[-0.92,0.35,3.45+distance], [-0.92,0.35,3.45+distance2],
[-2.379,0.35,3.45+distance],[-2.379,0.35,3.45+distance2] ]

#Add the control points to the animation path
for x in range(0,len(Paths)):
cp = viz.add(viz.CONTROL_POINT)
cp.translate(Positions[2*x])
Paths[x].add(cp,0)
cp2 = viz.add(viz.CONTROL_POINT)
cp2.translate(Positions[2*x+1])
Paths[x].add(cp2,ttc[ttc1])

#Set the wheels spinning
Carrotations = (distance - distance2)/2.011
Carfullrotations = math.floor(Carrotations)
Cardegreesrotations = Carfullrotations*360 + (Carrotations - Carfullrotations)*360
Carrotatespeed = Cardegreesrotations/ttc1
CarwheelRF.spin(1,0,0,-Carrotatespeed)
CarwheelLF.spin(1,0,0,Carrotatespeed)
CarwheelRB.spin(1,0,0,-Carrotatespeed)
CarwheelLB.spin(1,0,0,Carrotatespeed)

#Link the car and its wheels to the path; play the paths
Car.link(Paths[0])
CarwheelRF.link(Paths[1])
CarwheelLF.link(Paths[2])
CarwheelRB.link(Paths[3])
CarwheelLB.link(Paths[4])
Car.visible(viz.ON)
CarwheelRF.visible(viz.ON)
CarwheelLF.visible(viz.ON)
CarwheelRB.visible(viz.ON)
CarwheelLB.visible(viz.ON)
Paths[0].play()
Paths[1].play()
Paths[2].play()
Paths[3].play()
Paths[4].play()
Paths[0].loop(viz.LOOP)
Paths[1].loop(viz.LOOP)
Paths[2].loop(viz.LOOP)
Paths[3].loop(viz.LOOP)
Paths[4].loop(viz.LOOP)

def mykeyboard(whichKey):
#to quit the script
if whichKey == viz.KEY_ESCAPE:
print 'Esc key pressed'
viz.quit();
#to play the set of animations
elif whichKey == viz.KEY_RETURN:
playAnimations();
#otherwise do nothing
else:
print 'Incorrect key pressed'


viz.callback(viz.KEYDOWN_EVENT, mykeyboard)
Reply With Quote