Skylicht Engine
Loading...
Searching...
No Matches
CRenderMesh.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Entity/CEntityPrefab.h"
28#include "Entity/CEntityHandler.h"
29#include "Material/CMaterial.h"
30#include "Material/CMaterialManager.h"
31#include "RenderMesh/CRenderMeshData.h"
32#include "Transform/CWorldTransformData.h"
33
34namespace Skylicht
35{
45
80 class SKYLICHT_API CRenderMesh : public CEntityHandler
81 {
82 protected:
83 CEntity* m_root;
84
85 std::vector<CWorldTransformData*> m_renderTransforms;
86 std::vector<CWorldTransformData*> m_transforms;
87 std::vector<CRenderMeshData*> m_renderers;
88
89 ArrayMaterial m_materials;
90
91 std::string m_meshFile;
92 std::string m_materialFile;
93
94 bool m_optimizeForRender;
95 bool m_loadTexcoord2;
96 bool m_loadNormal;
97 bool m_fixInverseNormal;
98 bool m_enableInstancing;
99 u32 m_lightLayers;
100
101 bool m_shadowCasting;
102
103 public:
104 CRenderMesh();
105
106 virtual ~CRenderMesh();
107
108 virtual void initComponent();
109
110 virtual void updateComponent();
111
112 virtual CObjectSerializable* createSerializable();
113
114 virtual void loadSerializable(CObjectSerializable* object);
115
116 public:
117
118 void refreshModelAndMaterial(bool reloadModel = true);
119
120 void initFromPrefab(CEntityPrefab* prefab);
121
122 void initFromMeshFile(const char* path, bool loadNormalMap = true, bool loadTexcoord2 = false);
123
124 void initMaterialFromFile(const char* material);
125
126 void changeMaterialFromFile(const char* material);
127
128 void changeShaderForAllMaterials(const char* shader);
129
130 void initMaterial(ArrayMaterial& materials, bool cloneMaterial = false);
131
132 void enableOptimizeForRender(bool b)
133 {
134 m_optimizeForRender = b;
135 }
136
137 void enableInstancing(bool b);
138
139 void enableInstancingMaterialForEntity(bool b);
140
141 void setShadowCasting(bool b);
142
143 inline bool isShadowCasting()
144 {
145 return m_shadowCasting;
146 }
147
148 void setLightLayers(u32 layers);
149
150 inline u32 getLightLayers()
151 {
152 return m_lightLayers;
153 }
154
155 void removeRenderMeshName(const char* name);
156
157 void removeRenderMesh(CRenderMeshData* renderMesh);
158
159 void removeMaterials(ArrayMaterial& materials);
160
161 void attachMeshFromPrefab(CEntityPrefab* prefab, std::vector<std::string>& names, ArrayMaterial& materials, bool cloneMaterial = false, bool resetBoneTransform = false);
162
163 void resetDefaultTransform(CEntityPrefab* prefab, std::vector<std::string>& transformsName);
164
165 inline int getMaterialCount()
166 {
167 return (int)m_materials.size();
168 }
169
170 const std::string& getMeshResource()
171 {
172 return m_meshFile;
173 }
174
175 const std::string& getMaterialResource()
176 {
177 return m_materialFile;
178 }
179
180 CMaterial* getMaterial(int i)
181 {
182 return m_materials[i];
183 }
184
185 std::vector<CRenderMeshData*>& getRenderers()
186 {
187 return m_renderers;
188 }
189
190 std::vector<CWorldTransformData*>& getRenderTransforms()
191 {
192 return m_renderTransforms;
193 }
194
195 std::vector<CWorldTransformData*>& getAllTransforms()
196 {
197 return m_transforms;
198 }
199
200 core::aabbox3df getBounds();
201
202 void printEntites();
203
204 CWorldTransformData* getChildTransform(const char* name);
205
206 int getChildTransforms(const char* name, std::vector<CWorldTransformData*>& childs);
207
208 int getChildTransforms(CWorldTransformData* transform, std::vector<CWorldTransformData*>& childs, size_t from = 0);
209
210 DECLARE_GETTYPENAME(CRenderMesh)
211
212 protected:
213
214 void initNoOptimizeFromPrefab(CEntityPrefab* prefab);
215
216 void initOptimizeFromPrefab(CEntityPrefab* prefab);
217
218 void releaseMaterial();
219
220 void releaseEntities();
221
222 bool addMaterial(CMaterial* material);
223 };
224}
This is the object class that describes an entity.
Definition CEntity.h:58
This object class is created to store data in an array of multiple CEntities.
Definition CEntityPrefab.h:38
The object class describes material information such as which shader it's associated with,...
Definition CMaterial.h:84
Definition CObjectSerializable.h:36
Definition CRenderMeshData.h:38
Definition CWorldTransformData.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
aabbox3d< f32 > aabbox3df
Typedef for a f32 3d bounding box.
Definition aabbox3d.h:351
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58