vrshoot

diff libs/assimp/BVHLoader.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/BVHLoader.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,169 @@
     1.4 +/** Defines the BHV motion capturing loader class */
     1.5 +
     1.6 +/*
     1.7 +Open Asset Import Library (assimp)
     1.8 +----------------------------------------------------------------------
     1.9 +
    1.10 +Copyright (c) 2006-2012, assimp team
    1.11 +All rights reserved.
    1.12 +
    1.13 +Redistribution and use of this software in source and binary forms, 
    1.14 +with or without modification, are permitted provided that the 
    1.15 +following conditions are met:
    1.16 +
    1.17 +* Redistributions of source code must retain the above
    1.18 +copyright notice, this list of conditions and the
    1.19 +following disclaimer.
    1.20 +
    1.21 +* Redistributions in binary form must reproduce the above
    1.22 +copyright notice, this list of conditions and the
    1.23 +following disclaimer in the documentation and/or other
    1.24 +materials provided with the distribution.
    1.25 +
    1.26 +* Neither the name of the assimp team, nor the names of its
    1.27 +contributors may be used to endorse or promote products
    1.28 +derived from this software without specific prior
    1.29 +written permission of the assimp team.
    1.30 +
    1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.42 +
    1.43 +----------------------------------------------------------------------
    1.44 +*/
    1.45 +
    1.46 +/** @file BVHLoader.h
    1.47 + *  @brief Biovision BVH import
    1.48 + */
    1.49 +
    1.50 +#ifndef AI_BVHLOADER_H_INC
    1.51 +#define AI_BVHLOADER_H_INC
    1.52 +
    1.53 +#include "BaseImporter.h"
    1.54 +
    1.55 +namespace Assimp
    1.56 +{
    1.57 +
    1.58 +// --------------------------------------------------------------------------------
    1.59 +/** Loader class to read Motion Capturing data from a .bvh file. 
    1.60 + *
    1.61 + * This format only contains a hierarchy of joints and a series of keyframes for
    1.62 + * the hierarchy. It contains no actual mesh data, but we generate a dummy mesh
    1.63 + * inside the loader just to be able to see something.
    1.64 +*/
    1.65 +class BVHLoader : public BaseImporter
    1.66 +{
    1.67 +
    1.68 +	/** Possible animation channels for which the motion data holds the values */
    1.69 +	enum ChannelType
    1.70 +	{
    1.71 +		Channel_PositionX,
    1.72 +		Channel_PositionY,
    1.73 +		Channel_PositionZ,
    1.74 +		Channel_RotationX,
    1.75 +		Channel_RotationY,
    1.76 +		Channel_RotationZ
    1.77 +	};
    1.78 +
    1.79 +	/** Collected list of node. Will be bones of the dummy mesh some day, addressed by their array index */
    1.80 +	struct Node
    1.81 +	{
    1.82 +		const aiNode* mNode;
    1.83 +		std::vector<ChannelType> mChannels;
    1.84 +		std::vector<float> mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames
    1.85 +
    1.86 +		Node() { }
    1.87 +		Node( const aiNode* pNode) : mNode( pNode) { }
    1.88 +	};
    1.89 +
    1.90 +public:
    1.91 +
    1.92 +	BVHLoader();
    1.93 +	~BVHLoader();
    1.94 +
    1.95 +public:
    1.96 +	/** Returns whether the class can handle the format of the given file. 
    1.97 +	 * See BaseImporter::CanRead() for details.	*/
    1.98 +	bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const;
    1.99 +
   1.100 +	void SetupProperties(const Importer* pImp);
   1.101 +	const aiImporterDesc* GetInfo () const;
   1.102 +
   1.103 +protected:
   1.104 +
   1.105 +
   1.106 +	/** Imports the given file into the given scene structure. 
   1.107 +	 * See BaseImporter::InternReadFile() for details
   1.108 +	 */
   1.109 +	void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
   1.110 +
   1.111 +protected:
   1.112 +	/** Reads the file */
   1.113 +	void ReadStructure( aiScene* pScene);
   1.114 +
   1.115 +	/** Reads the hierarchy */
   1.116 +	void ReadHierarchy( aiScene* pScene);
   1.117 +
   1.118 +	/** Reads a node and recursively its childs and returns the created node. */
   1.119 +	aiNode* ReadNode();
   1.120 +
   1.121 +	/** Reads an end node and returns the created node. */
   1.122 +	aiNode* ReadEndSite( const std::string& pParentName);
   1.123 +
   1.124 +	/** Reads a node offset for the given node */
   1.125 +	void ReadNodeOffset( aiNode* pNode);
   1.126 +
   1.127 +	/** Reads the animation channels into the given node */
   1.128 +	void ReadNodeChannels( BVHLoader::Node& pNode);
   1.129 +
   1.130 +	/** Reads the motion data */
   1.131 +	void ReadMotion( aiScene* pScene);
   1.132 +
   1.133 +	/** Retrieves the next token */
   1.134 +	std::string GetNextToken();
   1.135 +
   1.136 +	/** Reads the next token as a float */
   1.137 +	float GetNextTokenAsFloat();
   1.138 +
   1.139 +	/** Aborts the file reading with an exception */
   1.140 +	void ThrowException( const std::string& pError);
   1.141 +
   1.142 +	/** Constructs an animation for the motion data and stores it in the given scene */
   1.143 +	void CreateAnimation( aiScene* pScene);
   1.144 +
   1.145 +protected:
   1.146 +	/** Filename, for a verbose error message */
   1.147 +	std::string mFileName;
   1.148 +
   1.149 +	/** Buffer to hold the loaded file */
   1.150 +	std::vector<char> mBuffer;
   1.151 +
   1.152 +	/** Next char to read from the buffer */
   1.153 +	std::vector<char>::const_iterator mReader;
   1.154 +
   1.155 +	/** Current line, for error messages */
   1.156 +	unsigned int mLine;
   1.157 +
   1.158 +	/** Collected list of nodes. Will be bones of the dummy mesh some day, addressed by their array index.
   1.159 +	* Also contain the motion data for the node's channels
   1.160 +	*/
   1.161 +	std::vector<Node> mNodes;
   1.162 +
   1.163 +	/** basic Animation parameters */
   1.164 +	float mAnimTickDuration;
   1.165 +	unsigned int mAnimNumFrames;
   1.166 +
   1.167 +	bool noSkeletonMesh;
   1.168 +};
   1.169 +
   1.170 +} // end of namespace Assimp
   1.171 +
   1.172 +#endif // AI_BVHLOADER_H_INC