From e91557fe1db38f403577274e9e21583ae44b221e Mon Sep 17 00:00:00 2001 From: Michael PLATINGS Date: Wed, 12 May 2010 08:54:22 +0000 Subject: [PATCH] From Martins Innus: The current fbx writer doesn't seem to support BIND_PER_VERTEX for normals. If you have this type of geometry it, exports the the first normal in the array over the whole primitive set. I don't know that the attached change should be applied as is, since I don't know enough about DrawArrays and Draw Elements to know if the indices for the vertices and normals are guaranteed to be the same. I tried it on a couple models and that seemed to be the case. The alternative is to have the logic down in setControlPointAndNormalsAndUV and set the normals there with the "vertexIndex" if the binding type is per vertex. Not sure what is cleaner. --- src/osgPlugins/fbx/WriterNodeVisitor.cpp | 17 +++++++++++++---- src/osgPlugins/fbx/WriterNodeVisitor.h | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.cpp b/src/osgPlugins/fbx/WriterNodeVisitor.cpp index ce159b623..891320542 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.cpp +++ b/src/osgPlugins/fbx/WriterNodeVisitor.cpp @@ -77,7 +77,16 @@ public: triangle.t1 = i1; triangle.t2 = i2; triangle.t3 = i3; - triangle.normalIndex = _curNormalIndex; + if (_normalBinding == osg::Geometry::BIND_PER_VERTEX){ + triangle.normalIndex1 = i1; + triangle.normalIndex2 = i2; + triangle.normalIndex3 = i3; + } + else{ + triangle.normalIndex1 = _curNormalIndex; + triangle.normalIndex2 = _curNormalIndex; + triangle.normalIndex3 = _curNormalIndex; + } triangle.material = _material; _listTriangles.push_back(std::make_pair(triangle, _drawable_n)); } @@ -486,9 +495,9 @@ unsigned int addPolygon(MapIndices & index_vert, unsigned int vertIndex, unsigne void addPolygon(KFbxMesh * mesh, MapIndices & index_vert, const Triangle & tri, unsigned int drawableNum) { - mesh->AddPolygon(addPolygon(index_vert, tri.t1, tri.normalIndex, drawableNum)); - mesh->AddPolygon(addPolygon(index_vert, tri.t2, tri.normalIndex, drawableNum)); - mesh->AddPolygon(addPolygon(index_vert, tri.t3, tri.normalIndex, drawableNum)); + mesh->AddPolygon(addPolygon(index_vert, tri.t1, tri.normalIndex1, drawableNum)); + mesh->AddPolygon(addPolygon(index_vert, tri.t2, tri.normalIndex2, drawableNum)); + mesh->AddPolygon(addPolygon(index_vert, tri.t3, tri.normalIndex3, drawableNum)); } diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.h b/src/osgPlugins/fbx/WriterNodeVisitor.h index 97e714322..e73e854a6 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.h +++ b/src/osgPlugins/fbx/WriterNodeVisitor.h @@ -35,7 +35,9 @@ struct Triangle unsigned int t1; unsigned int t2; unsigned int t3; - unsigned int normalIndex; ///< Normal index for all bindings except BIND_PER_VERTEX and BIND_OFF. + unsigned int normalIndex1; ///< Normal index for all bindings except BIND_PER_VERTEX and BIND_OFF. + unsigned int normalIndex2; + unsigned int normalIndex3; int material; };