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 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 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 OnInit( self ): self.text = basenodes.Text( ) self.sg = basenodes.sceneGraph( children = [ basenodes.Transform( scale = (.5,.5,.5), translation = (-3,0,0), children = [ basenodes.Shape( geometry = self.text, ), ], ) ], ) self.strings = [] self.strings.append( 'Integers/Booleans:' ) for name, argument, description in booleanarguments: # really should make "glGet" an alias so this doesn't look so weird... result = glGetIntegerv( argument ) self.strings.append( ' %s -> %s' % (name, result ) ) self.strings.append( 'Doubles/Floats:' ) for name, argument, description in doublearguments: result1,result2 = glGetDoublev( argument ), glGetFloatv( argument ) self.strings.append( ' %s -> %s' % (name, result1 ) ) self.strings.append( 'Strings:' ) for name, argument, description in stringarguments: # really should make "glGet" an alias so this doesn't look so weird... result = glGetString( argument ) self.strings.append( ' %s -> %s' % (name, result ) ) self.strings.append( 'Extensions:' ) for extension in glGetString( GL_EXTENSIONS).split(): self.strings.append( ' %s'%( extension ) ) self.text.string = self.strings
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): """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 ): """Setup callbacks and build geometry for rendering""" self.addEventHandler( "mousebutton", button = 0, state = 1, function = self.OnClick1 ) print """Click on the spheres and watch here for feedback...""" self.objects = basenodes.sceneGraph() self.buildGeometry() self.addEventHandler( "mousebutton", button = 0, state = 1, node = self.objects.children[-1].children[-1], function = self.OnClick2, ) r = threading.Thread( target = self.randomiser ) r.setDaemon(1) r.start()
def OnInit(self): """Setup callbacks and build geometry for rendering""" self.addEventHandler("mousebutton", button=0, state=1, function=self.OnClick1) print("""Click on the spheres and watch here for feedback...""") self.objects = basenodes.sceneGraph() self.buildGeometry() self.addEventHandler( "mousebutton", button=0, state=1, node=self.objects.children[-1].children[-1], function=self.OnClick2, ) r = threading.Thread(target=self.randomiser) r.setDaemon(1) r.start()
def OnInit( self ): """Setup callbacks and build geometry for rendering""" self.addEventHandler( "mousebutton", button = 0, state = 1, function = self.OnClick1 ) print("""Click on the spheres and watch here for feedback...""") self.objects = basenodes.sceneGraph() self.buildGeometry() table = {} setattr( self.objects.children[-1], ' eventHandlers', table ) self.objects.children[-1].children[ -1 ].appearance.material.diffuseColor = (1,0,0) self.addEventHandler( "mousebutton", button = 0, state = 1, #name = id(self.objects.children[-1]), node = self.objects.children[-1].children[-1], function = self.OnClick2, )
def OnInit( self ): """Setup callbacks and build geometry for rendering""" self.addEventHandler( "mousebutton", button = 0, state = 1, function = self.OnClick1 ) print """Click on the spheres and watch here for feedback...""" self.objects = basenodes.sceneGraph() self.buildGeometry() table = {} setattr( self.objects.children[-1], ' eventHandlers', table ) self.objects.children[-1].children[ -1 ].appearance.material.diffuseColor = (1,0,0) self.addEventHandler( "mousebutton", button = 0, state = 1, #name = id(self.objects.children[-1]), node = self.objects.children[-1].children[-1], function = self.OnClick2, )
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(): 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 parse( self, data, baseURL, *args, **named ): """Parse the loaded data (with the provided meta-information) This implementation simply creates VRML97 scenegraph nodes out of the .obj format data. """ sg = basenodes.sceneGraph( ) # these three are shared among all shapes hash = md5( baseURL ).hexdigest() coord = basenodes.Coordinate( DEF='Coord-%s'%(hash,) ) normal = basenodes.Normal(DEF='Norm-%s'%(hash,)) texCoord = basenodes.TextureCoordinate(DEF='TexCoord-%s'%(hash,)) mesh = None # transforms group = None # shape material = None # appearance, material, texture materials = {} # indices are 1-based, the first values are never used... vertices = [[0., 0., 0.]] normals = [[0., 0., 0.]] tex_coords = [[0., 0.]] current_vertex_indices = [] current_normal_indices = [] current_texcoord_indices = [] for line in data.splitlines(): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': vertices.append(map(float, values[1:4])) elif values[0] == 'vn': normals.append(map(float, values[1:4])) elif values[0] == 'vt': tex_coords.append(map(float, values[1:3])) elif values[0] == 'mtllib': self.load_material_library(values[1], materials, baseURL) elif values[0] in ('usemtl', 'usemat'): material = materials.get(values[1], None) if material is None: log.warn('Unknown material: %s', values[1]) material = self.defaultMaterial() if mesh is not None: if group and current_vertex_indices: group.geometry.coordIndex = current_vertex_indices group.geometry.texCoordIndex = current_texcoord_indices group.geometry.normalIndex = current_normal_indices current_vertex_indices = [] current_texcoord_indices = [] current_normal_indices = [] group = basenodes.Shape( geometry = basenodes.IndexedFaceSet( coord = coord, normal = normal, texCoord = texCoord, solid=False, ), appearance = material, ) mesh.children.append(group) elif values[0] == 'o': mesh = basenodes.Transform( DEF = values[1] ) sg.children.append( mesh ) sg.regDefName( values[1], mesh ) # previous shape is no longer current... group = None elif values[0] == 's': # a smoothing-group definition... # not currently supported... pass elif values[0] == 'f': # adds a single face if mesh is None: # anonymous transform mesh = basenodes.Transform() sg.children.append(mesh) if material is None: material = self.defaultMaterial() if group is None: group = basenodes.Shape( geometry = basenodes.IndexedFaceSet( coord = coord, normal = normal, texCoord = texCoord, solid=False, ), appearance = material, ) mesh.children.append(group) for i, v in enumerate(values[1:]): v_index, t_index, n_index = self._cleanIndex( v ) current_vertex_indices.append( v_index ) current_texcoord_indices.append( t_index ) current_normal_indices.append( n_index ) current_vertex_indices.append( -1 ) current_texcoord_indices.append( -1 ) current_normal_indices.append( -1 ) else: log.warn( """Unrecognized operation: %r""", values ) if group and current_vertex_indices: group.geometry.coordIndex = current_vertex_indices group.geometry.texCoordIndex = current_texcoord_indices group.geometry.normalIndex = current_normal_indices coord.point = vertices normal.normal = normals texCoord.texCoord = tex_coords return True,sg
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
def parse( self, data, baseURL, *args, **named ): """Parse the loaded data (with the provided meta-information) This implementation simply creates VRML97 scenegraph nodes out of the .obj format data. """ sg = basenodes.sceneGraph( ) # these three are shared among all shapes hash = md5( baseURL ).hexdigest() coord = basenodes.Coordinate( DEF='Coord-%s'%(hash,) ) normal = basenodes.Normal(DEF='Norm-%s'%(hash,)) texCoord = basenodes.TextureCoordinate(DEF='TexCoord-%s'%(hash,)) mesh = None # transforms group = None # shape material = None # appearance, material, texture materials = {} # indices are 1-based, the first values are never used... vertices = [[0., 0., 0.]] normals = [[0., 0., 0.]] tex_coords = [[0., 0.]] current_vertex_indices = [] current_normal_indices = [] current_texcoord_indices = [] for line in data.splitlines(): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': vertices.append(map(float, values[1:4])) elif values[0] == 'vn': normals.append(map(float, values[1:4])) elif values[0] == 'vt': tex_coords.append(map(float, values[1:3])) elif values[0] == 'mtllib': self.load_material_library(values[1], materials, baseURL) elif values[0] in ('usemtl', 'usemat'): material = materials.get(values[1], None) if material is None: log.warn('Unknown material: %s', values[1]) material = self.defaultMaterial() if mesh is not None: if group and current_vertex_indices: group.geometry.coordIndex = current_vertex_indices group.geometry.texCoordIndex = current_texcoord_indices group.geometry.normalIndex = current_normal_indices current_vertex_indices = [] current_texcoord_indices = [] current_normal_indices = [] group = basenodes.Shape( geometry = basenodes.IndexedFaceSet( coord = coord, normal = normal, texCoord = texCoord, solid=False, ), appearance = material, ) mesh.children.append(group) elif values[0] == 'o': mesh = basenodes.Transform( DEF = values[1] ) sg.children.append( mesh ) sg.regDefName( values[1], mesh ) # previous shape is no longer current... group = None elif values[0] == 's': # a smoothing-group definition... # not currently supported... pass elif values[0] == 'f': # adds a single face if mesh is None: # anonymous transform mesh = basenodes.Transform() sg.children.append(mesh) if material is None: material = self.defaultMaterial() if group is None: group = basenodes.Shape( geometry = basenodes.IndexedFaceSet( coord = coord, normal = normal, texCoord = texCoord, solid=False, ), appearance = material, ) mesh.children.append(group) for i, v in enumerate(values[1:]): v_index, t_index, n_index = self._cleanIndex( v ) current_vertex_indices.append( v_index ) current_texcoord_indices.append( t_index ) current_normal_indices.append( n_index ) current_vertex_indices.append( -1 ) current_texcoord_indices.append( -1 ) current_normal_indices.append( -1 ) else: log.warn( """Unrecognized operation: %r""", values ) if group and current_vertex_indices: group.geometry.coordIndex = current_vertex_indices group.geometry.texCoordIndex = current_texcoord_indices group.geometry.normalIndex = current_normal_indices coord.point = vertices normal.normal = normals texCoord.texCoord = tex_coords return True,sg