ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
model.hpp
Go to the documentation of this file.
1
11
12#ifndef TOYMAKERENGINE_MODEL_H
13#define TOYMAKERENGINE_MODEL_H
14
15#include <vector>
16#include <string>
17
18#include <GL/glew.h>
19#include <glm/glm.hpp>
20
21#include <assimp/Importer.hpp>
22#include <assimp/scene.h>
23#include <assimp/material.h>
24#include <nlohmann/json.hpp>
25
26#include "core/ecs_world_resource_ext.hpp" // this instead of the regular ECS and resource includes
28#include "mesh.hpp"
29#include "material.hpp"
30
31namespace ToyMaker {
32
50 class StaticModel : public Resource<StaticModel>{
51 public:
57 inline static std::string getResourceTypeName() { return "StaticModel"; }
58
64 inline static std::string getComponentTypeName() { return "StaticModel"; }
65
75 StaticModel(const std::vector<std::shared_ptr<StaticMesh>>& meshHandles, const std::vector<std::shared_ptr<Material>>& materialHandles);
76
79
81 StaticModel(StaticModel&& other);
83 StaticModel(const StaticModel& other);
84
88 StaticModel& operator=(const StaticModel& other);
89
95 std::vector<std::shared_ptr<StaticMesh>> getMeshHandles() const;
96
102 std::vector<std::shared_ptr<Material>> getMaterialHandles() const;
103
110 inline void setBounds(const ObjectBounds& newBounds) {
111 mCoarseBounds = newBounds;
112 mCoarseBoundsDirty = false;
113 }
114
119 inline ObjectBounds getBounds() const {
120 return mCoarseBounds;
121 }
122
128 inline const bool boundsNeedRecompute() const { return mCoarseBoundsDirty; }
129
130 private:
134 std::vector<std::shared_ptr<StaticMesh>> mMeshHandles {};
135
140 std::vector<std::shared_ptr<Material>> mMaterialHandles {};
141
147
153 bool mCoarseBoundsDirty { true };
154
159 void free();
160
165 void stealResources(StaticModel& other);
166
171 void copyResources(const StaticModel& other);
172
177 void destroyResource();
178
183 void releaseResource();
184 };
185
222 class StaticModelFromFile: public ResourceConstructor<StaticModel, StaticModelFromFile> {
223 public:
229
235 inline static std::string getResourceConstructorName() { return "fromFile"; }
236
237 private:
238
246 std::shared_ptr<IResource> createResource(const nlohmann::json& methodParameters) override;
247 };
248}
249
250#endif
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:488
Resource(int explicitlyInitializeMe)
Definition resource_database.hpp:386
StaticModelFromFile()
Creates a StaticModelFromFile object.
Definition model.cpp:98
std::shared_ptr< IResource > createResource(const nlohmann::json &methodParameters) override
Creates a StaticModel resource based on its parameters.
Definition model.cpp:102
static std::string getResourceConstructorName()
Gets the resource constructor type string for this constructor.
Definition model.hpp:235
This engine's representation of a single unrigged 3D model.
Definition model.hpp:50
const bool boundsNeedRecompute() const
Indicates whether this static model requires its bounding box recomputed.
Definition model.hpp:128
void destroyResource()
Destroys the resources associated with this object.
Definition model.cpp:93
std::vector< std::shared_ptr< StaticMesh > > getMeshHandles() const
Gets the list of StaticMeshes associated with this Model object.
Definition model.cpp:70
std::vector< std::shared_ptr< StaticMesh > > mMeshHandles
The meshes that make up this model.
Definition model.hpp:134
StaticModel(const std::vector< std::shared_ptr< StaticMesh > > &meshHandles, const std::vector< std::shared_ptr< Material > > &materialHandles)
Constructs a model out of a list of handles to meshes and materials.
Definition model.cpp:28
ObjectBounds getBounds() const
Returns the latest computed bounding box encapsulating the model in its untransformed state.
Definition model.hpp:119
void stealResources(StaticModel &other)
Utility method for taking resources from another instance of this class.
Definition model.cpp:77
std::vector< std::shared_ptr< Material > > getMaterialHandles() const
Gets the materials associated with this model object.
Definition model.cpp:71
void free()
Utility method for destroying resources associated with this model.
Definition model.cpp:72
void setBounds(const ObjectBounds &newBounds)
Sets a new object oriented bounding box for this object.
Definition model.hpp:110
ObjectBounds mCoarseBounds
The coarse object bounds for this model, used mainly for mouse picking.
Definition model.hpp:146
void releaseResource()
Releases resources associated with this object so that they may be claimed by another part of the pro...
Definition model.cpp:96
~StaticModel()
Model destructor.
Definition model.cpp:39
std::vector< std::shared_ptr< Material > > mMaterialHandles
The materials that correspond to each mesh on this model.
Definition model.hpp:140
static std::string getResourceTypeName()
Gets the resource type string for this object.
Definition model.hpp:57
static std::string getComponentTypeName()
Gets the component type string for this object.
Definition model.hpp:64
bool mCoarseBoundsDirty
Whether any of the meshes under this object has been modified, requiring a recompute of this object's...
Definition model.hpp:153
StaticModel & operator=(StaticModel &&other)
Move assignment.
Definition model.cpp:47
void copyResources(const StaticModel &other)
Utility method for deeply replicating resources from another instance of this class.
Definition model.cpp:87
Header file that makes Resource objects useable as ECS components.
Functions related to rendering materials.
A file containing the ToyMaker::StaticMesh class and related structures.
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:25
Classes and structs representing data related to the engine's spatial query system (the precursor to ...
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition types.hpp:845