MxEngine
ObjectLoader.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include <sstream>
32 
33 #include "Utilities/Math/Math.h"
34 #include "Core/BoundingObjects/AABB.h"
35 #include "Utilities/STL/MxHashMap.h"
36 #include "Utilities/STL/MxString.h"
37 #include "Utilities/STL/MxVector.h"
38 #include "Core/Resources/MeshData.h"
39 
40 namespace MxEngine
41 {
45  struct MaterialInfo
46  {
50  MxString Name;
51 
55  MxString AmbientMap;
59  MxString DiffuseMap;
63  MxString SpecularMap;
67  MxString EmmisiveMap;
71  MxString HeightMap;
75  MxString NormalMap;
76 
80  float SpecularExponent = 0.0f;
84  float Transparency = 0.0f;
88  float Displacement = 0.0f;
89 
93  Vector3 AmbientColor{ 0.0f };
97  Vector3 DiffuseColor{ 0.0f };
101  Vector3 SpecularColor{ 0.0f };
105  Vector3 EmmisiveColor{ 0.0f };
106  };
107 
111  struct MeshInfo
112  {
116  MxString name;
120  MxVector<Vertex> vertecies;
121  /*
122  face indicies to access buffer of verteces
123  */
124  MxVector<uint32_t> indicies;
128  MaterialInfo* material = nullptr;
132  bool useTexture = false;
136  bool useNormal = false;
137 
141  size_t GetVertexCount() const { return this->vertecies.size(); }
142  };
143 
144  using MaterialLibrary = MxVector<MaterialInfo>;
145 
150  struct ObjectInfo
151  {
155  MaterialLibrary materials;
159  MxVector<MeshInfo> meshes;
160  };
161 
167  {
168  public:
169  /*
170  loads object from disk by its file path
171  \param path absoulute or relative to executable folder path to a file to load
172  \returns ObjectInfo instance
173  \warning this function is not thread safe
174  */
175  static ObjectInfo Load(const MxString& path);
176  static MaterialLibrary LoadMaterials(const MxString& path);
177  static void DumpMaterials(const MaterialLibrary& materials, const MxString& path);
178  };
179 }
Vector3 DiffuseColor
Definition: ObjectLoader.h:97
MxVector< Vertex > vertecies
Definition: ObjectLoader.h:120
float SpecularExponent
Definition: ObjectLoader.h:80
MxString DiffuseMap
Definition: ObjectLoader.h:59
Definition: ObjectLoader.h:166
MxString SpecularMap
Definition: ObjectLoader.h:63
MxString Name
Definition: ObjectLoader.h:50
size_t GetVertexCount() const
Definition: ObjectLoader.h:141
Definition: ObjectLoader.h:150
MxString AmbientMap
Definition: ObjectLoader.h:55
Definition: ObjectLoader.h:111
Definition: ObjectLoader.h:45
MxString NormalMap
Definition: ObjectLoader.h:75
MxString name
Definition: ObjectLoader.h:116
MxString EmmisiveMap
Definition: ObjectLoader.h:67
MxString HeightMap
Definition: ObjectLoader.h:71
Vector3 SpecularColor
Definition: ObjectLoader.h:101
MxVector< MeshInfo > meshes
Definition: ObjectLoader.h:159
Vector3 AmbientColor
Definition: ObjectLoader.h:93
MaterialLibrary materials
Definition: ObjectLoader.h:155
Definition: Application.cpp:49
float Transparency
Definition: ObjectLoader.h:84
float Displacement
Definition: ObjectLoader.h:88
Vector3 EmmisiveColor
Definition: ObjectLoader.h:105