nuclear@0: /** Defines the BHV motion capturing loader class */ nuclear@0: nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file BVHLoader.h nuclear@0: * @brief Biovision BVH import nuclear@0: */ nuclear@0: nuclear@0: #ifndef AI_BVHLOADER_H_INC nuclear@0: #define AI_BVHLOADER_H_INC nuclear@0: nuclear@0: #include "BaseImporter.h" nuclear@0: nuclear@0: namespace Assimp nuclear@0: { nuclear@0: nuclear@0: // -------------------------------------------------------------------------------- nuclear@0: /** Loader class to read Motion Capturing data from a .bvh file. nuclear@0: * nuclear@0: * This format only contains a hierarchy of joints and a series of keyframes for nuclear@0: * the hierarchy. It contains no actual mesh data, but we generate a dummy mesh nuclear@0: * inside the loader just to be able to see something. nuclear@0: */ nuclear@0: class BVHLoader : public BaseImporter nuclear@0: { nuclear@0: nuclear@0: /** Possible animation channels for which the motion data holds the values */ nuclear@0: enum ChannelType nuclear@0: { nuclear@0: Channel_PositionX, nuclear@0: Channel_PositionY, nuclear@0: Channel_PositionZ, nuclear@0: Channel_RotationX, nuclear@0: Channel_RotationY, nuclear@0: Channel_RotationZ nuclear@0: }; nuclear@0: nuclear@0: /** Collected list of node. Will be bones of the dummy mesh some day, addressed by their array index */ nuclear@0: struct Node nuclear@0: { nuclear@0: const aiNode* mNode; nuclear@0: std::vector mChannels; nuclear@0: std::vector mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames nuclear@0: nuclear@0: Node() { } nuclear@0: Node( const aiNode* pNode) : mNode( pNode) { } nuclear@0: }; nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: BVHLoader(); nuclear@0: ~BVHLoader(); nuclear@0: nuclear@0: public: nuclear@0: /** Returns whether the class can handle the format of the given file. nuclear@0: * See BaseImporter::CanRead() for details. */ nuclear@0: bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const; nuclear@0: nuclear@0: void SetupProperties(const Importer* pImp); nuclear@0: const aiImporterDesc* GetInfo () const; nuclear@0: nuclear@0: protected: nuclear@0: nuclear@0: nuclear@0: /** Imports the given file into the given scene structure. nuclear@0: * See BaseImporter::InternReadFile() for details nuclear@0: */ nuclear@0: void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler); nuclear@0: nuclear@0: protected: nuclear@0: /** Reads the file */ nuclear@0: void ReadStructure( aiScene* pScene); nuclear@0: nuclear@0: /** Reads the hierarchy */ nuclear@0: void ReadHierarchy( aiScene* pScene); nuclear@0: nuclear@0: /** Reads a node and recursively its childs and returns the created node. */ nuclear@0: aiNode* ReadNode(); nuclear@0: nuclear@0: /** Reads an end node and returns the created node. */ nuclear@0: aiNode* ReadEndSite( const std::string& pParentName); nuclear@0: nuclear@0: /** Reads a node offset for the given node */ nuclear@0: void ReadNodeOffset( aiNode* pNode); nuclear@0: nuclear@0: /** Reads the animation channels into the given node */ nuclear@0: void ReadNodeChannels( BVHLoader::Node& pNode); nuclear@0: nuclear@0: /** Reads the motion data */ nuclear@0: void ReadMotion( aiScene* pScene); nuclear@0: nuclear@0: /** Retrieves the next token */ nuclear@0: std::string GetNextToken(); nuclear@0: nuclear@0: /** Reads the next token as a float */ nuclear@0: float GetNextTokenAsFloat(); nuclear@0: nuclear@0: /** Aborts the file reading with an exception */ nuclear@0: void ThrowException( const std::string& pError); nuclear@0: nuclear@0: /** Constructs an animation for the motion data and stores it in the given scene */ nuclear@0: void CreateAnimation( aiScene* pScene); nuclear@0: nuclear@0: protected: nuclear@0: /** Filename, for a verbose error message */ nuclear@0: std::string mFileName; nuclear@0: nuclear@0: /** Buffer to hold the loaded file */ nuclear@0: std::vector mBuffer; nuclear@0: nuclear@0: /** Next char to read from the buffer */ nuclear@0: std::vector::const_iterator mReader; nuclear@0: nuclear@0: /** Current line, for error messages */ nuclear@0: unsigned int mLine; nuclear@0: nuclear@0: /** Collected list of nodes. Will be bones of the dummy mesh some day, addressed by their array index. nuclear@0: * Also contain the motion data for the node's channels nuclear@0: */ nuclear@0: std::vector mNodes; nuclear@0: nuclear@0: /** basic Animation parameters */ nuclear@0: float mAnimTickDuration; nuclear@0: unsigned int mAnimNumFrames; nuclear@0: nuclear@0: bool noSkeletonMesh; nuclear@0: }; nuclear@0: nuclear@0: } // end of namespace Assimp nuclear@0: nuclear@0: #endif // AI_BVHLOADER_H_INC