ColladaLoader.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /** Implementation of the Collada loader */
  2. /*
  3. ---------------------------------------------------------------------------
  4. Open Asset Import Library (ASSIMP)
  5. ---------------------------------------------------------------------------
  6. Copyright (c) 2006-2008, ASSIMP Development Team
  7. All rights reserved.
  8. Redistribution and use of this software in source and binary forms,
  9. with or without modification, are permitted provided that the following
  10. conditions are met:
  11. * Redistributions of source code must retain the above
  12. copyright notice, this list of conditions and the
  13. following disclaimer.
  14. * Redistributions in binary form must reproduce the above
  15. copyright notice, this list of conditions and the
  16. following disclaimer in the documentation and/or other
  17. materials provided with the distribution.
  18. * Neither the name of the ASSIMP team, nor the names of its
  19. contributors may be used to endorse or promote products
  20. derived from this software without specific prior
  21. written permission of the ASSIMP Development Team.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. ---------------------------------------------------------------------------
  34. */
  35. #include "AssimpPCH.h"
  36. #include "../include/aiAnim.h"
  37. #include "ColladaLoader.h"
  38. #include "ColladaParser.h"
  39. using namespace Assimp;
  40. // ------------------------------------------------------------------------------------------------
  41. // Constructor to be privately used by Importer
  42. ColladaLoader::ColladaLoader()
  43. {
  44. }
  45. // ------------------------------------------------------------------------------------------------
  46. // Destructor, private as well
  47. ColladaLoader::~ColladaLoader()
  48. {
  49. }
  50. // ------------------------------------------------------------------------------------------------
  51. // Returns whether the class can handle the format of the given file.
  52. bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
  53. {
  54. // check file extension
  55. std::string::size_type pos = pFile.find_last_of('.');
  56. // no file extension - can't read
  57. if( pos == std::string::npos)
  58. return false;
  59. std::string extension = pFile.substr( pos);
  60. for( std::string::iterator it = extension.begin(); it != extension.end(); ++it)
  61. *it = tolower( *it);
  62. if( extension == ".dae")
  63. return true;
  64. return false;
  65. }
  66. // ------------------------------------------------------------------------------------------------
  67. // Imports the given file into the given scene structure.
  68. void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
  69. {
  70. mFileName = pFile;
  71. // parse the input file
  72. ColladaParser parser( pFile);
  73. // build the node hierarchy from it
  74. pScene->mRootNode = BuildHierarchy( parser, parser.mRootNode);
  75. pScene->mFlags = AI_SCENE_FLAGS_INCOMPLETE;
  76. }
  77. // ------------------------------------------------------------------------------------------------
  78. // Recursively constructs a scene node for the given parser node and returns it.
  79. aiNode* ColladaLoader::BuildHierarchy( const ColladaParser& pParser, const ColladaParser::Node* pNode)
  80. {
  81. // create a node for it
  82. aiNode* node = new aiNode( pNode->mName);
  83. // calculate the transformation matrix for it
  84. node->mTransformation = pParser.CalculateResultTransform( pNode->mTransforms);
  85. // add children
  86. node->mNumChildren = pNode->mChildren.size();
  87. node->mChildren = new aiNode*[node->mNumChildren];
  88. for( unsigned int a = 0; a < pNode->mChildren.size(); a++)
  89. {
  90. node->mChildren[a] = BuildHierarchy( pParser, pNode->mChildren[a]);
  91. node->mChildren[a]->mParent = node;
  92. }
  93. return node;
  94. }