-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathexample-drawing-controller.py
More file actions
61 lines (44 loc) · 2.22 KB
/
Copy pathexample-drawing-controller.py
File metadata and controls
61 lines (44 loc) · 2.22 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
import Sofa
import SofaTypes
import numpy
from numpy import array
from Sofa.Types import RGBAColor
class DrawingExamples(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)
self.target = kwargs.get("target", None)
self.mo = kwargs.get("mo", None)
def draw(self, visual_context):
dt = visual_context.getDrawTool()
if self.target is not None:
dt.disableLighting()
dt.drawPoints(self.target.position, 5.0, RGBAColor("blue"))
dt.drawTriangles(self.target.position, self.target.triangles, RGBAColor("white"))
dt.drawQuads(self.target.position, self.target.quads, RGBAColor("white"))
dt.enableLighting()
dt.drawFrames(self.mo.position, [0.1,0.1,0.1])
dt.disableLighting()
dt.drawPoints(array([[-1.5,-1.0,0.0]]), 5.0, RGBAColor("red"))
dt.drawPoints([[-1.3,0,-1], [1.3,0,-1]], 10.0, RGBAColor("green"))
dt.drawLines([[-1.3,0,-1], [1.3,0,-1]], 1.0, RGBAColor("green"))
dt.drawFrames([[-1.5,0.1,-1]], [[0.0,0,0,1.0]], [0.1,0.1,0.1])
dt.drawText([-2.0,-1.0,0.0], 0.5, "This is not a raptor", RGBAColor("white"))
dt.drawOverlayText([10, 10], 16, "Overlay text", RGBAColor("pink"))
dt.enableLighting()
def createScene(root):
root.dt = 0.01
root.bbox = [[-1,-1,-1],[1,1,1]]
root.addObject("RequiredPlugin", pluginName=['Sofa.Component.IO.Mesh',
'Sofa.Component.StateContainer'])
root.addObject('DefaultVisualManagerLoop')
root.addObject('DefaultAnimationLoop')
root.addObject("MeshOBJLoader", name="loader", filename="mesh/raptor_35kp.obj")
root.addObject("MechanicalObject",
name="mo",
template="Rigid3",
position=[[float(i)/10.0, 0.0,0.0, 0.0, 0.0, 0.0, 1.0] for i in range(0,10)])
# Add our python controller in the scene
root.addObject( DrawingExamples(name="DrawingController2",
target=root.loader,
mo=root.mo) )