Ejemplo n.º 1
1
	def circle (self, radius, axis, offset):	
		
		# since we're doing line segments, just vertices in our geom 
		format = GeomVertexFormat.getV3() 
		
		# build our data structure and get a handle to the vertex column 
		vdata = GeomVertexData ('', format, Geom.UHStatic) 
		vertices = GeomVertexWriter (vdata, 'vertex') 
				
		# build a linestrip vertex buffer 
		lines = GeomLinestrips (Geom.UHStatic) 
		
		for i in range (0, self.subdiv): 
			angle = i / float(self.subdiv) * 2.0 * math.pi 
			ca = math.cos (angle) 
			sa = math.sin (angle) 
			if axis == "x": 
				vertices.addData3f (0, radius * ca, radius * sa + offset) 
			if axis == "y": 
				vertices.addData3f (radius * ca, 0, radius * sa + offset) 
			if axis == "z": 
				vertices.addData3f (radius * ca, radius * sa, offset) 
		
		for i in range (1, self.subdiv): 
			lines.addVertices(i - 1, i) 
		lines.addVertices (self.subdiv - 1, 0) 
			
		lines.closePrimitive() 
		
		geom = Geom (vdata) 
		geom.addPrimitive (lines) 
		# Add our primitive to the geomnode 
		self.gnode.addGeom (geom) 
Ejemplo n.º 2
0
    def get_format():
        if SimpleTree.geom_vertex_format is None:
            format_array = GeomVertexArrayFormat()
            format_array.addColumn(InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther)
            format = GeomVertexFormat(GeomVertexFormat.getV3n3cpt2())
            format.addArray(format_array)
            SimpleTree.geom_vertex_format = GeomVertexFormat.registerFormat(format)

        return SimpleTree.geom_vertex_format
