README.md 2.18 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)
Janis Born's avatar
Janis Born committed
2 3 4
# 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)

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

Isaak Lim's avatar
Isaak Lim committed
7 8
## Installation
`pip install threevis`
Dario Seyb's avatar
Dario Seyb committed
9

Janis Born's avatar
Janis Born committed
10 11 12
## Examples

### Quick Mesh Inspection
Dario Seyb's avatar
Dario Seyb committed
13 14

```python
15
import threevis
16
import openmesh as om
Dario Seyb's avatar
Dario Seyb committed
17

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

20
threevis.display_openmesh(m)
Dario Seyb's avatar
Dario Seyb committed
21 22
```

Janis Born's avatar
Janis Born committed
23 24
### Custom Rendering

Dario Seyb's avatar
Dario Seyb committed
25
```python
26
import threevis
Dario Seyb's avatar
Dario Seyb committed
27 28 29 30
import openmesh as om
import numpy as np

# Load Mesh
Isaak Lim's avatar
Isaak Lim committed
31
m = om.read_trimesh('mouse.obj')
Dario Seyb's avatar
Dario Seyb committed
32 33

# Create Context
34
ctx = threevis.Context(width=640, height=480)
Dario Seyb's avatar
Dario Seyb committed
35 36 37 38 39 40

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

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

# Choose a random color for each face
44
colors = threevis.FaceAttribute(np.random.rand(len(faces), 3))
Dario Seyb's avatar
Dario Seyb committed
45 46 47 48 49 50 51 52 53

# 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(), 
54
               colors = threevis.FaceAttribute(np.random.rand(len(m.ev_indices()), 3)),
Dario Seyb's avatar
Dario Seyb committed
55 56 57
               linewidth=3)

# Calculate data to display normals as edges
58
normal_vis_verts, normal_vis_edges = threevis.calculateNormalEdges(vertices, faces, normals, length=0.05)
Dario Seyb's avatar
Dario Seyb committed
59 60 61 62 63 64 65 66 67 68 69

# 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
70
![mouse](https://www.graphics.rwth-aachen.de:9000/threevis/threevis/raw/master/docs/images/mouse.PNG)
Isaak Lim's avatar
Isaak Lim committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84

## 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