View Single Post
  #3  
Old 11-11-2015, 07:38 AM
vserchi vserchi is offline
Member
 
Join Date: Sep 2013
Posts: 7
Sorry my bad. Here is the simplest example I could think about. Even if I am interested only in the motion of the quads, I added also balls to show that my elements superimpose. When I attach a texture to the quads and they superimpose, the resulting effect is a flashing of the overlaid part. Do you have any suggestion?

Code:
import viz
import vizinfo
import vizact

viz.setMultiSample(4)
viz.fov(60)
viz.go()

#Add the ground plane
ground = viz.addChild('ground.osgb')

#Move the viewpoint back
viz.MainView.move([ 0, 0, -4])

#Initialize an array of control points
positions = [[ 2, 0, 0], [ 1, 0, 0], [ 0, 0, 0], [ -1, 0, 0], [ -2, 0, 0], [ -3, 0, 0], [ -4, 0, 0]]

#Define a variable to store the animation paths relative to each element
PATH = []

for i in range(0, len(positions)):	
	viz.startlayer(viz.QUADS) 
	viz.texCoord( 0, 1)
	viz.vertex(  -0.5, .005, -0.5)
	viz.texCoord( 1, 1)
	viz.vertex(  -0.5, .005, 0.5)
	viz.texCoord( 1, 0)
	viz.vertex(  0.5, .005, 0.5)
	viz.texCoord( 0, 0)
	viz.vertex(0.5, .005, -0.5)
	
	quad = viz.endLayer()
	ball= viz.addChild("beachball.osgb")
	
	exec('path' + str(i) + ' = viz.addAnimationPath()')
	PATH.append(eval('path' + str(i)))
	
	for x, pos in enumerate(positions):
		#Add a ball at each control point and make it
		#semi-transparent, so the user can see where the
		#control points are
		b = viz.addChild('beachball.osgb',cache=viz.CACHE_CLONE)
		b.setPosition(pos)
		b.alpha(0.2)
		
		PATH[i].addControlPoint( x + 1, pos = pos)
	
	#Set the initial loop mode to circular
	PATH[i].setLoopMode(viz.ON)
	
	# Add a control point at the second control point of path-i
	PATH[i].addEventAtControlPoint("positions", 1)
	
	# Link the ball  and the quad to the path
	viz.link( PATH[i], ball)
	viz.link( PATH[i], quad)
	
index = 1
def onPointReached1():
	# Trigger the start of the following animation path
	global index
	
	if index < len(PATH):
		PATH[index].play()

	index += 1
	
# Setup callbacks for each animation path
for i in range( 0, len(PATH) - 1):
	vizact.onPathEvent( PATH[i], "positions", onPointReached1)

#Play the first animation path
PATH[0].play()

#Setup path control panel
controlPanel = vizinfo.InfoPanel(text = None, title = 'Settings', icon = False)
slider_speed = controlPanel.addLabelItem('Speed', viz.addSlider())
slider_speed.set(0.1)

def changeSpeed(pos):
	#Adjust the speed of the animation path
	for i in range(0, len(PATH)):
		PATH[i].setSpeed( pos * 10 )

#Setup callbacks for slider events
vizact.onslider(slider_speed, changeSpeed)
Reply With Quote