def create_hexagon(radius):
    """ Creates a hexagon shape that is centered at (0,0,0) with the corners having a distance of radius to the center and
    the normals pointing in direction (0,-1,0). 
    Returns the tuple (PandaNode, GeomVertexData). """
    format = GeomVertexFormat.getV3n3c4t2()
    vdata=GeomVertexData('hexagon', format, Geom.UHStatic)
    vertex=GeomVertexWriter(vdata, 'vertex')
    normal=GeomVertexWriter(vdata, 'normal')
    # create the vertices
    vertex.addData3f(0,0,0)
    normal.addData3f(0,-1,0)
    # add the other vertices
    for phi in range(0,360,60):
        # right-hand-rule (with middle finger pointing upwards): the y-axis points towards the screen,
        # therefore the hexagon will be created in the x,z plane, with x-axis pointing to the right
        # and the z-axis pointing up
        # get the next vertex coordinates by rotating the point (0,0,radius) in the x,z plane
        x,z = rotate_phi_degrees_counter_clockwise(phi, (0,radius))
        #print (x,z)
        vertex.addData3f(x,0,z) 
        normal.addData3f(0,-1,0) # the normal vector points away from the screen
    # add the vertices to a geometry primitives
    prim = GeomTrifans(Geom.UHStatic)
    for i in range(7):
        prim.addVertex(i)
    prim.addVertex(1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    hex_node = GeomNode('')
    hex_node.addGeom(geom)
    return hex_node, vdata
Ejemplo n.º 4
0
    def drawCircle(self, radius, axis, offset):

        # since we're doing line segments, just vertices in our geom
        format = GeomVertexFormat.getV3()

        # build our data structure and get a handle to the vertex column
        vdata = GeomVertexData('', format, Geom.UHStatic)
        vertices = GeomVertexWriter(vdata, 'vertex')

        # build a linestrip vertex buffer
        lines = GeomLinestrips(Geom.UHStatic)

        for i in range(0, self.subdiv):
            angle = i / float(self.subdiv) * 2.0 * math.pi
            ca = math.cos(angle)
            sa = math.sin(angle)
            if axis == "x":
                vertices.addData3f(0, radius * ca, radius * sa + offset)
            if axis == "y":
                vertices.addData3f(radius * ca, 0, radius * sa + offset)
            if axis == "z":
                vertices.addData3f(radius * ca, radius * sa, offset)

        for i in range(1, self.subdiv):
            lines.addVertices(i - 1, i)
        lines.addVertices(self.subdiv - 1, 0)

        lines.closePrimitive()

        geom = Geom(vdata)
        geom.addPrimitive(lines)
        # Add our primitive to the geomnode
        self.gnode.addGeom(geom)
Ejemplo n.º 5
0
	def __init__(self, parent, point, coords):
		self.parent = parent
		self.format = GeomVertexFormat.getV3c4()
		self.point = point
		self.coords = coords
		self.node_path = None
		self.init_node_path()
Ejemplo n.º 6
0
    def __init__(self, width=1, depth=1, height=1, origin=Point3(0, 0, 0)):

        # Create vetex data format
        gvf = GeomVertexFormat.getV3n3()
        gvd = GeomVertexData("vertexData", gvf, Geom.UHStatic)

        # Create vetex writers for each type of data we are going to store
        gvwV = GeomVertexWriter(gvd, "vertex")
        gvwN = GeomVertexWriter(gvd, "normal")

        # Write out all points
        for p in GetPointsForBox(width, depth, height):
            gvwV.addData3f(Point3(p) - origin)

        # Write out all the normals
        for n in ((-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)):
            for i in range(4):
                gvwN.addData3f(n)

        geom = Geom(gvd)
        for i in range(0, gvwV.getWriteRow(), 4):

            # Create and add both triangles
            geom.addPrimitive(GetGeomTriangle(i, i + 1, i + 2))
            geom.addPrimitive(GetGeomTriangle(i, i + 2, i + 3))

        # Init the node path, wrapping the box
        geomNode = GeomNode("box")
        geomNode.addGeom(geom)
        NodePath.__init__(self, geomNode)
Ejemplo n.º 7
0
    def generate(self):
        format = GeomVertexFormat.getV3()
        data = GeomVertexData("Data", format, Geom.UHStatic)
        vertices = GeomVertexWriter(data, "vertex")

        vertices.addData3f(-self.w, -self.h, -self.d)
        vertices.addData3f(+self.w, -self.h, -self.d)
        vertices.addData3f(-self.w, +self.h, -self.d)
        vertices.addData3f(+self.w, +self.h, -self.d)
        vertices.addData3f(-self.w, -self.h, +self.d)
        vertices.addData3f(+self.w, -self.h, +self.d)
        vertices.addData3f(-self.w, +self.h, +self.d)
        vertices.addData3f(+self.w, +self.h, +self.d)

        triangles = GeomTriangles(Geom.UHStatic)

        def addQuad(v0, v1, v2, v3):
            triangles.addVertices(v0, v1, v2)
            triangles.addVertices(v0, v2, v3)
            triangles.closePrimitive()

        addQuad(4, 5, 7, 6)  # Z+
        addQuad(0, 2, 3, 1)  # Z-
        addQuad(3, 7, 5, 1)  # X+
        addQuad(4, 6, 2, 0)  # X-
        addQuad(2, 6, 7, 3)  # Y+
        addQuad(0, 1, 5, 4)  # Y+

        geom = Geom(data)
        geom.addPrimitive(triangles)

        node = GeomNode("BoxMaker")
        node.addGeom(geom)

        return NodePath(node)
Ejemplo n.º 8
0
def create_side(x_z_top_left, x_z_bottom_right, static=True):
    x1, z1 = x_z_top_left
    x2, z2 = x_z_bottom_right
    format = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('', format, Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1) # top left
    vertex.addData3f(x2, 0, z1) # top right
    vertex.addData3f(x2, 0, z2) # bottom right
    vertex.addData3f(x1, 0, z2) # bottom left
    for _i in range(4):
        normal.addData3f(0, - 1, 0)
    if static:
        prim_hint = Geom.UHStatic
    else:
        prim_hint = Geom.UHDynamic
    prim = GeomTristrips(prim_hint)
    prim.addVertices(1, 0, 2, 3)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return (node, vdata)
def create_side(x_z_top_left, x_z_bottom_right, static=True):
    x1, z1 = x_z_top_left
    x2, z2 = x_z_bottom_right
    format = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('', format, Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1) # top left
    vertex.addData3f(x2, 0, z1) # top right
    vertex.addData3f(x2, 0, z2) # bottom right
    vertex.addData3f(x1, 0, z2) # bottom left
    for _i in range(4):
        normal.addData3f(0, - 1, 0)
    if static:
        prim_hint = Geom.UHStatic
    else:
        prim_hint = Geom.UHDynamic
    prim = GeomTristrips(prim_hint)
    prim.addVertices(1, 0, 2, 3)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return (node, vdata)
Ejemplo n.º 10
0
	def __init__(self, parent):
		self.parent = parent
		self.format = GeomVertexFormat.getV3c4()
		self.node_path = None
		self.node_path_line = None
		self.color = None
		self.direction = None
Ejemplo n.º 11
0
 def draw(self):
     format=GeomVertexFormat.getV3n3cpt2()
     vdata=GeomVertexData('square', format, Geom.UHDynamic)
     vertex=GeomVertexWriter(vdata, 'vertex')
     normal=GeomVertexWriter(vdata, 'normal')
     color=GeomVertexWriter(vdata, 'color')
     circle=Geom(vdata)
     # Create vertices
     vertex.addData3f(self.pos)
     color.addData4f(self.color)
     for v in range(self._EDGES):
         x = self.pos.getX() + (self.size * math.cos((2*math.pi/self._EDGES)*v))
         y = self.pos.getY() + (self.size * math.sin((2*math.pi/self._EDGES)*v))
         z = self.pos.getZ()
         vertex.addData3f(x, y, z)
         color.addData4f(self.color)
     
     # Create triangles
     for t in range(self._EDGES):
         tri = GeomTriangles(Geom.UHDynamic)
         tri.addVertex(0)
         tri.addVertex(t+1)
         if (t+2) > self._EDGES:
             tri.addVertex(1)
         else:
             tri.addVertex(t+2)
         tri.closePrimitive()
         circle.addPrimitive(tri)
     
     gn = GeomNode('Circle')
     gn.addGeom(circle)
     np = NodePath(gn)
     np.setHpr(0, 90, 0)
     return np
def create_triangle(x_z_left, x_z_top, x_z_right, static=True):
    x1,z1 = x_z_left
    x2,z2 = x_z_top
    x3,z3 = x_z_right
    format = GeomVertexFormat.getV3n3c4t2()
    vdata=GeomVertexData('', format, Geom.UHStatic)
    vertex=GeomVertexWriter(vdata, 'vertex')
    normal=GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1) # left
    vertex.addData3f(x2, 0, z2) # top
    vertex.addData3f(x3, 0, z3) # right
    for _i in range(3):
        normal.addData3f(0,-1,0)
    if static:
        prim_hint = Geom.UHStatic
    else:
        prim_hint = Geom.UHDynamic
    prim = GeomTriangles(prim_hint)
    prim.addVertices(0,2,1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return node
Ejemplo n.º 13
0
def create_hexagon(radius):
    """ Creates a hexagon shape that is centered at (0,0,0) with the corners having a distance of radius to the center and
    the normals pointing in direction (0,-1,0). 
    Returns the tuple (PandaNode, GeomVertexData). """
    format = GeomVertexFormat.getV3n3c4t2()
    vdata=GeomVertexData('hexagon', format, Geom.UHStatic)
    vertex=GeomVertexWriter(vdata, 'vertex')
    normal=GeomVertexWriter(vdata, 'normal')
    # create the vertices
    vertex.addData3f(0,0,0)
    normal.addData3f(0,-1,0)
    # add the other vertices
    for phi in range(0,360,60):
        # right-hand-rule (with middle finger pointing upwards): the y-axis points towards the screen,
        # therefore the hexagon will be created in the x,z plane, with x-axis pointing to the right
        # and the z-axis pointing up
        # get the next vertex coordinates by rotating the point (0,0,radius) in the x,z plane
        x,z = rotate_phi_degrees_counter_clockwise(phi, (0,radius))
        #print (x,z)
        vertex.addData3f(x,0,z) 
        normal.addData3f(0,-1,0) # the normal vector points away from the screen
    # add the vertices to a geometry primitives
    prim = GeomTrifans(Geom.UHStatic)
    for i in range(7):
        prim.addVertex(i)
    prim.addVertex(1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    hex_node = GeomNode('')
    hex_node.addGeom(geom)
    return hex_node, vdata
Ejemplo n.º 14
0
def create_triangle(x_z_left, x_z_top, x_z_right, static=True):
    x1,z1 = x_z_left
    x2,z2 = x_z_top
    x3,z3 = x_z_right
    format = GeomVertexFormat.getV3n3c4t2()
    vdata=GeomVertexData('', format, Geom.UHStatic)
    vertex=GeomVertexWriter(vdata, 'vertex')
    normal=GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1) # left
    vertex.addData3f(x2, 0, z2) # top
    vertex.addData3f(x3, 0, z3) # right
    for _i in range(3):
        normal.addData3f(0,-1,0)
    if static:
        prim_hint = Geom.UHStatic
    else:
        prim_hint = Geom.UHDynamic
    prim = GeomTriangles(prim_hint)
    prim.addVertices(0,2,1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return node
Ejemplo n.º 15
0
	def __init__(self):
		formatArray=GeomVertexArrayFormat()
		formatArray.addColumn(InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther)

		format=GeomVertexFormat(GeomVertexFormat.getV3n3cpt2())
		format.addArray(formatArray)
		self.format=GeomVertexFormat.registerFormat(format)

		bodydata=GeomVertexData("body vertices", format, Geom.UHStatic)

		self.barkTexture=loader.loadTexture("barkTexture.jpg")
		treeNodePath=NodePath("Tree Holder")
		makeFractalTree(bodydata,treeNodePath,Vec3(4,4,7))

		treeNodePath.setTexture(self.barkTexture,1)
		treeNodePath.reparentTo(render)

		self.accept("q", self.regenTree)
		self.accept("n", self.newPop)
		self.accept("w", self.addTree)
		self.accept("arrow_up", self.upIterations)
		self.accept("arrow_down", self.downIterations)
		self.accept("arrow_right", self.upCopies)
		self.accept("arrow_left", self.downCopies)

		[self.accept("%d" % i, self.selectBest, ['%d' % i]) for i in range(0,9)]

		self.numIterations=11
		self.numCopies=4
		
		
		self.upDownEvent = OnscreenText( 
 			 text="Up/Down: Increase/Decrease the number of Iteratations("+str(self.numIterations)+")",
     			 style=1, fg=(1,1,1,1), pos=(-1.3, 0.85),
			 align=TextNode.ALeft, scale = .05, mayChange=True)
		
		self.leftRightEvent = OnscreenText( 
 			 text="Left/Right: Increase/Decrease branching("+str(self.numCopies)+")",
     			 style=1, fg=(1,1,1,1), pos=(-1.3, 0.80),
			 align=TextNode.ALeft, scale = .05, mayChange=True)
		

                curstudy = 'speedtree.yml'
                ga = evolve.init_iga({'app_name': curstudy})
                self.genomes = ga.draw()
                self.ga = ga
                print 'genomes', self.genomes
Ejemplo n.º 16
0
Archivo: Grid.py Proyecto: crempp/psg
	def drawSquare(self, x1,y1,z1, x2,y2,z2):
		format=GeomVertexFormat.getV3n3cpt2()
		vdata=GeomVertexData('square', format, Geom.UHStatic)
		
		vertex=GeomVertexWriter(vdata, 'vertex')
		normal=GeomVertexWriter(vdata, 'normal')
		color=GeomVertexWriter(vdata, 'color')
		texcoord=GeomVertexWriter(vdata, 'texcoord')
		
		#make sure we draw the sqaure in the right plane
		#if x1!=x2:
		vertex.addData3f(x1, y1, z1)
		vertex.addData3f(x2, y1, z1)
		vertex.addData3f(x2, y2, z2)
		vertex.addData3f(x1, y2, z2)

		normal.addData3f(self.myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x2-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
		normal.addData3f(self.myNormalize(Vec3(2*x1-1, 2*y2-1, 2*z2-1)))
		
		#adding different colors to the vertex for visibility
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		color.addData4f(0.0,0.5,0.0,0.5)
		
		texcoord.addData2f(0.0, 1.0)
		texcoord.addData2f(0.0, 0.0)
		texcoord.addData2f(1.0, 0.0)
		texcoord.addData2f(1.0, 1.0)

		#quads arent directly supported by the Geom interface
		#you might be interested in the CardMaker class if you are
		#interested in rectangle though
		tri1=GeomTriangles(Geom.UHStatic)
		tri2=GeomTriangles(Geom.UHStatic)
		
		tri1.addVertex(0)
		tri1.addVertex(1)
		tri1.addVertex(3)
		
		tri2.addConsecutiveVertices(1,3)
		
		tri1.closePrimitive()
		tri2.closePrimitive()
		
		square=Geom(vdata)
		square.addPrimitive(tri1)
		square.addPrimitive(tri2)
		#square.setIntoCollideMask(BitMask32.bit(1))
		
		squareNP = NodePath(GeomNode('square gnode')) 
		squareNP.node().addGeom(square)
		squareNP.setTransparency(1) 
		squareNP.setAlphaScale(.5) 
		squareNP.setTwoSided(True)
		squareNP.setCollideMask(BitMask32.bit(1))
		return squareNP
Ejemplo n.º 17
0
    def createPitchLineOld(self,points=[0.5,0.25,-0.25,-0.5],
                            tick=0.00,colour=None):
        """ create a line to hint at the pitch of the aircraft on the hud """
        if colour is None:
            colour = self.colour

        l = LineNodePath(aspect2d,'pitchline',4,Vec4(colour[0],colour[1],
                                                       colour[2],colour[3]))

        plist = []
        for p in points:
            plist.append((p,0.0,0.0))
        plist.insert(0,(points[0],0.0,tick))
        plist.append((points[3],0.0,tick))

        linelist = []
        linelist = [[plist[p],plist[p+1]] for p in range(len(plist)-1)]
        linelist.pop(2)
        l.drawLines(linelist)
        l.create()

        # These lines are drawn from scratch rather than using a graphic file

        format = GeomVertexFormat.getV3()
        vdata = GeomVertexData("vertices",format,Geom.UHStatic)

        # create vertices to add to use in creating lines
        vertexWriter=GeomVertexWriter(vdata,"vertex")
        # here we define enough positions to create two separated lines
        for p in points:
            vertexWriter.addData3f(p,0.0,0.0)
        # and another two positions for the 'ticks' at the line ends
        vertexWriter.addData3f(points[0],0.0,tick)
        vertexWriter.addData3f(points[3],0.0,tick)

        # create the primitives
        line = GeomLines(Geom.UHStatic)
        line.addVertices(4,0) # the tick part
        line.addVertices(0,1) # part of the horizontal line
        line.closePrimitive()
        line2 = GeomLines(Geom.UHStatic)
        line2.addVertices(2,3) # other part of the horizontal line
        line2.addVertices(3,5) # second tick
        line2.closePrimitive()

        # add the lines to a geom object
        lineGeom = Geom(vdata)
        lineGeom.addPrimitive(line)
        lineGeom.addPrimitive(line2)

        # create the node..
        lineGN=GeomNode("splitline")
        lineGN.addGeom(lineGeom)

        # and parent the node to aspect2d
        lineNP = aspect2d.attachNewNode(lineGN)
        return lineNP
Ejemplo n.º 18
0
    def resetWriters(self):
        '''
        '''
        self.vdata = GeomVertexData('street', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic)

        self.vertex = GeomVertexWriter(self.vdata, 'vertex')
        self.normal = GeomVertexWriter(self.vdata, 'normal')
        self.color = GeomVertexWriter(self.vdata, 'color')
        self.texcoord = GeomVertexWriter(self.vdata, 'texcoord')
        self.prim = GeomTriangles(Geom.UHStatic)
Ejemplo n.º 19
0
 def CreateVertexFormat(self):
     """ Creates a custom vertex format. 
     
     This was needed so that I could add a second array of texture data for having
     multiple textures for a BlockFace
     """
 
     array = GeomVertexArrayFormat()
     array.addColumn(InternalName.make('vertex'), 3,
                     Geom.NTFloat32, Geom.CPoint)
     array.addColumn(InternalName.make('normal'), 3,
                     Geom.NTFloat32, Geom.CVector)
     array.addColumn(InternalName.make('texcoord'), 2,
             Geom.NTFloat32, Geom.CTexcoord)
     array.addColumn(InternalName.make('texcoord.light'), 2,
             Geom.NTFloat32, Geom.CTexcoord)
     gvformat = GeomVertexFormat()
     gvformat.addArray(array)
     gvformat = GeomVertexFormat.registerFormat(gvformat)
     self.geomVertexFormat = gvformat
Ejemplo n.º 20
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData('cloud', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        color = GeomVertexWriter(vdata, 'color')

        for point, value in self._points.iteritems():
            vertex.addData3f(point[0], point[1], value)
            color.addData4f(*self._color)

        self._vdata = vdata
Ejemplo n.º 21
0
    def __init__(self, subdivides=3, scale=1.0):
        super(SphereNode, self).__init__('sphere')
        uniform = True
        # see if scale is a tuple
        try:
            xs, ys, zs = scale
            uniform = False
        except TypeError:
            # no, it's a scalar
            xs, ys, zs = scale, scale, scale

        north = (0.0, 1.0, 0.0)
        g = Octahedron()

        for i in range(subdivides):
            g.UniformSubdivide(midpointdisplace=NormalizeVert)

        #print "%d faces per sphere"%len(g.faces)

        # okay, we're gonna use setShaderInput to set constants for
        # surface coverages and planetary seed, so all we need per
        # vertex is position and normal
        # and we kind of don't need normal for a unit sphere, but
        # we want to use the same shader for other thangs
        format = GeomVertexFormat.getV3n3()
        vdata = GeomVertexData('sphere', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')

        for (x, y, z) in g.verts:
            vertex.addData3f(x * xs, y * ys, z * zs)
            if uniform:
                normal.addData3f(x, y, z)
            else:
                n = NormalizeVert(
                    (x / (xs * xs), y / (ys * ys), z / (zs * zs)))
                normal.addData3f(n[0], n[1], n[2])

        trilist = GeomTriangles(Geom.UHDynamic)

        for (a, b, c) in g.faces:
            trilist.addVertex(a)
            trilist.addVertex(b)
            trilist.addVertex(c)

        trilist.closePrimitive()
        self.geom = Geom(vdata)
        self.geom.addPrimitive(trilist)

        self.addGeom(self.geom)
Ejemplo n.º 22
0
    def __init__(self,subdivides=3,scale=1.0):
        super(SphereNode,self).__init__('sphere')
        uniform = True
        # see if scale is a tuple
        try:
            xs,ys,zs = scale
            uniform = False
        except TypeError:
            # no, it's a scalar
            xs,ys,zs = scale,scale,scale
               
        north = (0.0,1.0,0.0)
        g = Octahedron()
        
        for i in range(subdivides):
            g.UniformSubdivide( midpointdisplace = NormalizeVert )
            
        #print "%d faces per sphere"%len(g.faces)
        
        # okay, we're gonna use setShaderInput to set constants for 
        # surface coverages and planetary seed, so all we need per 
        # vertex is position and normal
        # and we kind of don't need normal for a unit sphere, but 
        # we want to use the same shader for other thangs
        format=GeomVertexFormat.getV3n3()
        vdata=GeomVertexData('sphere', format, Geom.UHDynamic)

        vertex=GeomVertexWriter(vdata, 'vertex')
        normal=GeomVertexWriter(vdata, 'normal')


        for (x,y,z) in g.verts:
            vertex.addData3f( x*xs, y*ys, z*zs )
            if uniform:            
                normal.addData3f( x, y, z )
            else:
                n = NormalizeVert( (x/(xs*xs),y/(ys*ys),z/(zs*zs)) )
                normal.addData3f( n[0], n[1], n[2] )  
            
        trilist=GeomTriangles(Geom.UHDynamic)
        
        for (a,b,c) in g.faces:
            trilist.addVertex(a)
            trilist.addVertex(b)
            trilist.addVertex(c)
        
        trilist.closePrimitive()
        self.geom = Geom(vdata)
        self.geom.addPrimitive( trilist )
        
        self.addGeom( self.geom )
Ejemplo n.º 23
0
    def __init__(self, radius=1.0, height=1.0, numSegs=16, degrees=360, axis=Vec3(0, 0, 1), origin=Point3(0, 0, 0)):

        # Create vetex data format
        gvf = GeomVertexFormat.getV3n3()
        gvd = GeomVertexData("vertexData", gvf, Geom.UHStatic)

        # Create vetex writers for each type of data we are going to store
        gvwV = GeomVertexWriter(gvd, "vertex")
        gvwN = GeomVertexWriter(gvd, "normal")

        # Get the points for an arc
        points = GetPointsForArc(degrees, numSegs, True)
        for i in range(len(points) - 1):

            # Rotate the points around the desired axis
            p1 = Point3(points[i][0], points[i][1], 0) * radius
            p1 = RotatePoint3(p1, Vec3(0, 0, 1), axis) - origin
            p2 = Point3(points[i + 1][0], points[i + 1][1], 0) * radius
            p2 = RotatePoint3(p2, Vec3(0, 0, 1), axis) - origin

            cross = (p2 - axis).cross(p1 - axis)
            cross.normalize()

            gvwV.addData3f(p1)
            gvwV.addData3f(axis * height - origin)
            gvwV.addData3f(p2)
            gvwN.addData3f(cross)
            gvwN.addData3f(cross)
            gvwN.addData3f(cross)

            # Base
            gvwV.addData3f(p2)
            gvwV.addData3f(Point3(0, 0, 0) - origin)
            gvwV.addData3f(p1)
            gvwN.addData3f(-axis)
            gvwN.addData3f(-axis)
            gvwN.addData3f(-axis)

        geom = Geom(gvd)
        for i in range(0, gvwV.getWriteRow(), 3):

            # Create and add triangle
            geom.addPrimitive(GetGeomTriangle(i, i + 1, i + 2))

        # Init the node path, wrapping the box
        geomNode = GeomNode("cone")
        geomNode.addGeom(geom)
        NodePath.__init__(self, geomNode)
Ejemplo n.º 24
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData('cloud', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        color = GeomVertexWriter(vdata, 'color')

        for index, point in enumerate(self._points):
            vertex.addData3f(*point[0:3])
            if self._colors != None:
                color.addData4f(*self._colors[index])
            else:
                color.addData4f(*self._color)

        self._vdata = vdata
Ejemplo n.º 25
0
    def createCentreMarkOld(self,colour=None):
        """ create a line to hint at the pitch of the aircraft on the hud """
        if colour is None:
            colour = self.colour

        # These lines are drawn from scratch rather than using a graphic file

        format = GeomVertexFormat.getV3()
        vdata = GeomVertexData("vertices",format,Geom.UHStatic)

        # create vertices to add to use in creating lines
        vertexWriter=GeomVertexWriter(vdata,"vertex")
        # essentially I am trying to create a line that gives an idea of
        #       where the forward vector of the plane is pointing which
        #       helps indicate the pitch
        # the bends in the line could be used to indicate a few angles but
        #       I am not sure how useful this really is.
        vertexWriter.addData3f(0.15,0.0,0.0)
        vertexWriter.addData3f(0.10,0.0,0.0)
        vertexWriter.addData3f(0.05,0.0,-0.025)
        vertexWriter.addData3f(0.00,0.0,0.025)
        vertexWriter.addData3f(-0.05,0.0,-0.025)
        vertexWriter.addData3f(-0.10,0.0,0.0)
        vertexWriter.addData3f(-0.15,0.0,0.0)

        # create the primitives
        line = GeomLines(Geom.UHStatic)
        line.addVertices(0,1)
        line.addVertices(1,2)
        line.addVertices(2,3)
        line.addVertices(3,4)
        line.addVertices(4,5)
        line.addVertices(5,6)
        line.closePrimitive()

        # add the lines to a geom object
        lineGeom = Geom(vdata)
        lineGeom.addPrimitive(line)

        # create the node..
        lineGN=GeomNode("centremark")
        lineGN.addGeom(lineGeom)

        # and parent the node to aspect2d
        lineNP = aspect2d.attachNewNode(lineGN)
        return lineNP
Ejemplo n.º 26
0
def create_line(x1, z1, x2, z2):
    format = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('', format, Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1)
    vertex.addData3f(x2, 0, z2) 
    for _i in range(2):
        normal.addData3f(0, - 1, 0)
    prim_hint = Geom.UHStatic
    prim = GeomLines(prim_hint)
    prim.addVertices(0, 1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return (node, vdata)
Ejemplo n.º 27
0
	def __init__(self, parent):
		self.parent = parent
		self.source = None
		self.terrain_coords = None
		self.format = GeomVertexFormat.getV3n3c4t2()
		self.node_path = None
		self.old_color = None
		self.is_hovered = False
		self.is_selected = False
		self.palette = None
		self.vA = None
		self.vB = None
		self.vC = None
		self.vD = None
		self.nA = None
		self.nB = None
		self.nC = None
		self.nD = None
def create_line(x1, z1, x2, z2):
    format = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('', format, Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    vertex.addData3f(x1, 0, z1)
    vertex.addData3f(x2, 0, z2) 
    for _i in range(2):
        normal.addData3f(0, - 1, 0)
    prim_hint = Geom.UHStatic
    prim = GeomLines(prim_hint)
    prim.addVertices(0, 1)
    prim.closePrimitive()
    geom = Geom(vdata)
    geom.addPrimitive(prim)
    node = GeomNode('')
    node.addGeom(geom)
    return (node, vdata)
Ejemplo n.º 29
0
def create_table_geom():
    format = GeomVertexFormat.getV3n3c4t2()
    # GeomVertexData. 
    vdata = GeomVertexData('table_vertex', format, Geom.UHStatic)
    
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    texcoord = GeomVertexWriter(vdata, 'texcoord')

    vertex.addData3f(xmax, ymin, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(1, 0)
    
    vertex.addData3f(xmax, ymax, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(1, 1)
    
    vertex.addData3f(xmin, ymax, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(0, 1)
    
    vertex.addData3f(xmin, ymin, 0)
    normal.addData3f(0, 0, 1)
    color.addData4f(0, 0, 1, 1)
    texcoord.addData2f(0, 0)
    
    prim = GeomTriangles(Geom.UHStatic)
    prim.addVertex(0)
    prim.addVertex(1)
    prim.addVertex(2)
    prim.closePrimitive()
    
    prim.addVertex(0)
    prim.addVertex(2)
    prim.addVertex(3)
    prim.closePrimitive()

    geom = Geom(vdata)
    geom.addPrimitive(prim)
    return geom
Ejemplo n.º 30
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData("surface", format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, "vertex")
        normal = GeomVertexWriter(vdata, "normal")
        color = GeomVertexWriter(vdata, "color")

        for triangle in self._halfedge_mesh.faces:
            for v in triangle.iter_vertices():
                vertex.addData3f(*v.coordinates)
                normal.addData3f(*v.normal)
                color.addData4f(*self._color)
                tri.addNextVertices(1)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri]
Ejemplo n.º 31
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData('plane', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')

        for x in xrange(self._width):
            for y in xrange(self._height):
                cur_index = x * self._height + y
                vertex.addData3f(*self._points[cur_index][0:3])
                if self._normals:
                    normal.addData3f(*self._normals[cur_index])
                else:
                    normal.addData3f(0, 0, 1)
                color.addData4f(*self._color)

        self._vdata = vdata
Ejemplo n.º 32
0
    def drawRect(self, width, height, axis):

        # since we're doing line segments, just vertices in our geom
        format = GeomVertexFormat.getV3()

        # build our data structure and get a handle to the vertex column
        vdata = GeomVertexData('', format, Geom.UHStatic)
        vertices = GeomVertexWriter(vdata, 'vertex')

        # build a linestrip vertex buffer
        lines = GeomLinestrips(Geom.UHStatic)

        # draw a box
        if axis == "x":
            vertices.addData3f(0, -width, -height)
            vertices.addData3f(0, width, -height)
            vertices.addData3f(0, width, height)
            vertices.addData3f(0, -width, height)
        if axis == "y":
            vertices.addData3f(-width, 0, -height)
            vertices.addData3f(width, 0, -height)
            vertices.addData3f(width, 0, height)
            vertices.addData3f(-width, 0, height)
        if axis == "z":
            vertices.addData3f(-width, -height, 0)
            vertices.addData3f(width, -height, 0)
            vertices.addData3f(width, height, 0)
            vertices.addData3f(-width, height, 0)

        for i in range(1, 3):
            lines.addVertices(i - 1, i)
        lines.addVertices(3, 0)

        lines.closePrimitive()

        geom = Geom(vdata)
        geom.addPrimitive(lines)
        # Add our primitive to the geomnode
        self.gnode.addGeom(geom)
Ejemplo n.º 33
0
    def generate(self):
        format = GeomVertexFormat.getV3()
        data = GeomVertexData("Data", format, Geom.UHStatic)
        vertices = GeomVertexWriter(data, "vertex")

        size = self.size
        vertices.addData3f(-size, -size, -size)
        vertices.addData3f(+size, -size, -size)
        vertices.addData3f(-size, +size, -size)
        vertices.addData3f(+size, +size, -size)
        vertices.addData3f(-size, -size, +size)
        vertices.addData3f(+size, -size, +size)
        vertices.addData3f(-size, +size, +size)
        vertices.addData3f(+size, +size, +size)

        triangles = GeomTriangles(Geom.UHStatic)

        def addQuad(v0, v1, v2, v3):
            triangles.addVertices(v0, v1, v2)
            triangles.addVertices(v0, v2, v3)
            triangles.closePrimitive()

        addQuad(4, 5, 7, 6) # Z+
        addQuad(0, 2, 3, 1) # Z-
        addQuad(3, 7, 5, 1) # X+
        addQuad(4, 6, 2, 0) # X-
        addQuad(2, 6, 7, 3) # Y+
        addQuad(0, 1, 5, 4) # Y+

        geom = Geom(data)
        geom.addPrimitive(triangles)

        node = GeomNode("CubeMaker")
        node.addGeom(geom)

        path = NodePath(node)
        path.setColor(1.0, 0.0, 1.0)

        return NodePath(node)
Ejemplo n.º 34
0
	def rect (self, width, height, axis): 
		
		# since we're doing line segments, just vertices in our geom 
		format = GeomVertexFormat.getV3() 
		
		# build our data structure and get a handle to the vertex column 
		vdata = GeomVertexData ('', format, Geom.UHStatic) 
		vertices = GeomVertexWriter (vdata, 'vertex') 
				
		# build a linestrip vertex buffer 
		lines = GeomLinestrips (Geom.UHStatic) 
		
		# draw a box 
		if axis == "x": 
			vertices.addData3f (0, -width, -height) 
			vertices.addData3f (0, width, -height) 
			vertices.addData3f (0, width, height) 
			vertices.addData3f (0, -width, height) 
		if axis == "y": 
			vertices.addData3f (-width, 0, -height) 
			vertices.addData3f (width, 0, -height) 
			vertices.addData3f (width, 0, height) 
			vertices.addData3f (-width, 0, height) 
		if axis == "z": 
			vertices.addData3f (-width, -height, 0) 
			vertices.addData3f (width, -height, 0) 
			vertices.addData3f (width, height, 0) 
			vertices.addData3f (-width, height, 0) 

		for i in range (1, 3): 
			lines.addVertices(i - 1, i) 
		lines.addVertices (3, 0) 
			
		lines.closePrimitive() 
		
		geom = Geom (vdata) 
		geom.addPrimitive (lines) 
		# Add our primitive to the geomnode 
		self.gnode.addGeom (geom) 
Ejemplo n.º 35
0
    def drawLine(self, start, end):

        # since we're doing line segments, just vertices in our geom
        format = GeomVertexFormat.getV3()

        # build our data structure and get a handle to the vertex column
        vdata = GeomVertexData('', format, Geom.UHStatic)
        vertices = GeomVertexWriter(vdata, 'vertex')

        # build a linestrip vertex buffer
        lines = GeomLinestrips(Geom.UHStatic)

        vertices.addData3f(start[0], start[1], start[2])
        vertices.addData3f(end[0], end[1], end[2])

        lines.addVertices(0, 1)

        lines.closePrimitive()

        geom = Geom(vdata)
        geom.addPrimitive(lines)
        # Add our primitive to the geomnode
        self.gnode.addGeom(geom)
Ejemplo n.º 36
0
	def line (self, start, end):	
		
		# since we're doing line segments, just vertices in our geom 
		format = GeomVertexFormat.getV3() 
		
		# build our data structure and get a handle to the vertex column 
		vdata = GeomVertexData ('', format, Geom.UHStatic) 
		vertices = GeomVertexWriter (vdata, 'vertex') 
				
		# build a linestrip vertex buffer 
		lines = GeomLinestrips (Geom.UHStatic) 
		
		vertices.addData3f (start[0], start[1], start[2]) 
		vertices.addData3f (end[0], end[1], end[2]) 
		
		lines.addVertices (0, 1) 
			
		lines.closePrimitive() 
		
		geom = Geom (vdata) 
		geom.addPrimitive (lines) 
		# Add our primitive to the geomnode 
		self.gnode.addGeom (geom) 
Ejemplo n.º 37
0
	def __init__(self, parent):
		self.parent = parent
		self.format = GeomVertexFormat.getV3c4()
		self.node_path = None
		self.tile_color = None
		self.x = None
		self.y = None
		self.z = None
		self.coords = None
		self.unknown1 = None
		self.surface_type = None
		self.unknown2 = None
		self.height = None
		self.depth = None
		self.slope_height = None
		self.slope_type = None
		self.unknown3 = None
		self.unknown4 = None
		self.cant_walk = None
		self.cant_cursor = None
		self.unknown5 = None
		self.is_hovered = False
		self.is_selected = False
Ejemplo n.º 38
0
    def draw(self):
        format = GeomVertexFormat.getV3n3cpt2()
        vdata = GeomVertexData('square', format, Geom.UHDynamic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        circle = Geom(vdata)
        # Create vertices
        vertex.addData3f(self.pos)
        color.addData4f(self.color)
        for v in range(self._EDGES):
            x = self.pos.getX() + (self.size * math.cos(
                (2 * math.pi / self._EDGES) * v))
            y = self.pos.getY() + (self.size * math.sin(
                (2 * math.pi / self._EDGES) * v))
            z = self.pos.getZ()
            vertex.addData3f(x, y, z)
            color.addData4f(self.color)

        # Create triangles
        for t in range(self._EDGES):
            tri = GeomTriangles(Geom.UHDynamic)
            tri.addVertex(0)
            tri.addVertex(t + 1)
            if (t + 2) > self._EDGES:
                tri.addVertex(1)
            else:
                tri.addVertex(t + 2)
            tri.closePrimitive()
            circle.addPrimitive(tri)

        gn = GeomNode('Circle')
        gn.addGeom(circle)
        np = NodePath(gn)
        np.setHpr(0, 90, 0)
        return np
Ejemplo n.º 39
0
    def visualize(self,
                  parentNodePath,
                  highlightVerts=[],
                  pathVerts=[],
                  visitedVerts=[]):
        '''
        XXX Should move this into a product-specific class.
        '''
        gFormat = GeomVertexFormat.getV3cp()
        self.visVertexData = GeomVertexData("OMGVERTEXDATA2", gFormat,
                                            Geom.UHDynamic)
        self.visVertexWriter = GeomVertexWriter(self.visVertexData, "vertex")
        self.visVertexColorWriter = GeomVertexWriter(self.visVertexData,
                                                     "color")

        vertToWriterIndex = {}
        currIndex = 0

        for v in self.vertexCoords.keys():
            vertToWriterIndex[v] = currIndex
            x = self.vertexCoords[v][0]
            y = self.vertexCoords[v][1]
            z = self.vertexCoords[v][2]
            self.visVertexWriter.addData3f(x, y, z + 0.5)
            if v in highlightVerts:
                self.visVertexColorWriter.addData4f(1.0, 0.0, 0.0, 1.0)
            elif v in visitedVerts:
                self.visVertexColorWriter.addData4f(0.0, 0.0, 1.0, 1.0)
            else:
                self.visVertexColorWriter.addData4f(1.0, 1.0, 0.0, 1.0)
            currIndex += 1

        pathOffsetIntoIndex = currIndex

        for v in pathVerts:
            self.visVertexWriter.addData3f(v[0], v[1], v[2] + 0.5)
            self.visVertexColorWriter.addData4f(0.0, 1.0, 0.0, 1.0)
            currIndex += 1

        lines = GeomLinestrips(Geom.UHStatic)

        for p in self.polyToVerts.keys():
            for v in self.polyToVerts[p]:
                lines.addVertex(vertToWriterIndex[v])
            lines.addVertex(vertToWriterIndex[self.polyToVerts[p][0]])
            lines.closePrimitive()

        if len(pathVerts) > 0:
            for i in xrange(len(pathVerts)):
                lines.addVertex(pathOffsetIntoIndex + i)
            lines.closePrimitive()

        self.visGeom = Geom(self.visVertexData)
        self.visGeom.addPrimitive(lines)

        self.visGN = GeomNode("NavMeshVis")
        self.visGN.addGeom(self.visGeom)

        self.visNodePath = parentNodePath.attachNewNode(self.visGN)

        self.visNodePath.setTwoSided(True)
Ejemplo n.º 40
0
 def addGeometry(self, geomData):
   debugGui = dict()
   
   format = GeomVertexFormat.getV3n3t2()
   vdata = GeomVertexData('name', format, Geom.UHStatic)
   vertex = GeomVertexWriter(vdata, 'vertex')
   normal = GeomVertexWriter(vdata, 'normal')
   texcoord = GeomVertexWriter(vdata, 'texcoord')
   prim = GeomTriangles(Geom.UHStatic)
   
   postphonedTriangles = list()
   vtxTargetId0 = vtxTargetId1 = vtxTargetId2 = None
   vtxDataCounter = 0
   for vtxSourceId0, vtxSourceId1, vtxSourceId2 in geomData.triangles:
     vx0,vy0,vz0 = v0 = geomData.getVertex(vtxSourceId0)
     vx1,vy1,vz1 = v1 = geomData.getVertex(vtxSourceId1)
     vx2,vy2,vz2 = v2 = geomData.getVertex(vtxSourceId2)
     # prepare the vertices
     uvx0, uvy0 = uv0 = geomData.getUv(vtxSourceId0)
     uvx1, uvy1 = uv1 = geomData.getUv(vtxSourceId1)
     uvx2, uvy2 = uv2 = geomData.getUv(vtxSourceId2)
     #
     n0 = geomData.getNormal(vtxSourceId0)
     n1 = geomData.getNormal(vtxSourceId1)
     n2 = geomData.getNormal(vtxSourceId2)
     
     # make it wrap nicely
     if min(uvx0,uvx1,uvx2) < .25 and max(uvx0,uvx1,uvx2) > 0.75:
       if uvx0 < 0.25: uvx0 += 1.0
       if uvx1 < 0.25: uvx1 += 1.0
       if uvx2 < 0.25: uvx2 += 1.0
     
     vertex.addData3f(*v0)
     normal.addData3f(*n0)
     texcoord.addData2f(*uv0)
     vtxTargetId0 = vtxDataCounter
     vtxDataCounter += 1
   
     vertex.addData3f(*v1)
     normal.addData3f(*n1)
     texcoord.addData2f(*uv1)
     vtxTargetId1 = vtxDataCounter
     vtxDataCounter += 1
   
     vertex.addData3f(*v2)
     normal.addData3f(*n2)
     texcoord.addData2f(*uv2)
     vtxTargetId2 = vtxDataCounter
     vtxDataCounter += 1
     
     prim.addVertex(vtxTargetId0)
     prim.addVertex(vtxTargetId1)
     prim.addVertex(vtxTargetId2)
     prim.closePrimitive()
     
     if False:
       if vtxSourceId0 not in debugGui:
         i = InfoTextBillaboarded(render)
         i.setScale(0.05)
         i.billboardNodePath.setPos(Vec3(x0,y0,z0)*1.1)
         i.setText('%i: %.1f %.1f %.1f\n%.1f %.1f' % (vtxSourceId0, x0,y0,z0, nx0, ny0))
         debugGui[vtxSourceId0] = i
       if vtxSourceId1 not in debugGui:
         i = InfoTextBillaboarded(render)
         i.setScale(0.05)
         i.billboardNodePath.setPos(Vec3(x1,y1,z1)*1.1)
         i.setText('%i: %.1f %.1f %.1f\n%.1f %.1f' % (vtxSourceId1, x1,y1,z1, nx1, ny1))
         debugGui[vtxSourceId1] = i
       if vtxSourceId2 not in debugGui:
         i = InfoTextBillaboarded(render)
         i.setScale(0.05)
         i.billboardNodePath.setPos(Vec3(x2,y2,z2)*1.1)
         i.setText('%i: %.1f %.1f %.1f\n%.1f %.1f' % (vtxSourceId2, x2,y2,z2, nx2, ny2))
         debugGui[vtxSourceId2] = i
   
   geom = Geom(vdata)
   geom.addPrimitive(prim)
   
   node = GeomNode('gnode')
   node.addGeom(geom)
   
   nodePath = self.attachNewNode(node)
   return nodePath
Ejemplo n.º 41
0
    def pandaRender(self):
        frameList = []
        for node in self.compositeFrames.getiterator('composite-frame'):
            if node.tag == "composite-frame" and node.attrib.get("id") == str(self.internalFrameIndex):
                for frameCallNode in node:
                    for frameNode in self.frames.getiterator('frame'):
                        if frameNode.tag == "frame" and frameNode.attrib.get("id") == frameCallNode.attrib.get("id"):
                            offsetX = 0 if frameCallNode.attrib.get("offset-x") == None else float(frameCallNode.attrib.get("offset-x"))
                            offsetY = 0 if frameCallNode.attrib.get("offset-y") == None else float(frameCallNode.attrib.get("offset-y"))
                            tweenId = frameCallNode.attrib.get("tween")
                            frameInTween = 0 if frameCallNode.attrib.get("frame-in-tween") == None else int(frameCallNode.attrib.get("frame-in-tween"))
                            addWidth = 0 if frameNode.attrib.get("w") == None else float(frameNode.attrib.get("w"))
                            addHeight = 0 if frameNode.attrib.get("h") == None else float(frameNode.attrib.get("h"))
                            sInPixels = 0 if frameNode.attrib.get("s") == None else float(frameNode.attrib.get("s"))
                            tInPixels = 0 if frameNode.attrib.get("t") == None else float(frameNode.attrib.get("t"))
                            swInPixels = sInPixels + addWidth
                            thInPixels = tInPixels + addHeight
                            s = (sInPixels / self.baseWidth)
                            t = 1 - (tInPixels / self.baseHeight) # Complemented to deal with loading image upside down.
                            S = (swInPixels / self.baseWidth)
                            T = 1 - (thInPixels / self.baseHeight) # Complemented to deal with loading image upside down.
                            blend = "overwrite" if frameCallNode.attrib.get("blend") == None else frameCallNode.attrib.get("blend")
                            scaleX = 1 if frameCallNode.attrib.get("scale-x") == None else float(frameCallNode.attrib.get("scale-x"))
                            scaleY = 1 if frameCallNode.attrib.get("scale-y") == None else float(frameCallNode.attrib.get("scale-y"))
                            color = Color(1,1,1,1)
                            tweenHasColor = False
                            frameCallHasColor = False
                            frameCallColorName = frameCallNode.attrib.get("color-name")
                            if frameCallColorName != None:
                                # Get color at frame call as first resort.
                                frameCallHasColor = True
                                for colorNode in self.colors.getiterator('color'):
                                    if colorNode.tag == 'color' and colorNode.attrib.get("name") == frameCallColorName:
                                        R = 1 if colorNode.attrib.get("r") == None else float(colorNode.attrib.get("r"))
                                        G = 1 if colorNode.attrib.get("g") == None else float(colorNode.attrib.get("g"))
                                        B = 1 if colorNode.attrib.get("b") == None else float(colorNode.attrib.get("b"))
                                        A = 1 if colorNode.attrib.get("a") == None else float(colorNode.attrib.get("a"))
                                        color = Color(R, G, B, A)
                                        break # leave for loop when we find the correct color
                                pass

                            if tweenId != None and tweenId != "0":
                                # Get color at tween frame as second resort.
                                thisTween = None
                                frameLength = 1
                                advancementFunction = "linear"
                                foundTween = False
                                pointList = []
                                colorList = []
                                for tweenNode in self.tweens.getiterator('motion-tween'):
                                    if tweenNode.tag == "motion-tween" and tweenNode.attrib.get("id") == tweenId:
                                        foundTween = True
                                        frameLength = 1 if tweenNode.attrib.get("length-in-frames") == None else tweenNode.attrib.get("length-in-frames")
                                        advancementFunction = "linear" if tweenNode.attrib.get("advancement-function") == None else tweenNode.attrib.get("advancement-function")
                                        for pointOrColorNode in tweenNode.getiterator():
                                            if pointOrColorNode.tag == "point":
                                                pX = 0 if pointOrColorNode.attrib.get("x") == None else float(pointOrColorNode.attrib.get("x"))
                                                pY = 0 if pointOrColorNode.attrib.get("y") == None else float(pointOrColorNode.attrib.get("y"))
                                                pointList.append(Point(pX, pY, 0))
                                            elif pointOrColorNode.tag == "color-state":
                                                colorName = "white" if pointOrColorNode.attrib.get("name") == None else pointOrColorNode.attrib.get("name")
                                                for colorNode in self.colors.getiterator('color'):
                                                    if colorNode.tag == 'color' and colorNode.attrib.get("name") == colorName:
                                                        R = 1 if colorNode.attrib.get("r") == None else float(colorNode.attrib.get("r"))
                                                        G = 1 if colorNode.attrib.get("g") == None else float(colorNode.attrib.get("g"))
                                                        B = 1 if colorNode.attrib.get("b") == None else float(colorNode.attrib.get("b"))
                                                        A = 1 if colorNode.attrib.get("a") == None else float(colorNode.attrib.get("a"))
                                                        colorList.append(Color(R, G, B, A))
                                                        break # leave for loop when we find the correct color reference
                                            pass # Run through all child nodes of selected tween
                                        break # Exit after finding correct tween
                                pass
                                if foundTween:
                                    thisTween = Tween(frameLength, advancementFunction, pointList, colorList)
                                    offset = thisTween.XYFromFrame(frameInTween);
                                    offsetFromTweenX = int(offset.X);
                                    offsetFromTweenY = int(offset.Y);
                                    offsetX += int(offset.X);
                                    offsetY += int(offset.Y);
                                    if thisTween.hasColorComponent():
                                        tweenHasColor = True;
                                        if frameCallHasColor == False:
                                            color = thisTween.colorFromFrame(frameInTween);
                                    pass
                            if frameNode.attrib.get("color-name") != None and frameCallHasColor == False and tweenHasColor == False:
                                # Get color at frame definition as last resort.
                                for colorNode in colors.getiterator('color'):
                                    if colorNode.tag == 'color' and colorNode.attrib.get("name") == frameNode.attrib.get("color-name"):
                                        R = 1 if colorNode.attrib.get("r") == None else float(colorNode.attrib.get("r"))
                                        G = 1 if colorNode.attrib.get("g") == None else float(colorNode.attrib.get("g"))
                                        B = 1 if colorNode.attrib.get("b") == None else float(colorNode.attrib.get("b"))
                                        A = 1 if colorNode.attrib.get("a") == None else float(colorNode.attrib.get("a"))
                                        color = Color(R, G, B, A)
                                        break # leave for loop when we find the correct color
                                pass
                            rotationZ = 0 if frameCallNode.attrib.get("rotation-z") == None else float(frameCallNode.attrib.get("rotation-z"))
                            frameList.append(Frame(Bound(offsetX, offsetY, addWidth, addHeight), s, t, S, T, blend, scaleX, scaleY, color, rotationZ))
                    pass 
                break # Leave once we've found the appropriate frame

        # Prepare tracking list of consumed nodes.
        self.clearNodesForDrawing()
        # Make an identifier to tack onto primitive names in Panda3d's scene graph.
        frameIndexForName = 1
                
        # Loop through loaded frames that make up composite frame.
        for loadedFrame in frameList:              
            # For debugging purposes, print the object.
            if False:
                loadedFrame.printAsString()
            
            # Set up place to store primitive 3d object; note: requires vertex data made by GeomVertexData
            squareMadeByTriangleStrips = GeomTristrips(Geom.UHDynamic)
              
            # Set up place to hold 3d data and for the following coordinates:
            #   square's points (V3: x, y, z), 
            #   the colors at each point of the square (c4: r, g, b, a), and
            #   for the UV texture coordinates at each point of the square     (t2: S, T).
            vertexData = GeomVertexData('square-'+str(frameIndexForName), GeomVertexFormat.getV3c4t2(), Geom.UHDynamic)
            vertex = GeomVertexWriter(vertexData, 'vertex')
            color = GeomVertexWriter(vertexData, 'color')
            texcoord = GeomVertexWriter(vertexData, 'texcoord') 
              
            # Add the square's data
            # Upper-Left corner of square
            vertex.addData3f(-loadedFrame.bound.Width / 2.0, 0, -loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R,loadedFrame.color.G,loadedFrame.color.B,loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.s, loadedFrame.T)

            # Upper-Right corner of square
            vertex.addData3f(loadedFrame.bound.Width / 2.0, 0, -loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R,loadedFrame.color.G,loadedFrame.color.B,loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.S, loadedFrame.T)
            
            # Lower-Left corner of square
            vertex.addData3f(-loadedFrame.bound.Width / 2.0, 0, loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R,loadedFrame.color.G,loadedFrame.color.B,loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.s, loadedFrame.t)
            
            # Lower-Right corner of square
            vertex.addData3f(loadedFrame.bound.Width / 2.0, 0, loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R,loadedFrame.color.G,loadedFrame.color.B,loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.S, loadedFrame.t)

            # Pass data to primitive
            squareMadeByTriangleStrips.addNextVertices(4)
            squareMadeByTriangleStrips.closePrimitive()
            square = Geom(vertexData)
            square.addPrimitive(squareMadeByTriangleStrips)
            # Pass primtive to drawing node
            drawPrimitiveNode=GeomNode('square-'+str(frameIndexForName))    
            drawPrimitiveNode.addGeom(square)
            # Pass node to scene (effect camera)
            nodePath = self.effectCameraNodePath.attachNewNode(drawPrimitiveNode)
            # Linear dodge:
            if loadedFrame.blendMode == "darken":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOneMinusFbufferColor, ColorBlendAttrib.OOneMinusIncomingColor))
                pass
            elif loadedFrame.blendMode == "multiply":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OFbufferColor, ColorBlendAttrib.OZero))
                pass
            elif loadedFrame.blendMode == "color-burn":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OZero, ColorBlendAttrib.OOneMinusIncomingColor))
                pass
            elif loadedFrame.blendMode == "linear-burn":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OZero, ColorBlendAttrib.OIncomingColor))
                pass
            elif loadedFrame.blendMode == "lighten":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MMax, ColorBlendAttrib.OIncomingColor, ColorBlendAttrib.OFbufferColor))
                pass
            elif loadedFrame.blendMode == "color-dodge":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOne))
                pass
            elif loadedFrame.blendMode == "linear-dodge":
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOneMinusIncomingColor))
                pass
            else: # Overwrite:
                nodePath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OIncomingAlpha, ColorBlendAttrib.OOneMinusIncomingAlpha))
                pass
            nodePath.setDepthTest(False)
            # Apply texture
            nodePath.setTexture(self.tex)
            # Apply translation, then rotation, then scaling to node.
            nodePath.setPos((loadedFrame.bound.X + loadedFrame.bound.Width / 2.0, 1, -loadedFrame.bound.Y - loadedFrame.bound.Height / 2.0))
            nodePath.setR(loadedFrame.rotationZ)
            nodePath.setScale(loadedFrame.scaleX, 1, loadedFrame.scaleY)
            nodePath.setTwoSided(True)
            self.consumedNodesList.append(nodePath)
            frameIndexForName = frameIndexForName + 1
        # Loop continues on through each frame called in the composite frame.
        pass
