Unable to see two .stl at the same time #5069
-
The issue:I can't visualize two of the .stl objects at the same time but I can see them separately. Location of the objects: STL.zip
Version:
The code:#-*- coding: utf-8 -*-
import Sofa
#import contoller.py
def createScene(rootNode):
# Required plugins
rootNode.addObject('RequiredPlugin', name='Sofa.Component.IO.Mesh') # Needed to use components [MeshSTLLoader]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mapping.Linear') # Needed to use components [IdentityMapping]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mass') # Needed to use components [UniformMass]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.StateContainer') # Needed to use components [MechanicalObject]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Visual') # Needed to use components [VisualStyle]
rootNode.addObject('RequiredPlugin', name='Sofa.GL.Component.Rendering3D') # Needed to use components [OglModel]
rootNode.addObject('VisualStyle', displayFlags='showForceFields showBehaviorModels')
rootNode.addObject('DefaultAnimationLoop')
rootNode.addObject('DefaultVisualManagerLoop')
# Setting the timestep in seconds
rootNode.dt = 0.01
rootNode.addObject('RequiredPlugin',
pluginName='SoftRobots SofaPython3')
# Load the mesh file of the actuator and the plane.
rootNode.addObject('MeshSTLLoader', name='loader_actuator', filename='STL/Actuador.stl')
rootNode.addObject('MeshSTLLoader', name='loader_plane', filename='STL/plane.stl')
# Basic mechanical modelling of the actuator
actuator = rootNode.addChild('MechanicalModel')
actuator.addObject('MechanicalObject', name='actuator',
translation=[0,0,0],
showObject=True, showObjectScale=1.0,
rotation=[0.0, 0.0, 0.0])
actuator.addObject('UniformMass')
# Visual object for actuator
visual_actuator = rootNode.addChild('VisualModelActuator')
visual_actuator.addObject('OglModel', name='renderer_actuator',
src=rootNode.loader_actuator.getLinkPath(),
color=[1.0, 1.0, 1.0, 0.5])
visual_actuator.addObject('IdentityMapping',
input=actuator.actuator.getLinkPath(),
output=visual_actuator.renderer_actuator.getLinkPath())
# Basic mechanical modelling of the plane
plane = rootNode.addChild('MechanicalModelPlane')
plane.addObject('MechanicalObject', name='plane',
position=rootNode.loader_plane.position.getLinkPath(),
showObject=True, showObjectScale=1.0,
rotation=[0.0, 0.0, 0.0])
plane.addObject('UniformMass')
# Visual object for plane
visual_plane = rootNode.addChild('VisualModelPlane')
visual_plane.addObject('OglModel', name='renderer_plane',
src=rootNode.loader_plane.getLinkPath(),
color=[0.5, 0.5, 0.5, 1.0])
visual_plane.addObject('IdentityMapping',
input=plane.plane.getLinkPath(),
output=visual_plane.renderer_plane.getLinkPath())
'''
def onAnimateBeginEvent(event):
rootNode = event['rootNode']
pressureComponent = rootNode.getObject('pressureComponent')
if pressureComponent:
pressure = pressureComponent.findData('pressure').value
print(f'Pressure: {pressure}')
'''
return rootNode
def main():
import Sofa.Gui
root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.init(root)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("End of simulation.")
if __name__ == '__main__':
main() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thanks for rising the point @rickysaettone |
Beta Was this translation helpful? Give feedback.
-
Hi, I just checked on my side. The problem is not coming from the MeshSTLLoader but how you structured your scene file. The first mechanical Object is missing Here is a working version with other mesh available in the SOFA source code base.
|
Beta Was this translation helpful? Give feedback.
Hi,
I just checked on my side. The problem is not coming from the MeshSTLLoader but how you structured your scene file.
The first mechanical Object is missing
position=rootNode.loader_actuator.position.getLinkPath(),
Then I also suggest that the mapped node should be child of the first node with the mechanicalObject to avoid any confusion in the identityMapping:
visual_actuator = actuator.addChild('VisualModelActuator')
Here is a working version with other mesh available in the SOFA source code base.