Beispiel #1
0
    def create_geom_node(self):
        xyzero = False

        i = 0
        for i, x in enumerate(self.normal):
            if x == 1:
                xyzero = True
                break

        # vt=tuple(self.vertices)

        t = Triangulator()
        fmt = GeomVertexFormat.getV3cp()
        vdata = GeomVertexData('name', fmt, Geom.UHStatic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        _ = GeomVertexWriter(vdata, 'color')

        for point in self._vertices:
            (x, y, z) = point
            v = (x, y)
            if not xyzero:
                v = (x, y)
            elif i == 0:
                v = (y, z)
            elif i == 1:
                v = (x, z)
            elif i == 2:
                v = (x, y)

            t.addPolygonVertex(t.addVertex(*v))
            vertex.addData3f(x, y, z)
        t.triangulate()
        prim = GeomTriangles(Geom.UHStatic)

        for n in range(t.getNumTriangles()):
            prim.addVertices(t.getTriangleV0(n), t.getTriangleV1(n),
                             t.getTriangleV2(n))

        prim.closePrimitive()
        geom = Geom(vdata)
        geom.addPrimitive(prim)
        node = GeomNode('gnode')
        node.addGeom(geom)

        return node
Beispiel #2
0
	def draw_vert(self,v, v_color):
		format = GeomVertexFormat.getV3cp()
		vdata=GeomVertexData('vert', format, Geom.UHDynamic)
		vertex=GeomVertexWriter(vdata, 'vertex')
		color=GeomVertexWriter(vdata, 'color')
		vertex.addData3f(0.0,0.0,0.0)
		color.addData4f(v_color)		
		mesh = Geom(vdata)
		point = GeomPoints(Geom.UHDynamic)
		point.addVertex(0)
		point.closePrimitive()
		mesh.addPrimitive(point)
		vert_node = GeomNode(self.mesh.name+'_vert_'+str(v.ID))
		vert_node.addGeom(mesh)
		vert_node.setTag('ID',str(v.ID))
		rendered_vert = self.render_root.attachNewNode(vert_node)
		rendered_vert.setPos(v.pos.x,v.pos.y,v.pos.z)
		rendered_vert.setRenderModeThickness(5.0)
		self.render_nodes['vert_'+str(v.ID)] = rendered_vert
Beispiel #3
0
 def draw_vert(self, v, v_color):
     format = GeomVertexFormat.getV3cp()
     vdata = GeomVertexData('vert', format, Geom.UHDynamic)
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     vertex.addData3f(0.0, 0.0, 0.0)
     color.addData4f(v_color)
     mesh = Geom(vdata)
     point = GeomPoints(Geom.UHDynamic)
     point.addVertex(0)
     point.closePrimitive()
     mesh.addPrimitive(point)
     vert_node = GeomNode(self.mesh.name + '_vert_' + str(v.ID))
     vert_node.addGeom(mesh)
     vert_node.setTag('ID', str(v.ID))
     rendered_vert = self.render_root.attachNewNode(vert_node)
     rendered_vert.setPos(v.pos.x, v.pos.y, v.pos.z)
     rendered_vert.setRenderModeThickness(5.0)
     self.render_nodes['vert_' + str(v.ID)] = rendered_vert
Beispiel #4
0
    def _build_grid(self):
        color = getattr(self.parameters, "color", (0, 0, 0, 0))

        node = NodePath(self.identifier)
        sx = self.grid.maxx - self.grid.minx + 1
        sy = self.grid.maxy - self.grid.miny + 1

        # 1. the squares
        squares = {}
        card = CardMaker('')
        cardgeom = NodePath(card.generate())
        for n in range(sx):
            for nn in range(sy):
                square = NodePath(self.identifier + '-square-%d-%d' %
                                  (n + 1, nn + 1))
                cardgeom.instanceTo(square)
                square.setPos(float(n) / sx, 0, -float(nn + 1) / sy)
                square.setScale(1.0 / sx, 1, 1.0 / sy)
                square.setColor(0, 0, 0, 1)
                square.reparentTo(node)
                squares[n, nn] = square

                #2: the lines
        gnode = GeomNode(self.identifier + "-lines")
        vformat = GeomVertexFormat.getV3cp()
        vdata = GeomVertexData(self.identifier + '-lines', vformat,
                               Geom.UHStatic)
        v_vertex = GeomVertexWriter(vdata, 'vertex')
        v_colors = GeomVertexWriter(vdata, 'color')

        for n in range(sx + 1):
            px = float(n) / sx
            v_vertex.addData3f(px, 0.0, 0.0)
            v_colors.addData4f(*color)
            v_vertex.addData3f(px, 0, -1)
            v_colors.addData4f(*color)
        for n in range(sy + 1):
            py = float(n) / sy
            v_vertex.addData3f(0.0, 0.0, -py)
            v_colors.addData4f(*color)
            v_vertex.addData3f(1.0, 0, -py)
            v_colors.addData4f(*color)

        geom = Geom(vdata)
        prim = GeomLines(Geom.UHStatic)
        for n in range(sx + 1):
            prim.addVertex(2 * n)
            prim.addVertex(2 * n + 1)
        for n in range(sy + 1):
            prim.addVertex(2 * (sx + n + 1))
            prim.addVertex(2 * (sx + n + 1) + 1)

        prim.closePrimitive()
        geom.addPrimitive(prim)

        gnode.addGeom(geom)
        node1 = NodePath(gnode)
        node1.reparentTo(node)

        self.node, self.squares, self.sx, self.sy = node, squares, sx, sy
        self.node.reparentTo(self.parentnode)