plot2gltf


Nameplot2gltf JSON
Version 1.0.7 PyPI version JSON
download
home_pageNone
SummaryA module for creating GLTF files with various geometric primitives and 3D text labels.
upload_time2024-11-06 20:14:39
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # plot2gltf

A [Claude](https://claude.ai)-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](<https://modelviewer.dev>)
- Online viewers like <https://gltf-viewer.donmccurdy.com/>
- [Three.js](https://threejs.org)-based web viewers
- [Blender](http://blender.org)

Key features:

1. 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
2. Automatic color generation using the golden ratio for visually distinct colors
3. Optional manual color specification
4. All geometries are combined into a single GLTF file
5. Proper material setup with metallic-roughness PBR workflow

It is meant to be as easy to use as generating a 3D [matplotlib](https://matplotlib.org) plot.

## Example

```python
# 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:

1. Geometric Primitives:
   - Triangles (cube and house)
   - Lines (coordinate axes)
   - Points (spiral pattern)
   - Normals (orientation vectors)

2. Text Features:
   - Different sizes
   - Different colors
   - Labels for geometric objects
   - Stand-alone text examples

3. Color Usage:
   - Manual color specification
   - Automatic color generation
   - Different colors for different object types

4. 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.

![All the things the demo file showcases](demo_scene.png "demo_scene.gltf")

## License

Public Domain ([CC0](https://creativecommons.org/public-domain/cc0/))

The included [DejaVu font](https://dejavu-fonts.github.io) has its own (free) license.

## Publish to PyPi

Increment `__version__`. Commit changes.

```
FLIT_USERNAME=__token__ flit publish
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "plot2gltf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Yotam Gingold <yotam@yotamgingold.com>",
    "download_url": "https://files.pythonhosted.org/packages/32/98/6f02382f5779483678007a02f963952c63e34f97daa2b157f61b49a6929d/plot2gltf-1.0.7.tar.gz",
    "platform": null,
    "description": "# plot2gltf\n\nA [Claude](https://claude.ai)-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:\n\n- [The `<model-viewer>` tag](<https://modelviewer.dev>)\n- Online viewers like <https://gltf-viewer.donmccurdy.com/>\n- [Three.js](https://threejs.org)-based web viewers\n- [Blender](http://blender.org)\n\nKey features:\n\n1. Supports multiple geometry types:\n    - Triangle meshes\n    - Line segments and line strips (as hairlines or cylinder tubes)\n    - Points (as dots or spheres)\n    - Normal vectors (as lines or arrows)\n    - Text labels\n2. Automatic color generation using the golden ratio for visually distinct colors\n3. Optional manual color specification\n4. All geometries are combined into a single GLTF file\n5. Proper material setup with metallic-roughness PBR workflow\n\nIt is meant to be as easy to use as generating a 3D [matplotlib](https://matplotlib.org) plot.\n\n## Example\n\n```python\n# Example usage:\nfrom plot2gltf import GLTFGeometryExporter\n\nexporter = GLTFGeometryExporter()\n\n# Add a triangle mesh\nvertices = [\n    [0, 0, 0],\n    [1, 0, 0],\n    [0, 1, 0]\n]\nfaces = [[0, 1, 2]]\nexporter.add_triangles(vertices, faces, color=(1, 0, 0))  # Red triangles\n\n# Add some lines\nline_vertices = [\n    [0, 0, 0],\n    [1, 1, 1]\n]\nedges = [[0, 1]]\nexporter.add_lines(line_vertices, edges)  # Auto-generated color\n\n# Create a square as a line strip\npoints = [\n    [0,0,0],\n    [1,0,0],\n    [1,1,0],\n    [0,1,0]\n]\nexporter.add_linestrip(points, color=(1,0,0))  # Creates a line strip\n# The same but as cylinders with sphere mitering and endcaps\nexporter.add_cylinder_strips(points, color=(1,0,0), radius=0.03, add_spheres=True)\n\n# Add labels for some points\nexporter.add_text([0, 0, 0.1], \"Origin\", size=0.2, color=(1, 1, 1))  # White text\nexporter.add_text([1, 1, 1.1], \"Point 2\", size=0.3)  # Auto-colored text\n\n# Or for a curve\nt = np.linspace(0, 2*np.pi, 50)\ncurve_points = np.column_stack([\n    np.cos(t),\n    np.sin(t),\n    np.zeros_like(t)\n])\nexporter.add_linestrip(curve_points, color=(0,1,0))  # Creates a smooth curve\n# The same but as cylinders with sphere mitering and endcaps\nexporter.add_cylinder_strips(curve_points, color=(0,1,0), radius=0.03, add_spheres=True)\n\n# Add points\npoints = [\n    [0, 0, 0],\n    [1, 0, 0],\n    [0, 1, 0]\n]\nexporter.add_points(points, color=(0, 1, 0))  # Green points\n# The same but as spheres\nexporter.add_spheres(points, color=(0, 1, 0))  # Green points\n\n# Add normals\nnormal_points = [[0, 0, 0]]\nnormal_directions = [[0, 0, 1]]\nexporter.add_normals(normal_points, normal_directions, color=(0, 0, 1))  # Blue normals\n# The same but as cylinders with cone caps\nexporter.add_normal_arrows(\n            normal_points, normal_directions, color=(0, 0, 1),\n            shaft_radius=0.02, head_radius=0.04\n        )\n\n# Save the file\nexporter.save(\"output.gltf\")\n```\n\n## Installation\n\n```\npip install plot2gltf\n```\n\nIf you want to hack on it, you can just copy the `plot2gltf` directory and install dependencies via:\n\n```\npip install -r requirements.txt\n```\n\n## Demo\n\nThere is a weird, Claude-generated comprehensive demo. Run it via:\n\n```\npython demo.py\n```\n\nThe output file is named `demo_scene.gltf`.\n\nThis demo file showcases:\n\n1. Geometric Primitives:\n   - Triangles (cube and house)\n   - Lines (coordinate axes)\n   - Points (spiral pattern)\n   - Normals (orientation vectors)\n\n2. Text Features:\n   - Different sizes\n   - Different colors\n   - Labels for geometric objects\n   - Stand-alone text examples\n\n3. Color Usage:\n   - Manual color specification\n   - Automatic color generation\n   - Different colors for different object types\n\n4. Complex Shapes:\n   - A cube with multiple faces\n   - A spiral point cloud\n   - A simple house shape\n   - Coordinate axes\n\nThe scene includes a variety of objects arranged in a way that makes it easy to see all the features.\n\n![All the things the demo file showcases](demo_scene.png \"demo_scene.gltf\")\n\n## License\n\nPublic Domain ([CC0](https://creativecommons.org/public-domain/cc0/))\n\nThe included [DejaVu font](https://dejavu-fonts.github.io) has its own (free) license.\n\n## Publish to PyPi\n\nIncrement `__version__`. Commit changes.\n\n```\nFLIT_USERNAME=__token__ flit publish\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A module for creating GLTF files with various geometric primitives and 3D text labels.",
    "version": "1.0.7",
    "project_urls": {
        "Home": "https://github.com/yig/plot2gltf"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "73d4a9b153033b23f1b1b411a649ca6363aaa963efb608ba57e5bcd20130a9f0",
                "md5": "3fd21d5f0dc8c1dea0be2b615631e376",
                "sha256": "e565ae701502cd28ce6d31c5274b9814b996cd4a035f136ebf1dd978de8b0583"
            },
            "downloads": -1,
            "filename": "plot2gltf-1.0.7-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3fd21d5f0dc8c1dea0be2b615631e376",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 222315,
            "upload_time": "2024-11-06T20:14:37",
            "upload_time_iso_8601": "2024-11-06T20:14:37.988862Z",
            "url": "https://files.pythonhosted.org/packages/73/d4/a9b153033b23f1b1b411a649ca6363aaa963efb608ba57e5bcd20130a9f0/plot2gltf-1.0.7-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "32986f02382f5779483678007a02f963952c63e34f97daa2b157f61b49a6929d",
                "md5": "e1ad427d69968edd62e4d86a1cc0e4d2",
                "sha256": "729e7b4a6e884b7ca5a574bd0b54185c3dccb4d29e1e4eda53c511b98ec7fb75"
            },
            "downloads": -1,
            "filename": "plot2gltf-1.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "e1ad427d69968edd62e4d86a1cc0e4d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 351655,
            "upload_time": "2024-11-06T20:14:39",
            "upload_time_iso_8601": "2024-11-06T20:14:39.694140Z",
            "url": "https://files.pythonhosted.org/packages/32/98/6f02382f5779483678007a02f963952c63e34f97daa2b157f61b49a6929d/plot2gltf-1.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-06 20:14:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yig",
    "github_project": "plot2gltf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "plot2gltf"
}
        
Elapsed time: 0.37939s