forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemptyController.py
More file actions
122 lines (83 loc) · 3.26 KB
/
emptyController.py
File metadata and controls
122 lines (83 loc) · 3.26 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import Sofa
# This python script shows the functions to be implemented
# in order to create your Controller in python
class EmptyController(Sofa.Core.Controller):
def __init__(self, *args, **kwargs):
# These are needed (and the normal way to override from a python class)
Sofa.Core.Controller.__init__(self, *args, **kwargs)
# Default BaseObject functions********************************
def init(self):
pass
def bwdInit():
pass
def reinit():
pass
# Default Events *********************************************
def onAnimateBeginEvent(self, event): # called at each begin of animation step
pass
def onAnimateEndEvent(self, event): # called at each end of animation step
pass
def onKeypressedEvent(self, event):
key = event['key']
if ord(key) == 19: # up
print("You pressed the Up key")
if ord(key) == 21: # down
print("You pressed the Down key")
if ord(key) == 18: # left
print("You pressed the Left key")
if ord(key) == 20: # right
print("You pressed the Right key")
if key == 'M': # M key of the keyboard
print("You pressed the M key")
def onKeyreleasedEvent(self, event):
key = event['key']
if ord(key) == 19: # up
print("You released the Up key")
if ord(key) == 21: # down
print("You released the Down key")
if ord(key) == 18: # left
print("You released the Left key")
if ord(key) == 20: # right
print("You released the Right key")
if key == 'M': # M key of the keyboard
print("You released the M key")
def onMouseEvent(self, event):
if (event['State']== 0): # mouse moving
print("Mouse is moving (x,y) = "+str(event['mouseX'])+" , "+str(event['mouseY']))
if (event['State']==1): # left mouse clicked
print("Left mouse clicked")
if (event['State']==2): # left mouse released
print("Left mouse released")
if (event['State']==3): # right mouse released
print("Right mouse clicked")
if (event['State']==4): # right mouse released
print("Right mouse released")
if (event['State']==5): # wheel clicked
print("Mouse wheel clicked")
if (event['State']==6): # wheel released
print("Mouse wheel released")
def onScriptEvent(self, event):
pass
def onEvent(self, event):
pass
def createScene(root):
root.dt = 0.01
root.bbox = [[-1, -1, -1],[1,1,1]]
root.addObject('DefaultVisualManagerLoop')
root.addObject('DefaultAnimationLoop')
# Add our python controller in the scene
root.addObject( EmptyController(name="MyEmptyController") )
def main():
import SofaImGui
import Sofa.Gui
root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("End of simulation.")
if __name__ == '__main__':
main()