示例#1
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)
示例#2
0
 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,
                         ),
                     ),
                 ],
             ),
         ])
示例#3
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
示例#4
0
 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
示例#5
0
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,
                 ),
             ),
         ], ),
     ])
示例#7
0
 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 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
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
    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