ya2 · news · projects · code · about

outline
[pmachines.git] / pmachines / items / box.py
1 from panda3d.core import CullFaceAttrib
2 from panda3d.bullet import BulletBoxShape, BulletRigidBodyNode
3
4 class Box:
5
6 def __init__(self, world):
7 shape = BulletBoxShape((.5, .5, .5))
8 self.node = BulletRigidBodyNode('box')
9 # self.node.set_mass(1) # static/dynamic
10 self.node.add_shape(shape)
11 np = render.attach_new_node(self.node)
12 np.set_pos(0, 0, 1)
13 world.attach_rigid_body(self.node)
14 model = loader.load_model('assets/gltf/box/box.gltf')
15 model.flatten_light()
16 model.reparent_to(np)
17 self._set_outline_model(np)
18
19 def _set_outline_model(self, np):
20 self._outline_model = loader.load_model('assets/gltf/box/box.gltf')
21 clockw = CullFaceAttrib.MCullClockwise
22 self._outline_model.set_attrib(CullFaceAttrib.make(clockw))
23 self._outline_model.reparent_to(np)
24 self._outline_model.set_scale(-1.08, -1.08, -1.08)
25 self._outline_model.set_light_off()
26 self._outline_model.set_color(.4, .4, .4, 1)
27 self._outline_model.set_color_scale(.4, .4, .4, 1)
28 self._outline_model.hide()
29
30 def on_click(self, hit):
31 print(hit.get_hit_pos())
32
33 def on_mouse_on(self):
34 self._outline_model.show()
35
36 def on_mouse_off(self):
37 self._outline_model.hide()