From 1f0a8aff323deb109eedb8fa0d0c8fea67d23619 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Jan 2011 17:29:11 +0000 Subject: [PATCH] Changed dos endings to unix line endings --- src/osgPlugins/fbx/WriterCompareTriangle.cpp | 298 +++++++++--------- src/osgPlugins/fbx/WriterCompareTriangle.h | 100 +++--- src/osgPlugins/fbx/WriterNodeVisitor.cpp | 20 +- src/osgPlugins/fbx/WriterNodeVisitor.h | 4 +- .../fbx/fbxMaterialToOsgStateSet.cpp | 8 +- src/osgPlugins/fbx/fbxRAnimation.cpp | 22 +- src/osgPlugins/fbx/fbxRNode.cpp | 16 +- src/osgPlugins/fbx/fbxReader.h | 12 +- 8 files changed, 240 insertions(+), 240 deletions(-) diff --git a/src/osgPlugins/fbx/WriterCompareTriangle.cpp b/src/osgPlugins/fbx/WriterCompareTriangle.cpp index dc0f5488c..90344365d 100644 --- a/src/osgPlugins/fbx/WriterCompareTriangle.cpp +++ b/src/osgPlugins/fbx/WriterCompareTriangle.cpp @@ -1,150 +1,150 @@ -#include "WriterCompareTriangle.h" - -WriterCompareTriangle::WriterCompareTriangle(const osg::Geode& geode, - unsigned int nbVertices) - : geode(geode) -{ - cutscene(nbVertices, geode.getDrawable(0)->asGeometry()->getBound()); -} - -bool -WriterCompareTriangle::operator()(const std::pair& t1, - const std::pair& t2) const -{ - const osg::Geometry* g = geode.getDrawable( t1.second )->asGeometry(); - - const osg::Vec3Array* vecs= static_cast(g->getVertexArray()); - const osg::Vec3::value_type x1 = (*vecs)[t1.first.t1].x(); - const osg::Vec3::value_type y1 = (*vecs)[t1.first.t1].y(); - const osg::Vec3::value_type z1 = (*vecs)[t1.first.t1].z(); - - if (t1.second != t2.second) - { - const osg::Geometry* g = geode.getDrawable( t2.second )->asGeometry(); - vecs = static_cast(g->getVertexArray()); - } - const osg::Vec3::value_type x2 = (*vecs)[t2.first.t1].x(); - const osg::Vec3::value_type y2 = (*vecs)[t2.first.t1].y(); - const osg::Vec3::value_type z2 = (*vecs)[t2.first.t1].z(); - int val1 = inWhichBox(x1,y1,z1); - int val2 = inWhichBox(x2,y2,z2); - - return (val1 < val2); -}; - -void -WriterCompareTriangle::setMaxMin(unsigned int& nbVerticesX, - unsigned int& nbVerticesY, - unsigned int& nbVerticesZ) const -{ - static const unsigned int min = 1; - if (nbVerticesX < min) - nbVerticesX = min; - if (nbVerticesY < min) - nbVerticesY = min; - if (nbVerticesZ < min) - nbVerticesZ = min; - - static const unsigned int max = 20; - - if (nbVerticesX > max) - nbVerticesX = max; - if (nbVerticesY > max) - nbVerticesY = max; - if (nbVerticesZ > max) - nbVerticesZ = max; -} - -void -WriterCompareTriangle::cutscene(int nbVertices, - const osg::BoundingBox& sceneBox) -{ - osg::BoundingBox::vec_type length = sceneBox._max - sceneBox._min; - - static const unsigned int k = 4; - - unsigned int nbVerticesX = (nbVertices * k) / (length.z() * length.y()); - unsigned int nbVerticesY = (nbVertices * k) / (length.z() * length.x()); - unsigned int nbVerticesZ = (nbVertices * k) / (length.x() * length.y()); - - setMaxMin (nbVerticesX, nbVerticesY, nbVerticesZ); - - OSG_DEBUG << "Cutting x by " << nbVerticesX << std::endl - << "Cutting y by " << nbVerticesY << std::endl - << "Cutting z by " << nbVerticesZ << std::endl; - - osg::BoundingBox::value_type blocX = length.x() / nbVerticesX; //These 3 lines set the size of a box in x, y and z - osg::BoundingBox::value_type blocY = length.y() / nbVerticesY; - osg::BoundingBox::value_type blocZ = length.z() / nbVerticesZ; - - boxList.reserve(nbVerticesX * nbVerticesY * nbVerticesZ); - short yinc = 1; - short xinc = 1; - unsigned int y = 0; - unsigned int x = 0; - for (unsigned int z = 0; z < nbVerticesZ; ++z) - { - while (x < nbVerticesX && x >= 0) - { - while (y < nbVerticesY && y >= 0) - { - osg::BoundingBox::value_type xMin = sceneBox.xMin() + x * blocX; - if (x == 0) //to prevent from mesh with no case - xMin -= 10; - - osg::BoundingBox::value_type yMin = sceneBox.yMin() + y * blocY; - if (y == 0) //to prevent from mesh with no case - yMin -= 10; - - osg::BoundingBox::value_type zMin = sceneBox.zMin() + z * blocZ; - if (z == 0) //to prevent from mesh with no case - zMin -= 10; - - osg::BoundingBox::value_type xMax = sceneBox.xMin() + (x + 1) * blocX; - if (x == nbVerticesX - 1) //to prevent from mesh with no case - xMax += 10; - - osg::BoundingBox::value_type yMax = sceneBox.yMin() + (y + 1) * blocY; - if (y == nbVerticesY - 1) //to prevent from mesh with no case - yMax += 10; - - osg::BoundingBox::value_type zMax = sceneBox.zMin() + (z + 1) * blocZ; - if (z == nbVerticesZ - 1) //to prevent from mesh with no case - zMax += 10; - - boxList.push_back(osg::BoundingBox(xMin, // Add a box to the list - yMin, - zMin, - xMax, - yMax, - zMax)); - y += yinc; - } - yinc = -yinc; - y += yinc; - x += xinc; - } - xinc = -xinc; - x += xinc; - } -} - -int -WriterCompareTriangle::inWhichBox(const osg::Vec3::value_type x, - const osg::Vec3::value_type y, - const osg::Vec3::value_type z) const -{ - for (unsigned int i = 0; i < boxList.size(); ++i) - { - if (x >= boxList[i].xMin() && - x < boxList[i].xMax() && - y >= boxList[i].yMin() && - y < boxList[i].yMax() && - z >= boxList[i].zMin() && - z < boxList[i].zMax()) - { - return i; - } - } - throw "Point is not in any box"; +#include "WriterCompareTriangle.h" + +WriterCompareTriangle::WriterCompareTriangle(const osg::Geode& geode, + unsigned int nbVertices) + : geode(geode) +{ + cutscene(nbVertices, geode.getDrawable(0)->asGeometry()->getBound()); +} + +bool +WriterCompareTriangle::operator()(const std::pair& t1, + const std::pair& t2) const +{ + const osg::Geometry* g = geode.getDrawable( t1.second )->asGeometry(); + + const osg::Vec3Array* vecs= static_cast(g->getVertexArray()); + const osg::Vec3::value_type x1 = (*vecs)[t1.first.t1].x(); + const osg::Vec3::value_type y1 = (*vecs)[t1.first.t1].y(); + const osg::Vec3::value_type z1 = (*vecs)[t1.first.t1].z(); + + if (t1.second != t2.second) + { + const osg::Geometry* g = geode.getDrawable( t2.second )->asGeometry(); + vecs = static_cast(g->getVertexArray()); + } + const osg::Vec3::value_type x2 = (*vecs)[t2.first.t1].x(); + const osg::Vec3::value_type y2 = (*vecs)[t2.first.t1].y(); + const osg::Vec3::value_type z2 = (*vecs)[t2.first.t1].z(); + int val1 = inWhichBox(x1,y1,z1); + int val2 = inWhichBox(x2,y2,z2); + + return (val1 < val2); +}; + +void +WriterCompareTriangle::setMaxMin(unsigned int& nbVerticesX, + unsigned int& nbVerticesY, + unsigned int& nbVerticesZ) const +{ + static const unsigned int min = 1; + if (nbVerticesX < min) + nbVerticesX = min; + if (nbVerticesY < min) + nbVerticesY = min; + if (nbVerticesZ < min) + nbVerticesZ = min; + + static const unsigned int max = 20; + + if (nbVerticesX > max) + nbVerticesX = max; + if (nbVerticesY > max) + nbVerticesY = max; + if (nbVerticesZ > max) + nbVerticesZ = max; +} + +void +WriterCompareTriangle::cutscene(int nbVertices, + const osg::BoundingBox& sceneBox) +{ + osg::BoundingBox::vec_type length = sceneBox._max - sceneBox._min; + + static const unsigned int k = 4; + + unsigned int nbVerticesX = (nbVertices * k) / (length.z() * length.y()); + unsigned int nbVerticesY = (nbVertices * k) / (length.z() * length.x()); + unsigned int nbVerticesZ = (nbVertices * k) / (length.x() * length.y()); + + setMaxMin (nbVerticesX, nbVerticesY, nbVerticesZ); + + OSG_DEBUG << "Cutting x by " << nbVerticesX << std::endl + << "Cutting y by " << nbVerticesY << std::endl + << "Cutting z by " << nbVerticesZ << std::endl; + + osg::BoundingBox::value_type blocX = length.x() / nbVerticesX; //These 3 lines set the size of a box in x, y and z + osg::BoundingBox::value_type blocY = length.y() / nbVerticesY; + osg::BoundingBox::value_type blocZ = length.z() / nbVerticesZ; + + boxList.reserve(nbVerticesX * nbVerticesY * nbVerticesZ); + short yinc = 1; + short xinc = 1; + unsigned int y = 0; + unsigned int x = 0; + for (unsigned int z = 0; z < nbVerticesZ; ++z) + { + while (x < nbVerticesX && x >= 0) + { + while (y < nbVerticesY && y >= 0) + { + osg::BoundingBox::value_type xMin = sceneBox.xMin() + x * blocX; + if (x == 0) //to prevent from mesh with no case + xMin -= 10; + + osg::BoundingBox::value_type yMin = sceneBox.yMin() + y * blocY; + if (y == 0) //to prevent from mesh with no case + yMin -= 10; + + osg::BoundingBox::value_type zMin = sceneBox.zMin() + z * blocZ; + if (z == 0) //to prevent from mesh with no case + zMin -= 10; + + osg::BoundingBox::value_type xMax = sceneBox.xMin() + (x + 1) * blocX; + if (x == nbVerticesX - 1) //to prevent from mesh with no case + xMax += 10; + + osg::BoundingBox::value_type yMax = sceneBox.yMin() + (y + 1) * blocY; + if (y == nbVerticesY - 1) //to prevent from mesh with no case + yMax += 10; + + osg::BoundingBox::value_type zMax = sceneBox.zMin() + (z + 1) * blocZ; + if (z == nbVerticesZ - 1) //to prevent from mesh with no case + zMax += 10; + + boxList.push_back(osg::BoundingBox(xMin, // Add a box to the list + yMin, + zMin, + xMax, + yMax, + zMax)); + y += yinc; + } + yinc = -yinc; + y += yinc; + x += xinc; + } + xinc = -xinc; + x += xinc; + } +} + +int +WriterCompareTriangle::inWhichBox(const osg::Vec3::value_type x, + const osg::Vec3::value_type y, + const osg::Vec3::value_type z) const +{ + for (unsigned int i = 0; i < boxList.size(); ++i) + { + if (x >= boxList[i].xMin() && + x < boxList[i].xMax() && + y >= boxList[i].yMin() && + y < boxList[i].yMax() && + z >= boxList[i].zMin() && + z < boxList[i].zMax()) + { + return i; + } + } + throw "Point is not in any box"; } \ No newline at end of file diff --git a/src/osgPlugins/fbx/WriterCompareTriangle.h b/src/osgPlugins/fbx/WriterCompareTriangle.h index 17a83d01a..a3c841d13 100644 --- a/src/osgPlugins/fbx/WriterCompareTriangle.h +++ b/src/osgPlugins/fbx/WriterCompareTriangle.h @@ -1,51 +1,51 @@ -#ifndef _3DS_WRITER_COMPARE_TRIANGLE_HEADER__ -#define _3DS_WRITER_COMPARE_TRIANGLE_HEADER__ - -#include -#include -#include - -struct Triangle -{ - unsigned int t1; - unsigned int t2; - unsigned int t3; - unsigned int material; -}; - -class WriterCompareTriangle { -public: - WriterCompareTriangle(const osg::Geode& geode, - unsigned int nbVertices); - - bool operator()(const std::pair& t1, - const std::pair& t2) const; -private: - void // This function prevents the scene being cut into too many boxes - setMaxMin(unsigned int& nbVerticesX, - unsigned int& nbVerticesY, - unsigned int& nbVerticesZ) const; - - /** - * Cut the scene in different box to sort. - * \param nbVertices is the number of vertices in mesh. - * \param sceneBox contain the size of the scene. - */ - void - cutscene(int nbVertices, - const osg::BoundingBox& sceneBox); - - /** - * Find in which box those points are. - * \return the place of the box in the vector. - * \sa See cutScene() about the definition of the boxes for faces sorting. - */ - int inWhichBox(const osg::Vec3::value_type x, - const osg::Vec3::value_type y, - const osg::Vec3::value_type z) const; - - const osg::Geode& geode; - std::vector boxList; -}; - +#ifndef _3DS_WRITER_COMPARE_TRIANGLE_HEADER__ +#define _3DS_WRITER_COMPARE_TRIANGLE_HEADER__ + +#include +#include +#include + +struct Triangle +{ + unsigned int t1; + unsigned int t2; + unsigned int t3; + unsigned int material; +}; + +class WriterCompareTriangle { +public: + WriterCompareTriangle(const osg::Geode& geode, + unsigned int nbVertices); + + bool operator()(const std::pair& t1, + const std::pair& t2) const; +private: + void // This function prevents the scene being cut into too many boxes + setMaxMin(unsigned int& nbVerticesX, + unsigned int& nbVerticesY, + unsigned int& nbVerticesZ) const; + + /** + * Cut the scene in different box to sort. + * \param nbVertices is the number of vertices in mesh. + * \param sceneBox contain the size of the scene. + */ + void + cutscene(int nbVertices, + const osg::BoundingBox& sceneBox); + + /** + * Find in which box those points are. + * \return the place of the box in the vector. + * \sa See cutScene() about the definition of the boxes for faces sorting. + */ + int inWhichBox(const osg::Vec3::value_type x, + const osg::Vec3::value_type y, + const osg::Vec3::value_type z) const; + + const osg::Geode& geode; + std::vector boxList; +}; + #endif // _3DS_WRITER_COMPARE_TRIANGLE_HEADER__ \ No newline at end of file diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.cpp b/src/osgPlugins/fbx/WriterNodeVisitor.cpp index 51025954c..d8254f725 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.cpp +++ b/src/osgPlugins/fbx/WriterNodeVisitor.cpp @@ -78,16 +78,16 @@ public: triangle.t1 = i1; triangle.t2 = i2; triangle.t3 = i3; - 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; - } + 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)); } diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.h b/src/osgPlugins/fbx/WriterNodeVisitor.h index e73e854a6..03632da9a 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.h +++ b/src/osgPlugins/fbx/WriterNodeVisitor.h @@ -35,8 +35,8 @@ struct Triangle unsigned int t1; unsigned int t2; unsigned int t3; - unsigned int normalIndex1; ///< Normal index for all bindings except BIND_PER_VERTEX and BIND_OFF. - unsigned int normalIndex2; + unsigned int normalIndex1; ///< Normal index for all bindings except BIND_PER_VERTEX and BIND_OFF. + unsigned int normalIndex2; unsigned int normalIndex3; int material; }; diff --git a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp index 3f488d72b..653b8db03 100644 --- a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp +++ b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp @@ -170,10 +170,10 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat) // if using an emission map then adjust material properties accordingly... if (result.emissiveTexture) { - osg::Vec4 diffuse = pOsgMat->getDiffuse(osg::Material::FRONT_AND_BACK); - pOsgMat->setEmission(osg::Material::FRONT_AND_BACK, diffuse); - pOsgMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,diffuse.a())); - pOsgMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,diffuse.a())); + osg::Vec4 diffuse = pOsgMat->getDiffuse(osg::Material::FRONT_AND_BACK); + pOsgMat->setEmission(osg::Material::FRONT_AND_BACK, diffuse); + pOsgMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,diffuse.a())); + pOsgMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,diffuse.a())); } } diff --git a/src/osgPlugins/fbx/fbxRAnimation.cpp b/src/osgPlugins/fbx/fbxRAnimation.cpp index ac3a79115..5c273efb2 100644 --- a/src/osgPlugins/fbx/fbxRAnimation.cpp +++ b/src/osgPlugins/fbx/fbxRAnimation.cpp @@ -458,27 +458,27 @@ osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode, std::string OsgFbxReader::readFbxAnimation(KFbxNode* pNode, const char* targetName) { std::string result; - for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i) - { - KFbxAnimStack* pAnimStack = KFbxCast(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i)); - - int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer)); - + for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i) + { + KFbxAnimStack* pAnimStack = KFbxCast(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i)); + + int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer)); + const char* pTakeName = pAnimStack->GetName(); if (!pTakeName || !*pTakeName) continue; - for (int j = 0; j < nbAnimLayers; j++) - { - KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j); - + for (int j = 0; j < nbAnimLayers; j++) + { + KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j); + if (osgAnimation::Animation* pAnimation = ::readFbxAnimation( pNode, pAnimLayer, pTakeName, targetName, pAnimationManager)) { result = targetName; } - } + } } return result; } diff --git a/src/osgPlugins/fbx/fbxRNode.cpp b/src/osgPlugins/fbx/fbxRNode.cpp index 26ba1ee18..9f6586548 100644 --- a/src/osgPlugins/fbx/fbxRNode.cpp +++ b/src/osgPlugins/fbx/fbxRNode.cpp @@ -205,14 +205,14 @@ void readRotationElement(KFbxTypedProperty& prop, { if (quatInterpolate) { - if (!staticTransform.isIdentity()) - { - pUpdate->getStackedTransforms().push_back( - new osgAnimation::StackedMatrixElement(staticTransform)); - staticTransform.makeIdentity(); - } - pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedQuaternionElement( - "quaternion", makeQuat(prop.Get(), fbxRotOrder))); + if (!staticTransform.isIdentity()) + { + pUpdate->getStackedTransforms().push_back( + new osgAnimation::StackedMatrixElement(staticTransform)); + staticTransform.makeIdentity(); + } + pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedQuaternionElement( + "quaternion", makeQuat(prop.Get(), fbxRotOrder))); } else { diff --git a/src/osgPlugins/fbx/fbxReader.h b/src/osgPlugins/fbx/fbxReader.h index a00d03c86..b9e4fb605 100644 --- a/src/osgPlugins/fbx/fbxReader.h +++ b/src/osgPlugins/fbx/fbxReader.h @@ -29,12 +29,12 @@ public: const osgDB::Options& options; bool lightmapTextures, tessellatePolygons; - enum AuthoringTool - { - UNKNOWN, - OPENSCENEGRAPH, - AUTODESK_3DSTUDIO_MAX - } authoringTool; + enum AuthoringTool + { + UNKNOWN, + OPENSCENEGRAPH, + AUTODESK_3DSTUDIO_MAX + } authoringTool; OsgFbxReader( KFbxSdkManager& pSdkManager1,