This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17.alpha_transparency.py
More file actions
executable file
·101 lines (89 loc) · 3.14 KB
/
Copy path17.alpha_transparency.py
File metadata and controls
executable file
·101 lines (89 loc) · 3.14 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import visii
import math
import PySide2
from PySide2.QtCore import *
from PySide2.QtWidgets import *
visii.initialize()
visii.set_max_bounce_depth(diffuse_depth=2, specular_depth=20)
visii.enable_denoiser()
# Set the sky
dome = visii.texture.create_from_file("dome", "content/teatro_massimo_2k.hdr")
visii.set_dome_light_intensity(.5)
visii.set_dome_light_texture(dome)
# Set camera
camera = visii.entity.create(
name = "camera",
transform = visii.transform.create(name = "camera_transform"),
camera = visii.camera.create(
name = "camera_camera",
aspect = 1.0
)
)
camera.get_transform().look_at(
at = (0, 0, 0.9), # at position
up = (0, 0, 1), # up vector
eye = (0, 5, 2) # eye position
)
visii.set_camera_entity(camera)
# Floor
floor = visii.entity.create(
name = "floor",
mesh = visii.mesh.create_plane("mesh_floor"),
transform = visii.transform.create("transform_floor"),
material = visii.material.create("material_floor")
)
floor.get_material().set_base_color((0.19,0.16,0.19))
floor.get_material().set_metallic(0)
floor.get_material().set_roughness(1)
floor.get_transform().set_scale((5,5,1))
# Teapot
teapotahedron = visii.entity.create(
name="teapotahedron",
mesh = visii.mesh.create_teapotahedron("teapotahedron", segments = 32),
transform = visii.transform.create("teapotahedron"),
material = visii.material.create("teapotahedron")
)
teapotahedron.get_transform().set_rotation(visii.angleAxis(visii.pi() / 4.0, (0,0,1)))
teapotahedron.get_transform().set_position((0,0,0.41))
teapotahedron.get_transform().set_scale((0.4, 0.4, 0.4))
teapotahedron.get_material().set_base_color((1.0,1.0,1.0))
teapotahedron.get_material().set_roughness(0.0)
# Objects can be made to be "alpha transparent", which simulates little holes in the
# mesh that let light through. The smaller the alpha, the more little holes.
teapotahedron.get_material().set_alpha(0.5)
# Make a QT window to demonstrate the difference between alpha transparency and transmission
app = QApplication([]) # Start an application.
window = QWidget() # Create a window.
layout = QVBoxLayout() # Create a layout.
def rotateCamera(value):
value = value / 100.0
camera.get_transform().look_at(
at = (0, 0, 0.9), # at position
up = (0, 0, 1), # up vector
eye = (5 * math.cos(value * 2 * visii.pi()), 5 * math.sin(value * 2 * visii.pi()), 2) # eye position
)
dial = QDial()
dial.setWrapping(True)
dial.valueChanged[int].connect(rotateCamera)
layout.addWidget(QLabel('Camera rotation'))
layout.addWidget(dial)
def setTransmission(value):
value = value / 100.0
teapotahedron.get_material().set_transmission(value)
slider = QSlider(Qt.Horizontal)
slider.valueChanged[int].connect(setTransmission)
slider.setValue(0)
layout.addWidget(QLabel('Transmission'))
layout.addWidget(slider)
def setAlpha(value):
value = value / 100.0
teapotahedron.get_material().set_alpha(value)
slider = QSlider(Qt.Horizontal)
slider.valueChanged[int].connect(setAlpha)
slider.setValue(50)
layout.addWidget(QLabel('Alpha'))
layout.addWidget(slider)
window.setLayout(layout)
window.show()
app.exec_()
visii.deinitialize()