-
Notifications
You must be signed in to change notification settings - Fork 1
/
csg.py
44 lines (36 loc) · 1.33 KB
/
csg.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
import pyln
def main():
pyln.utility.compile_numba()
sphere = pyln.Sphere(texture=1)
cube = pyln.StripedCube([-0.8, -0.8, -0.8], [0.8, 0.8, 0.8], 20)
cylinder = pyln.Cylinder(0.4, -2.0, 2.0)
shape = (sphere & cube) - cylinder - cylinder.rotate_x(90) - cylinder.rotate_y(90)
images = []
for index, i in enumerate(range(0, 90, 10)):
scene = pyln.Scene()
scene.add(shape.rotate_z(i))
# define camera parameters
eye = [0.0, 6.0, 2.0] # camera position
center = [0.0, 0.0, 0.0] # camera looks at
up = [0.0, 0.0, 1.0] # up direction
# define rendering parameters
width = 750 # rendered width
height = 750 # rendered height
fovy = 20.0 # vertical field of view, degrees
znear = 0.1 # near z plane
zfar = 100.0 # far z plane
step = 0.01 # how finely to chop the paths for visibility testing
# compute 2D paths that depict the 3D scene
paths = scene.render(eye, center, up, width, height, fovy, znear, zfar, step)
images.append(paths.to_image(width, height))
# save results
images[0].save(
"examples/images/csg.gif",
save_all=True,
append_images=images[1:],
optimize=True,
duration=100,
loop=0,
)
if __name__ == "__main__":
main()