README.md 2.13 KB
Newer Older
Janis Born's avatar
Janis Born committed
1
![threevis](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/logo-90.png)
2
# threevis [![pipeline status](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
3
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
14 15

### Optional
Dario Seyb's avatar
Dario Seyb committed
16 17
- [openmesh-python](https://graphics.rwth-aachen.de:9000/adielen/openmesh-python) latest

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
24
import openmesh as om
Dario Seyb's avatar
Dario Seyb committed
25

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

28
threevis.display_openmesh(m)
Dario Seyb's avatar
Dario Seyb committed
29 30
```

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

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

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

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

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

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

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

# 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(), 
62
               colors = threevis.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),
Dario Seyb's avatar
Dario Seyb committed
63 64 65
               linewidth=3)

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

# 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
78
![mouse](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/mouse.PNG)