Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8305,9 +8305,7 @@ name = "raw_mesh"
version = "0.27.0-alpha.8+dev"
dependencies = [
"anyhow",
"bytes",
"clap",
"gltf",
"rerun",
]

Expand Down
83 changes: 58 additions & 25 deletions examples/python/raw_mesh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ thumbnail_dimensions = [480, 480]
channel = "release"
-->

Demonstrates logging of raw 3D mesh data (so-called "triangle soups") with simple material properties and their transform hierarchy.
Demonstrates how to construct and log raw 3D mesh data (so-called "triangle soups") programmatically from scratch.

Note that while this example loads GLTF meshes to illustrate [`Mesh3D`](https://rerun.io/docs/reference/types/archetypes/mesh3d)'s abilitites, you can also send various kinds of mesh assets
directly via [`Asset3D`](https://rerun.io/docs/reference/types/archetypes/asset3d).
This example shows how to create mesh geometry by manually defining vertices, normals, colors, and texture coordinates for various geometric primitives, each demonstrating different features of the [`Mesh3D`](https://rerun.io/docs/reference/types/archetypes/mesh3d) archetype.

<!-- TODO(#1957): How about we load something elseto avoid confusion? -->
If you want to log existing mesh files (like GLTF, OBJ, STL, etc.), use the [`Asset3D`](https://rerun.io/docs/reference/types/archetypes/asset3d) archetype instead.

<picture data-inline-viewer="examples/raw_mesh">
<img src="https://static.rerun.io/raw_mesh/d5d008b9f1b53753a86efe2580443a9265070b77/full.png" alt="">
Expand All @@ -25,43 +24,77 @@ directly via [`Asset3D`](https://rerun.io/docs/reference/types/archetypes/asset3
[`Transform3D`](https://www.rerun.io/docs/reference/types/archetypes/transform3d), [`Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d)

## Background
Raw 3D mesh data refers to the basic geometric representation of a three-dimensional object, typically composed of interconnected triangles.
These triangles collectively form the surface of the object, defining its shape and structure in a digital environment.
Rerun was employed to visualize and manage this raw mesh data, along with its associated simple material properties and transform hierarchy.
Raw 3D mesh data refers to the basic geometric representation of a three-dimensional object, typically composed of interconnected triangles (vertices, edges, and faces). This example demonstrates how to construct such data programmatically without loading external files.

## Geometric Primitives

The example generates several geometric primitives, each showcasing different `Mesh3D` features:

### Cube (per-vertex colors)
A cube where each face has a different color, demonstrating how to use `vertex_colors` for per-vertex coloring.

### Pyramid (UV texture)
A four-sided pyramid with UV texture coordinates and a procedurally generated checkerboard texture, demonstrating `vertex_texcoords` and `albedo_texture`.

### Sphere (smooth shading)
A UV sphere with vertex normals for smooth shading, demonstrating `vertex_normals` and `albedo_factor`.

### Icosahedron (flat shading)
A 20-sided regular polyhedron rendered without vertex normals, resulting in flat-shaded faces.

## Logging and visualizing with Rerun

The visualizations in this example were created with the following Rerun code:

### 3D mesh data
The raw 3D mesh data are logged as [`Mesh3D`](https://www.rerun.io/docs/reference/types/archetypes/mesh3d) objects, and includes details about vertex positions, colors, normals, texture coordinates, material properties, and face indices for an accurate reconstruction and visualization.
### Cube with vertex colors
```python
rr.log(
"world/cube",
rr.Mesh3D(
vertex_positions=cube["vertex_positions"],
vertex_colors=cube["vertex_colors"],
triangle_indices=cube["triangle_indices"],
),
)
```

### Pyramid with texture
```python
rr.log(
path,
"world/pyramid",
rr.Mesh3D(
vertex_positions=mesh.vertices,
vertex_colors=vertex_colors,
vertex_normals=mesh.vertex_normals,
vertex_texcoords=vertex_texcoords,
albedo_texture=albedo_texture,
triangle_indices=mesh.faces,
albedo_factor=albedo_factor,
vertex_positions=pyramid["vertex_positions"],
vertex_texcoords=pyramid["vertex_texcoords"],
albedo_texture=texture,
triangle_indices=pyramid["triangle_indices"],
),
)
```
Through Rerun's [`Transform3D`](https://www.rerun.io/docs/reference/types/archetypes/transform3d) archetype, essential details are captured to ensure precise positioning and orientation of meshes within the 3D scene.

### Sphere with smooth shading
```python
rr.log(
path,
rr.Transform3D(
translation=trimesh.transformations.translation_from_matrix(world_from_mesh),
mat3x3=world_from_mesh[0:3, 0:3],
"world/sphere",
rr.Mesh3D(
vertex_positions=sphere["vertex_positions"],
vertex_normals=sphere["vertex_normals"],
albedo_factor=np.array([100, 150, 255, 255], dtype=np.uint8),
triangle_indices=sphere["triangle_indices"],
),
)
```

### Icosahedron with flat shading
```python
rr.log(
"world/icosahedron",
rr.Mesh3D(
vertex_positions=icosahedron["vertex_positions"],
albedo_factor=np.array([255, 180, 100, 255], dtype=np.uint8),
triangle_indices=icosahedron["triangle_indices"],
),
)
```

## Run the code
To run this example, make sure you have the Rerun repository checked out and the latest SDK installed:
Expand All @@ -79,11 +112,11 @@ To experiment with the provided example, simply execute the main Python script:
```bash
python -m raw_mesh # run the example
```
You can specify scene:
You can customize the sphere subdivisions for more or less detail:
```bash
python -m raw_mesh --scene {lantern,avocado,buggy,brain_stem}
python -m raw_mesh --sphere-subdivisions 64
```
If you wish to customize it, explore additional features, or save it use the CLI with the `--help` option for guidance:
If you wish to explore additional features or save it, use the CLI with the `--help` option for guidance:
```bash
python -m raw_mesh --help
```
2 changes: 1 addition & 1 deletion examples/python/raw_mesh/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "raw_mesh"
version = "0.1.0"
readme = "README.md"
dependencies = ["numpy", "requests>=2.31,<3", "rerun-sdk", "trimesh"]
dependencies = ["numpy", "rerun-sdk"]

[project.scripts]
raw_mesh = "raw_mesh.__main__:main"
Expand Down
Loading
Loading