Ejemplo n.º 42
0
  def make_layer(self, i, a, b):
    # get data
    data = self.subdata[a][b]

    # set color + alpha of vertex texture
    def ap(n):
      alpha = 0
      if i == n:
        alpha = 1.0
      return alpha
    def tp(n):
      list = [0, 0, 0, 0]
      if i == n:
        list = [1, 1, 1, 0.75]
      return list

    # set vertex data
    vdata = GeomVertexData('plane', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    uv = GeomVertexWriter(vdata, 'texcoord')

    # set vertices
    number = 0
    for x in range(0, len(data) - 1):
      for y in range(0, len(data[x]) - 1):
        # get vertex data
        v1 = Vec3(x, y, data[x][y]['h'])
        c1 = data[x][y]['c']
        t1 = data[x][y]['texnum']
        v2 = Vec3(x+1, y, data[x+1][y]['h'])
        c2 = data[x+1][y]['c']
        t2 = data[x+1][y]['texnum']
        v3 = Vec3(x+1, y+1, data[x+1][y+1]['h'])
        c3 = data[x+1][y+1]['c']
        t3 = data[x+1][y+1]['texnum']
        v4 = Vec3(x, y+1, data[x][y+1]['h'])
        c4 = data[x][y+1]['c']
        t4 = data[x][y+1]['texnum']
        n=(0, 0, 1) # normal

        # assign vertex colors + alpha
        a1, a2, a3, a4 = ap(t1), ap(t2), ap(t3), ap(t4)
        t1, t2, t3, t4 = tp(t1), tp(t2), tp(t3), tp(t4)

        if v1[2]==0:
          t1 = [data[x][y]['c'][0], data[x][y]['c'][1], data[x][y]['c'][2],
                a1]
        if v2[2]==0:
          t2 = [data[x+1][y]['c'][0], data[x+1][y]['c'][1],
                data[x+1][y]['c'][2], a2]
        if v3[2]==0:
          t3 = [data[x+1][y+1]['c'][0], data[x+1][y+1]['c'][1],
                data[x+1][y+1]['c'][2], a3]
        if v4[2]==0:
          t4 = [data[x][y+1]['c'][0], data[x][y+1]['c'][1],
                data[x][y+1]['c'][2], a4]

        if a1 == 0 and a2 == 0 and a3 == 0 and a4 == 0:
          continue

        # add vertices
        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*t1)
        uv.addData2f(0,0)

        vertex.addData3f(v2)
        normal.addData3f(*n)
        color.addData4f(*t2)
        uv.addData2f(1,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*t3)
        uv.addData2f(1,1)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*t1)
        uv.addData2f(0,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*t3)
        uv.addData2f(1,1)

        vertex.addData3f(v4)
        normal.addData3f(*n)
        color.addData4f(*t4)
        uv.addData2f(0,1)

        number = number + 2

    # add triangles
    prim = GeomTriangles(Geom.UHStatic)
    for n in range(number):
      prim.addVertices((n * 3) + 2, (n * 3) + 0, (n * 3) + 1)
    prim.closePrimitive()

    # make geom
    geom = Geom(vdata)
    geom.addPrimitive(prim)

    # make geom node
    node = GeomNode("layer" + str(i) + "_" + str(a) + "_" + str(b))
    node.addGeom(geom)

    # make mesh nodePath
    mesh = NodePath(node)

    # load and assign texture
    txfile = self.tiles[i]['tex']
    tx = base.loader.loadTexture(txfile)
    tx.setMinfilter(Texture.FTLinearMipmapLinear)
    mesh.setDepthTest(DepthTestAttrib.MLessEqual)
    mesh.setDepthWrite(False)
    mesh.setTransparency(True)
    mesh.setTexture(tx)

    # set render order
    mesh.setBin("", 1)

    # locate mesh
    mesh.setPos(self.divsep * (a * int(len(self.data[a]) / self.div)),
                self.divsep * (b * int(len(self.data[b]) / self.div)), 0.001)

    # reparent mesh
    mesh.reparentTo(self.root)

    # return mesh
    return mesh
