3baf29aed1cac5a8ef6ef1ec3ad8df3df4ad77a7
1 from panda3d
.core
import AmbientLight
, DirectionalLight
, Point3
2 from direct
.showbase
.DirectObject
import DirectObject
3 from pmachines
.items
.background
import Background
4 from pmachines
.items
.box
import Box
7 class Scene(DirectObject
):
9 def __init__(self
, world
):
16 self
.items
= [Box(world
)]
18 def _set_camera(self
):
19 base
.camera
.set_pos(0, -20, 0)
20 base
.camera
.look_at(0, 0, 0)
22 def _set_directional_light(self
, name
, hpr
, color
):
23 light
= DirectionalLight(name
)
24 light_np
= render
.attach_new_node(light
)
25 light_np
.set_hpr(*hpr
)
26 light
.set_color(color
)
27 render
.set_light(light_np
)
29 def _set_lights(self
):
30 alight
= AmbientLight('alight') # for ao
31 alight
.set_color((.4, .4, .4, 1))
32 alnp
= render
.attach_new_node(alight
)
33 render
.set_light(alnp
)
34 self
._set
_directional
_light
('key light', (315, -60, 0),
36 self
._set
_directional
_light
('fill light', (195, -30, 0),
38 self
._set
_directional
_light
('rim light', (75, -30, 0), (.3, .3, .3, 1))
41 self
.accept('mouse1-up', self
.on_click
)
44 if not base
.mouseWatcherNode
.has_mouse(): return
45 p_from
= Point3() # in camera coordinates
46 p_to
= Point3() # in camera coordinates
47 base
.camLens
.extrude(base
.mouseWatcherNode
.get_mouse(), p_from
, p_to
)
48 p_from
= render
.get_relative_point(base
.cam
, p_from
) # global coords
49 p_to
= render
.get_relative_point(base
.cam
, p_to
) # global coords
50 for hit
in self
._world
.ray_test_all(p_from
, p_to
).get_hits():
51 for item
in [i
for i
in self
.items
if hit
.get_node() == i
.node
]: