17 April 2019 at 16 h 13 min #13417
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.
Zahra23 April 2019 at 12 h 22 min #13423
To add more clarity to my question, I’m posting the related files here:
This is my main python file:
the input mesh files:
In 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.
Zahra28 April 2019 at 18 h 38 min #13438
Just to save us some time, could you explain why you need this controller, what it is meant to do?
Hugo30 April 2019 at 17 h 51 min #13446
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.
Zahra4 May 2019 at 7 h 52 min #13455
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 here
Let me know if this helps.
Hugo6 May 2019 at 14 h 12 min #13459
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,
Zahra8 May 2019 at 18 h 38 min #13463
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>
Hugo11 May 2019 at 17 h 32 min #13472
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.
Zahra12 May 2019 at 18 h 33 min #13474
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
MeshObjLoaderwith any other loader format (
MeshGmshLoaderfor instance) as long as they include a surface mesh topology.
Hugo15 May 2019 at 13 h 13 min #13479
- You must be logged in to reply to this topic.