forked from prideout/svg3d
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
44 lines (33 loc) · 1.41 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from coxeter.families import ArchimedeanFamily
import svg3d
from svg3d import get_lookat_matrix, get_projection_matrix
# The style of our SVG images can be stored in a dictionary object
style = {
"fill": "#71618D",
"fill_opacity": "0.85",
"stroke": "black",
"stroke_linejoin": "round",
"stroke_width": "0.005",
}
def generate_svg(filename, poly):
pos_object = [0.0, 0.0, 0.0] # "at" position
pos_camera = [40, 40, 120] # "eye" position
vec_up = [0.0, 1.0, 0.0] # "up" vector of camera. This is the default value.
z_near, z_far = 1.0, 200.0
aspect = 1.0 # Aspect ratio of the view cone
fov_y = 1.0 # Opening angle of the view cone. fov_x is equal to fov_y * aspect
look_at = get_lookat_matrix(pos_object, pos_camera, vec_up=vec_up)
projection = get_projection_matrix(
z_near=z_near, z_far=z_far, fov_y=fov_y, aspect=aspect
)
# A "scene" is a list of Mesh objects, which can be easily generated from Coxeter!
shader = svg3d.shaders.DiffuseShader.from_style_dict(style)
scene = [svg3d.Mesh.from_coxeter(poly, style=style, shader=shader)]
view = svg3d.View.from_look_at_and_projection(
look_at=look_at,
projection=projection,
scene=scene,
)
svg3d.Engine([view]).render(filename)
truncated_cube = ArchimedeanFamily.get_shape("Truncated Cube")
generate_svg(filename="doc/svgs/truncated_cube.svg", poly=truncated_cube)