README.md 2.45 KB
Newer Older
1 2
![](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/logo-90.png)

Janis Born's avatar
Janis Born committed
3
# threevis
4 5

[![](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/badges/master/pipeline.svg)](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/commits/master)
Janis Born's avatar
Janis Born committed
6

7
A Python library for visualizing meshes, point clouds, and other geometry in Jupyter notebooks
Dario Seyb's avatar
Dario Seyb committed
8

Isaak Lim's avatar
Isaak Lim committed
9
## Installation
Janis Born's avatar
Janis Born committed
10
    pip install threevis
Dario Seyb's avatar
Dario Seyb committed
11

12 13 14 15 16 17
This should also install [pythreejs](https://github.com/jupyter-widgets/pythreejs) as a dependency.
In order to set up the pythreejs plugin for Jupyter, you may need to also run

    jupyter nbextension install --py --symlink --sys-prefix pythreejs
    jupyter nbextension enable --py --sys-prefix pythreejs

Janis Born's avatar
Janis Born committed
18 19 20
## Examples

### Quick Mesh Inspection
Dario Seyb's avatar
Dario Seyb committed
21 22

```python
23
import threevis as tv
24
import openmesh as om
Dario Seyb's avatar
Dario Seyb committed
25

26
m = om.read_trimesh('models/bunny.obj')
27
tv.display_openmesh(m, normals='face')
Dario Seyb's avatar
Dario Seyb committed
28 29
```

Janis Born's avatar
Janis Born committed
30 31
### Custom Rendering

Dario Seyb's avatar
Dario Seyb committed
32
```python
33
import threevis as tv
Dario Seyb's avatar
Dario Seyb committed
34 35 36 37
import openmesh as om
import numpy as np

# Load Mesh
38
m = om.read_trimesh('models/mouse.obj')
Dario Seyb's avatar
Dario Seyb committed
39 40

# Create Context
41
ctx = tv.Context(width=640, height=480)
Dario Seyb's avatar
Dario Seyb committed
42 43 44 45 46 47

# Get vertices and faces from the mesh
vertices = m.points()
faces = m.face_vertex_indices()

# We don't have normals, calculate them
48
normals = tv.calculate_face_normals(m.points(), m.face_vertex_indices())
Dario Seyb's avatar
Dario Seyb committed
49 50

# Choose a random color for each face
51
colors = tv.FaceAttribute(np.random.rand(len(faces), 3))
Dario Seyb's avatar
Dario Seyb committed
52 53 54

# Draw the mesh with flat shading
ctx.draw_faces(vertices, faces, 
55 56 57
               normals=normals,
               colors=colors,
               shading='flat')
Dario Seyb's avatar
Dario Seyb committed
58 59 60

# Draw edges on top with random colors
ctx.draw_edges(vertices, m.ev_indices(), 
61 62
               colors=tv.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),
               line_width=3)
Dario Seyb's avatar
Dario Seyb committed
63 64

# Calculate data to display normals as edges
65
normal_vis_verts, normal_vis_edges = tv.calculate_normal_edges(vertices, faces, normals, length=0.05)
Dario Seyb's avatar
Dario Seyb committed
66 67

# Draw the normals in
68
ctx.draw_edges(normal_vis_verts, normal_vis_edges, colors=colors)
Dario Seyb's avatar
Dario Seyb committed
69 70 71 72 73 74 75 76

# Draw a point for each vertex
ctx.draw_vertices(vertices, point_size=4, colors='red')

# Finally display it
ctx.display()
```

77
![](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/mouse.PNG)
Isaak Lim's avatar
Isaak Lim committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91

## Development Setup

- Install dependencies
- Clone the repository
- `pip install -e .`

## Dependencies

- [pythreejs](https://github.com/jovyan/pythreejs/) >= 1.0.0

### Optional
- [openmesh-python](https://graphics.rwth-aachen.de:9000/adielen/openmesh-python) latest