Home › Forum › SOFA › Using SOFA › [SOLVED] How to export .OBJ files at specified time steps, before ending the animation?
Tagged: 64_bits, Linux_ubuntu, SOFA_1706
- This topic has 9 replies, 2 voices, and was last updated 5 years, 6 months ago by Zahra.
-
AuthorPosts
-
17 April 2019 at 16:13 #13417ZahraBlocked
Hi,
I need to consecutively animate a model under certain applied forces. For this purpose, I did some changes in the method “onBeginAnimationStep” so that after animating the model with a certain applied force with specified time steps, the deformed mesh is exported. Then the scene resets (by reseting the state vectors of the MechanicalObject), and then again another force is applied on the mesh until all the forces are applied and finally the animation stops.
My problem here is This:
I need to export the meshes in both formats of .GMSH (for the FEM deformation) and .OBJ (for visual model). The Problem here is that the OBJExporter just exports the file after the animation stops, which means just the last simulation is considered. Does anybody know how I can fix this problem?
I don’t have this problem for meshExporter, as by selecting the option ‘exportEveryNumberOfSteps’, it exports the meshes from all the simulations. However, this option doesn’t work for OBJExporter.
Best,
Zahra23 April 2019 at 12:22 #13423ZahraBlockedHi again,
To add more clarity to my question, I’m posting the related files here:
This is my main python file:
https://gist.github.com/zbounik/fa61c74209a6dbc85cacbe170f9f17b5the controller:
https://gist.github.com/zbounik/569971d696522a2b5b4088888a535dd0
the input mesh files:
https://gist.github.com/zbounik/0525820bbe52a9b74b421d3785048259In the main file, if I disable the “controller” and run the file, the obj mesh is extracted correctly. However, if I enable the controller and run the main file again, the obj meshes are not extracted. Any help is appreciated.
Best,
Zahra28 April 2019 at 18:38 #13438HugoKeymasterHi @zahra
Just to save us some time, could you explain why you need this controller, what it is meant to do?
ThanksHugo
30 April 2019 at 17:51 #13446ZahraBlockedDear @Hugo,
I use this controller to, each time, apply different forces on a number of nodes on the mesh, to have a variety of liver deformations. For example, the force of magnitude -20 is applied on the node 88, and after the accumulative time steps of 0.5, the deformed mesh is saved. Then the simulation resets (by resetting the mechanicalObject’s positions and velocities). Afterwards, the force of magnitude -10 is applied and again the deformed mesh is saved. In my code the lengths of i(which defines the applied forces) and j(which defines the indices on which the forces are applied) are high, but I changed the uploaded one to decrease the execution time for anyone who wants to try it.
Best,
Zahra4 May 2019 at 07:52 #13455HugoKeymasterHi Zahra
I have not used the OBJExporter which is an old component exporting not only one but all visual models available. It would need a lot of reformatting and cleaning.
A trick for you would be to mimic a key pressed (pressing ctrl+p seems to trigger an export). you could do this when the export is needed.
See python example hereLet me know if this helps.
BestHugo
6 May 2019 at 14:12 #13459ZahraBlockedHi @Hugo,
Thank you for your guidance. Before trying other tricks, I need to give more information on my problem, as you may know other more straight ways for solving it.
Yes, there are bothering problems with OBJExporter. In fact, I prefer to extract the visual mesh in GMSH format, but when I use the meshExporter in the visual node, it still extracts the deformation mesh and not the visual mesh. Is there any other way to solve this problem?
I have another question here: the filemesh in OGLModel must be in the format of OBJ? As if I use other formats, there would be no visual model in the run window.
Thanks in advance,
Zahra
8 May 2019 at 18:38 #13463HugoKeymasterHi @zahra
Yes you can indeed a way to solve your issue and fo what you described. You can add the MeshExporter in the visual node and specify the data field (position, edges, triangles) you want to export.
Here is an example :
<Node name="Visu" tags="Visual" gravity="0 -9.81 0"> <OglModel name="VisualModel" fileMesh="mesh/liver-smooth.obj" /> <BarycentricMapping name="visual mapping" input="@../dofs" output="@VisualModel" /> <MeshExporter filename="testMyAwesomeExport" position="@VisualModel.position" edges="@VisualModel.edges" triangles="@VisualModel.triangles" exportEveryNumberOfSteps="1" format="gmsh"/> </Node>
Best
Hugo
11 May 2019 at 17:32 #13472ZahraBlockedHi @Hugo,
Wow! That’s great! Thank you so much.
What about using the filemesh format in OGLModel? Should it be in the format of OBJ? As when I use other formats, there is no visual model in the run window.
Best,
Zahra12 May 2019 at 18:33 #13474HugoKeymasterHi @zahra
Actually the right way to write it is as follows:
<Node name="Visu" tags="Visual" gravity="0 -9.81 0"> <MeshObjLoader name="VisualLoader" filename="mesh/liver-smooth.obj" /> <OglModel name="VisualModel" src="@VisualLoader" /> <BarycentricMapping name="visual mapping" input="@../dofs" output="@VisualModel" /> <MeshExporter filename="testMyAwesomeExport" position="@VisualModel.position" edges="@VisualModel.edges" triangles="@VisualModel.triangles" exportEveryNumberOfSteps="1" format="gmsh"/> </Node>
and there, you can actually replace the
MeshObjLoader
with any other loader format (MeshGmshLoader
for instance) as long as they include a surface mesh topology.Best
Hugo
15 May 2019 at 13:13 #13479 -
AuthorPosts
- You must be logged in to reply to this topic.