Skylicht Engine
Loading...
Searching...
No Matches
CPrimitive.h
1/*
2!@
3MIT License
4
5Copyright (c) 2022 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 "CPrimiviteData.h"
28#include "Entity/CEntityHandler.h"
29#include "RenderMesh/CMesh.h"
30
31namespace Skylicht
32{
55 class COMPONENT_API CPrimitive : public CEntityHandler
56 {
57 protected:
58 CPrimiviteData::EPrimitive m_type;
59
60 SColor m_color;
61
62 bool m_instancing;
63
64 bool m_useCustomMaterial;
65
66 bool m_useNormalMap;
67
68 CMaterial* m_material;
69
70 CMaterial* m_customMaterial;
71
72 std::string m_materialPath;
73
74 protected:
75
76 CPrimitive();
77
78 virtual ~CPrimitive();
79
80 virtual void initComponent();
81
82 virtual CObjectSerializable* createSerializable();
83
84 virtual void loadSerializable(CObjectSerializable* object);
85
86 virtual CEntity* spawn();
87
88 public:
89
97 CEntity* addPrimitive(const core::vector3df& pos, const core::vector3df& rotDeg, const core::vector3df& scale);
98
106
112
117 inline const SColor& getColor()
118 {
119 return m_color;
120 }
121
126 void setColor(const SColor& color);
127
133
138 void setInstancing(bool b);
139
144 inline bool isInstancing()
145 {
146 return m_instancing;
147 }
148
153 inline void setEnableNormalMap(bool b)
154 {
155 m_useNormalMap = b;
156 }
157
162 inline bool isUseNormalMap()
163 {
164 return m_useNormalMap;
165 }
166
171 inline CPrimiviteData::EPrimitive getType()
172 {
173 return m_type;
174 }
175
176 DECLARE_GETTYPENAME(CPrimitive)
177 };
178}
This is the object class that describes an entity.
Definition CEntity.h:58
The object class describes material information such as which shader it's associated with,...
Definition CMaterial.h:84
Definition CMesh.h:75
Definition CObjectSerializable.h:36
Base class for primitive shape components (Cube, Sphere, Plane). Supports multi-instance rendering wi...
Definition CPrimitive.h:56
CPrimiviteData::EPrimitive getType()
Get the primitive type.
Definition CPrimitive.h:171
void setColor(const SColor &color)
Set the default material color.
void setCustomMaterial(CMaterial *material)
Set a custom material for all instances.
void setEnableNormalMap(bool b)
Enable or disable normal map support (uses tangent vertices).
Definition CPrimitive.h:153
void setInstancing(bool b)
Enable or disable hardware instancing.
CMesh * getMesh()
Get the internal mesh used for rendering.
CEntity * addPrimitive(const core::vector3df &pos, const core::vector3df &rotDeg, const core::vector3df &scale)
Add a primitive instance to this component.
bool isUseNormalMap()
Check if normal map is enabled.
Definition CPrimitive.h:162
bool isInstancing()
Check if hardware instancing is enabled.
Definition CPrimitive.h:144
const SColor & getColor()
Get the default material color.
Definition CPrimitive.h:117
CMaterial * getMaterial()
Get the active material.
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445