/src/assimp/code/AssetLib/BVH/BVHLoader.h
Line | Count | Source |
1 | | /** Defines the BHV motion capturing loader class */ |
2 | | |
3 | | /* |
4 | | Open Asset Import Library (assimp) |
5 | | ---------------------------------------------------------------------- |
6 | | |
7 | | Copyright (c) 2006-2026, 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 final : 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{nullptr}; |
79 | | std::vector<ChannelType> mChannels{}; |
80 | | std::vector<float> mChannelValues{}; // motion data values for that node. Of size NumChannels * NumFrames |
81 | | |
82 | | Node() = default; |
83 | 279 | explicit Node(const aiNode *pNode) :mNode(pNode) { |
84 | | // empty |
85 | 279 | } |
86 | | }; |
87 | | |
88 | | public: |
89 | | /// @brief Default constructor |
90 | 165k | BVHLoader() = default; |
91 | | |
92 | | /// @brief Default destructor |
93 | 165k | ~BVHLoader() override = default; |
94 | | |
95 | | bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool cs) const override; |
96 | | void SetupProperties(const Importer *pImp) override; |
97 | | const aiImporterDesc *GetInfo() const override; |
98 | | |
99 | | protected: |
100 | | void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override; |
101 | | |
102 | | /// Reads the file. |
103 | | void ReadStructure(aiScene *pScene); |
104 | | |
105 | | /// Reads the hierarchy |
106 | | void ReadHierarchy(aiScene *pScene); |
107 | | |
108 | | /// Reads a node and recursively its children and returns the created node. |
109 | | aiNode *ReadNode(); |
110 | | |
111 | | /// Reads an end node and returns the created node. |
112 | | aiNode *ReadEndSite(const std::string &pParentName); |
113 | | |
114 | | /// Reads a node offset for the given node |
115 | | void ReadNodeOffset(aiNode *pNode); |
116 | | |
117 | | /// Reads the animation channels into the given node |
118 | | void ReadNodeChannels(Node &pNode); |
119 | | |
120 | | /// Reads the motion data |
121 | | void ReadMotion(aiScene *pScene); |
122 | | |
123 | | /// Retrieves the next token |
124 | | std::string GetNextToken(); |
125 | | |
126 | | /// Reads the next token as a float |
127 | | float GetNextTokenAsFloat(); |
128 | | |
129 | | /// Aborts the file reading with an exception |
130 | | template<typename... T> |
131 | | AI_WONT_RETURN void ThrowException(T&&... args) AI_WONT_RETURN_SUFFIX; |
132 | | |
133 | | /// Constructs an animation for the motion data and stores it in the given scene |
134 | | void CreateAnimation(aiScene *pScene); |
135 | | |
136 | | protected: |
137 | | std::string mFileName{}; ///< Filename, for a verbose error message |
138 | | std::vector<char> mBuffer{}; ///< Buffer to hold the loaded file |
139 | | std::vector<char>::const_iterator mReader{}; ///< Next char to read from the buffer |
140 | | unsigned int mLine{0}; ///< Current line, for error messages |
141 | | std::vector<Node> mNodes{}; ///< Collected list of nodes. Will be bones of the dummy mesh some day, addressed by their array index. |
142 | | float mAnimTickDuration{0}; ///< basic Animation parameters |
143 | | unsigned int mAnimNumFrames{0}; ///< Number of frames in the animation |
144 | | bool noSkeletonMesh{false}; ///< Whether to create a skeleton mesh or not |
145 | | }; |
146 | | |
147 | | } // end of namespace Assimp |
148 | | |
149 | | #endif // AI_BVHLOADER_H_INC |