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