MeshLab: Render obj file with my own computed normals
Asked Answered
N

2

7

I am trying to write a obj file with vertices. I am computing the vertex normals in my code and writing to this file as well. When I try to render this file in Meshlab it reads the vertices correctly, but when I go to 'Render->Show vertex normals', it is not showing the normals that I computed. Rather MeshLab computes its own normals and shows them.

I am not sure how I can visualize the normals that I computed/wrote to file. I want to apply Meshlab shader later based on my computed normals.

To test this I created a test obj file-

vn 0.517350 0.517350 0.517350
v 0.500000 0.500000 0.500000
vn -0.333333 0.666667 0.666667
v -0.500000 0.500000 0.500000
vn 0.666667 -0.333333 0.666667
v 0.500000 -0.500000 0.500000
vn -0.666667 -0.666667 0.333333
v -0.500000 -0.500000 0.500000
f 1//1 2//2 3//3
f 4//4 3//3 2//2

This is just one square. Now if I change the normal values in this file, it still shows its own vertex normals when I select 'Render->Show vertex normals'. How can I have my own normals and apply shader that works on my computed normals?? Please help.

Thanks!!

Novelty answered 29/6, 2011 at 0:14 Comment(2)
Did you try first declaring all vertices, then all normals? Maybe the .obj file parse expects that (some parsers do). Another suggestion: try to also include texture coordinates, even if you don't use them.Millicent
Not all OBJ importers respect normals and will sometimes just override the mesh with their own calculated normals. I would first make sure that's not the case with MeshLab, otherwise you might be doing everything right and still get the wrong result.Boland
B
1

Not all OBJ importers respect normals. I found this old bug which appears to still be open about how MeshLab's ignores normals in OBJs: http://sourceforge.net/p/meshlab/bugs/70/

You might be doing everything correctly but the issue may not be on your side.

When dealing with mesh interchange which can get quite hairy because of the different levels of support in various software, it's handy if you are doing it a lot to have multiple 3D applications to test your exported data against. Then you can more quickly figure out if the problem is on your side or theirs.

One workaround if you absolutely need the object to display correctly against a broken importer and can't use other formats is to manually unweld (duplicate) the vertices to give you those sharp creases/hard edges. That won't give you as much freedom as arbitrarily specifying normals, but it'll allow you to preserve those discontinuous boundaries where regions should not be smoothly interpolated and instead have a crease.

Boland answered 24/5, 2015 at 8:15 Comment(0)
Z
1

It seem than today (2019) the problem is solved in meshlab.

In the image below you can see your original .obj file (left), and one modified version changing the orientation of a normal (right). The normal has changed as expected.

enter image description here

Zetana answered 12/11, 2019 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.