forked from SofaDefrost/STLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainheader.py
More file actions
71 lines (54 loc) · 2.1 KB
/
mainheader.py
File metadata and controls
71 lines (54 loc) · 2.1 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
# -*- coding: utf-8 -*-
import Sofa
from splib3.animation import AnimationManager
import platform
def MainHeader(node, gravity=[0.0, -9.8, 0.0], dt=0.01, plugins=[], repositoryPaths=[], doDebug=False):
'''
Args:
gravity (vec3f): define the gravity vector.
dt (float): define the timestep.
plugins (list str): list of plugins to load
repositoryPaths (list str): list of path to the specific data repository
Structure:
.. sourcecode:: qml
rootNode : {
gravity : gravity,
dt : dt,
VisualStyle,
RepositoryPath,
RequiredPlugin,
OglSceneFrame,
FreeMotionAnimationLoop,
BlockGaussSeidelConstraintSolver,
DiscreteIntersection
}
'''
node.addObject('VisualStyle')
node.findData('gravity').value = gravity
node.findData('dt').value = dt
node.addObject('DefaultVisualManagerLoop')
if not isinstance(plugins, list):
Sofa.msg_error("MainHeader", "'plugins' expected to be a list, got "+str(type(plugins)))
return node
if "SofaPython3" not in plugins:
plugins.append("SofaPython3")
confignode = node.addChild("Config")
for name in plugins:
confignode.addObject('RequiredPlugin', name=name, printLog=False)
i=0
for repository in repositoryPaths:
confignode.addObject('AddDataRepository', name="AddDataRepository"+str(i), path=repository)
i+=1
if platform.system() != "Darwin":
confignode.addObject('OglSceneFrame', style="Arrows", alignment="TopRight")
else:
Sofa.msg_warning("MainHeader", "MacOs detected, removing OglSceneFrame from the Settings because of compatibility problem.")
if doDebug:
from splib3.debug import DebugManager
DebugManager(node)
AnimationManager(node)
return node
### This function is just an example on how to use the DefaultHeader function.
def createScene(rootNode):
import os
MainHeader(rootNode, plugins=["SofaPython3"], repositoryPaths=[os.getcwd()])