Home › Forum › SOFA › Using SOFA › Exporting OBJ files : wrong normals
- This topic has 16 replies, 4 voices, and was last updated 3 years ago by Julien D..
-
AuthorPosts
-
20 July 2021 at 11:08 #20042Julien D.Blocked
Hello everyone
I have an issue regarding the OBJ export.
I am deforming a regular grid topology (filled with a triangular FEM force field) which I can deform in several locations simultaneously.I’d like to export this mesh to reimport it using Unity.
That’s what I’m currently doing using an OBJExporter component with the line
<OBJExporter name="export_OBJ" filename="@../export_surf.filename" exportEveryNumberOfSteps="10" exportAtBegin="false" />
in my .scn file.However, when I export the mesh the vertex normals are not properly exported : wrong values are given inside the .obj file. I’m going to comment with a post with pictures proving that, thanks to import using Blender displaying the normals.
I hope that any of you has a solution to export the normals properly.
Thank you in advance for your answer.
Best wishes to everyone and enjoy your summer 🙂
22 July 2021 at 16:17 #20047Julien D.BlockedSo, to complete, here is the SOFA mesh with a top and side views, displaying the vertex normals in green :
And here are the face normals, which are well rendered by Blender (and are correctly estimated) :
And there the vertex normals which are not properly calculated :
The normals data in the .obj file (vn) are effectively wrong and correspond to what is displayed in Blender. So the issue comes from the OBJExporter component and not from the mesh import on Blender (or Unity).
Thank you in advance for your help 🙂
23 July 2021 at 11:26 #20071Julien D.BlockedHello, I don’t know why but the images cannot be displayed, even though I’ve used the proper tool and copied the links in my previous post…
So basically the normals displayed in SOFA are properly perpendicular to my planar surface, but they are not anymore after I’ve exported the mesh from SOFA and re-imported it either on Unity or on Blender.
However I’m getting on holidays, so I might be slower to answer too.
Thank you in advance for your help 🙂
23 July 2021 at 12:42 #20075jnbrunetModerator23 July 2021 at 14:39 #200761 September 2021 at 14:47 #20286younesssssBlockedHi @julien,
I think it’s a rotation issue between these two coordinates systems (SOFA and Blender).
Export three normals Nx (1, 0, 0), Ny (0, 1, 0) and Nz (0, 0, 1) from one of the coordinate systems to the other in order to obtain the transformation.1 September 2021 at 14:49 #20287Julien D.BlockedHi @younessss , thank you a lot for your help 🙂
I’m gonna try it as soon as possible.
Have a great day 🙂
1 September 2021 at 22:17 #20292Julien D.BlockedOkie guys, we learn something every day, right ?
So today I’ve learnt that according to the model considered by SOFA (mechanical or visual, for instance), the normals aren’t the same at all !
You can compare by your own eyes the normals calculated from the FEM models (in red, green and blue) and the normals computed from the visual models (in white). The last ones are wrong while the others are good.image
(I don’t know how to set up images properly here so I’ve also put the link above)So there’s a transformation between the axis of VISUAL and mechanical models. It’s very strange.
Have a good night/day
1 September 2021 at 22:23 #20293Julien D.BlockedOkie guys, we learn something every day, right ?
So today I’ve learnt that according to the model considered by SOFA (mechanical or visual, for instance), the normals aren’t the same at all !
You can compare by your own eyes the normals calculated from the FEM models (in red, green and blue) and the normals computed from the visual models (in white). The last ones are wrong while the others are good.PS : I have an issue to send the image, so here’s the link
2 September 2021 at 17:20 #20298Julien D.BlockedEveryone the issue is solved !
So actually, the only issue from Sofa is that it doesn’t calculate the normals of regular grids properly.
For a regular grid, some normals of edges point outside and some point inside of the volume, therefore the interpolated vertex normals are wrong.Then, to calculate the normals properly, you do your geometric mesh on Blender (which I have done) and you make sure to recalculate the normals outside (very easy to do in Blender).
When the mesh is deformed, the normals stay well calculated.Many thanks to @youness and @damien for their help !
7 October 2021 at 10:25 #20540HugoKeymasterHey @jducrocq007
Thanks for the feedback.
Do you have a simple scene highlighting this issue?
Have you understood where the problem comes from in the code? A PR on this would be great!Best wishes,
Hugo
11 October 2021 at 12:26 #20587Julien D.BlockedHey @Hugo,
I prefer being honest and say that I am NOT an expert regarding SOFA code, I barely understand it.
And I’m a beginner regarding git world and all of this, so I know what a Pull Request is but I’m not qualified enough yet to do it myself. More qualified people in SOFA code should modify the SOFA code if it need to be done.Anyways, I have discussed this issue with Damien and a few others on Defrost team, and it came out were the issue “mathematically” came from. On regular grid topologies, the normals of the faces are oriented to the exterior or the interior of the mesh. Therefore, the normals of each vertex, which are an interpolation of the normals of the faces, are calculated wrong.
As a simple scene, you can just place a regularGridTopology component of any size in an empty scene, with a visual model being itself, and visualize its normals. If you export this models with the OBJExporter and visualize the model and display its faces normals, you’ll see the issue.
If he doesn’t mind, if think that you should ask @Damien from Defrost Team to give you more details about this, Hugo.
11 October 2021 at 12:28 #20588Julien D.BlockedAs an example, my scene :
<?xml version="1.0" ?> <Node name="root" dt="0.1" gravity="0 0 0"> <RequiredPlugin pluginName="SofaSparseSolver"/> <RequiredPlugin pluginName="SofaOpenglVisual"/> <RequiredPlugin pluginName="SofaMiscCollision"/> <RequiredPlugin pluginName='SofaBoundaryCondition'/> <RequiredPlugin pluginName='SofaGeneralDeformable'/> <RequiredPlugin pluginName='SofaImplicitOdeSolver'/> <RequiredPlugin pluginName='SofaLoader'/> <RequiredPlugin pluginName='SofaMiscFem'/> <VisualStyle displayFlags="showBehavior hideVisual hideCollision" /> <EulerImplicit name="cg_odesolver" printLog="false" /> <CGLinearSolver iterations="25" name="linear solver" tolerance="1.0e-9" threshold="1.0e-9" /> <!-- define variables to reuse several times --> <MeshGmshLoader name="export_filename" filename="C:/Users/jducr/Documents/Developpement/Sofa_ws/scenes/exports/membrane_7x7_quads"/> <!-- The object to export --> <Node name="MyLittleObject"> <MechanicalObject name="mo"/> <UniformMass vertexMass="0.2" /> <RegularGrid name="hexaGrid" nx="8" ny="8" nz="4" xmin="-10.0" xmax="10.0" ymin="-10.0" ymax="10.0" zmin="0" zmax="0.50"/> <HexahedronSetTopologyContainer name="Topo" src="@hexaGrid" /> <HexahedralFEMForceField name="FEM" youngModulus="1e13" poissonRatio="0.3" method="large" /> <!-- Visual node to allow the exportation --> <Node name="VisualNode" > <OglModel name="Visual" color="green" /> <IdentityMapping input="@.." output="@Visual" /> </Node> <!-- <OBJExporter name="export_OBJ" filename="@../export_filename.filename" exportAtBegin="true" exportEveryNumberOfSteps="0" /> --> <MeshExporter name="export_GMSH" filename="../exports/membrane_7x7_quads" position="@Visual.position" edges="@Visual.edges" triangles="@Visual.triangles" exportAtBegin="true" exportEveryNumberOfSteps="0" format="gmsh"/> </Node> </Node>
14 October 2021 at 09:08 #20605HugoKeymasterHey @jducrocq007
There is no such man as a full expert of all aspects of SOFA! So please, dare making pull-requests even if you are unsure of your contribution. The dev team always welcome it.
Otherwise, create an issue on GitHub about this problem so that other devs can solve it.
Best wishes,
Hugo
14 October 2021 at 20:41 #20618Julien D.BlockedHello @Hugo, I
I’ll try to do one of those options, but the issue is probably more on the mathematical definition of the faces normals of a regularGridTopology than a code issue.
It’s more a thing like “do we want the faces normals to point inwards or outwards” ?
In my case, i would have liked them to be computed outwards, but perhaps some others would prefer them inwards so I don’t know if this is really an issue.However, thanks to the awesome explanations of Damien I’ve understood that the vertices normals were poorly calculated, in my case, because some faces normals of my regularGridTopology were pointing inwards and others were pointing outwards.
Best wishes,
Julien
29 October 2021 at 17:28 #20712HugoKeymasterHey @jducrocq007
Since the topic is now well identified and open in a GitHub issue, I think we can close this topic and follow up in the issue. Is it fine for you?
Best
Hugo
31 October 2021 at 17:43 #20716 -
AuthorPosts
- You must be logged in to reply to this topic.