-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-6-5.py
95 lines (74 loc) · 3.06 KB
/
test-6-5.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
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
# import standard library
import sys
# import third party library
# import local library
from core.base import Base, baseApp
from core.renderer import Renderer
from core.scene import Scene
from core.camera import Camera
from core.mesh import Mesh
from core.texture import Texture
from light.ambientLight import AmbientLight
from light.directionalLight import DirectionalLight
from material.phongMaterial import PhongMaterial
from material.textureMaterial import TextureMaterial
from geometry.rectangleGeometry import RectangleGeometry
from geometry.sphereGeometry import SphereGeometry
from extras.movementRig import MovementRig
from extras.directionalLightHelper import DirectionalLightHelper
# testing shadows
class Test(Base):
def __init__(self, screenSize=[512, 512], title=""):
super().__init__(screenSize, title)
def initializeGL(self):
super().initializeGL()
self.renderer = Renderer(self)
self.scene = Scene()
self.camera = Camera(aspectRatio=800/600)
self.camera.setPosition([0, 0, 6])
self.rig = MovementRig()
self.rig.add(self.camera)
self.scene.add(self.rig)
self.rig.setPosition([0, 2, 5])
ambLight = AmbientLight(color=[0.2, 0.2, 0.2])
self.scene.add(ambLight)
self.dirLight = DirectionalLight(direction=[-1, -1, 0])
self.dirLight.setPosition([2, 4, 0])
self.scene.add(self.dirLight)
directHelper = DirectionalLightHelper(self.dirLight)
self.dirLight.add(directHelper)
sphereGeometry = SphereGeometry()
phongMaterial = PhongMaterial(
texture=Texture("images/grid.png"),
useShadow=True)
sphere1 = Mesh(sphereGeometry, phongMaterial)
sphere1.setPosition([-2, 1, 0])
self.scene.add(sphere1)
sphere2 = Mesh(sphereGeometry, phongMaterial)
sphere2.setPosition([1, 2.2, -0.5])
self.scene.add(sphere2)
self.renderer.enableShadows(self.dirLight)
# optional: render depth texture to mesh in scene
# depthTexture = self.renderer.shadowObject.renderTarget.texture
# shadowDisplay = Mesh( RectangleGeometry(),TextureMaterial(depthTexture) )
# shadowDisplay.setPosition([-1,3,0])
# self.scene.add( shadowDisplay )
floor = Mesh(RectangleGeometry(width=20, height=20), phongMaterial)
floor.rotateX(-3.14/2)
self.scene.add(floor)
def paintGL(self):
super().paintGL()
# view dynamic shadows -- need to increase shadow camera range
# self.dirLight.rotateY(0.01337, False)
self.rig.update(self.input, self.deltaTime)
self.renderer.render(self.scene, self.camera)
# render scene from shadow camera
# shadowCam = self.renderer.shadowObject.camera
# self.renderer.render( self.scene, shadowCam )
def main():
app = baseApp(sys.argv)
window = Test([800, 600], "Test-6-5")
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()