52c577b9984cbbdc0c5e18747f286c09fb26aa48
1 from panda3d
.core
import CullFaceAttrib
2 from panda3d
.bullet
import BulletBoxShape
, BulletRigidBodyNode
6 def __init__(self
, world
):
8 shape
= BulletBoxShape((.5, .5, .5))
9 self
.node
= BulletRigidBodyNode('box')
10 self
.node
.add_shape(shape
)
11 self
._np
= render
.attach_new_node(self
.node
)
12 self
._np
.set_pos(0, 0, 1)
13 world
.attach_rigid_body(self
.node
)
14 model
= loader
.load_model('assets/gltf/box/box.gltf')
16 model
.reparent_to(self
._np
)
17 self
._set
_outline
_model
()
18 self
._start
_drag
_pos
= None
20 def _set_outline_model(self
):
21 self
._outline
_model
= loader
.load_model('assets/gltf/box/box.gltf')
22 clockw
= CullFaceAttrib
.MCullClockwise
23 self
._outline
_model
.set_attrib(CullFaceAttrib
.make(clockw
))
24 self
._outline
_model
.reparent_to(self
._np
)
25 self
._outline
_model
.set_scale(-1.08, -1.08, -1.08)
26 self
._outline
_model
.set_light_off()
27 self
._outline
_model
.set_color(.4, .4, .4, 1)
28 self
._outline
_model
.set_color_scale(.4, .4, .4, 1)
29 self
._outline
_model
.hide()
32 self
._world
.remove_rigid_body(self
.node
)
34 self
._world
.attach_rigid_body(self
.node
)
36 def on_click(self
, pos
):
37 self
._start
_drag
_pos
= pos
, self
._np
.get_pos()
40 self
._start
_drag
_pos
= None
42 def on_mouse_on(self
):
43 self
._outline
_model
.show()
45 def on_mouse_off(self
):
46 self
._outline
_model
.hide()
48 def on_mouse_move(self
, pos
):
49 if not self
._start
_drag
_pos
: return
50 self
._np
.set_pos(self
._start
_drag
_pos
[1] + (pos
- self
._start
_drag
_pos
[0]))