README.md 1.94 KB
Newer Older
Janis Born's avatar
Janis Born committed
1 2 3
![threevis](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/logo-90.png)
# threevis
a Python library for visualizing meshes, point clouds, and other geometry in Jupyter notebooks
Dario Seyb's avatar
Dario Seyb committed
4 5 6

## Setup

Dario Seyb's avatar
Dario Seyb committed
7
- Install dependencies
Dario Seyb's avatar
Dario Seyb committed
8
- Clone the repository
Janis Born's avatar
Janis Born committed
9
- `pip install -e .`
Dario Seyb's avatar
Dario Seyb committed
10 11 12

## Dependencies

Isaak Lim's avatar
Isaak Lim committed
13
- [pythreejs](https://github.com/jovyan/pythreejs/) >= 1.0.0
Dario Seyb's avatar
Dario Seyb committed
14 15
- [openmesh-python](https://graphics.rwth-aachen.de:9000/adielen/openmesh-python) latest

Janis Born's avatar
Janis Born committed
16 17 18
## Examples

### Quick Mesh Inspection
Dario Seyb's avatar
Dario Seyb committed
19 20

```python
21
import threevis
22
import openmesh as om
Dario Seyb's avatar
Dario Seyb committed
23

Isaak Lim's avatar
Isaak Lim committed
24
m = om.read_trimesh('examples/models/bunny.obj')
Dario Seyb's avatar
Dario Seyb committed
25

26
threevis.display_openmesh(m)
Dario Seyb's avatar
Dario Seyb committed
27 28
```

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

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

# Load Mesh
Isaak Lim's avatar
Isaak Lim committed
37
m = om.read_trimesh('mouse.obj')
Dario Seyb's avatar
Dario Seyb committed
38 39

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

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

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

# Choose a random color for each face
50
colors = threevis.FaceAttribute(np.random.rand(len(faces), 3))
Dario Seyb's avatar
Dario Seyb committed
51 52 53 54 55 56 57 58 59

# Draw the mesh with flat shading
ctx.draw_faces(vertices, faces, 
               normals = normals,
               colors = colors,
               shading = 'flat')

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

# Calculate data to display normals as edges
64
normal_vis_verts, normal_vis_edges = threevis.calculateNormalEdges(vertices, faces, normals, length=0.05)
Dario Seyb's avatar
Dario Seyb committed
65 66 67 68 69 70 71 72 73 74 75

# Draw the normals in
ctx.draw_edges(normal_vis_verts, normal_vis_edges, colors = colors)

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

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

Isaak Lim's avatar
Isaak Lim committed
76
![mouse](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/mouse.PNG)