Hi all

These few fixes adds custom smoothing angle to normal calculation. The extra
line of code checks if the touching face normal is less than 'smooth angle'
away from face normal in question.

- Jesper Knudsen

void
//--> (1) new smooth angle argument
lib3ds_mesh_calculate_normals(Lib3dsMesh *mesh, Lib3dsVector *normalL ,
Lib3dsFloat smoothangle_deg )
{
//--> (2) treshold for smoothing
  Lib3dsFloat alimit = (float)cos(smoothangle_deg*1.74532925199432958e-2 );

  Lib3dsFaces **fl; 
  Lib3dsFaces *fa; 
  unsigned i,j,k;

  if (!mesh->faces) {
    return;
  }

//...
//...
//...

      ASSERT(f->points[j]<mesh->points);

      if (f->smoothing) {
        lib3ds_vector_zero(n);
        k=0;
        for (p=fl[f->points[j]]; p; p=p->next) {
          found=0;
          for (l=0; l<k; ++l) {
            if (fabs(lib3ds_vector_dot(N[l], p->face->normal)-1.0)<1e-5) {
              found=1;
              break;
            }
          }
          if (!found) {
//--> (3) 'f->smoothing' removed, wouldn't be here if false
            if (p->face->smoothing) {
//--> (4) dot this face and neighbor face
              Lib3dsFloat dot = lib3ds_vector_dot(f->normal,p->face->normal
);
//--> (5) only consider this neighbor face, if angle is close enough
              if( dot > alimit )
              {
                lib3ds_vector_add(n,n, p->face->normal);
                lib3ds_vector_copy(N[k], p->face->normal);
                ++k;
              }
            }
          }
        }
      } 
 
//...
//...
//...

}




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel

Reply via email to