1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2021, 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 #pragma once
42 
43 #include <assimp/vector3.h>
44 #include <assimp/matrix4x4.h>
45 #include <assimp/ParsingUtils.h>
46 #include <vector>
47 #include <string>
48 
49 struct aiMaterial;
50 struct aiMesh;
51 
52 namespace Assimp {
53 namespace D3MF {
54 
55 enum class ResourceType {
56     RT_Object,
57     RT_BaseMaterials,
58     RT_EmbeddedTexture2D,
59     RT_Texture2DGroup,
60     RT_Unknown
61 }; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
62 
63 class Resource {
64 public:
65     int mId;
66 
Resource(int id)67     Resource(int id) :
68             mId(id) {
69         // empty
70     }
71 
~Resource()72     virtual ~Resource() {
73         // empty
74     }
75 
getType()76     virtual ResourceType getType() const {
77         return ResourceType::RT_Unknown;
78     }
79 };
80 
81 class EmbeddedTexture : public Resource {
82 public:
83     std::string mPath;
84     std::string mContentType;
85     std::string mTilestyleU;
86     std::string mTilestyleV;
87     std::vector<char> mBuffer;
88 
EmbeddedTexture(int id)89     EmbeddedTexture(int id) :
90             Resource(id),
91             mPath(),
92             mContentType(),
93             mTilestyleU(),
94             mTilestyleV() {
95         // empty
96     }
97 
98     ~EmbeddedTexture() = default;
99 
getType()100     ResourceType getType() const override {
101         return ResourceType::RT_EmbeddedTexture2D;
102     }
103 };
104 
105 class Texture2DGroup : public Resource {
106 public:
107     std::vector<aiVector2D> mTex2dCoords;
108     int mTexId;
Texture2DGroup(int id)109     Texture2DGroup(int id) :
110             Resource(id),
111             mTexId(-1) {
112         // empty
113     }
114 
115     ~Texture2DGroup() = default;
116 
getType()117     ResourceType getType() const override {
118         return ResourceType::RT_Texture2DGroup;
119     }
120 };
121 
122 class BaseMaterials : public Resource {
123 public:
124     std::vector<unsigned int> mMaterialIndex;
125 
BaseMaterials(int id)126     BaseMaterials(int id) :
127             Resource(id),
128             mMaterialIndex() {
129         // empty
130     }
131 
132     ~BaseMaterials() = default;
133 
getType()134     ResourceType getType() const override {
135         return ResourceType::RT_BaseMaterials;
136     }
137 };
138 
139 struct Component {
140     int mObjectId;
141     aiMatrix4x4 mTransformation;
142 };
143 
144 class Object : public Resource {
145 public:
146     std::vector<aiMesh *> mMeshes;
147     std::vector<unsigned int> mMeshIndex;
148     std::vector<Component> mComponents;
149     std::string mName;
150 
Object(int id)151     Object(int id) :
152             Resource(id),
153             mName(std::string("Object_") + ai_to_string(id)) {
154         // empty
155     }
156 
157     ~Object() = default;
158 
getType()159     ResourceType getType() const override {
160         return ResourceType::RT_Object;
161     }
162 };
163 
164 } // namespace D3MF
165 } // namespace Assimp
166