Home › Forum › SOFA › Programming with SOFA › load model built by solidworks
Tagged: 64_bits, Linux_ubuntu, Plugin_SoftRobots, SOFA_1912
- This topic has 1 reply, 2 voices, and was last updated 4 years, 6 months ago by Hugo.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
27 May 2020 at 15:24 #16402wrfBlocked
Hi,
I use the solidworks to build a ‘Cube’, and then output the ‘Cube’ in ‘stl’ style. I want to use the sofa to load the model, but it fails.
My code is:import os from stlib.scene import Scene dirPath = os.path.dirname(os.path.abspath(__file__))+’/’ def createScene(rootNode): # Setting the gravity, assuming the length unit is in millimeters scene = Scene(rootNode, gravity=[0.0, -9810, 0.0], plugins=[“SofaSparseSolver”]) # Setting the timestep in seconds rootNode.dt = 0.001 # Tool to load the mesh file of the silicone piece. It will be used for both the mechanical and the visual models. rootNode.createObject(“MeshSTLLoader”, name=”loader2″, filename=”mesh/cube.STL”) # Basic mechanical modelling of the silicone piece elasticbody = rootNode.createChild(“MechanicalBody”) elasticbody.createObject(“MechanicalObject”, name=”dofs”, position=rootNode.loader2.position, showObject=True, showObjectScale=5.0, rotation=[90.0, 0.0, 0.0]) elasticbody.createObject(“UniformMass”) elasticbody.createObject(“EulerImplicitSolver”) elasticbody.createObject(“SparseLDLSolver”) # Visual object visual = rootNode.createChild(“Visual”) # The mesh used for the Visual object is the same as the one for the MechanicalObject, and has been introduced in the rootNode visual.createObject(“OglModel”, name=”renderer”, src=’@../loader2′, color=[1.0, 1.0, 1.0, 2]) # A mapping applies the deformations computed on the mechanical model (the input parameter) # to the visual model (the output parameter). elasticbody.createObject(“IdentityMapping”, input=elasticbody.dofs.getLinkPath(), output=visual.renderer.getLinkPath())
And I got the information in terminal as following:
[INFO] [SceneCheckerVisitor] Validating node “root” with checks: [SceneCheckDuplicatedName, SceneCheckMissingRequiredPlugin, SceneCheckUsingAlias] [INFO] [SceneCheckerVisitor] Finished validating node “root”. [WARNING] [UniformMass(UniformMass)] indices vector size is <= 0 [WARNING] [RealGUI] Global Bounding Box seems very small; Your viewer settings (based on the bbox) are likely invalid, switching to default value of [-1,-1,-1,1,1,1].This is caused by using component which does not implement properly the updateBBox function.You can remove this warning by manually forcing a value in the parameter bbox="minX minY minZ maxX maxY maxZ" in your root node
31 May 2020 at 23:45 #16481HugoKeymasterHi @ruofeng
The error in the console is giving you a hint:
[WARNING] [UniformMass(UniformMass)] indices vector size is <= 0
Here your MechanicalObject has a size 0, because your initialization is not properly defined. It should be:
... # Tool to load the mesh file of the silicone piece. It will be used for both the mechanical and the visual models. loader2 = rootNode.createObject("MeshSTLLoader", name="loader2", filename="mesh/cube.STL") # Basic mechanical modelling of the silicone piece elasticbody = rootNode.createChild("MechanicalBody") elasticbody.createObject("MechanicalObject", name="dofs", position=loader2.position, showObject=True, showObjectScale=5.0, rotation=[90.0, 0.0, 0.0]) elasticbody.createObject("UniformMass") ...
your MechanicalObject could also be initiated like:
elasticbody.createObject("MechanicalObject", name="dofs", position="@../loader2.position", showObject=True, showObjectScale=5.0, rotation=[90.0, 0.0, 0.0])
Let us know if this works fine.
Hugo
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.