def createScene(rootNode): print ("Scene Phase :"+str(phase)) # Import Original scene originalScene.createScene(rootNode) dt = rootNode.dt timeExe = nbIterations * dt # Add Animation Manager to Scene # (ie: python script controller to which we will pass our differents animations) # more details at splib.animation.AnimationManager (https://stlib.readthedocs.io/en/latest/) if isinstance(rootNode, Wrapper): AnimationManager(rootNode.node) else: AnimationManager(rootNode) # Now that we have the AnimationManager & a list of the nodes we want to animate # we can add an animation to then according to the arguments in listObjToAnimate u.addAnimation(rootNode,phase,timeExe,dt,listObjToAnimate) # Now that all the animations are defined we need to record their results # for that we take the parent node normally given as an argument in paramWrapper path, param = paramWrapper myParent = get(rootNode,path[1:]) # We need rest_position and because it is normally always the same we record it one time # during the first phase with the argument writeX0 put to True if phase == phaseToSave: myParent.createObject('WriteState', filename="stateFile.state",period=listObjToAnimate[0].params["incrPeriod"]*dt, writeX="1", writeX0="1", writeV="0") else : myParent.createObject('WriteState', filename="stateFile.state", period=listObjToAnimate[0].params["incrPeriod"]*dt, writeX="1", writeX0="0", writeV="0") # If you want to save also the velocity uncomment the what is below. # Then after if you give to **ReduceModel** *saveVelocitySnapshots = True* as parameter # all the different velocity saved will be added to one file as the stateFile # myParent.createObject('WriteState', filename="stateFileVelocity.state",period=listObjToAnimate[0].params["incrPeriod"]*dt, # writeX = "0", writeX0 = "0", writeV = "1")
def createScene(rootNode): confignode = rootNode.addChild("Config") confignode.addObject('RequiredPlugin', name="SofaPython3", printLog=False) manager = AnimationManager(rootNode) rootNode.addObject(manager) sphere1 = Sphere(rootNode, "sphere1", [-20, 0, 0, 0, 0, 0, 1], [1 / 10.0, 1 * 0.7 / 10.0, 0.9]) sphere2 = Sphere(rootNode, "sphere2", [-20, 1, 0, 0, 0, 0, 1], [7 / 10.0, 7 * 0.7 / 10.0, 0.9]) addAnimation(myAnimate, {"target": sphere1}, 5, mode="pingpong") addAnimation(myAnimate, {"target": sphere2}, 5, mode="pingpong", realTimeClock=True) return rootNode
def createScene(rootNode): # This scene is an example scene that shows the different easing functions implemented in SofaPython3 confignode = rootNode.addChild("Config") confignode.addObject('RequiredPlugin', name="SofaPython3", printLog=False) manager = AnimationManager(rootNode) spheres = [] for i in range(22): sphere = Sphere(rootNode, "sphere" + str(i), [-20, i, 0, 0, 0, 0, 1], [i / 10.0, i * 0.7 / 10.0, 0.9]) spheres.append(sphere) addAnimation(myAnimate, {"target": sphere}, 10.0, mode="pingpong") Sofa.Simulation.init(rootNode) print(len(spheres)) return rootNode
def createScene(rootNode): rootNode.createObject("RequiredPlugin", name="SoftRobots") rootNode.createObject("RequiredPlugin", name="SoftRobots.Inverse") rootNode.createObject("RequiredPlugin", name="SofaSparseSolver") rootNode.createObject("RequiredPlugin", name="SofaPreconditioner") rootNode.createObject("RequiredPlugin", name="SofaPython") rootNode.createObject("RequiredPlugin", name="CosseratPlugin") AnimationManager(rootNode) rootNode.createObject( "VisualStyle", displayFlags= 'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields showWireframe' ) rootNode.gravity = [0., -9810., 0.] rootNode.createObject("FreeMotionAnimationLoop") # For direct resolution, i.e direct control of the cable displacement # rootNode.createObject("GenericConstraintSolver", maxIterations=100, tolerance=1e-5) # For inverse resolution, i.e control of effectors position rootNode.createObject("QPInverseProblemSolver", epsilon=1e-1) simulation = rootNode.createChild("Simulation") simulation.createObject('EulerImplicitSolver', name='odesolver', firstOrder="0", rayleighMass="0.1", rayleighStiffness="0.1") simulation.createObject('ShewchukPCGLinearSolver', name='linearSolver', iterations='500', tolerance='1.0e-18', preconditioners="precond") simulation.createObject('SparseLDLSolver', name='precond') simulation.createObject('GenericConstraintCorrection', solverName="precond") trunk = Trunk(simulation, inverseMode=True) trunk.addVisualModel(color=[1., 1., 1., 0.8]) trunk.fixExtremity() target = effectorTarget(rootNode) trunk.addEffectors(target=target.dofs.getData("position").getLinkPath(), position=[[0., 0., 195]])
def createScene(rootNode): rootNode.createObject("RequiredPlugin", name="SoftRobots") rootNode.createObject("RequiredPlugin", name="SoftRobots.Inverse") rootNode.createObject("RequiredPlugin", name="SofaSparseSolver") rootNode.createObject("RequiredPlugin", name="SofaPreconditioner") rootNode.createObject("RequiredPlugin", name="SofaPython") rootNode.createObject("RequiredPlugin", name="CosseratPlugin") AnimationManager(rootNode) #rootNode.createObject("VisualStyle", displayFlags='showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields showWireframe') rootNode.createObject('VisualStyle', displayFlags='showVisualModels showInteractionForceFields ShowForceFields') rootNode.gravity = "0 0 0" rootNode.createObject("FreeMotionAnimationLoop") #### For direct resolution, i.e direct control of the cable displacement # rootNode.createObject('GenericConstraintSolver', tolerance="1e-20", maxIterations="500", printLog="0") #### For inverse resolution, i.e control of effectors position rootNode.createObject("QPInverseProblemSolver", printLog='0', epsilon=1e-1, maxIterations="500") rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765') # ############### # New adds to use the sliding Actuator ############### cableNode = rootNode.createChild('cableNode') cableNode.createObject('EulerImplicitSolver', firstOrder="0",rayleighMass="0.1", rayleighStiffness="0.1") cableNode.createObject('SparseLUSolver', name='solver') #cableNode.createObject('SparseLDLSolver', name='solver') cableNode.createObject('GenericConstraintCorrection') #tabOfNode = [] Cable = CosseratCable(cableNode) simulation = rootNode.createChild("Simulation") simulation.createObject('EulerImplicitSolver', name='odesolver', firstOrder="0", rayleighMass="0.1", rayleighStiffness="0.1") simulation.createObject('ShewchukPCGLinearSolver', name='linearSolver', iterations='500', tolerance='1.0e-18', preconditioners="precond") simulation.createObject('SparseLDLSolver', name='precond') simulation.createObject('GenericConstraintCorrection', solverName="precond") trunk = Trunk(simulation, inverseMode=True) trunk.addVisualModel(color=[1., 1., 1., 0.8]) trunk.fixExtremity() mappedPointsNodeTab = Cable.mappedPointsNodeTab cableDofMOTab = Cable.cableDofMOTab outputViolationMOTab = Cable.outputViolationMOTab framesMoTab = Cable.framesMoTab for i in range(0,nbCables): mappedPointsNode = mappedPointsNodeTab[i] trunk.addConstraintPoints(cstPoints[i],i,mappedPointsNode) #### Get link to different Mo for the multi map constraintPointMo = trunk.constraintPointMoTab[i] cableDofMO = cableDofMOTab[i] outputViolationMO = outputViolationMOTab[i] print(" ==================+++++> The Link is : ", framesMoTab[i]) mappedPointsNode.createObject('DifferenceMultiMapping', name="pointsMulti", input1=constraintPointMo, input2=cableDofMO, output=outputViolationMO, direction=framesMoTab[i]+".position") target = effectorTarget(rootNode) trunk.addEffectors(target=target.dofs.getData("position").getLinkPath(), position=[[0., 0., 195.]]) ################################ # Animation (to move the dofs) # ################################ Animation(target)
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, GenericConstraintSolver, DiscreteIntersection } ''' node.createObject('VisualStyle') i = 0 for repository in repositoryPaths: node.createObject('AddResourceRepository', name="AddResourceRepository" + str(i), path=repository) i += 1 node.findData('gravity').value = gravity node.findData('dt').value = dt if not isinstance(plugins, list): Sofa.msg_error( "MainHeader", "'plugins' expected to be a list, got " + str(type(plugins))) return node if "SofaMiscCollision" not in plugins: plugins.append("SofaMiscCollision") if "SofaPython" not in plugins: plugins.append("SofaPython") for name in plugins: node.createObject('RequiredPlugin', name=name, printLog=False) node.createObject('OglSceneFrame', style="Arrows", alignment="TopRight") if doDebug: from splib.debug import DebugManager DebugManager(node) AnimationManager(node) return node
def createScene(rootNode): rootNode.addObject('RequiredPlugin', name='SofaPython3') rootNode.addObject('RequiredPlugin', pluginName='BeamAdapter') rootNode.dt = 0.01 rootNode.addObject( 'VisualStyle', displayFlags= 'showVisualModels showBehaviorModels showCollisionModels hideMappings showForceFields showWireframe' ) # rootNode.addObject('RequiredPlugin', pluginName='BeamAdapter') # rootNode.addObject('BackgroundSetting', color='0 0.568627 0.711765') rootNode.addObject('OglSceneFrame', style="Arrows", alignment="TopRight") # rootNode.addObject("LightManager") # rootNode.addObject("SpotLight", position=source, direction=[1.0, 0.0, 0.0]) # rootNode.addObject("InteractiveCamera", name="camera", position=source, lookAt=target) # rootNode.addObject("InteractiveCamera", name="camera") # rootNode.addObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels showCollisionModels showMappings hideForceFields') rootNode.addObject('FreeMotionAnimationLoop') rootNode.addObject('LCPConstraintSolver', mu=0.1, tolerance=3e-4, maxIt=1000, build_lcp=False) rootNode.addObject('CollisionPipeline', draw=False, depth=6, verbose=False) rootNode.addObject('BruteForceDetection', name='N2') rootNode.addObject('LocalMinDistance', contactDistance=0.1, alarmDistance=0.3, name='localmindistance', angleCone=0.02) rootNode.addObject('CollisionResponse', name='Response', response='FrictionContact') # rootNode.addObject('CollisionGroup', name='Group') manager = AnimationManager(rootNode) # topoLines_guide = createGuide(rootNode, 'guide', straightLength=980.0, length=1000.0, # youngModulus=20000, numEdges=200, spireDiameter=25, # numEdgesCollis=[50,10], spireHeight=0.0, densityOfBeams=[30,5], # youngModulusExtremity=1000) topoLines_guide = rootNode.addChild('topoLines_guide') wire = topoLines_guide.addObject('WireRestShape', name='guideRestShape', straightLength=980.0, length=1000.0, numEdges=200, youngModulus=20000, spireDiameter=25, numEdgesCollis=[50, 10], printLog=False, template='Rigid3d', spireHeight=0.0, densityOfBeams=[30, 5], youngModulusExtremity=1000) topoLines_guide.addObject('MechanicalObject', name='dofTopo2', template='Rigid3d') topoLines_guide.addObject('EdgeSetTopologyContainer', name='meshLinesGuide') topoLines_guide.addObject('EdgeSetTopologyModifier', name='Modifier') topoLines_guide.addObject('EdgeSetTopologyAlgorithms', name='TopoAlgo', template='Vec3d') topoLines_guide.addObject('EdgeSetGeometryAlgorithms', name='GeomAlgo', template='Rigid3d') # instrumentsCombined = createInstrumentsCombined(rootNode) InstrumentCombined = rootNode.addChild('InstrumentCombined') InstrumentCombined.addObject('EulerImplicit', rayleighStiffness=0.2, printLog=False, rayleighMass=0.1) InstrumentCombined.addObject('BTDLinearSolver', verification=False, subpartSolve=False, verbose=False) InstrumentCombined.addObject('RegularGrid', name='meshLinesCombined', zmax=1, zmin=1, nx=60, ny=1, nz=1, xmax=1.0, xmin=0.0, ymin=0, ymax=0) InstrumentCombined.addObject('MechanicalObject', showIndices=False, name='DOFs', template='Rigid3d', ry=-90) InstrumentCombined.addObject( 'WireBeamInterpolation', WireRestShape='@../topoLines_guide/guideRestShape', radius=0.15, printLog=False, name='Interpolguide') InstrumentCombined.addObject('AdaptiveBeamForceFieldAndMass', massDensity=0.00000155, name='guideForceField', interpolation='@Interpolguide') intrevention = InstrumentCombined.addObject( 'InterventionalRadiology', xtip=0.0, name='m_ircontroller', instruments=['Interpolguide'], step=0.5, printLog=False, listening=True, template='Rigid3d', startingPos=[0, 0, 0, 1, 0, 0, 0], rotationInstrument=[0, 0, 0], speed=0, controlledInstrument=0) InstrumentCombined.addObject('LinearSolverConstraintCorrection', wire_optimization='true', printLog=False) InstrumentCombined.addObject('FixedConstraint', indices=0, name='FixedConstraint') InstrumentCombined.addObject('RestShapeSpringsForceField', points='@m_ircontroller.indexFirstNode', angularStiffness=1e8, stiffness=1e8) return (rootNode) InstrumentCombined.addObject(Animation(intrevention, 0, step, angularStep)) # Visualization Guide VisuGuide = InstrumentCombined.addChild('VisuGuide') VisuGuide.addObject('MechanicalObject', name='Quads') VisuGuide.addObject('QuadSetTopologyContainer', name='ContainerGuide') VisuGuide.addObject('QuadSetTopologyModifier', name='Modifier') VisuGuide.addObject('QuadSetTopologyAlgorithms', name='TopoAlgo', template='Vec3d') VisuGuide.addObject('QuadSetGeometryAlgorithms', name='GeomAlgo', template='Vec3d') VisuGuide.addObject('Edge2QuadTopologicalMapping', radius='1', listening='true', input='@../../topoLines_guide/meshLinesGuide', nbPointsOnEachCircle='10', flipNormals='true', output='@ContainerGuide') VisuGuide.addObject('AdaptiveBeamMapping', interpolation='@../InterpolGuide', name='visuMapGuide', output='@Quads', isMechanical=False, input='@../DOFs', useCurvAbs=True, printLog=False) # Ogl model VisuOgl = VisuGuide.addChild('VisuOgl') VisuOgl.addObject( 'OglModel', color=[0.2, 0.2, 0.8], quads='@../ContainerGuide.quads', material= 'texture Ambient 1 0.2 0.2 0.2 0.0 Diffuse 1 1.0 1.0 1.0 1.0 Specular 1 1.0 1.0 1.0 1.0 Emissive 0 0.15 0.05 0.05 0.0 Shininess 1 20', name='Visual') VisuOgl.addObject('IdentityMapping', input='@../Quads', output='@Visual') return (rootNode)