Forum Replies Created
-
AuthorPosts
-
timpBlocked
Hi @hugo,
Thanks for having a look at my scene! Your explanation for why the simulation crashes makes sense, I changed the scene accordingly and now it works.
Thank you!timpBlockedHi @hugo
Thanks for your reply!
Here’s the full scene:import Sofa import os def createScene(rootNode): ########################################## # Scene setup # ########################################## rootNode.createObject('RequiredPlugin', name='SofaPython') rootNode.createObject('RequiredPlugin', name='SofaSparseSolver') rootNode.createObject('VisualStyle', displayFlags='showVisualModels showBehaviorModels hideCollisionModels hideBoundingCollisionModels') rootNode.createObject('BackgroundSetting', color='1 1 1') rootNode.createObject('OglSceneFrame', style='Arrows', alignment='TopRight') rootNode.findData('gravity').value='0 0 0' rootNode.createObject('FreeMotionAnimationLoop') rootNode.createObject('GenericConstraintSolver', maxIterations='1000', tolerance = '0.001') rootNode.createObject('DefaultPipeline') rootNode.createObject('BruteForceDetection', name='N2') rootNode.createObject('DefaultContactManager', response='FrictionContact', responseParams='mu=0.6') rootNode.createObject('LocalMinDistance', name='Proximity', alarmDistance='2.0', contactDistance='0.5') ########################################## # Cube # ########################################## cube = rootNode.createChild('cube') cube.createObject('EulerImplicitSolver', name='odesolver_cube') cube.createObject('SparseLDLSolver', name='LDLsolver') cube.createObject('MeshVTKLoader', name='loader', filename='mesh/cube.vtk', rotation='180 0 0', translation='0 30 0') cube.createObject('TetrahedronSetTopologyContainer', src='@loader', name='container') cube.createObject('TetrahedronSetTopologyModifier') cube.createObject('TetrahedronSetTopologyAlgorithms', template='Vec3d') cube.createObject('TetrahedronSetGeometryAlgorithms', template='Vec3d') cube.createObject('MechanicalObject', name='MO_cube', template='Vec3d') cube.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM_cube', method='large', poissonRatio='0.3', youngModulus='200', drawAsEdges='false') cube.createObject('UniformMass', totalMass='0.0008') cube.createObject('LinearSolverConstraintCorrection', solverName='LDLsolver') cube.createObject('BoxROI', name='cubeROI_fix', box='20 -2 -20 -20 2 20', drawBoxes='true', position='@MO_cube.rest_position', tetrahedra='@container.tetrahedra') cube.createObject('FixedConstraint', indices='@cubeROI_fix.indices') #cube/cubeVisu cubeVisu = cube.createChild('visualModel') cubeVisu.createObject('MeshSTLLoader', filename='mesh/cube.stl', name='loader', rotation='180 0 0', translation='0 30 0') cubeVisu.createObject('OglModel', name='visual', src='@loader', color='0.5 0.8 0.2 0.5') cubeVisu.createObject('BarycentricMapping') #cube/collision cubeCollision = cube.createChild('collisionModel') cubeCollision.createObject('MeshSTLLoader', name='loader', filename='mesh/cube.stl', triangulate='1', rotation='180 0 0', translation='0 30 0') cubeCollision.createObject('MeshTopology', src='@loader') cubeCollision.createObject('MechanicalObject', src='@loader') cubeCollision.createObject('TTriangleModel', selfCollision='0') cubeCollision.createObject('TLineModel', selfCollision='0') cubeCollision.createObject('TPointModel', selfCollision='0') cubeCollision.createObject('BarycentricMapping') #cube/cubeInterfacePoints cubeInterPts = cube.createChild('cubeInterfacePoints') cubeInterPts.createObject('MeshSTLLoader', filename='mesh/cube_surface.stl', name='loader', rotation='180 0 0', translation='0 30 0') cubeInterPts.createObject('MeshTopology', position='@loader.position', triangles='@loader.triangles', name='mesh_cubeInterface') cubeInterPts.createObject('MechanicalObject', name='pointCloud_cube', template='Vec3d', showObject='1', showObjectScale='15') cubeInterPts.createObject('TTriangleModel') cubeInterPts.createObject('TLineModel') cubeInterPts.createObject('TPointModel') cubeInterPts.createObject('SubsetMapping') ########################################## # Cuboid # ########################################## cuboid = rootNode.createChild('cuboid') cuboid.createObject('EulerImplicitSolver', name='odesolver_cuboid') cuboid.createObject('SparseLDLSolver', name='LDLsolver') cuboid.createObject('MeshVTKLoader', name='loader', filename='mesh/cuboid.vtk', rotation='0 0 90', translation='15 45 0') cuboid.createObject('TetrahedronSetTopologyContainer', src='@loader', name='container') cuboid.createObject('TetrahedronSetTopologyModifier') cuboid.createObject('TetrahedronSetTopologyAlgorithms', template='Vec3d') cuboid.createObject('TetrahedronSetGeometryAlgorithms', template='Vec3d') cuboid.createObject('MechanicalObject', name='MO_cuboid', template='Vec3d') cuboid.createObject('TetrahedronFEMForceField', template='Vec3d', name='FEM_cuboid', method='large', poissonRatio='0.3', youngModulus='500', drawAsEdges='false') cuboid.createObject('UniformMass', totalMass='0.0008') #cuboid.createObject('UncoupledConstraintCorrection') cuboid.createObject('LinearSolverConstraintCorrection', solverName='LDLsolver') #cuboid/cuboidVisu cuboidVisu = cuboid.createChild('visualModel') cuboidVisu.createObject('MeshSTLLoader', filename='mesh/cuboid.stl', name='loader', rotation='0 0 90', translation='15 45 0') cuboidVisu.createObject('OglModel', name='visual', src='@loader', color='0.1 0.6 0.5 0.5') cuboidVisu.createObject('BarycentricMapping') #cuboid/collision cuboidCollision = cuboid.createChild('collisionModel') cuboidCollision.createObject('MeshSTLLoader', name='loader', filename='mesh/cuboid.stl', triangulate='1', rotation='0 0 -90', translation='-45 45 0') cuboidCollision.createObject('MeshTopology', src='@loader') cuboidCollision.createObject('MechanicalObject', src='@loader') cuboidCollision.createObject('TTriangleModel', selfCollision='0') cuboidCollision.createObject('TLineModel', selfCollision='0') cuboidCollision.createObject('TPointModel', selfCollision='0') cuboidCollision.createObject('BarycentricMapping') #cuboid/cuboidConnection cuboidConn = cuboid.createChild('cuboidConnection') cuboidConn.createObject('MeshSTLLoader', filename='mesh/cube_surface.stl', name='loader', rotation='180 0 0', translation='0 30 0') cuboidConn.createObject('MeshTopology', position='@loader.position', triangles='@loader.triangles') cuboidConn.createObject('MechanicalObject', name='pointCloud_cuboid', template='Vec3d', showObject='1', showObjectScale='5') cuboidConn.createObject('TTriangleModel') cuboidConn.createObject('TLineModel') cuboidConn.createObject('TPointModel') cuboidConn.createObject('BarycentricMapping') ########################################## # Bilateral Interaction Constraint # ########################################## id_pts="" for i in range(len(cubeInterPts.getObject('mesh_cubeInterface').findData('position').value)): id_pts= id_pts+str(i)+" " rootNode.createObject( 'BilateralInteractionConstraint', name='BIC', template='Vec3d', object1='@cube/cubeInterfacePoints/pointCloud_cube', object2='@cuboid/cuboidConnection/pointCloud_cuboid', first_point=id_pts, second_point=id_pts, ) return rootNode
Thank you!
26 March 2020 at 09:58 in reply to: [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin #15567timpBlockedHi @jnbrunet,
Okay, makes sense. For now, I don’t really need to start the GUI from Python, just thought it would be nice to have the option.
Thanks again for the explanation and your help!24 March 2020 at 12:13 in reply to: [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin #15540timpBlockedHi @jnbrunet,
The output is
SOFAGUI_QGLVIEWER:BOOL=ON SOFAGUI_QTVIEWER:BOOL=ON
I am not so sure what you mean by GUI support. But, I did not change any of the preconfigured settings related to the GUI when compiling SOFA. Does that help?
24 March 2020 at 11:49 in reply to: [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin #15538timpBlockedHey @jnbrunet,
Great, we are getting closer. 😉
Now the only thing that is still complaining is the GUIManager:
>>> Sofa.Gui.GUIManager.Init("example", "qglviewer") [ERROR] [GUIManager] No GUI registered. 1
If I type
Sofa.Gui.GUIManager.ListSupportedGUI(",")
I get an empty string.Any idea how to fix this? Thanks for your patience.
23 March 2020 at 15:08 in reply to: [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin #15526timpBlockedHi @jnbrunet,
I added the Sofa build directory to PATH. Trying option 1 gives the following output (same with option 2):>>> import SofaRuntime
>>> from Sofa.Core import Simulation
[ERROR] [PythonScript] ImportError: cannot import name ‘Simulation’ from ‘Sofa.Core’ (/home/tip/.local/lib/python3.7/site-packages/Sofa/Core.cpython-37m-x86_64-linux-gnu.so)
File “<stdin>”, line 1, in <module>Thanks for your help!
23 March 2020 at 10:19 in reply to: [SOLVED] Error when running scene in python interpreter with SofaPython3 plugin #15523timpBlockedHi @jnbrunet,
Thanks for your reply! I cannot test it right now but I will let you know if it worked soon.timpBlockedHi @Bruno,
thanks for your reply and the detailed explanation. I will have a look atpyautogui
then or try to find a workaround.timpBlockedHi all,
I have a follow-up question. In my Python scene I would like to be able stop and start the animation upon pressing a key. While I can stop the animation using:
rootNode.getRootContext().animate = False
starting it again by writing:
rootNode.getRootContext().animate = True
does not work.
Is it not possible to restart the animation in this way?
I appreciate your help! -
AuthorPosts