Skip to content

Commit

Permalink
remove python2: (#80)
Browse files Browse the repository at this point in the history
- remove old mor/python lib
- rename python3 -> python
- make according changes in cmake
- change python3 reference to new path in project
  • Loading branch information
VannesteFelix authored Oct 17, 2023
1 parent 58ec061 commit 9212fd2
Show file tree
Hide file tree
Showing 143 changed files with 913 additions and 324,707 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ if (CollisionOBBCapsule_FOUND)
endif()

# Config files and install rules for pythons scripts
sofa_install_pythonscripts(PLUGIN_NAME ${PROJECT_NAME} PYTHONSCRIPTS_SOURCE_DIR "python")

sofa_install_pythonscripts(PLUGIN_NAME ${PROJECT_NAME} PYTHONSCRIPTS_SOURCE_DIR "python3")

find_file(SofaPython3Tools NAMES "SofaPython3/lib/cmake/SofaPython3/SofaPython3Tools.cmake")
Expand All @@ -117,11 +115,11 @@ if(SofaPython3Tools OR SofaPython3_FOUND)
endif()
message("-- Python3 packages will be installed in: ${SP3_PYTHON_PACKAGES_DIRECTORY}.")
SP3_add_python_package(
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python3/mor
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/mor
TARGET_DIRECTORY mor
)
SP3_add_python_package(
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python3/morlib
SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/morlib
TARGET_DIRECTORY morlib
)
endif()
Expand Down
6 changes: 3 additions & 3 deletions python/mor/animation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"""
__all__=["shakingAnimations"]
from shakingAnimations import defaultShaking
from shakingAnimations import shakingSofia
from shakingAnimations import shakingInverse
from mor.animation.shakingAnimations import defaultShaking
from mor.animation.shakingAnimations import shakingSofia
from mor.animation.shakingAnimations import shakingInverse
54 changes: 47 additions & 7 deletions python/mor/animation/shakingAnimations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

def upDateValue(actualValue,actuatorMaxPull,actuatorIncrement):
if actualValue < actuatorMaxPull:
print "INCREMENT ++"
print ("INCREMENT ++")
return actualValue + actuatorIncrement
else:
print "Done"
print ("Done")
return actualValue

def rotationPoint(Pos0, angle, brasLevier):
print ("In rotation POint")
size0 = len(Pos0);
posOut = [0.0]*3*size0;

for i in range(size0):

posOut[3*i] = Pos0[i][0]- brasLevier*cos(angle);
posOut[3*i+1] = Pos0[i][1] - brasLevier*sin(angle);
posOut[3*i+2] = Pos0[i][2]
print(posOut)

return posOut

Expand Down Expand Up @@ -69,15 +70,54 @@ def defaultShaking( objToAnimate, dt, factor, **param):
writeCurrent = True

if (writeCurrent):

print("For Actuator : "+objToAnimate.location)

actualValue = objToAnimate.item.findData(objToAnimate.params["dataToWorkOn"]).value[0][0]
actualValue = objToAnimate.item.findData(objToAnimate.params["dataToWorkOn"]).value[0]#[0]
actualValue = upDateValue(actualValue,objToAnimate.params['rangeOfAction'],objToAnimate.params['incr'])
objToAnimate.item.findData(objToAnimate.params["dataToWorkOn"]).value = actualValue
objToAnimate.item.findData(objToAnimate.params["dataToWorkOn"]).value = [float(actualValue)]

print ("Updated Value :"+str(actualValue)+'\n')

def shakingLiver( objToAnimate, dt, factor, **param):
"""
**Animation function made specifically to apply deformation on the liver scene.
It's an example of what can be a custom shaking animation.
The animation consist on taking a position in entry, rotate it, and then update it in the component.
To use it the **params** parameters of :py:class:`.ObjToAnimate` which is a dictionnary will need 6 keys:
**Keys:**
+---------------+-------+-----------------------------------------------------------------------+
| argument | type | definition |
+===============+=======+=======================================================================+
| dataToWorkOn | str | Name of the Sofa datafield we will work on here it will be *position* |
+---------------+-------+-----------------------------------------------------------------------+
| incrPeriod | float | Period between each increment |
+---------------+-------+-----------------------------------------------------------------------+
| incr | float | Value of each increment |
+---------------+-------+-----------------------------------------------------------------------+
| rangeOfAction | float | Until which value the data will increase |
+---------------+-------+-----------------------------------------------------------------------+
| angle | float | Initial angle value in radian |
+---------------+-------+-----------------------------------------------------------------------+
| rodRadius | float | Radius Lenght of the circle |
+---------------+-------+-----------------------------------------------------------------------+
"""
moduloResult = int( round( (factor * objToAnimate.duration)*1000 ) ) % int( dt * objToAnimate.params['incrPeriod']*1000 )
# print("currentTime - startTime : "+str(factor * objToAnimate.duration))
if moduloResult == 0:
currentPositions = objToAnimate.item.findData(objToAnimate.params["dataToWorkOn"]).value

objToAnimate.params['angle'] = upDateValue( objToAnimate.params['angle'],
objToAnimate.params['rangeOfAction'],
objToAnimate.params['incr'])

with objToAnimate.item.position.writeable() as positions:
newPositions = rotationPoint(positions, -objToAnimate.params['angle'], objToAnimate.params['rodRadius'])
for i in range(11):
positions[i] = newPositions[3*i:3*i+3]

def shakingSofia( objToAnimate, dt, factor, **param):
"""
**Animation function made specifically to shake the leg of
Expand Down
Loading

0 comments on commit 9212fd2

Please sign in to comment.