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