Ejemplo n.º 43
0
  def make_base(self, a, b):
    # get data
    data = self.subdata[a][b]
    # set vertex data
    vdata = GeomVertexData('plane', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    uv = GeomVertexWriter(vdata, 'texcoord')

    # set vertices
    number = 0
    for x in range(0, len(data) - 1):
      for y in range(0, len(data[x]) - 1):
        # get vertex data
        v1 = Vec3(x, y, data[x][y]['h'])
        v2 = Vec3(x + 1, y, data[x+1][y]['h'])
        v3 = Vec3(x + 1, y + 1, data[x+1][y+1]['h'])
        v4 = Vec3(x, y + 1, data[x][y+1]['h'])
        n = (0, 0, 1) # normal

        # assign vertex colors + alpha
        option = 1 # black
        if option == 1:
          c = 0
          c1 = [c, c, c, 1]
          c2 = [c, c, c, 1]
          c3 = [c, c, c, 1]
          c4 = [c, c, c, 1]
        # option2: color vertices
        if option == 2:
          alpha = 1.0
          c1 = [data[x][y]['c'][0], data[x][y]['c'][1],
                data[x][y]['c'][2], alpha]
          c2 = [data[x+1][y]['c'][0], data[x+1][y]['c'][1],
                data[x+1][y]['c'][2], alpha]
          c3 = [data[x+1][y+1]['c'][0], data[x+1][y+1]['c'][1],
                data[x+1][y+1]['c'][2], alpha]
          c4 = [data[x][y+1]['c'][0], data[x][y+1]['c'][1],
                data[x][y+1]['c'][2], alpha]

        if option == 3:
          c1 = self.color_vertex(v1)
          c2 = self.color_vertex(v2)
          c3 = self.color_vertex(v3)
          c4 = self.color_vertex(v4)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*c1)
        uv.addData2f(0,0)

        vertex.addData3f(v2)
        normal.addData3f(*n)
        color.addData4f(*c2)
        uv.addData2f(1,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*c3)
        uv.addData2f(1,1)

        vertex.addData3f(v1)
        normal.addData3f(*n)
        color.addData4f(*c1)
        uv.addData2f(0,0)

        vertex.addData3f(v3)
        normal.addData3f(*n)
        color.addData4f(*c3)
        uv.addData2f(1,1)

        vertex.addData3f(v4)
        normal.addData3f(*n)
        color.addData4f(*c4)
        uv.addData2f(0,1)

