예제 #1
0
    def __init__(self, size, translation, rotation, color, text):
        self._visible = False
        wy, wx, wz = size[0], size[1], size[2]
        format = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData('cu_points', format, Geom.UHStatic)
        vdata.setNumRows(8)
        self._pos_writer = GeomVertexWriter(vdata, 'vertex')
        self._color_writer = GeomVertexWriter(vdata, 'color')
        self._pos_writer.set_row(0)
        self._color_writer.set_row(0)
        self._pos_writer.addData3f(-0.5 * wx, -0.5 * wy, 0.)
        self._pos_writer.addData3f(-0.5 * wx, -0.5 * wy, wz)
        self._pos_writer.addData3f(0.5 * wx, -0.5 * wy, wz)
        self._pos_writer.addData3f(0.5 * wx, -0.5 * wy, 0.)
        self._pos_writer.addData3f(-0.5 * wx, 0.5 * wy, 0.)
        self._pos_writer.addData3f(-0.5 * wx, 0.5 * wy, wz)
        self._pos_writer.addData3f(0.5 * wx, 0.5 * wy, wz)
        self._pos_writer.addData3f(0.5 * wx, 0.5 * wy, 0.)
        for i in range(8):
            self._color_writer.addData4f(color[0], color[1], color[2],
                                         color[3])

        lines = GeomLines(Geom.UHStatic)
        lines.addVertices(0, 1)
        lines.addVertices(1, 2)
        lines.addVertices(2, 3)
        lines.addVertices(3, 0)
        lines.addVertices(4, 5)
        lines.addVertices(5, 6)
        lines.addVertices(6, 7)
        lines.addVertices(7, 4)
        lines.addVertices(0, 4)
        lines.addVertices(1, 5)
        lines.addVertices(2, 6)
        lines.addVertices(3, 7)
        cuboid = Geom(vdata)
        cuboid.addPrimitive(lines)
        node = GeomNode('cuboid')
        node.addGeom(cuboid)
        self._node_path = NodePath(node)
        # self.title = OnscreenText(text=text, style=1, fg=(1, 1, 1, 1), pos=(-0.1, 0.1), scale=.05,
        #                           parent=self._node_path, align=TextNode.ARight)

        self._txt_node = TextNode('id')
        self._txt_node.setText(text)
        self._txt_node.setTextScale(0.2)
        self._txt_node.setCardColor(0, 0, 1, 1)
        self._txt_node.setCardAsMargin(0, 0, 0, 0)
        self._txt_node.setCardDecal(True)
        self._txt_node.set_align(2)
        text_geom = GeomNode('text')
        text_geom.addChild(self._txt_node)
        self._txt_np = NodePath(text_geom)
        self._txt_np.reparentTo(self._node_path)

        self.show()
        self.update_values(size, translation, rotation, color, text)
예제 #2
0
    def __init__(self, max_r):
        self.max_r = max_r
        format = GeomVertexFormat.getV3c4()
        vdata = GeomVertexData('point', format, Geom.UHDynamic)
        self._pos_writer = GeomVertexWriter(vdata, 'vertex')
        self._color_writer = GeomVertexWriter(vdata, 'color')

        line_num = 60
        vdata.setNumRows(line_num)

        angles = np.linspace(0, np.pi * 2 - np.pi * 2 / line_num, line_num)

        other_rgba = (0., 0., 0.3, 0.1)
        other2_rgba = (0.1, 0.1, 0.4, 0.4)
        axis_rgba = (0.2, 0.2, 0.5, 1.0)
        max_r = 250
        for indx, angle in enumerate(angles):
            if indx % 5 == 0:
                rgba = axis_rgba
            else:
                rgba = other_rgba
            self._pos_writer.addData3d(0, 0, 0.)
            self._color_writer.addData4f(rgba[0], rgba[1], rgba[2], rgba[3])
            self._pos_writer.addData3d(max_r * np.sin(angle),
                                       max_r * np.cos(angle), 0.)
            self._color_writer.addData4f(rgba[0], rgba[1], rgba[2], rgba[3])

        grnd_prmtv = GeomLines(Geom.UHStatic)
        grnd_prmtv.addConsecutiveVertices(0, 2 * line_num)
        grnd_prmtv.closePrimitive()
        ground_geom = Geom(vdata)
        ground_geom.addPrimitive(grnd_prmtv)
        snode = GeomNode('ground_lines')
        snode.addGeom(ground_geom)

        self.points_node = base.render.attachNewNode(snode)
        self.points_node.setTwoSided(True)

        for rad in range(int(max_r)):
            color = axis_rgba
            pp = makeArc(angleDegrees=360,
                         numSteps=160,
                         scale=rad,
                         color=color)
            tn = TextNode('dd')
            tn.setText(str(rad))
            tn.setTextScale(0.2)
            tn.setTextColor(color)
            text_geom = GeomNode('text')
            text_geom.addChild(tn)
            tp = NodePath(text_geom)
            tp.setPos((0, rad - 0.2, 0))
            tp.setHpr((0, -90, 0))
            tp.reparentTo(self.points_node)
            pp.reparentTo(self.points_node)