Hello Daniel, On 07/13/2012 05:23 AM, Daniel Weber wrote:
i've observed problems with the automatic computation of normals when reading triangular meshes from .off files. The direction of the normals is simply wrong. I know that there has already been a discussion on this mailing list, suggesting to simply flip the normals after the node has been generated.But when I use other file formats the normals are computed correctly. I therefore used Meshlab (and Blender) to generate a simple sphere and saved it in different file formats: .wrl. obj. and .off. (I've attached the files). In the attached example, the lighting looks wrong for the .off, whereas .obj and .wrl.are rendered correctly. I assume, that it is a bug in the .off file reader that accidentally flips indices of the triangles. If I load different file formats, I always need to check the file ending for flipping the normals afterwards or not. For me it would help a lot, if this distinction was not necessary. Can anybody point me to the routines for loading the .off files and (automatically) computing the normals? Maybe, i can send a patch then.
it appears the .off file reader reverses the order of vertices in a face. The file format descriptions I could find with a quick search don't mention if the faces are given in CCW or CW order. Given the problem you are running into it seems to me the loader should better preserve the orientation from the file, the attached patch should do that.
Could you give it a try please? Cheers, Carsten
diff --git a/Source/System/FileIO/OFF/OSGOFFSceneFileType.cpp b/Source/System/FileIO/OFF/OSGOFFSceneFileType.cpp index e78238e..5ed9e99 100644 --- a/Source/System/FileIO/OFF/OSGOFFSceneFileType.cpp +++ b/Source/System/FileIO/OFF/OSGOFFSceneFileType.cpp @@ -338,8 +338,10 @@ NodeTransitPtr OFFSceneFileType::read( std::istream &is, if(fN == i) { - n += vN = UInt32(faceVec[j].size()); - for(k = vN - 1; k >= 0; k--) + vN = UInt32(faceVec[j].size()); + n += vN; + + for(k = 0; k < vN; ++k) { index->editFieldPtr()->push_back(faceVec[j][k]); } @@ -366,7 +368,7 @@ NodeTransitPtr OFFSceneFileType::read( std::istream &is, pType = 0; break; } - + if(pType) { lens->push_back(n);
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users