#         # add vertex h
#         vertex.addData3f(v1)
#         # normal.addData3f(*n)
#         vertex.addData3f(v2)
#         # normal.addData3f(*n)
#         vertex.addData3f(v3)
#         # normal.addData3f(*n)
#         vertex.addData3f(v1)
#         # normal.addData3f(*n)
#         vertex.addData3f(v3)
#         # normal.addData3f(*n)
#         vertex.addData3f(v4)
#         # normal.addData3f(*n)
#         # add vertex color
#         color.addData4f(*c1)
#         color.addData4f(*c2)
#         color.addData4f(*c3)
#         color.addData4f(*c1)
#         color.addData4f(*c3)
#         color.addData4f(*c4)

        # iterate
        number = number + 2

    # add triangles
    prim = GeomTriangles(Geom.UHStatic)
    for n in range(number):
      prim.addVertices((n * 3) + 2, (n * 3) + 0, (n * 3) + 1)
    prim.closePrimitive()

    # make geom
    geom = Geom(vdata)
    geom.addPrimitive(prim)

    # make geom node
    node = GeomNode("base" + "_" + str(a) + "_" + str(b))
    node.addGeom(geom)

    # make mesh nodePath
    mesh = NodePath(node)
    # set render order
    mesh.setBin("", 1)

    # locate mesh
    mesh.setPos(self.divsep * (a * int(len(self.data[a]) / self.div)),
                self.divsep * (b * int(len(self.data[b]) / self.div)), 0)

    # reparent mesh
    mesh.reparentTo(self.root)

    # return mesh
    return mesh
