diff --git a/examples/BaseCamera.py b/examples/BaseCamera.py deleted file mode 100644 index e2ac348c..00000000 --- a/examples/BaseCamera.py +++ /dev/null @@ -1,95 +0,0 @@ -import Sofa.Core -from Sofa.constants import * -from random import randint -from splib.animation import easing -import math -import numpy - -def eulerToQuat(a): - """ This function takes an array of Euler Angles as argument and returns a Quaternion - """ - yaw, pitch, roll = a - cy = math.cos(yaw * 0.5); - sy = math.sin(yaw * 0.5); - cp = math.cos(pitch * 0.5); - sp = math.sin(pitch * 0.5); - cr = math.cos(roll * 0.5); - sr = math.sin(roll * 0.5); - - q = [0 for k in range(4)] - q[3] = cy * cp * cr + sy * sp * sr; - q[0] = cy * cp * sr - sy * sp * cr; - q[1] = sy * cp * sr + cy * sp * cr; - q[2] = sy * cp * cr - cy * sp * sr; - - return q - - -class KeyPressedController(Sofa.Core.Controller): - """ This controller monitors key and Mouse movements. - """ - def __init__(self, *args, **kwargs): - print(kwargs) - Sofa.Core.Controller.__init__(self, *args, **kwargs) - self.listening = True - self.name = "keyPressedController" - self.camera = kwargs.get("camera", None) - self.mousePositionOnClick=[0,0] - self.hasClicked = False - - def onKeypressedEvent(self, event): - N = 100 - if event['key'] == Key.Z: - for i in range(1,N): - self.camera.position[2] += - 0.5*(easing.sineInOut(i/(N-1))- easing.sineInOut((i-1)/(N-1))) - elif event['key'] == Key.Q: - for i in range(1,N): - self.camera.position[0] += - 0.5*(easing.sineInOut(i/(N-1))- easing.sineInOut((i-1)/(N-1))) - elif event['key'] == Key.D: - for i in range(1,N): - self.camera.position[0] += 0.5*(easing.sineInOut(i/(N-1))- easing.sineInOut((i-1)/(N-1))) - elif event['key'] == Key.X: - for i in range(1,N): - self.camera.position[2] += 0.5*(easing.sineInOut(i/(N-1))- easing.sineInOut((i-1)/(N-1))) - else : - print("") - - def onMouseEvent(self, event): - if (event['State']==1): - self.mousePositionOnClick[0] = event['mouseX'] - self.mousePositionOnClick[1] = event['mouseY'] - self.hasClicked = True - if (event['State']== 0): - if (self.hasClicked): - euler = [ 0.0, (event['mouseX'] - self.mousePositionOnClick[0])*0.001, (event['mouseY'] - self.mousePositionOnClick[1])*0.001] - quat = eulerToQuat(euler) - self.camera.rotate(quat) - self.mousePositionOnClick[0] = event['mouseX'] - self.mousePositionOnClick[1] = event['mouseY'] - if (event['State']==2): - self.hasClicked = False - - -def Sphere(rootNode, name, position, color): - #Creating the sphere - sphere = rootNode.addChild(name) - sphere.addObject('MechanicalObject', name="mstate", template="Rigid3", position=position) - - #### Visualization of the sphere - sphereVisu = sphere.addChild("VisualModel") - sphereVisu.loader = sphereVisu.addObject('MeshObjLoader', name="loader", - filename="mesh/ball.obj", scale=0.5) - sphereVisu.addObject('OglModel', name="model", src="@loader", color=color) - sphereVisu.addObject('RigidMapping') - return sphere - -def createScene(rootNode): - """ This scene is an example scene to demonstrate an implementation of a Controller for the Camera in runSofa. - To test this, in runSofa, you must put the View parameter (top left of the runSofa window) to OpenGL - Then click on Animate, and move the Camera using Ctrl + z, q, d and x, orientate it by clicking and moving with the Mouse! - """ - for i in range(30): - sphere = Sphere(rootNode, "sphere"+str(i), [randint(0,6),randint(0,6),randint(0,6),0,0,0,1],[i/40.0,i*0.7/40.0,0.9]) - rootNode.addObject("Camera", name = "camera") - rootNode.addObject(KeyPressedController(name = "MyController", camera = rootNode.camera)) - return rootNode diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 74fc8bae..e28bd2f1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,11 +3,8 @@ project(Examples) set(EXAMPLES_FILES ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/advanced_timer.py - ${CMAKE_CURRENT_SOURCE_DIR}/BaseCamera.py ${CMAKE_CURRENT_SOURCE_DIR}/basic.py ${CMAKE_CURRENT_SOURCE_DIR}/basic-addGUI.py - ${CMAKE_CURRENT_SOURCE_DIR}/easingScene.py - ${CMAKE_CURRENT_SOURCE_DIR}/easingSceneMatplotlib.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyController.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyDataEngine.py ${CMAKE_CURRENT_SOURCE_DIR}/emptyForceField.py @@ -17,9 +14,8 @@ set(EXAMPLES_FILES ${CMAKE_CURRENT_SOURCE_DIR}/liver.py ${CMAKE_CURRENT_SOURCE_DIR}/loadXMLfromPython.py ${CMAKE_CURRENT_SOURCE_DIR}/ReadTheDocs_Example.py - ${CMAKE_CURRENT_SOURCE_DIR}/realTimeClockScene.py ${CMAKE_CURRENT_SOURCE_DIR}/additional-examples/ControllerScene.py ) add_custom_target(${PROJECT_NAME} SOURCES ${EXAMPLES_FILES}) -install(FILES ${EXAMPLES_FILES} DESTINATION share/SofaPython3/examples COMPONENT resources) \ No newline at end of file +install(FILES ${EXAMPLES_FILES} DESTINATION share/SofaPython3/examples COMPONENT resources) diff --git a/examples/easingScene.py b/examples/easingScene.py deleted file mode 100644 index 4fdec8f3..00000000 --- a/examples/easingScene.py +++ /dev/null @@ -1,45 +0,0 @@ -import Sofa.Core -from splib.animation import easing -from splib.animation import AnimationManager, addAnimation -functionDict = { - "sphere0":easing.sineIn, "sphere1":easing.sineOut, "sphere2":easing.sineInOut, - "sphere3":easing.quadIn, "sphere4":easing.quadOut, "sphere5":easing.quadInOut, - "sphere6":easing.cubicIn, "sphere7":easing.cubicOut, "sphere8":easing.cubicInOut, - "sphere9":easing.quarticIn, "sphere10":easing.quarticOut, "sphere11":easing.quarticInOut, - "sphere12":easing.quinticIn, "sphere13":easing.quinticOut, "sphere14":easing.quinticInOut, - "sphere15":easing.expoIn, "sphere16":easing.expoOut, "sphere17":easing.expoInOut, - "sphere18":easing.circIn, "sphere19":easing.circOut, "sphere20":easing.circInOut, - "sphere21":easing.LinearRamp -} - -def myAnimate(target, factor): - with target.mstate.position.writeable() as tr: - tr[0][0] = -20 + functionDict[target.name.value](factor)*25 - target.mstate.init() - -def Sphere(rootNode, name, position, color): - #Creating the sphere - sphere = rootNode.addChild(name) - sphere.addObject('MechanicalObject', name="mstate", template="Rigid3", position=position) - - #### Visualization of the sphere - sphereVisu = sphere.addChild("VisualModel") - sphereVisu.loader = sphereVisu.addObject('MeshObjLoader', name="loader", filename="mesh/ball.obj", scale=0.5) - sphereVisu.addObject('OglModel', name="model", src="@loader", color=color) - sphereVisu.addObject('RigidMapping') - return sphere - -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 diff --git a/examples/easingSceneMatplotlib.py b/examples/easingSceneMatplotlib.py deleted file mode 100644 index cd64dcc7..00000000 --- a/examples/easingSceneMatplotlib.py +++ /dev/null @@ -1,60 +0,0 @@ -import numpy as np -from splib.animation import easing -import matplotlib.pyplot as plt - -Nbpoints = 150 - -functionList = [ - easing.sineIn, easing.sineOut, easing.sineInOut, - easing.quadIn, easing.quadOut, easing.quadInOut, - easing.cubicIn, easing.cubicOut, easing.cubicInOut, - easing.quarticIn, easing.quarticOut, easing.quarticInOut, - easing.quinticIn, easing.quinticOut, easing.quinticInOut, - easing.expoIn, easing.expoOut, easing.expoInOut, - easing.circIn, easing.circOut, easing.circInOut, - easing.LinearRamp -] - -functionName = [ - "sine", - "quad", - "cubic", - "quartic", - "quintic", - "expo", - "circ", - "LinearRamp" -] - -color = [ "red", "green", "blue", "yellow", "orange", "purple", "brown", "grey"] - -functionNameInOut = ["sineIn", "sineOut", "sineInOut"] - -X = np.linspace(0, 1, Nbpoints ,endpoint=True) -fig = plt.figure(figsize=(18,6)) -fig.canvas.set_window_title("Easing functions") - -plt.subplot(1, 2, 1) -for i in range(3): - Y =[] - for j in range(Nbpoints): - Y.append(functionList[i](X[j])) - plt.plot(X, Y, label=functionNameInOut[i]) -plt.legend(loc='upper left') -plt.title("Comparing In, Out and InAndOut for the sinus easing functions") - -plt.subplot(1, 2, 2) -for i in range(22): - Y =[] - for j in range(Nbpoints): - Y.append(functionList[i](X[j])) - k = i//3 - if (i/3 == k): - plt.plot(X, Y, label=functionName[k], color=color[k]) - else: - plt.plot(X, Y, color=color[k]) -plt.legend(loc='upper left') -plt.title("Comparing all of the easing functions available in SofaPython3") -plt.show() - - diff --git a/examples/realTimeClockScene.py b/examples/realTimeClockScene.py deleted file mode 100644 index beee4f5e..00000000 --- a/examples/realTimeClockScene.py +++ /dev/null @@ -1,33 +0,0 @@ -import Sofa.Core -from splib.animation import AnimationManager, addAnimation -import Sofa.Core -from splib.animation import easing -from splib.animation import AnimationManager, addAnimation - -def myAnimate(target, factor): - with target.mstate.position.writeable() as tr: - tr[0][0] = -20 + easing.sineInOut(factor)*20 - target.mstate.init() - -def Sphere(rootNode, name, position, color): - #Creating the sphere - sphere = rootNode.addChild(name) - sphere.addObject('MechanicalObject', name="mstate", template="Rigid3", position=position) - #### Visualization of the sphere - sphereVisu = sphere.addChild("VisualModel") - sphereVisu.loader = sphereVisu.addObject('MeshObjLoader', name="loader", filename="mesh/ball.obj", scale=0.5) - sphereVisu.addObject('OglModel', name="model", src="@loader", color=color) - sphereVisu.addObject('RigidMapping') - return sphere - -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 -