Skip to content

[examples] Update examples using imgui as default #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions examples/basic-addGUI.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Required import for python
import Sofa


# Choose in your script to activate or not the GUI
USE_GUI = True

def main():
# Required import for python
import Sofa
import SofaRuntime
import Sofa.Gui
# Make sure to load all SOFA libraries

#Create the root node
root = Sofa.Core.Node("root")
Expand All @@ -20,12 +16,13 @@ def main():
for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
import SofaQt
import Sofa.Gui
SofaRuntime.importPlugin("SofaImGui")

# Find out the supported GUIs
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
# Launch the GUI (qt or qglviewer)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
# Launch the GUI (imgui is now by default, to use Qt please refer to the example "basic-useQtGui.py")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
# Initialization of the scene will be done here
Expand Down
59 changes: 59 additions & 0 deletions examples/basic-useQtGUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Choose in your script to activate or not the GUI
USE_GUI = True

def main():
# Required import for python
import Sofa
import SofaRuntime

# Make sure to load all SOFA libraries

#Create the root node
root = Sofa.Core.Node("root")
# Call the below 'createScene' function to create the scene graph
createScene(root)
Sofa.Simulation.initRoot(root)

if not USE_GUI:
for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
import Sofa.Gui
import SofaQt

# Find out the supported GUIs
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
# Launch the GUI (qt or qglviewer)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
# Initialization of the scene will be done here
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("GUI was closed")

print("Simulation is done.")


# Function called when the scene graph is being created
def createScene(root):

root.addObject('RequiredPlugin', name='Sofa.Component.StateContainer')

# Scene must now include a AnimationLoop
root.addObject('DefaultAnimationLoop')

# Add new nodes and objects in the scene
node1 = root.addChild("Node1")
node2 = root.addChild("Node2")

node1.addObject("MechanicalObject", template="Rigid3d", position="0 0 0 0 0 0 1", showObject="1")

node2.addObject("MechanicalObject", template="Rigid3d", position="1 1 1 0 0 0 1", showObject="1")

return root


# Function used only if this script is called from a python environment
if __name__ == '__main__':
main()
12 changes: 10 additions & 2 deletions examples/emptyController.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def onKeypressedEvent(self, event):

if ord(key) == 20: # right
print("You pressed the Right key")

if key == 'M': # M key of the keyboard
print("You pressed the M key")


def onKeyreleasedEvent(self, event):
key = event['key']
Expand All @@ -54,6 +58,10 @@ def onKeyreleasedEvent(self, event):
if ord(key) == 20: # right
print("You released the Right key")

if key == 'M': # M key of the keyboard
print("You released the M key")


def onMouseEvent(self, event):
if (event['State']== 0): # mouse moving
print("Mouse is moving (x,y) = "+str(event['mouseX'])+" , "+str(event['mouseY']))
Expand Down Expand Up @@ -96,13 +104,13 @@ def createScene(root):
def main():
import SofaRuntime
import Sofa.Gui
import SofaQt
SofaRuntime.importPlugin("SofaImGui")

root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)

Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand Down
4 changes: 2 additions & 2 deletions examples/emptyDataEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def createScene(root):
def main():
import Sofa.Gui
import SofaRuntime
import SofaQt
SofaRuntime.importPlugin("SofaImGui")

root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)

Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand Down
4 changes: 2 additions & 2 deletions examples/emptyForceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def createScene(root):
def main():
import SofaRuntime
import Sofa.Gui
import SofaQt
SofaRuntime.importPlugin("SofaImGui")

root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)

Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand Down
4 changes: 2 additions & 2 deletions examples/example-forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def createScene(root):
def main():
import SofaRuntime
import Sofa.Gui
import SofaQt
SofaRuntime.importPlugin("SofaImGui")

root=Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)

Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand Down
8 changes: 4 additions & 4 deletions examples/liver-scriptcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ def main():
Sofa.Simulation.initRoot(root)

if not USE_GUI:
import SofaQt

for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
SofaRuntime.importPlugin("SofaImGui")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand All @@ -43,12 +42,13 @@ def createScene(root):
'Sofa.Component.ODESolver.Backward',
'Sofa.Component.SolidMechanics.FEM.Elastic',
'Sofa.Component.StateContainer',
'Sofa.Component.MechanicalLoad',
'Sofa.Component.Topology.Container.Dynamic',
'Sofa.Component.Visual',
'Sofa.GL.Component.Rendering3D'
])

root.addObject('DefaultAnimationLoop')
root.addObject('DefaultAnimationLoop', computeBoundingBox=False)

root.addObject('VisualStyle', displayFlags="showCollisionModels hideVisualModels showForceFields")
root.addObject('CollisionPipeline', name="CollisionPipeline")
Expand Down
5 changes: 2 additions & 3 deletions examples/liver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ def main():
for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
import SofaQt

Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
SofaRuntime.importPlugin("SofaImGui")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
Sofa.Gui.GUIManager.MainLoop(root)
Expand Down
6 changes: 3 additions & 3 deletions examples/loadXMLfromPython.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def createScene(root):
def main():
import SofaRuntime
import Sofa.Gui
import SofaQt

root = Sofa.Core.Node("root")
createScene(root)
Sofa.Simulation.initRoot(root)

# Find out the supported GUIs
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
# Launch the GUI (qt or qglviewer)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
# Launch the GUI (imgui is now by default, to use Qt please refer to the example "basic-useQtGui.py")
SofaRuntime.importPlugin("SofaImGui")
Sofa.Gui.GUIManager.Init("myscene", "imgui")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
# Initialization of the scene will be done here
Expand Down
Loading