Ejemplo n.º 44
0
	def __init__(self, parent):
		self.parent = parent
		self.format = GeomVertexFormat.getV3c4()
		self.node_path = None
		self.init_node_path()
Ejemplo n.º 45
0
    def draw(self):
        format = GeomVertexFormat.getV3n3cpt2()
        vdata = GeomVertexData('square', format, Geom.UHStatic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        texcoord = GeomVertexWriter(vdata, 'texcoord')

        #make sure we draw the sqaure in the right plane
        #if x1!=x2:
        vertex.addData3f(self.x1, self.y1, self.z1)
        vertex.addData3f(self.x2, self.y1, self.z1)
        vertex.addData3f(self.x2, self.y2, self.z2)
        vertex.addData3f(self.x1, self.y2, self.z2)

        normal.addData3f(
            Vec3(2 * self.x1 - 1, 2 * self.y1 - 1,
                 2 * self.z1 - 1).normalize())
        normal.addData3f(
            Vec3(2 * self.x2 - 1, 2 * self.y1 - 1,
                 2 * self.z1 - 1).normalize())
        normal.addData3f(
            Vec3(2 * self.x2 - 1, 2 * self.y2 - 1,
                 2 * self.z2 - 1).normalize())
        normal.addData3f(
            Vec3(2 * self.x1 - 1, 2 * self.y2 - 1,
                 2 * self.z2 - 1).normalize())

        #adding different colors to the vertex for visibility
        color.addData4f(self.r, self.g, self.b, self.a)
        color.addData4f(self.r, self.g, self.b, self.a)
        color.addData4f(self.r, self.g, self.b, self.a)
        color.addData4f(self.r, self.g, self.b, self.a)

        texcoord.addData2f(0.0, 1.0)
        texcoord.addData2f(0.0, 0.0)
        texcoord.addData2f(1.0, 0.0)
        texcoord.addData2f(1.0, 1.0)

        #quads arent directly supported by the Geom interface
        #you might be interested in the CardMaker class if you are
        #interested in rectangle though
        tri1 = GeomTriangles(Geom.UHStatic)
        tri2 = GeomTriangles(Geom.UHStatic)

        tri1.addVertex(0)
        tri1.addVertex(1)
        tri1.addVertex(3)

        tri2.addConsecutiveVertices(1, 3)

        tri1.closePrimitive()
        tri2.closePrimitive()

        square = Geom(vdata)
        square.addPrimitive(tri1)
        square.addPrimitive(tri2)
        #square.setIntoCollideMask(BitMask32.bit(1))

        self.squareNP = NodePath(GeomNode('square gnode'))
        self.squareNP.node().addGeom(square)
        self.squareNP.setTransparency(1)
        self.squareNP.setAlphaScale(.5)
        self.squareNP.setTwoSided(True)
        #squareNP.setCollideMask(BitMask32.bit(1))
        self.squareNP.reparentTo(self.parent)

        return self.squareNP
Ejemplo n.º 46
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData('surface', format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')

        vertmap = [(0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4), (0, 4), (1, 5), (2, 6), (3, 7)]

        def generate_index(x, y, z):
            return x + \
                   y * (self._surface.mls_subdivisions+2) + \
                   z * (self._surface.mls_subdivisions+2)**2

        numbering_scheme = [
                (0, 0, 1),
                (1, 0, 1),
                (1, 0, 0),
                (0, 0, 0),
                (0, 1, 1),
                (1, 1, 1),
                (1, 1, 0),
                (0, 1, 0)]

        vertices = zeros((12,), dtype='3f')
        vertex_normals = zeros((12,), dtype='3f')
        # walk the cubes
        for x_index in range(self._surface.mls_subdivisions+1):
            for y_index in range(self._surface.mls_subdivisions+1):
                for z_index in range(self._surface.mls_subdivisions+1):
                    #points = map(lambda offsets: self._surface.mls_points[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    points = [
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    values = [
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    #values = map(lambda offsets: self._surface.mls_distances[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    cubeindex = self._get_cubeindex(values)
                    for n in range(12):
                        if self.edge_table[cubeindex] & (2**n):
                            t_v, t_n = self._interpolate(points[vertmap[n][0]], points[vertmap[n][1]], values[vertmap[n][0]], values[vertmap[n][1]])
                            vertices[n] = t_v
                            vertex_normals[n] = t_n/norm(t_n)
                        else:
                            vertices[n] = 0
                            vertex_normals[n] = 0

                    triangles = []
                    i = 0
                    while self.triangle_table[cubeindex][i] != -1:
                        triangles.append([self.triangle_table[cubeindex][i],
                                         self.triangle_table[cubeindex][i+1],
                                         self.triangle_table[cubeindex][i+2]])
                        i += 3

                    for triangle in triangles:
                        vertex.addData3f(*vertices[triangle[0]])
                        vertex.addData3f(*vertices[triangle[1]])
                        vertex.addData3f(*vertices[triangle[2]])
                        normal.addData3f(*vertex_normals[triangle[0]])
                        normal.addData3f(*vertex_normals[triangle[1]])
                        normal.addData3f(*vertex_normals[triangle[2]])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        tri.addNextVertices(3)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri, ]
Ejemplo n.º 47
0
    def pandaRender(self):
        frameList = []
        for node in self.compositeFrames.getiterator("composite-frame"):
            if node.tag == "composite-frame" and node.attrib.get("id") == str(self.internalFrameIndex):
                for frameCallNode in node:
                    for frameNode in self.frames.getiterator("frame"):
                        if frameNode.tag == "frame" and frameNode.attrib.get("id") == frameCallNode.attrib.get("id"):
                            offsetX = (
                                0
                                if frameCallNode.attrib.get("offset-x") == None
                                else float(frameCallNode.attrib.get("offset-x"))
                            )
                            offsetY = (
                                0
                                if frameCallNode.attrib.get("offset-y") == None
                                else float(frameCallNode.attrib.get("offset-y"))
                            )
                            tweenId = frameCallNode.attrib.get("tween")
                            frameInTween = (
                                0
                                if frameCallNode.attrib.get("frame-in-tween") == None
                                else int(frameCallNode.attrib.get("frame-in-tween"))
                            )
                            addWidth = 0 if frameNode.attrib.get("w") == None else float(frameNode.attrib.get("w"))
                            addHeight = 0 if frameNode.attrib.get("h") == None else float(frameNode.attrib.get("h"))
                            sInPixels = 0 if frameNode.attrib.get("s") == None else float(frameNode.attrib.get("s"))
                            tInPixels = 0 if frameNode.attrib.get("t") == None else float(frameNode.attrib.get("t"))
                            swInPixels = sInPixels + addWidth
                            thInPixels = tInPixels + addHeight
                            s = sInPixels / self.baseWidth
                            t = 1 - (
                                tInPixels / self.baseHeight
                            )  # Complemented to deal with loading image upside down.
                            S = swInPixels / self.baseWidth
                            T = 1 - (
                                thInPixels / self.baseHeight
                            )  # Complemented to deal with loading image upside down.
                            blend = (
                                "overwrite"
                                if frameCallNode.attrib.get("blend") == None
                                else frameCallNode.attrib.get("blend")
                            )
                            scaleX = (
                                1
                                if frameCallNode.attrib.get("scale-x") == None
                                else float(frameCallNode.attrib.get("scale-x"))
                            )
                            scaleY = (
                                1
                                if frameCallNode.attrib.get("scale-y") == None
                                else float(frameCallNode.attrib.get("scale-y"))
                            )
                            color = Color(1, 1, 1, 1)
                            tweenHasColor = False
                            frameCallHasColor = False
                            frameCallColorName = frameCallNode.attrib.get("color-name")
                            if frameCallColorName != None:
                                # Get color at frame call as first resort.
                                frameCallHasColor = True
                                for colorNode in self.colors.getiterator("color"):
                                    if colorNode.tag == "color" and colorNode.attrib.get("name") == frameCallColorName:
                                        R = 1 if colorNode.attrib.get("r") == None else float(colorNode.attrib.get("r"))
                                        G = 1 if colorNode.attrib.get("g") == None else float(colorNode.attrib.get("g"))
                                        B = 1 if colorNode.attrib.get("b") == None else float(colorNode.attrib.get("b"))
                                        A = 1 if colorNode.attrib.get("a") == None else float(colorNode.attrib.get("a"))
                                        color = Color(R, G, B, A)
                                        break  # leave for loop when we find the correct color
                                pass

                            if tweenId != None and tweenId != "0":
                                # Get color at tween frame as second resort.
                                thisTween = None
                                frameLength = 1
                                advancementFunction = "linear"
                                foundTween = False
                                pointList = []
                                colorList = []
                                for tweenNode in self.tweens.getiterator("motion-tween"):
                                    if tweenNode.tag == "motion-tween" and tweenNode.attrib.get("id") == tweenId:
                                        foundTween = True
                                        frameLength = (
                                            1
                                            if tweenNode.attrib.get("length-in-frames") == None
                                            else tweenNode.attrib.get("length-in-frames")
                                        )
                                        advancementFunction = (
                                            "linear"
                                            if tweenNode.attrib.get("advancement-function") == None
                                            else tweenNode.attrib.get("advancement-function")
                                        )
                                        for pointOrColorNode in tweenNode.getiterator():
                                            if pointOrColorNode.tag == "point":
                                                pX = (
                                                    0
                                                    if pointOrColorNode.attrib.get("x") == None
                                                    else float(pointOrColorNode.attrib.get("x"))
                                                )
                                                pY = (
                                                    0
                                                    if pointOrColorNode.attrib.get("y") == None
                                                    else float(pointOrColorNode.attrib.get("y"))
                                                )
                                                pointList.append(Point(pX, pY, 0))
                                            elif pointOrColorNode.tag == "color-state":
                                                colorName = (
                                                    "white"
                                                    if pointOrColorNode.attrib.get("name") == None
                                                    else pointOrColorNode.attrib.get("name")
                                                )
                                                for colorNode in self.colors.getiterator("color"):
                                                    if (
                                                        colorNode.tag == "color"
                                                        and colorNode.attrib.get("name") == colorName
                                                    ):
                                                        R = (
                                                            1
                                                            if colorNode.attrib.get("r") == None
                                                            else float(colorNode.attrib.get("r"))
                                                        )
                                                        G = (
                                                            1
                                                            if colorNode.attrib.get("g") == None
                                                            else float(colorNode.attrib.get("g"))
                                                        )
                                                        B = (
                                                            1
                                                            if colorNode.attrib.get("b") == None
                                                            else float(colorNode.attrib.get("b"))
                                                        )
                                                        A = (
                                                            1
                                                            if colorNode.attrib.get("a") == None
                                                            else float(colorNode.attrib.get("a"))
                                                        )
                                                        colorList.append(Color(R, G, B, A))
                                                        break  # leave for loop when we find the correct color reference
                                            pass  # Run through all child nodes of selected tween
                                        break  # Exit after finding correct tween
                                pass
                                if foundTween:
                                    thisTween = Tween(frameLength, advancementFunction, pointList, colorList)
                                    offset = thisTween.XYFromFrame(frameInTween)
                                    offsetFromTweenX = int(offset.X)
                                    offsetFromTweenY = int(offset.Y)
                                    offsetX += int(offset.X)
                                    offsetY += int(offset.Y)
                                    if thisTween.hasColorComponent():
                                        tweenHasColor = True
                                        if frameCallHasColor == False:
                                            color = thisTween.colorFromFrame(frameInTween)
                                    pass
                            if (
                                frameNode.attrib.get("color-name") != None
                                and frameCallHasColor == False
                                and tweenHasColor == False
                            ):
                                # Get color at frame definition as last resort.
                                for colorNode in colors.getiterator("color"):
                                    if colorNode.tag == "color" and colorNode.attrib.get(
                                        "name"
                                    ) == frameNode.attrib.get("color-name"):
                                        R = 1 if colorNode.attrib.get("r") == None else float(colorNode.attrib.get("r"))
                                        G = 1 if colorNode.attrib.get("g") == None else float(colorNode.attrib.get("g"))
                                        B = 1 if colorNode.attrib.get("b") == None else float(colorNode.attrib.get("b"))
                                        A = 1 if colorNode.attrib.get("a") == None else float(colorNode.attrib.get("a"))
                                        color = Color(R, G, B, A)
                                        break  # leave for loop when we find the correct color
                                pass
                            rotationZ = (
                                0
                                if frameCallNode.attrib.get("rotation-z") == None
                                else float(frameCallNode.attrib.get("rotation-z"))
                            )
                            frameList.append(
                                Frame(
                                    Bound(offsetX, offsetY, addWidth, addHeight),
                                    s,
                                    t,
                                    S,
                                    T,
                                    blend,
                                    scaleX,
                                    scaleY,
                                    color,
                                    rotationZ,
                                )
                            )
                    pass
                break  # Leave once we've found the appropriate frame

        # Prepare tracking list of consumed nodes.
        self.clearNodesForDrawing()
        # Make an identifier to tack onto primitive names in Panda3d's scene graph.
        frameIndexForName = 1

        # Loop through loaded frames that make up composite frame.
        for loadedFrame in frameList:
            # For debugging purposes, print the object.
            if False:
                loadedFrame.printAsString()

            # Set up place to store primitive 3d object; note: requires vertex data made by GeomVertexData
            squareMadeByTriangleStrips = GeomTristrips(Geom.UHDynamic)

            # Set up place to hold 3d data and for the following coordinates:
            #   square's points (V3: x, y, z),
            #   the colors at each point of the square (c4: r, g, b, a), and
            #   for the UV texture coordinates at each point of the square     (t2: S, T).
            vertexData = GeomVertexData(
                "square-" + str(frameIndexForName), GeomVertexFormat.getV3c4t2(), Geom.UHDynamic
            )
            vertex = GeomVertexWriter(vertexData, "vertex")
            color = GeomVertexWriter(vertexData, "color")
            texcoord = GeomVertexWriter(vertexData, "texcoord")

            # Add the square's data
            # Upper-Left corner of square
            vertex.addData3f(-loadedFrame.bound.Width / 2.0, 0, -loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R, loadedFrame.color.G, loadedFrame.color.B, loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.s, loadedFrame.T)

            # Upper-Right corner of square
            vertex.addData3f(loadedFrame.bound.Width / 2.0, 0, -loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R, loadedFrame.color.G, loadedFrame.color.B, loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.S, loadedFrame.T)

            # Lower-Left corner of square
            vertex.addData3f(-loadedFrame.bound.Width / 2.0, 0, loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R, loadedFrame.color.G, loadedFrame.color.B, loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.s, loadedFrame.t)

            # Lower-Right corner of square
            vertex.addData3f(loadedFrame.bound.Width / 2.0, 0, loadedFrame.bound.Height / 2.0)
            color.addData4f(loadedFrame.color.R, loadedFrame.color.G, loadedFrame.color.B, loadedFrame.color.A)
            texcoord.addData2f(loadedFrame.S, loadedFrame.t)

            # Pass data to primitive
            squareMadeByTriangleStrips.addNextVertices(4)
            squareMadeByTriangleStrips.closePrimitive()
            square = Geom(vertexData)
            square.addPrimitive(squareMadeByTriangleStrips)
            # Pass primtive to drawing node
            drawPrimitiveNode = GeomNode("square-" + str(frameIndexForName))
            drawPrimitiveNode.addGeom(square)
            # Pass node to scene (effect camera)
            nodePath = self.effectCameraNodePath.attachNewNode(drawPrimitiveNode)
            # Linear dodge:
            if loadedFrame.blendMode == "darken":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MAdd,
                        ColorBlendAttrib.OOneMinusFbufferColor,
                        ColorBlendAttrib.OOneMinusIncomingColor,
                    )
                )
                pass
            elif loadedFrame.blendMode == "multiply":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OFbufferColor, ColorBlendAttrib.OZero)
                )
                pass
            elif loadedFrame.blendMode == "color-burn":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MAdd, ColorBlendAttrib.OZero, ColorBlendAttrib.OOneMinusIncomingColor
                    )
                )
                pass
            elif loadedFrame.blendMode == "linear-burn":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MAdd, ColorBlendAttrib.OZero, ColorBlendAttrib.OIncomingColor
                    )
                )
                pass
            elif loadedFrame.blendMode == "lighten":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MMax, ColorBlendAttrib.OIncomingColor, ColorBlendAttrib.OFbufferColor
                    )
                )
                pass
            elif loadedFrame.blendMode == "color-dodge":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOne)
                )
                pass
            elif loadedFrame.blendMode == "linear-dodge":
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOneMinusIncomingColor
                    )
                )
                pass
            else:  # Overwrite:
                nodePath.setAttrib(
                    ColorBlendAttrib.make(
                        ColorBlendAttrib.MAdd, ColorBlendAttrib.OIncomingAlpha, ColorBlendAttrib.OOneMinusIncomingAlpha
                    )
                )
                pass
            nodePath.setDepthTest(False)
            # Apply texture
            nodePath.setTexture(self.tex)
            # Apply translation, then rotation, then scaling to node.
            nodePath.setPos(
                (
                    loadedFrame.bound.X + loadedFrame.bound.Width / 2.0,
                    1,
                    -loadedFrame.bound.Y - loadedFrame.bound.Height / 2.0,
                )
            )
            nodePath.setR(loadedFrame.rotationZ)
            nodePath.setScale(loadedFrame.scaleX, 1, loadedFrame.scaleY)
            nodePath.setTwoSided(True)
            self.consumedNodesList.append(nodePath)
            frameIndexForName = frameIndexForName + 1
        # Loop continues on through each frame called in the composite frame.
        pass
