Home › Forum › SOFA › Programming with SOFA › [SOLVED] How to convert obj to msh format file?
Tagged: Gmsh Loading
- This topic has 6 replies, 7 voices, and was last updated 4 years, 11 months ago by Eyad.
-
AuthorPosts
-
9 January 2018 at 07:13 #10283BennyYanBlocked
How to convert obj to msh format file?
No sample source code about it.
I try to make a ConvertObjToMsh function with MeshObjLoader/MeshExporter class, but it failed to execute.The source code is as follows:
================================================================
#include <sofa /core/objectmodel/SPtr.h> #include <sofaloader /MeshObjLoader.h> #include <sofaexporter /MeshExporter.h> #include <sofa /core/objectmodel/DataFileName.h> bool ConvertObjToMsh() { using sofa::component::loader::MeshObjLoader; using sofa::core::objectmodel::New; MeshObjLoader::SPtr loaderFixed = New<meshobjloader>(); loaderFixed->setName(“loader”); std::string filenameObj = “D:/skull_and_teeth_coarse.obj”; loaderFixed->setFilename(filenameObj); bool bResult = loaderFixed->load(); if (!bResult) { return false; } using sofa::component::misc::MeshExporter; // class BaseLoader : public virtual objectmodel::BaseObjec MeshExporter::SPtr exp = New<meshexporter>(); //loaderFixed sofa::core::objectmodel::BaseContext* pContextLoad = loaderFixed->getContext(); sofa::core::objectmodel::BaseContext* pContextExt = exp->getContext(); pContextExt = pContextLoad; exp->init(); // Execution here failed exp->writeMesh(); return true; }
How to convert obj to msh format file?
22 November 2018 at 17:00 #12511HugoKeymasterdear @bennyyan888888
In a simple way, you can load you *.obj mesh in blender, export in *.stl, then load the *.stl in the software gmesh and export a *.msh format.
If you really want to get it automatic in C++, you need to create the two classes (MeshObjLoader, MeshExporter) and specify each Data of the MeshExporter (position, edges, triangles, quads, tetras, hexas) from the loader info.
If you face issue, could you share the error output ?
Note that for mesh format loading and exporting, a project is going on to use the assimp library. Stay tuned.
Best
Hugo
22 November 2018 at 19:47 #12520HarrisBlockedThe way I convert .obj files into .msh:
1)Convert .obj to .stl in blender or in meshlab
2)Use tetgen to tetrahedralize the surface model.Tetgen make a .mesh file
3)Convert .mesh to .msh in gmsh softwarehope this helps,
Harris24 April 2019 at 15:39 #13431ZahraBlockedHi,
maybe this is simple question but I’am confused.
I am doing this as @Hugo mentioned: “load *.obj mesh in blender, export in *.stl, then load the *.stl in the software gmesh and export a *.msh format.” but there is some translation and rotation when I load the .obj file in blender. Anybody knows how I can have the exact file without translation and rotation?Best,
Zahra11 June 2019 at 07:26 #13620simonBlockedI used MeshLab to convert *.obj to *.stl and then used GMsh to convert *.stl to *.msh. There *.msh format I received is diffent from the *.msh given by Sofa
28 November 2019 at 15:25 #14661vickyBlockedhi Harris,
1. Convert .obj to .stl in blender and import in gmsh {http://gmsh.info/} from gmesh tool exported as mesh-Gmesh MSH(*.msh) .msh . this is not working.<MeshGmshLoader name=”GmshLoader” filename=”Sphere.msh” />
<Mesh src=”@GmshLoader”/>
<MechanicalObject name=”dofs” scale=”10″ src=”@GmshLoader” />
<TriangularBendingSprings name=”FEM-Bend” stiffness=”300″ damping=”1.0″ />
<TriangleCollisionModel />error:file’Sphere.msh’ finally appears not to be a Gmsh file
23 December 2019 at 10:40 #15084EyadBlockedTo get a .msh that works with SOFA, I imported a .stl file into gmsh, then exported into a “Mesh – Gmsh MSH (*.msh) format”.
When prompted for the msh options, select “Version 2 ASCII” format, for some reason ticking “select all elements” or not generates the same file for me, it works in both cases. Just don’t tick the “save parametric coordinates” box.Hope this helps!
-
AuthorPosts
- You must be logged in to reply to this topic.