|
3 | 3 | from numpy.random import random |
4 | 4 | from sys import argv |
5 | 5 |
|
6 | | -from SSD.Core import UserAPI |
| 6 | +from SSD.Core.Rendering import UserAPI |
7 | 7 |
|
8 | 8 | # 1. Create the visualization API |
9 | | -factory = UserAPI(database_name='visualization', |
| 9 | +factory = UserAPI(database_dir='my_databases', |
| 10 | + database_name='visualization', |
10 | 11 | remove_existing=True) |
11 | 12 |
|
12 | 13 | # 2. Create the object to render |
13 | | -armadillo = Mesh('armadillo.obj') |
| 14 | +mesh = Mesh('armadillo.obj').compute_normals() |
14 | 15 |
|
15 | 16 | # 3. Add objects to the Visualizer |
16 | 17 | # 3.1. Add a Mesh (object_id = 0) |
17 | | -factory.add_mesh(positions=armadillo.points(), |
18 | | - cells=armadillo.cells(), |
| 18 | +factory.add_mesh(positions=mesh.vertices, |
| 19 | + cells=mesh.cells, |
19 | 20 | at=0, |
20 | 21 | alpha=0.8, |
21 | 22 | c='orange6', |
22 | 23 | wireframe=False, |
23 | 24 | line_width=0.) |
24 | 25 | # 3.2. Add a PointCloud (object_id = 1) |
25 | | -factory.add_points(positions=armadillo.points(), |
| 26 | +factory.add_points(positions=mesh.vertices, |
26 | 27 | at=1, |
27 | 28 | point_size=5, |
28 | | - scalar_field=armadillo.points()[:, 1]) |
| 29 | + scalar_field=mesh.vertices[:, 1]) |
29 | 30 | # 3.3. Add Arrows (object_id = 2) |
30 | | -factory.add_arrows(positions=armadillo.points()[:100], |
31 | | - vectors=armadillo.normals()[:100], |
| 31 | +factory.add_arrows(positions=mesh.vertices[:100], |
| 32 | + vectors=mesh.vertex_normals[:100], |
32 | 33 | at=2, |
33 | 34 | res=15) |
34 | 35 | # 3.4. Add Markers (object_id = 3) |
35 | 36 | factory.add_markers(normal_to=0, |
36 | 37 | indices=arange(0, 10), |
37 | 38 | at=3, |
38 | 39 | size=1, |
39 | | - symbol='0') |
| 40 | + symbol='*') |
40 | 41 | # 3.5. Add Text (object_id = 4) |
41 | 42 | factory.add_text(content='0', |
42 | 43 | at=0, |
|
47 | 48 | factory.launch_visualizer(backend='vedo' if len(argv) == 1 else argv[1], |
48 | 49 | fps=20) |
49 | 50 |
|
50 | | -# 5. Run a few steps |
| 51 | +# # 5. Run a few steps |
51 | 52 | for step in range(100): |
52 | | - updated_armadillo = armadillo.clone().points(armadillo.points() + 0.1 * random(armadillo.points().shape)) |
| 53 | + updated_mesh = mesh.clone() |
| 54 | + updated_mesh.vertices = mesh.vertices + 0.1 * random(mesh.vertices.shape) |
53 | 55 | # 5.1. Update the Mesh |
54 | 56 | factory.update_mesh(object_id=0, |
55 | | - positions=updated_armadillo.points()) |
| 57 | + positions=updated_mesh.vertices) |
56 | 58 | if step == 50: |
57 | 59 | factory.update_mesh(object_id=0, |
58 | 60 | wireframe=True, |
59 | 61 | alpha=1., |
60 | 62 | line_width=2.) |
61 | 63 | # 5.2. Update the PointCloud |
62 | 64 | factory.update_points(object_id=1, |
63 | | - positions=updated_armadillo.points()) |
| 65 | + positions=updated_mesh.vertices) |
64 | 66 | if step == 50: |
65 | 67 | factory.update_points(object_id=1, |
66 | 68 | alpha=0.5, |
67 | 69 | point_size=10, |
68 | | - scalar_field=armadillo.points()[:, 2]) |
| 70 | + scalar_field=mesh.vertices[:, 2]) |
69 | 71 | # 5.3. Update the Arrows |
70 | 72 | factory.update_arrows(object_id=2, |
71 | | - positions=armadillo.points()[step:step + 100], |
72 | | - vectors=armadillo.normals()[step:step + 100]) |
| 73 | + positions=mesh.vertices[step:step + 100], |
| 74 | + vectors=mesh.vertex_normals[step:step + 100]) |
73 | 75 | if step == 50: |
74 | 76 | factory.update_arrows(object_id=2, |
75 | 77 | c='red') |
|
0 commit comments