Skylicht Engine
Loading...
Searching...
No Matches
CRenderMeshInstancing.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 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#include "Instancing/CInstancingMaterialData.h"
34
35namespace Skylicht
36{
79 class SKYLICHT_API CRenderMeshInstancing : public CEntityHandler
80 {
81 protected:
82 CEntity* m_root;
83 core::array<CEntity*> m_baseEntities;
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_loadTexcoord2;
95 bool m_loadNormal;
96 bool m_fixInverseNormal;
97
98 IVertexBuffer* m_instancingMaterials;
99 IVertexBuffer* m_instancingTransform;
100 IVertexBuffer* m_instancingLighting;
101 int m_shareDataTransform;
102 int m_shareDataMaterials;
103
104 public:
105 CRenderMeshInstancing();
106
107 virtual ~CRenderMeshInstancing();
108
109 virtual void initComponent();
110
111 virtual void updateComponent();
112
113 virtual CObjectSerializable* createSerializable();
114
115 virtual void loadSerializable(CObjectSerializable* object);
116
117 virtual void refreshModelAndMaterial();
118
119 virtual void initFromPrefab(CEntityPrefab* prefab);
120
121 virtual CEntity* spawn();
122
123 virtual CEntity* spawn(const core::matrix4& transform);
124
125 const std::string& getMeshResource()
126 {
127 return m_meshFile;
128 }
129
130 const std::string& getMaterialResource()
131 {
132 return m_materialFile;
133 }
134
135 void initFromMeshFile(const char* path, bool loadNormalMap = true, bool loadTexcoord2 = false);
136
137 void initMaterialFromFile(const char* material);
138
139 void initMaterial(ArrayMaterial& materials, bool cloneMaterial = false);
140
141 void applyShareTransformBuffer();
142
143 void applyShareMaterialBuffer();
144
145 inline int getMaterialCount()
146 {
147 return (int)m_materials.size();
148 }
149
150 CMaterial* getMaterial(int i)
151 {
152 return m_materials[i];
153 }
154
155 core::array<CEntity*>& getBaseEntities()
156 {
157 return m_baseEntities;
158 }
159
160 std::vector<CRenderMeshData*>& getRenderers()
161 {
162 return m_renderers;
163 }
164
165 std::vector<CWorldTransformData*>& getRenderTransforms()
166 {
167 return m_renderTransforms;
168 }
169
170 std::vector<CWorldTransformData*>& getAllTransforms()
171 {
172 return m_transforms;
173 }
174
175 DECLARE_GETTYPENAME(CRenderMeshInstancing)
176
177 protected:
178
179 virtual void releaseMaterial();
180
181 virtual void releaseEntities();
182
183 virtual void releaseBaseEntities();
184
185 void addRendererInstancing(CEntity* entity, CRenderMeshData* baseRenderMesh, CWorldTransformData* baseTransform);
186
187 void addMaterial(CMaterial* material);
188 };
189
190}
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
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
Definition IVertexBuffer.h:17
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241