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