-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathexample-drawing-controller.py
More file actions
52 lines (39 loc) · 2.06 KB
/
example-drawing-controller.py
File metadata and controls
52 lines (39 loc) · 2.06 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
import Sofa
import SofaTypes
from PIL import Image
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)
self.img = Image.open("oip.jpeg").convert("RGBA")
def draw(self, visual_context):
dt = visual_context.getDrawTool()
dt.drawPoints([SofaTypes.Vec3d(-1.5,0,-1)], 5.0)
dt.drawPoints([SofaTypes.Vec3d(-1.3,0,-1), SofaTypes.Vec3d(1.3,0,-1)], 5.0)
dt.drawLines([SofaTypes.Vec3d(-1.3,0,-1), SofaTypes.Vec3d(1.3,0,-1)], 1.0)
dt.drawFrames([SofaTypes.Vec3d(-1.5,0.1,-1)], [SofaTypes.Quat(0.0,0,0,1.0)], SofaTypes.Vec3d(0.1,0.1,0.1))
if self.target is not None:
dt.drawPoints(self.target.position, 2.0)
dt.draw3DText(SofaTypes.Vec3d(-2.0,0.0,0.0), 0.5, "This is not a raptor")
dt.drawText(10,10, 12, "Overlay text")
dt.drawFrames(self.mo.position, SofaTypes.Vec3d(0.1,0.1,0.1))
w,h = self.img.size
dt.drawRGBAImage("memory", SofaTypes.Vec3d(0.0,0.0,0.0), w ,h, 32, self.img.tobytes())
#dt.drawRGBAImage("image", SofaTypes.Vec3d(0.0,0.0,0.0), "oip.jpeg")
def createScene(root):
root.dt = 0.01
root.bbox = [[-1,-1,-1],[1,1,1]]
root.addObject('RequiredPlugin', name="Sofa.GL.Component.Shader")
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) )