vrshoot

view libs/assimp/BVHLoader.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
line source
1 /** Defines the BHV motion capturing loader class */
3 /*
4 Open Asset Import Library (assimp)
5 ----------------------------------------------------------------------
7 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
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.
40 ----------------------------------------------------------------------
41 */
43 /** @file BVHLoader.h
44 * @brief Biovision BVH import
45 */
47 #ifndef AI_BVHLOADER_H_INC
48 #define AI_BVHLOADER_H_INC
50 #include "BaseImporter.h"
52 namespace Assimp
53 {
55 // --------------------------------------------------------------------------------
56 /** Loader class to read Motion Capturing data from a .bvh file.
57 *
58 * This format only contains a hierarchy of joints and a series of keyframes for
59 * the hierarchy. It contains no actual mesh data, but we generate a dummy mesh
60 * inside the loader just to be able to see something.
61 */
62 class BVHLoader : public BaseImporter
63 {
65 /** Possible animation channels for which the motion data holds the values */
66 enum ChannelType
67 {
68 Channel_PositionX,
69 Channel_PositionY,
70 Channel_PositionZ,
71 Channel_RotationX,
72 Channel_RotationY,
73 Channel_RotationZ
74 };
76 /** Collected list of node. Will be bones of the dummy mesh some day, addressed by their array index */
77 struct Node
78 {
79 const aiNode* mNode;
80 std::vector<ChannelType> mChannels;
81 std::vector<float> mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames
83 Node() { }
84 Node( const aiNode* pNode) : mNode( pNode) { }
85 };
87 public:
89 BVHLoader();
90 ~BVHLoader();
92 public:
93 /** Returns whether the class can handle the format of the given file.
94 * See BaseImporter::CanRead() for details. */
95 bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool cs) const;
97 void SetupProperties(const Importer* pImp);
98 const aiImporterDesc* GetInfo () const;
100 protected:
103 /** Imports the given file into the given scene structure.
104 * See BaseImporter::InternReadFile() for details
105 */
106 void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
108 protected:
109 /** Reads the file */
110 void ReadStructure( aiScene* pScene);
112 /** Reads the hierarchy */
113 void ReadHierarchy( aiScene* pScene);
115 /** Reads a node and recursively its childs and returns the created node. */
116 aiNode* ReadNode();
118 /** Reads an end node and returns the created node. */
119 aiNode* ReadEndSite( const std::string& pParentName);
121 /** Reads a node offset for the given node */
122 void ReadNodeOffset( aiNode* pNode);
124 /** Reads the animation channels into the given node */
125 void ReadNodeChannels( BVHLoader::Node& pNode);
127 /** Reads the motion data */
128 void ReadMotion( aiScene* pScene);
130 /** Retrieves the next token */
131 std::string GetNextToken();
133 /** Reads the next token as a float */
134 float GetNextTokenAsFloat();
136 /** Aborts the file reading with an exception */
137 void ThrowException( const std::string& pError);
139 /** Constructs an animation for the motion data and stores it in the given scene */
140 void CreateAnimation( aiScene* pScene);
142 protected:
143 /** Filename, for a verbose error message */
144 std::string mFileName;
146 /** Buffer to hold the loaded file */
147 std::vector<char> mBuffer;
149 /** Next char to read from the buffer */
150 std::vector<char>::const_iterator mReader;
152 /** Current line, for error messages */
153 unsigned int mLine;
155 /** Collected list of nodes. Will be bones of the dummy mesh some day, addressed by their array index.
156 * Also contain the motion data for the node's channels
157 */
158 std::vector<Node> mNodes;
160 /** basic Animation parameters */
161 float mAnimTickDuration;
162 unsigned int mAnimNumFrames;
164 bool noSkeletonMesh;
165 };
167 } // end of namespace Assimp
169 #endif // AI_BVHLOADER_H_INC