Ejemplo n.º 48
0
def generate_sphere(name, radius, resolution):
    """
    Generates a sphere with the provided resolution.

    @type name: string
    @param name: Name of this sphere.

    @type radius: number
    @param radius: Radius of sphere in kilometers.

    @type resolution: number
    @param resolution: Resolution of sphere (minimum 2)

    @rtype: GeomNode
    @return: A GeomNode with the given sphere.
    """

    if resolution < 2:
        raise ValueError, "resolution must be >= 2"

    horizBands = resolution*2
    vertBands = horizBands*2

    vertexFormat = GeomVertexFormat.getV3n3c4t2()
    vdata = GeomVertexData('%s_vdata' % name, vertexFormat, Geom.UHDynamic)

    vertex = GeomVertexWriter(vdata, 'vertex')
    color = GeomVertexWriter(vdata, 'color')
    normal = GeomVertexWriter(vdata, 'normal')
    texcoord = GeomVertexWriter(vdata, 'texcoord')

    vertDelta = omath.TWOPI / vertBands
    horizDelta = omath.TWOPI / horizBands

    numVertices = 0

    for i in range(vertBands+1):
        lowTheta = i * vertDelta
        highTheta = (i+1) * vertDelta

        cosLowTheta = math.cos(lowTheta)
        sinLowTheta = math.sin(lowTheta)
        cosHighTheta = math.cos(highTheta)
        sinHighTheta = math.sin(highTheta)

        for j in range(horizBands):
            horizTheta = j * horizDelta

            cosHorizTheta = math.cos(horizTheta)
            sinHorizTheta = math.sin(horizTheta)

            ex = cosLowTheta*cosHorizTheta
            ey = sinLowTheta
            ez = cosLowTheta*sinHorizTheta

            vertex.addData3f(ex*radius, ey*radius, ez*radius)
            normal.addData3f(ex, ey, ez)
            color.addData4f(.75, .75, .75, 1)
            texcoord.addData2f(i / vertBands, j / horizBands)

            ex = cosHighTheta*cosHorizTheta
            ey = sinHighTheta
            ez = cosHighTheta*sinHorizTheta

            vertex.addData3f(ex*radius, ey*radius, ez*radius)
            normal.addData3f(ex, ey, ez)
            color.addData4f(.75, .75, .75, 1)
            texcoord.addData2f(i / vertBands, j / horizBands)

            numVertices += 2

    prim = GeomTristrips(Geom.UHStatic)
    prim.addConsecutiveVertices(0, numVertices)
    prim.closePrimitive()

    geom = Geom(vdata)
    geom.addPrimitive(prim)

    geomNode = GeomNode(name)
    geomNode.addGeom(geom)

    return GeomScaler(geomNode)
