Krabby127 / lib3ds

Automatically exported from code.google.com/p/lib3ds
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Keep default normal when smooth computation leads to null normal #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download the 3DS file http://www.baument.com/restore/Models/Faucet1.zip
available at http://www.baument.com/restore/archives.html
2. Read it with lib3ds
3. In smooth normals computation part of lib3ds_mesh_calculate_vertex_normals 
function of lib3ds_mesh.c, this should lead to a few incorrect normals (I say 
"should" because I got this result using a pseudo-translation of lib3ds in Java 
3D).

What is the expected output? What do you see instead?
Getting default normals from lib3ds_vector_normalize when length is 0 isn't a 
major issue, but it would be better to keep the default normal in that case 
(i.e. the normal computed before smoothing operation). After line 222 of 
lib3ds_mesh.c, I would suggest to add this test:

    if (lib3ds_vector_length(n) == 0) {
        lib3ds_vector_copy(n, fa[3*i+j].normal);
    }

(with an additional lib3ds_vector_length_squared function, you could spare a 
call to sqrt here)

What version of the product are you using? 
I looked to source code of version 20080909

Original issue reported on code.google.com by epuyba...@gmail.com on 16 Sep 2014 at 9:42