plot2gltf
A Claude-created Python module to save different types of simple geometry and annotations to glTF. You can view the result in any GLTF viewer, such as:
- The
<model-viewer>tag - Online viewers like https://gltf-viewer.donmccurdy.com/
- Three.js-based web viewers
- Blender
Key features:
- Supports multiple geometry types:
- Triangle meshes
- Line segments and line strips (as hairlines or cylinder tubes)
- Points (as dots or spheres)
- Normal vectors (as lines or arrows)
- Text labels
- Automatic color generation using the golden ratio for visually distinct colors
- Optional manual color specification
- All geometries are combined into a single GLTF file
- Proper material setup with metallic-roughness PBR workflow
It is meant to be as easy to use as generating a 3D matplotlib plot.
Example
# Example usage:
from plot2gltf import GLTFGeometryExporter
exporter = GLTFGeometryExporter()
# Add a triangle mesh
vertices = [
[0, 0, 0],
[1, 0, 0],
[0, 1, 0]
]
faces = [[0, 1, 2]]
exporter.add_triangles(vertices, faces, color=(1, 0, 0)) # Red triangles
# Add some lines
line_vertices = [
[0, 0, 0],
[1, 1, 1]
]
edges = [[0, 1]]
exporter.add_lines(line_vertices, edges) # Auto-generated color
# Create a square as a line strip
points = [
[0,0,0],
[1,0,0],
[1,1,0],
[0,1,0]
]
exporter.add_linestrip(points, color=(1,0,0)) # Creates a line strip
# The same but as cylinders with sphere mitering and endcaps
exporter.add_cylinder_strips(points, color=(1,0,0), radius=0.03, add_spheres=True)
# Add labels for some points
exporter.add_text([0, 0, 0.1], "Origin", size=0.2, color=(1, 1, 1)) # White text
exporter.add_text([1, 1, 1.1], "Point 2", size=0.3) # Auto-colored text
# Or for a curve
t = np.linspace(0, 2*np.pi, 50)
curve_points = np.column_stack([
np.cos(t),
np.sin(t),
np.zeros_like(t)
])
exporter.add_linestrip(curve_points, color=(0,1,0)) # Creates a smooth curve
# The same but as cylinders with sphere mitering and endcaps
exporter.add_cylinder_strips(curve_points, color=(0,1,0), radius=0.03, add_spheres=True)
# Add points
points = [
[0, 0, 0],
[1, 0, 0],
[0, 1, 0]
]
exporter.add_points(points, color=(0, 1, 0)) # Green points
# The same but as spheres
exporter.add_spheres(points, color=(0, 1, 0)) # Green points
# Add normals
normal_points = [[0, 0, 0]]
normal_directions = [[0, 0, 1]]
exporter.add_normals(normal_points, normal_directions, color=(0, 0, 1)) # Blue normals
# The same but as cylinders with cone caps
exporter.add_normal_arrows(
normal_points, normal_directions, color=(0, 0, 1),
shaft_radius=0.02, head_radius=0.04
)
# Save the file
exporter.save("output.gltf")
Installation
pip install plot2gltf
If you want to hack on it, you can just copy the plot2gltf directory and install dependencies via:
pip install -r requirements.txt
Demo
There is a weird, Claude-generated comprehensive demo. Run it via:
python demo.py
The output file is named demo_scene.gltf.
This demo file showcases:
-
Geometric Primitives:
- Triangles (cube and house)
- Lines (coordinate axes)
- Points (spiral pattern)
- Normals (orientation vectors)
-
Text Features:
- Different sizes
- Different colors
- Labels for geometric objects
- Stand-alone text examples
-
Color Usage:
- Manual color specification
- Automatic color generation
- Different colors for different object types
-
Complex Shapes:
- A cube with multiple faces
- A spiral point cloud
- A simple house shape
- Coordinate axes
The scene includes a variety of objects arranged in a way that makes it easy to see all the features.
License
Public Domain (CC0)
The included DejaVu font has its own (free) license.
Publish to PyPi
Increment __version__. Commit changes.
FLIT_USERNAME=__token__ flit publish
Metadata
Release files for plot2gltf 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| plot2gltf-1.0.7.tar.gz | 351.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| plot2gltf-1.0.7-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 574.0 kB
Release files / plot2gltf-1.0.7.tar.gz
| Download URL | plot2gltf-1.0.7.tar.gz |
|---|---|
| Size | 351.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
729e7b4a6e884b7ca5a574bd0b54185c3dccb4d29e1e4eda53c511b98ec7fb75
|
|
BLAKE2b-256 checksum How to use checksums |
32986f02382f5779483678007a02f963952c63e34f97daa2b157f61b49a6929d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / plot2gltf-1.0.7-py2.py3-none-any.whl
| Download URL | plot2gltf-1.0.7-py2.py3-none-any.whl |
|---|---|
| Size | 222.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e565ae701502cd28ce6d31c5274b9814b996cd4a035f136ebf1dd978de8b0583
|
|
BLAKE2b-256 checksum How to use checksums |
73d4a9b153033b23f1b1b411a649ca6363aaa963efb608ba57e5bcd20130a9f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Security for plot2gltf 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.