Skip to content

Instantly share code, notes, and snippets.

@jangirrishabh
Created July 4, 2019 16:00
Show Gist options
  • Save jangirrishabh/60c0ed0d412de1417ec24352b85eda1e to your computer and use it in GitHub Desktop.
Save jangirrishabh/60c0ed0d412de1417ec24352b85eda1e to your computer and use it in GitHub Desktop.
class workspace (Sofa.PythonScriptController):
def __init__(self, node, commandLineArguments) :
self.commandLineArguments = commandLineArguments
print "Command line arguments for python : "+str(commandLineArguments)
self.node = node
self.createGraph(node)
return None;
def createGraph(self,rootNode):
# rootNode
rootNode.createObject('VisualStyle', displayFlags='hideBehaviorModels hideCollisionModels hideMappings hideForceFields showVisualModels hideInteractionForceFields')
rootNode.createObject('RequiredPlugin', name='SofaMiscCollision')
rootNode.createObject('RequiredPlugin', pluginName='SofaPython', name='SofaPython')
rootNode.createObject('FreeMotionAnimationLoop', solveVelocityConstraintFirst='0')
rootNode.createObject('LCPConstraintSolver', mu='0.000000000001', maxIt='1000', printLog='0', initial_guess='false', multi_grid='false', build_lcp='true', tolerance='1e-6')
rootNode.createObject('CollisionPipeline', draw='0', depth='6', verbose='0')
rootNode.createObject('BruteForceDetection', name='N2')
rootNode.createObject('MinProximityIntersection', contactDistance='1.0', alarmDistance='3.0', name='Proximitty')
rootNode.createObject('CollisionResponse', name='Response', response='FrictionContact')
# rootNode/SquareGravity
SquareGravity = rootNode.createChild('SquareGravity')
self.SquareGravity = SquareGravity
sampled_translation = random.randint(0, 0)
translationRandom = str(sampled_translation) + ' -6 ' + str(sampled_translation)
SquareGravity.createObject('EulerImplicitSolver', name='cg_odesolver', printLog='false')
SquareGravity.createObject('CGLinearSolver', threshold='1.0e-100', tolerance='1.0e-9', name='linear solver', iterations='10')
SquareGravity.createObject('MeshGmshLoader', scale='70', name='loader', translation=translationRandom, createSubelements='true', rotation='90 0 0', filename='mesh/square3.msh')
SquareGravity.createObject('TriangleSetTopologyContainer', src='@loader', name='topo')
SquareGravity.createObject('TriangleSetGeometryAlgorithms', recomputeTrianglesOrientation='1', name='algo', template='Vec3d')
SquareGravity.createObject('MechanicalObject', src='@loader', name='cloth', template='Vec3d')
SquareGravity.createObject('DiagonalMass', massDensity='0.01')
SquareGravity.createObject('TriangularFEMForceField', youngModulus='1000', template='Vec3d', method='large', poissonRatio='0.1', name='FEM')
SquareGravity.createObject('TriangularBendingSprings', template='Vec3d', damping='2.0', stiffness='10', name='FEM-Bend')
SquareGravity.createObject('UncoupledConstraintCorrection', compliance='100')
# rootNode/SquareGravity/clothVisual
clothVisual = SquareGravity.createChild('clothVisual')
self.clothVisual = clothVisual
clothVisual.createObject('OglModel', color='red', src='@../loader', name='Visual', template='ExtVec3f')
clothVisual.createObject('IdentityMapping', input='@..', output='@Visual')
# rootNode/SquareGravity/Edge Mesh
Edge_Mesh = SquareGravity.createChild('Edge Mesh')
self.Edge_Mesh = Edge_Mesh
Edge_Mesh.createObject('EdgeSetTopologyContainer', name='Container')
Edge_Mesh.createObject('EdgeSetTopologyModifier', name='Modifier')
Edge_Mesh.createObject('EdgeSetGeometryAlgorithms', drawEdges='1', name='GeomAlgo', template='Vec3d')
Edge_Mesh.createObject('EdgeSetTopologyAlgorithms', name='TopoAlgo', template='Vec3d')
Edge_Mesh.createObject('Triangle2EdgeTopologicalMapping', input='@../topo', name='Mapping', output='@Container')
Edge_Mesh.createObject('MeshSpringForceField', template='Vec3d', stiffness='100', damping='1.0')
# rootNode/SquareGravity/Edge Mesh/Visu
Visu = Edge_Mesh.createChild('Visu')
self.Visu = Visu
SquareGravity.createObject('PlaneForceField', normal='0 1 0', d='-5', stiffness='0.5', damping='0.3')
return 0;
def initGraph(self, node):
## Please feel free to add an example for a simple usage in /home/rjangir/softwareInstalled/sofa/src/applications/plugins/SofaPython/scn2python.py
return 0;
def storeResetState(self):
## Please feel free to add an example for a simple usage in /home/rjangir/softwareInstalled/sofa/src/applications/plugins/SofaPython/scn2python.py
print "Store rtest state"
return 0;
def cleanup(self):
## Please feel free to add an example for a simple usage in /home/rjangir/softwareInstalled/sofa/src/applications/plugins/SofaPython/scn2python.py
return 0;
def reset(self):
## Please feel free to add an example for a simple usage in /home/rjangir/softwareInstalled/sofa/src/applications/plugins/SofaPython/scn2python.py
return 0;
def createScene(rootNode):
rootNode.findData('dt').value = '0.05'
try :
sys.argv[0]
except :
commandLineArguments = []
else :
commandLineArguments = sys.argv
myworkspace = workspace(rootNode,commandLineArguments)
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment