Exemplo n.º 1
0
    def _get_geom_data_plate(build_plate_size: LVector2d,
                             name: str = "") -> GeomVertexData:
        """Generate build plate GeomVertexData.

        Parameters
        ----------
        build_plate_size : LVector2d
            Build plate size.
        name : str
            Name for the generated GeomVertexData.
        """
        # noinspection PyArgumentList
        geom_data = GeomVertexData(name, GeomVertexFormat.get_v3t2(),
                                   Geom.UHStatic)
        geom_data.setNumRows(4)

        writer_vertex = GeomVertexWriter(geom_data, "vertex")
        writer_texture = GeomVertexWriter(geom_data, "texcoord")

        # Add build plate vertices
        writer_vertex.addData3d(0, 0, 0)
        writer_vertex.addData3d(build_plate_size.x, 0, 0)
        writer_vertex.addData3d(build_plate_size.x, build_plate_size.y, 0)
        writer_vertex.addData3d(0, build_plate_size.y, 0)

        for uv in [(0, 0), (1, 0), (1, 1), (0, 1)]:
            writer_texture.addData2(*uv)

        return geom_data
Exemplo n.º 2
0
    def __init__(self, base):
        # Load texture
        tex = Loader(base).loadTexture((Path(path.realpath(__file__)).parent.parent.parent / "res/images/checkerboard.png").absolute())
        tex.setMagfilter(SamplerState.FT_nearest)
        tex.setMinfilter(SamplerState.FT_nearest)

        # Set up vertex data
        vdata = GeomVertexData("floor_data", GeomVertexFormat.get_v3t2(), Geom.UHStatic)
        vdata.setNumRows(6)
        vertex = GeomVertexWriter(vdata, "vertex")
        texcoord = GeomVertexWriter(vdata, "texcoord")

        vertex.addData3(-5, -5, 0)
        texcoord.addData3(0, 0, 0)
        vertex.addData3(-5, 5, 0)
        texcoord.addData3(0, 10, 0)
        vertex.addData3(5, 5, 0)
        texcoord.addData3(10, 10, 0)

        vertex.addData3(5, 5, 0)
        texcoord.addData3(10, 10, 0)
        vertex.addData3(5, -5, 0)
        texcoord.addData3(10, 0, 0)
        vertex.addData3(-5, -5, 0)
        texcoord.addData3(0, 0, 0)

        # Create primitive
        prim = GeomTriangles(Geom.UHStatic)
        prim.addVertices(0, 1, 2)
        prim.addVertices(3, 4, 5)
        geom = Geom(vdata)
        geom.add_primitive(prim)

        # Initialize geometry node
        GeomNode.__init__(self, "floor")
        attrib = TextureAttrib.make(tex)
        state = RenderState.make(attrib)
        self.addGeom(geom, state)
Exemplo n.º 3
0
def make_points(vertices, colors=None, texture_coords=None, geom=None):
    """Make or update existing points set geometry.

    Arguments:
        root_path {str} -- path to the group's root node
        name {str} -- node name within a group
        vertices {list} -- point coordinates (and other data in a point cloud format)

    Keyword Arguments:
        colors {list} -- colors (default: {None})
        texture_coords {list} -- texture coordinates (default: {None})
        geom {Geom} -- geometry to update (default: {None})

    Returns:
        Geom -- p3d geometry
    """
    if not isinstance(vertices, np.ndarray):
        vertices = np.asarray(vertices, dtype=np.float32)

    if colors is not None:
        if not isinstance(colors, np.ndarray):
            colors = np.asarray(colors)
        if colors.dtype != np.uint8:
            colors = np.uint8(colors * 255)
        vertices = np.column_stack((
            vertices.view(dtype=np.uint32).reshape(-1, 3),
            colors.view(dtype=np.uint32)))

    if texture_coords is not None:
        if not isinstance(texture_coords, np.ndarray):
            texture_coords = np.asarray(texture_coords)
        vertices = np.column_stack((
            vertices.view(dtype=np.uint32).reshape(-1, 3),
            texture_coords.view(dtype=np.uint32).reshape(-1, 2)))

    data = vertices.tostring()

    if geom is None:
        if vertices.strides[0] == 12:
            vformat = GeomVertexFormat.get_v3()
        elif vertices.strides[0] == 16:
            vformat = GeomVertexFormat.get_v3c4()
        elif vertices.strides[0] == 20:
            vformat = GeomVertexFormat.get_v3t2()
        else:
            raise ViewerError('Incompatible point clout format: {},{}'.format(
                vertices.dtype, vertices.shape))

        vdata = GeomVertexData('vdata', vformat, Geom.UHDynamic)
        vdata.unclean_set_num_rows(len(vertices))
        vdata.modify_array_handle(0).set_subdata(0, len(data), data)

        prim = GeomPoints(Geom.UHDynamic)
        prim.clear_vertices()
        prim.add_consecutive_vertices(0, len(vertices))
        prim.close_primitive()

        geom = Geom(vdata)
        geom.add_primitive(prim)
    else:
        vdata = geom.modify_vertex_data()
        vdata.unclean_set_num_rows(len(vertices))
        vdata.modify_array_handle(0).set_subdata(0, len(data), data)

        prim = geom.modify_primitive(0)
        prim.clear_vertices()
        prim.add_consecutive_vertices(0, len(vertices))
        prim.close_primitive()

    return geom