View Single Post
  #13  
Old 09-19-2018, 03:10 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The following code works for me. The appearance of the cylinder parts do not change when the ground is faded. I had an issue with the alpha that was fixed after updating my nvidia graphics drivers.

Code:
import viz, vizshape, vizact
import random

viz.setMultiSample(4)
viz.go()

world = viz.addChild('ground.osgb')

light = viz.addLight()
light.setEuler(0,45,0)

# create spot
spot_elevation = .05
spot_height = 2.5
spot_nslices = 4	#originally 100
spot_slice_height = spot_height / spot_nslices
alpha_start = 0.5
alpha_end = 0.0
alpha_step = (alpha_end - alpha_start)/spot_nslices
print alpha_step
spot = []

for a in range(spot_nslices):
	cyl = vizshape.addCylinder(height=spot_slice_height, radius=0.30, color=viz.YELLOW, top=None)	
	print a*alpha_step
	cyl.alpha( alpha_start + a*alpha_step )
	cyl.enable(viz.SAMPLE_ALPHA_TO_COVERAGE)
	cyl.disable(viz.BLEND)
	spot_yPos = spot_slice_height/2 + spot_elevation + a*spot_slice_height
	cyl.setPosition([0,spot_yPos,10])
	spot.append(cyl)

# rotate ground
def random_rotate(object_to_rotate, duration):

        rotate_val = random.randint(1, 360)

        spinto = vizact.spinTo(euler=(rotate_val, 0, 0), time=0, mode=viz.REL_GLOBAL)
        fadeout = vizact.fadeTo(0, time=duration)
        fadein = vizact.fadeTo(1, time=duration)

        rotate_action = vizact.sequence(fadeout, spinto, fadein)
        object_to_rotate.addAction(rotate_action)

vizact.onkeydown('r', random_rotate, world, 1)


import vizcam
cam = vizcam.PivotNavigate(center=[0,0,10],distance = 7)
cam.rotateUp(30)
Reply With Quote