[Bf-python] FaceNormals

models at paposo.com models at paposo.com
Sat Oct 18 18:07:58 CEST 2003


This looks o.k.:

else if (strcmp(name, "normal") == 0)
 {
  if(EXPP_check_sequence_consistency(mf->v, &NMVert_Type))
  {
   float fNormal[3] = {0.0,0.0,0.0};
   int nSize = PyList_Size(mf->v);
   if(nSize == 4)
   {
    CalcNormFloat4( &((BPy_NMVert*)(PyList_GetItem(mf->v, 0)))->co,
        &((BPy_NMVert*)(PyList_GetItem(mf->v, 1)))->co,
        &((BPy_NMVert*)(PyList_GetItem(mf->v, 2)))->co,
        &((BPy_NMVert*)(PyList_GetItem(mf->v, 3)))->co,
        &fNormal);
    return Py_BuildValue("[f,f,f]",fNormal[0],fNormal[1],fNormal[2]);
   }
   else if(nSize == 3)
   {
    CalcNormFloat( &((BPy_NMVert*)(PyList_GetItem(mf->v, 0)))->co,
        &((BPy_NMVert*)(PyList_GetItem(mf->v, 1)))->co,
        &((BPy_NMVert*)(PyList_GetItem(mf->v, 2)))->co,
        &fNormal);
    return Py_BuildValue("[f,f,f]",fNormal[0],fNormal[1],fNormal[2]);
   }
   else
    return EXPP_ReturnPyObjError (PyExc_AttributeError,
          "face must contain either 3 or 4 verts");
  }
  else
   return EXPP_ReturnPyObjError (PyExc_AttributeError,
          "this face does not contain a series of NMVerts");
 }

I've tested this with a script looking at 3 and 4 sided faces.  It returns
the expected normal value. If you pass anything other 3 or 4 faces it
returns an error, or if you pass anything other than a set of NMVerts it
returns an error. Also if the values you pass are non-sensical then you get
back 0,0,0 (the default).  What's nice about this is that it returns the
right normal based on clockwise or counter-clockwise additions of verts to
the face.




More information about the Bf-python mailing list