Ejemplo n.º 49
0
    def __init__(self, inner, outer, sectors):
        super(RingNode, self).__init__('ring')
        self.inner = inner
        self.outer = outer
        self.sectors = sectors

        ringgeo = RawGeometry()

        # inner and outer radii are the true circular limits, so expand a little bit
        # for the sectored mesh
        mesh_inner = self.inner * 0.9
        mesh_outer = self.outer * 1.1

        angular_width = 2.0 * math.pi / self.sectors
        for sector in range(self.sectors):
            start = sector * angular_width
            end = (sector + 1) * angular_width
            # add a quad
            x0 = math.sin(start) * mesh_inner
            x1 = math.sin(start) * mesh_outer
            x2 = math.sin(end) * mesh_inner
            x3 = math.sin(end) * mesh_outer

            z0 = math.cos(start) * mesh_inner
            z1 = math.cos(start) * mesh_outer
            z2 = math.cos(end) * mesh_inner
            z3 = math.cos(end) * mesh_outer

            index = len(ringgeo.verts)
            ringgeo.verts.append((x0, 0, z0))
            ringgeo.verts.append((x1, 0, z1))
            ringgeo.verts.append((x2, 0, z2))
            ringgeo.verts.append((x3, 0, z3))

            # double-side the faces so they render from either side
            # top pair...
            ringgeo.faces.append((index + 0, index + 1, index + 2))
            ringgeo.faces.append((index + 1, index + 3, index + 2))
            # bottom pair...
            ringgeo.faces.append((index + 0, index + 2, index + 1))
            ringgeo.faces.append((index + 1, index + 2, index + 3))

        format = GeomVertexFormat.getV3n3()
        vdata = GeomVertexData('ring', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')

        for (x, y, z) in ringgeo.verts:
            vertex.addData3f(x, y, z)
            normal.addData3f(0, 1, 0)

        trilist = GeomTriangles(Geom.UHDynamic)

        for (a, b, c) in ringgeo.faces:
            trilist.addVertex(a)
            trilist.addVertex(b)
            trilist.addVertex(c)

        trilist.closePrimitive()
        ring = Geom(vdata)
        ring.addPrimitive(trilist)

        self.addGeom(ring)
Ejemplo n.º 50
0
    def __init__(self,inner,outer,sectors):
        super(RingNode,self).__init__('ring')
        self.inner = inner
        self.outer = outer
        self.sectors = sectors
        
        ringgeo = RawGeometry()
        
        # inner and outer radii are the true circular limits, so expand a little bit 
        # for the sectored mesh
        mesh_inner = self.inner * 0.9
        mesh_outer = self.outer * 1.1
        
        angular_width = 2.0 * math.pi / self.sectors
        for sector in range( self.sectors ):
            start = sector * angular_width
            end = (sector+1) * angular_width
            # add a quad
            x0 = math.sin(start) * mesh_inner
            x1 = math.sin(start) * mesh_outer
            x2 = math.sin(end  ) * mesh_inner
            x3 = math.sin(end  ) * mesh_outer
            
            z0 = math.cos(start) * mesh_inner
            z1 = math.cos(start) * mesh_outer
            z2 = math.cos(end  ) * mesh_inner
            z3 = math.cos(end  ) * mesh_outer
            
            index = len(ringgeo.verts)
            ringgeo.verts.append( (x0, 0, z0) )
            ringgeo.verts.append( (x1, 0, z1) )
            ringgeo.verts.append( (x2, 0, z2) )
            ringgeo.verts.append( (x3, 0, z3) )
            
            # double-side the faces so they render from either side
            # top pair...
            ringgeo.faces.append( (index+0,index+1,index+2) )
            ringgeo.faces.append( (index+1,index+3,index+2) )
            # bottom pair...
            ringgeo.faces.append( (index+0,index+2,index+1) )
            ringgeo.faces.append( (index+1,index+2,index+3) )
            
        format=GeomVertexFormat.getV3n3()
        vdata=GeomVertexData('ring', format, Geom.UHDynamic)

        vertex=GeomVertexWriter(vdata, 'vertex')
        normal=GeomVertexWriter(vdata, 'normal')


        for (x,y,z) in ringgeo.verts:
            vertex.addData3f( x, y, z )
            normal.addData3f( 0, 1, 0 )
            
        trilist=GeomTriangles(Geom.UHDynamic)
        
        for (a,b,c) in ringgeo.faces:
            trilist.addVertex(a)
            trilist.addVertex(b)
            trilist.addVertex(c)
        
        trilist.closePrimitive()
        ring = Geom(vdata)
        ring.addPrimitive( trilist )
        
        self.addGeom( ring )