13 December 2018 at 18 h 46 min #12595
I have a model (surgical scissors) which is made up of multiple meshes (base, connector, left & right scissors). I want to move the model as a whole at once using the keyboard, but I am not sure how to achieve this. I am trying to do it through python for now, by moving each mesh independently. Is there a better way of doing this?17 December 2018 at 14 h 38 min #12609
- SOFA Consortium
What you can actually do is to create yourself an animation : using WriteState. WriteState saves all positions into a file. Once you register the animation, you could replay it using ReadState.
To create rotation/translation/scaling of an object, you can always use the TransformEngine.
Let me know if it helps.
Hugo19 December 2018 at 11 h 19 min #12620
Can I get an example of a scene with a Rigid model and using TransformEngine.
Fayad19 December 2018 at 15 h 46 min #12623
- SOFA Consortium
Yes, take a look in examples/Components/engine/TransformEngine.scn
Hugo19 December 2018 at 22 h 21 min #12624
Thanks Hugo, I know about this example but it uses vec3d for the template, and I want to use a rigid one, when I do that it does not seem to work. So can you show me how I can do the TransformEngine with a rigid object that has a collision model.
Fayad19 December 2018 at 23 h 14 min #12625
- CNRS/Defrost Team
I tried in a small test to see how I would do a very simplified logic for a cissor.
Basically it is a “cissor” reference frame connected to two “child” frames to hold the local frames for each part of the cissor. The connection between the parent and child is done using a RigidRigidMapping. To any of these frame you can attach visual or collision models.
Then I made a python controller which actually connect the keypressed to actual transform of either the reference frame or the two sides when we open/close it.
It is quickly done and I have no idea if it is bullet proof… but here is the result, hoping you will find it useful.
# coding: utf-8 import Sofa def translate(x, t): p = x[0:3] q = x[3:] return [p+t, p+t, p+t]+q class CissorController(Sofa.PythonScriptController): '''Controller that handle open/close and movement of a cissor''' def __init__(self, node, cissor): self.cissor = cissor def onKeyPressed(self, c): o = None p = None if c == '+': o=0.1 elif c == '-': o=-0.1 elif c=='4': p = 0.1 elif c=='6': p = -0.1 if o is not None: # Open/Close the cissor. q = self.cissor.right.transform.rest_position self.cissor.right.transform.rest_position = translate(q,[o,0.0,0.0]) q = self.cissor.left.transform.rest_position self.cissor.left.transform.rest_position = translate(q,[-o,0.0,0.0]) if p is not None: ## Move along X the cissor q = self.cissor.transform.position self.cissor.transform.position = translate(q,[p,0.0,0.0]) class MyCissor(): '''A Sofa Prefab for a cissor.''' def __init__(self, node, name="MyCissor"): n = node.createChild(name) ## The reference transform to manipulate the whole cissor m = n.createObject("MechanicalObject", template="Rigid3", name="transform") ## The right side of the cissor with its own position/orientation. r = n.createChild("right") r.createObject("MechanicalObject", name="transform", template="Rigid3", position=[1.0,0.5,0.0,0,0,0,1]) r.createObject("RigidRigidMapping", name="map", initialPoints=r.transform.findData("rest_position").getLinkPath()) ## The left side of the cissor with its own position/orientation. l = n.createChild("left") l.createObject("MechanicalObject", name="transform", template="Rigid3", position=[-1.0,0.5,0.0,0,0,0,1]) l.createObject("RigidRigidMapping", name="map", initialPoints=l.transform.findData("rest_position").getLinkPath()) self.node = n def createScene(root): root.createObject("EulerImplicit") root.createObject("CGLinearSolver") c = MyCissor(root).node CissorController(c,c) c.transform.showObject=True c.right.transform.showObject=True c.left.transform.showObject=True
You must be logged in to reply to this topic.