/src/assimp/code/AssetLib/B3D/B3DImporter.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2025, assimp team |
6 | | |
7 | | All rights reserved. |
8 | | |
9 | | Redistribution and use of this software in source and binary forms, |
10 | | with or without modification, are permitted provided that the |
11 | | following conditions are met: |
12 | | |
13 | | * Redistributions of source code must retain the above |
14 | | copyright notice, this list of conditions and the |
15 | | following disclaimer. |
16 | | |
17 | | * Redistributions in binary form must reproduce the above |
18 | | copyright notice, this list of conditions and the |
19 | | following disclaimer in the documentation and/or other |
20 | | materials provided with the distribution. |
21 | | |
22 | | * Neither the name of the assimp team, nor the names of its |
23 | | contributors may be used to endorse or promote products |
24 | | derived from this software without specific prior |
25 | | written permission of the assimp team. |
26 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | |
39 | | ---------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | /** |
43 | | * @file Definition of the .b3d importer class. |
44 | | */ |
45 | | #pragma once |
46 | | #ifndef AI_B3DIMPORTER_H_INC |
47 | | #define AI_B3DIMPORTER_H_INC |
48 | | |
49 | | #include <assimp/types.h> |
50 | | #include <assimp/mesh.h> |
51 | | #include <assimp/material.h> |
52 | | #include <assimp/BaseImporter.h> |
53 | | |
54 | | #include <memory> |
55 | | #include <vector> |
56 | | |
57 | | struct aiNodeAnim; |
58 | | struct aiNode; |
59 | | struct aiAnimation; |
60 | | |
61 | | namespace Assimp{ |
62 | | |
63 | | class B3DImporter final : public BaseImporter{ |
64 | | public: |
65 | 1.19k | B3DImporter() = default; |
66 | | ~B3DImporter() override; |
67 | | bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const override; |
68 | | |
69 | | protected: |
70 | | const aiImporterDesc* GetInfo () const override; |
71 | | void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override; |
72 | | |
73 | | private: |
74 | | |
75 | | int ReadByte(); |
76 | | int ReadInt(); |
77 | | float ReadFloat(); |
78 | | aiVector2D ReadVec2(); |
79 | | aiVector3D ReadVec3(); |
80 | | aiQuaternion ReadQuat(); |
81 | | std::string ReadString(); |
82 | | std::string ReadChunk(); |
83 | | void ExitChunk(); |
84 | | size_t ChunkSize(); |
85 | | |
86 | | template<class T> |
87 | | T *to_array( const std::vector<T> &v ); |
88 | | |
89 | | struct Vertex{ |
90 | | aiVector3D vertex; |
91 | | aiVector3D normal; |
92 | | aiVector3D texcoords; |
93 | | unsigned char bones[4]; |
94 | | float weights[4]; |
95 | | }; |
96 | | |
97 | | AI_WONT_RETURN void Oops() AI_WONT_RETURN_SUFFIX; |
98 | | AI_WONT_RETURN void Fail(const std::string &str) AI_WONT_RETURN_SUFFIX; |
99 | | |
100 | | void ReadTEXS(); |
101 | | void ReadBRUS(); |
102 | | |
103 | | void ReadVRTS(); |
104 | | void ReadTRIS( int v0 ); |
105 | | void ReadMESH(); |
106 | | void ReadBONE( int id ); |
107 | | void ReadKEYS( aiNodeAnim *nodeAnim ); |
108 | | void ReadANIM(); |
109 | | |
110 | | aiNode *ReadNODE( aiNode *parent ); |
111 | | |
112 | | void ReadBB3D( aiScene *scene ); |
113 | | |
114 | | size_t _pos; |
115 | | std::vector<unsigned char> _buf; |
116 | | std::vector<size_t> _stack; |
117 | | |
118 | | std::vector<std::string> _textures; |
119 | | std::vector<std::unique_ptr<aiMaterial> > _materials; |
120 | | |
121 | | int _vflags,_tcsets,_tcsize; |
122 | | std::vector<Vertex> _vertices; |
123 | | |
124 | | std::vector<aiNode*> _nodes; |
125 | | std::vector<std::unique_ptr<aiMesh> > _meshes; |
126 | | std::vector<std::unique_ptr<aiNodeAnim> > _nodeAnims; |
127 | | std::vector<std::unique_ptr<aiAnimation> > _animations; |
128 | | }; |
129 | | |
130 | | } |
131 | | |
132 | | #endif |