Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

170 строки
5.0 KiB

  1. /** Defines the BHV motion capturing loader class */
  2. /*
  3. Open Asset Import Library (assimp)
  4. ----------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the
  9. following conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ----------------------------------------------------------------------
  33. */
  34. /** @file BVHLoader.h
  35. * @brief Biovision BVH import
  36. */
  37. #ifndef AI_BVHLOADER_H_INC
  38. #define AI_BVHLOADER_H_INC
  39. #include "BaseImporter.h"
  40. namespace Assimp
  41. {
  42. // --------------------------------------------------------------------------------
  43. /** Loader class to read Motion Capturing data from a .bvh file.
  44. *
  45. * This format only contains a hierarchy of joints and a series of keyframes for
  46. * the hierarchy. It contains no actual mesh data, but we generate a dummy mesh
  47. * inside the loader just to be able to see something.
  48. */
  49. class BVHLoader : public BaseImporter
  50. {
  51. /** Possible animation channels for which the motion data holds the values */
  52. enum ChannelType
  53. {
  54. Channel_PositionX,
  55. Channel_PositionY,
  56. Channel_PositionZ,
  57. Channel_RotationX,
  58. Channel_RotationY,
  59. Channel_RotationZ
  60. };
  61. /** Collected list of node. Will be bones of the dummy mesh some day, addressed by their array index */
  62. struct Node
  63. {
  64. const aiNode* mNode;
  65. std::vector<ChannelType> mChannels;
  66. std::vector<float> mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames
  67. Node() { }
  68. Node( const aiNode* pNode) : mNode( pNode) { }
  69. };
  70. public:
  71. BVHLoader();
  72. ~BVHLoader();
  73. public:
  74. /** Returns whether the class can handle the format of the given file.
  75. * See BaseImporter::CanRead() for details. */
  76. bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const;
  77. void SetupProperties(const Importer* pImp);
  78. const aiImporterDesc* GetInfo () const;
  79. protected:
  80. /** Imports the given file into the given scene structure.
  81. * See BaseImporter::InternReadFile() for details
  82. */
  83. void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
  84. protected:
  85. /** Reads the file */
  86. void ReadStructure( aiScene* pScene);
  87. /** Reads the hierarchy */
  88. void ReadHierarchy( aiScene* pScene);
  89. /** Reads a node and recursively its childs and returns the created node. */
  90. aiNode* ReadNode();
  91. /** Reads an end node and returns the created node. */
  92. aiNode* ReadEndSite( const std::string& pParentName);
  93. /** Reads a node offset for the given node */
  94. void ReadNodeOffset( aiNode* pNode);
  95. /** Reads the animation channels into the given node */
  96. void ReadNodeChannels( BVHLoader::Node& pNode);
  97. /** Reads the motion data */
  98. void ReadMotion( aiScene* pScene);
  99. /** Retrieves the next token */
  100. std::string GetNextToken();
  101. /** Reads the next token as a float */
  102. float GetNextTokenAsFloat();
  103. /** Aborts the file reading with an exception */
  104. void ThrowException( const std::string& pError);
  105. /** Constructs an animation for the motion data and stores it in the given scene */
  106. void CreateAnimation( aiScene* pScene);
  107. protected:
  108. /** Filename, for a verbose error message */
  109. std::string mFileName;
  110. /** Buffer to hold the loaded file */
  111. std::vector<char> mBuffer;
  112. /** Next char to read from the buffer */
  113. std::vector<char>::const_iterator mReader;
  114. /** Current line, for error messages */
  115. unsigned int mLine;
  116. /** Collected list of nodes. Will be bones of the dummy mesh some day, addressed by their array index.
  117. * Also contain the motion data for the node's channels
  118. */
  119. std::vector<Node> mNodes;
  120. /** basic Animation parameters */
  121. float mAnimTickDuration;
  122. unsigned int mAnimNumFrames;
  123. bool noSkeletonMesh;
  124. };
  125. } // end of namespace Assimp
  126. #endif // AI_BVHLOADER_H_INC