Beispiel #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) 
Beispiel #2
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)
Beispiel #3
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) 
Beispiel #4
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)
Beispiel #5
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) 
Beispiel #6
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)
Beispiel #7
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)