def OnInit(self): """Load the image on initial load of the application""" print """Should see two geodesic spheres over black background Sphere to left should be lit with normal-per-face, giving each face a hard-line edge with adjacent faces. Sphere to the right should be lit with normal-per-vertex which should make the lines between faces fuzzier.""" points, indices = loadData(ICOSDATA) ## light = basenodes.PointLight( ## location = (2,10,10) ## ) self.sg = basenodes.sceneGraph( ## lights = [ ## light ## ], children=[ ## light, basenodes.Transform( translation=(-1.5, 0, 0), children=[ basenodes.Shape( appearance=basenodes.Appearance( material=basenodes.Material(diffuseColor=(1, 0, 0))), geometry=basenodes.IndexedFaceSet( coord=basenodes.Coordinate(point=points, ), coordIndex=indices, ), ), ], ), basenodes.Transform( translation=(1.5, 0, 0), children=[ basenodes.Shape( appearance=basenodes.Appearance( material=basenodes.Material(diffuseColor=(1, 0, 0))), geometry=basenodes.IndexedFaceSet( coord=basenodes.Coordinate(point=points, ), coordIndex=indices, creaseAngle=3.14, normalPerVertex=1, ), ), ], ), ])
def OnInit( self ): self.sg = basenodes.sceneGraph( children = [ basenodes.Transform( children = [ basenodes.Shape( geometry = basenodes.Box( size = (2,3,4), ), appearance=basenodes.Appearance( material = basenodes.Material( diffuseColor = (1,0,0), ), ), ), ], ), basenodes.PointLight( location=(5,6,5), ), ], ) self.time = Timer( duration = 32.0, repeating = 1 ) self.time.addEventHandler( "fraction", self.OnTimerFraction ) self.time.register (self) self.time.start () self.rotation = 0
def addTunnel(self): tunnel = basenodes.Transform(children=[ basenodes.Transform( translation=(30.0, 0.0, 2.0), rotation=(0.0, 0.0, 1.0, 90 / 180.0 * pi), children=[ basenodes.Shape( geometry=basenodes.Cylinder( height=30.0, radius=6.0, side=True, top=False, bottom=False, slices=24, stacks=24, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.5, 0.5, 0.5), transparency=0.2, ), ), ), ], ), ], ) self.sg.children.append(tunnel) self.sg.regDefName('Tunnel', tunnel)
def buildGeometry(): from OpenGLContext.scenegraph import basenodes return basenodes.sceneGraph( children = [ basenodes.Transform( translation = (3,0,0), children = [ basenodes.TouchSensor(), basenodes.Shape( geometry = basenodes.Sphere( radius = 2 ), appearance = basenodes.Appearance( material = basenodes.Material( diffuseColor = (0,1,1))), ), ], ), basenodes.Transform( translation = (-3,2,-1), children = [ basenodes.TouchSensor(), basenodes.Shape( geometry = basenodes.Sphere( radius = 1 ), appearance = basenodes.Appearance( material = basenodes.Material( diffuseColor = (1,1,0))), ), ], ), basenodes.Transform( translation = (0,-2,2), children = [ basenodes.TouchSensor(), basenodes.Shape( geometry = basenodes.Sphere( radius = .25 ), appearance = basenodes.Appearance( material = basenodes.Material( diffuseColor = (0,1,0))), ), ], ), ])
def OnInit(self): """Load the image on initial load of the application""" print("""Should see 6-sided polygon with normal-per-vertex smoothing This polygon is produced using the GLU tesselator from a simple linear progression of indices across the 6 points of the polygon.""") points, indices = loadData(TESTDATA) self.sg = basenodes.sceneGraph(children=[ basenodes.Transform(children=[ basenodes.Shape( appearance=basenodes.Appearance( material=basenodes.Material(diffuseColor=(1, 0, 0))), geometry=basenodes.IndexedFaceSet( coord=basenodes.Coordinate(point=points, ), coordIndex=indices, creaseAngle=3.14, normalPerVertex=1, ), ), ], ), ])
def buildGeometry( self ): """Create some named geometry for selection""" objects = [] while len(objects) < self.COUNT: p = random.random()*6-3, random.random()*6-3, random.random()*6-3 c = (1,1,1)#random.random(), random.random(), random.random() s = random.random()/2.0 t = basenodes.Transform( translation = p, children = [ basenodes.TouchSensor(), basenodes.Shape( geometry = basenodes.Sphere( radius = s ), appearance = basenodes.Appearance( material = basenodes.Material( diffuseColor = c), ), ), ], ) objects.append( t) self.objects.children = objects
def defaultMaterial( self ): return basenodes.Appearance( material = basenodes.Material( diffuseColor = [.9,.9,.9 ]), )
def addTrafficLight(self, e): # Traffic Light traffic = basenodes.Transform( children=[ # Foot basenodes.Transform( translation=(e.x, e.y, e.z + 1.5), rotation=(1.0, 0.0, 0.0, 90 / 180.0 * pi), children=[ basenodes.Shape( geometry=basenodes.Cylinder( height=3.5, radius=0.2, side=True, top=False, bottom=False, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.5, 0.5, 0.5), transparency=0.0, ), ), ), ], ), # Head basenodes.Transform( translation=(e.x, e.y, e.z + 4.0), children=[ basenodes.Shape( geometry=basenodes.Sphere(radius=0.75, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.0, 1.0, 0.0), emissiveColor=(0.0, 1.0, 0.0), ambientIntensity=0.5, transparency=0.25, ), ), ), ], ), # Light # basenodes.Transform( # children = [ # basenodes.SpotLight( # location= (8, -3, 4), # intensity = 1.0, # direction = (-1, -1, -1), # color = (0, 1, 0), # on = True, # ), # basenodes.PointLight( # location= (8, -3, 4), # intensity = 1.0, # color = (0, 1, 0), # on = True, # radius = 15 # ), # ], # ), ], ) self.sg.children.append(traffic) self.sg.regDefName(e.name, traffic)
def addCar(self, e): car = basenodes.Transform( children=[ # Car Body basenodes.Transform( translation=(-e.size.x / 2, -e.size.y / 2, -e.size.z / 2), children=[ basenodes.Shape( geometry=basenodes.Box(size=e.size, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.5, 0.0, 0.5), transparency=0.0, ), ), ), ], ), # Neighbours basenodes.Transform( translation=(-e.size.x / 2, -e.size.y / 2, -e.size.z / 2), children=[ basenodes.Shape( geometry=basenodes.Sphere( radius=e.d, slices=24, stacks=24, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.75, 1.0, 0.75), transparency=0.9, ), ), ), ], ), # View basenodes.Transform( translation=(-e.size.x / 2 + e.d / 2 * math.cos(e.a / 2 * (math.pi / 180)), -e.size.y / 2, -e.size.z / 2), rotation=(0.0, 0.0, 1.0, 90 / 180.0 * pi), children=[ basenodes.Shape( geometry=basenodes.Cone( bottomRadius=e.d * math.sin(e.a / 2 * (math.pi / 180)), height=e.d * math.cos(e.a / 2 * (math.pi / 180)), bottom=False, side=True, slices=24, stacks=24, ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.5, 1.0, 0.5), transparency=0.75, ), ), ), ], ), ], ) self.sg.children.append(car) self.sg.regDefName(e.name, car) car.translation = (e.x, e.y, e.z)
def OnInit(self): # draw the ground surface self.cars = 0 self.returnValues = None # for FullScreen self.sg = basenodes.sceneGraph( children=[ basenodes.Transform( translation=(0, 0, -1), children=[ # Ground basenodes.Shape( geometry=basenodes.Box(size=(100, 100, 1), ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.3, 0.3, 0.15), transparency=0.0, ), #texture = imagetexture.ImageTexture(url = ["traffic.png"]), ), ), # Road 1 basenodes.Transform( translation=(0, -2.5, 0), children=[ basenodes.Shape( geometry=basenodes.Box(size=(100, 2, 1.5), ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.6, 0.6, 0.3), transparency=0.0, ), ), ), ], ), # Road 2 basenodes.Transform( translation=(0, 2.5, 0), children=[ basenodes.Shape( geometry=basenodes.Box(size=(100, 2, 1.5), ), appearance=basenodes.Appearance( material=basenodes.Material( diffuseColor=(0.6, 0.6, 0.3), transparency=0.0, ), ), ), ], ), ], ), # Light basenodes.PointLight(location=(-25, -25, 25), ), basenodes.DirectionalLight( ambientIntensity=2.5, intensity=1.5, color=(1, 1, 1), direction=(1, 1, -1), ), ], ) self.sg.regDefName('Ground', self.sg.children[0]) self.sg.getDEF('Ground').translation = (0.0, 0.0, -1.0) self.addTunnel() # self.addTrafficLight() # self.addCar() self.time = Timer(duration=32.0, repeating=1) self.time.addEventHandler("fraction", self.OnTimerFraction) self.time.register(self) self.time.start() self.rotation = 0.0