Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normals generation is wrong #37

Open
microy opened this issue Apr 21, 2014 · 2 comments
Open

Normals generation is wrong #37

microy opened this issue Apr 21, 2014 · 2 comments
Labels

Comments

@microy
Copy link

microy commented Apr 21, 2014

Hello,

the code used to generate the (vertex) normals gives a wrong result.

Original code :

def generateNormals(self):
    """If :attr:`normals` is `None` or you wish for normals to be
    recomputed, call this method to recompute them."""
    norms = numpy.zeros( self._vertex.shape, dtype=self._vertex.dtype )
    tris = self._vertex[self._vertex_index]
    n = numpy.cross( tris[::,1] - tris[::,0], tris[::,2] - tris[::,0] )
    normalize_v3(n)
    norms[ self._vertex_index[:,0] ] += n
    norms[ self._vertex_index[:,1] ] += n
    norms[ self._vertex_index[:,2] ] += n
    normalize_v3(norms)

    self._normal = norms
    self._normal_index = self._vertex_index

Problem :

    norms[ self._vertex_index[:,0] ] += n
    norms[ self._vertex_index[:,1] ] += n
    norms[ self._vertex_index[:,2] ] += n

Solution (naive implementation) :

   for i, f in enumerate( self._vertex_index ) :
         norms[ f ] += n[ i ]

The problem comes from the implementation norms[ self._vertex_index[:,0] ] += n where the face normal vector n is only added once per vertex (instead of a certain number).

Best regards !

@jterrace
Copy link
Member

Can you clarify what you mean? These are per vertex normals.

@microy
Copy link
Author

microy commented Apr 21, 2014

Yes but the implementation gives wrong result (as the vertex normal is the sum of the surrounding face normals).

The problem is the use of the integer indexing of the numpy array.

@jterrace jterrace added the bug label Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants