Skip to content

Potential incorrect Python bindings for implot3d.plot_mesh #320

@codyph

Description

@codyph

First off, thanks for making this amazing package, imgui_bundle is great.

I'm currently using imgui-bundle 1.6.2 on Windows 10 with Python 3.10.
I attempted to plot a simple cube mesh using implot3d and am continuously met with a TypeError.

The original signature for PlotMesh in C++ is:

IMPLOT3D_API void PlotMesh(const char* label_id, const ImPlot3DPoint* vtx, const unsigned int* idx, int vtx_count, int idx_count, ImPlot3DMeshFlags flags = 0)

While in Python, plot_mesh is:

def plot_mesh(label_id: str, vtx: Point, idx: int, vtx_count: int, idx_count: int, flags: MeshFlags = 0) -> None:
    pass

The Python binding appears to expect a single Point and a single int (for indices) rather than lists of them. I may be misunderstanding something, but this is where I expect the error originates from.

Example:

The following example for a cube mesh uses points taken directly from the implot3d github cpp__meshes file.

from imgui_bundle import imgui, immapp, implot3d

# Define cube vertices
cube_vertices = [
    implot3d.Point(-1.0, -1.0, -1.0),
    implot3d.Point( 1.0, -1.0, -1.0),
    implot3d.Point( 1.0,  1.0, -1.0),
    implot3d.Point(-1.0,  1.0, -1.0),
    implot3d.Point(-1.0, -1.0,  1.0),
    implot3d.Point( 1.0, -1.0,  1.0),
    implot3d.Point( 1.0,  1.0,  1.0),
    implot3d.Point(-1.0,  1.0,  1.0),
]

# Define cube indices
cube_indices = [
    0, 1, 2,  0, 2, 3,  # back face
    4, 5, 6,  4, 6, 7,  # front face
    0, 1, 5,  0, 5, 4,  # bottom face
    2, 3, 7,  2, 7, 6,  # top face
    1, 2, 6,  1, 6, 5,  # right face
    3, 0, 4,  3, 4, 7,  # left face
]

def gui():
    imgui.text("Cube Mesh with ImPlot3D")
    if implot3d.begin_plot("Cube Plot", (600, 400)):

        # Calling plot_mesh
        implot3d.plot_mesh("Cube", cube_vertices, cube_indices, len(cube_vertices), len(cube_indices))
        implot3d.end_plot()

if __name__ == "__main__":
    immapp.run(gui, with_implot3d=True, window_size=(800, 600))

Commenting out the plot_mesh line above causes the GUI to load normally with an empty 3D plot.

The specific TypeError I get in return is:

TypeError: plot_mesh(): incompatible function arguments. The following argument types are supported:
    1. plot_mesh(label_id: str, vtx: imgui_bundle._imgui_bundle.implot3d.Point, idx: int, vtx_count: int, idx_count: int, flags: int = 0) -> None

Invoked with types: str, list, list, int, int

I hope this is enough information to reproduce and diagnose the issue.
Thanks again for this great package, I hope to use the plot_mesh function with Python soon!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions