MQEngine
载入中...
搜索中...
未找到
Component.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/8/25.
3//
4
5#ifndef COMPONENT_H
6#define COMPONENT_H
7#include "NameTag.h"
9#include <boost/describe.hpp>
11namespace MQEngine {
13 {
14 std::string modelUuid; // 模型UUID,用于定位模型文件
15 std::string meshName; // 网格体名称,用于从模型中选择特定网格
16 FCT::StaticMesh<uint32_t>* mesh; // 实际存储的mesh,默认为nullptr表示未加载
17
18 StaticMeshInstance() : mesh(nullptr) {}
19
20 StaticMeshInstance(const std::string& uuid, const std::string& name)
21 : modelUuid(uuid), meshName(name), mesh(nullptr)
22 {
23 }
25
26 template<class Archive>
27 void serialize(Archive & ar, const unsigned int version)
28 {
29 ar & modelUuid;
30 ar & meshName;
31 }
32 };
33 BOOST_DESCRIBE_STRUCT(StaticMeshInstance, (), (modelUuid, meshName))
34
35 struct ENGINE_API TickerScriptComponent
36 {
37 std::string functionName;
38
39 TickerScriptComponent() = default;
40
41 TickerScriptComponent(const std::string& funcName)
42 : functionName(funcName)
43 {
44 }
45
46 friend class boost::serialization::access;
47
48 template<class Archive>
49 void serialize(Archive & ar, const unsigned int version)
50 {
51 ar & functionName;
52 }
53 };
54 BOOST_DESCRIBE_STRUCT(TickerScriptComponent, (), (functionName))
55
56 struct ENGINE_API OnStartScriptComponent
57 {
58 std::string functionName;
59
60 OnStartScriptComponent() = default;
61
62 OnStartScriptComponent(const std::string& funcName)
63 : functionName(funcName)
64 {
65 }
66
67 friend class boost::serialization::access;
68
69 template<class Archive>
70 void serialize(Archive & ar, const unsigned int version)
71 {
72 ar & functionName;
73 }
74 };
75 BOOST_DESCRIBE_STRUCT(OnStartScriptComponent, (), (functionName))
76
77 struct ENGINE_API DirectionalLightComponent
78 {
79 FCT::Vec3 direction = FCT::Vec3(0.0f, -1.0f, 0.0f); // 光照方向
80 FCT::Vec3 color = FCT::Vec3(1.0f, 1.0f, 1.0f); // 光照颜色
81 float intensity = 1.0f; // 光照强度
82 bool enabled = true; // 是否启用
83
84 DirectionalLightComponent() = default;
85
86 DirectionalLightComponent(const FCT::Vec3& dir, const FCT::Vec3& col, float intens, bool enable = true)
87 : direction(dir), color(col), intensity(intens), enabled(enable)
88 {
89 }
90
91 friend class boost::serialization::access;
92
93 template<class Archive>
94 void serialize(Archive & ar, const unsigned int version)
95 {
96 ar & direction;
97 ar & color;
98 ar & intensity;
99 ar & enabled;
100 }
101 };
102 BOOST_DESCRIBE_STRUCT(DirectionalLightComponent, (), (direction, color, intensity, enabled))
103
104 struct ENGINE_API DiffuseTextureComponent
105 {
106 std::string modelUuid;
107 std::string texturePath;
108 FCT::Image* texture = nullptr;
109 DiffuseTextureComponent() = default;
110
111 DiffuseTextureComponent(const std::string& uuid, const std::string& path)
112 : modelUuid(uuid), texturePath(path)
113 {
114 }
115
116 friend class boost::serialization::access;
117 template<class Archive>
118 void serialize(Archive & ar, const unsigned int version)
119 {
120 ar & modelUuid;
121 ar & texturePath;
122 }
123 };
124 BOOST_DESCRIBE_STRUCT(DiffuseTextureComponent, (), (modelUuid, texturePath))
125
126 struct ENGINE_API NormalMapComponent
127 {
128 std::string modelUuid;
129 std::string texturePath;
130 FCT::Image* texture = nullptr;
131 NormalMapComponent() = default;
132
133 NormalMapComponent(const std::string& uuid, const std::string& path)
134 : modelUuid(uuid), texturePath(path)
135 {
136 }
137
138 friend class boost::serialization::access;
139 template<class Archive>
140 void serialize(Archive & ar, const unsigned int version)
141 {
142 ar & modelUuid;
143 ar & texturePath;
144 }
145 };
146 BOOST_DESCRIBE_STRUCT(NormalMapComponent, (), (modelUuid, texturePath))
147
148 struct ENGINE_API ShininessComponent
149 {
150 float shininess = 32.0f;
151 ShininessComponent() = default;
152
153 ShininessComponent(float shininess)
154 : shininess(shininess)
155 {
156 }
157
158 friend class boost::serialization::access;
159 template<class Archive>
160 void serialize(Archive & ar, const unsigned int version)
161 {
162 ar & shininess;
163 }
164 };
165 BOOST_DESCRIBE_STRUCT(ShininessComponent, (), (shininess))
166
167 struct ENGINE_API CacheShininess
168 {
169 FCT::UniquePtr<FCT::Uniform> uniform;
170 bool init = false;
171
172 CacheShininess(FCT::Context* ctx)
173 {
174 uniform = FCT::makeUnique<FCT::Uniform>(ctx, ShininessUniformSlot);
175 }
176 };
177}
178
179#endif //COMPONENT_H
A header file containing third party libraries and macros for platform
#define ENGINE_API
定义 EnginePCH.h:14
Entrypoint for the program.
定义 application.h:5
constexpr FCT::UniformSlot ShininessUniformSlot
定义 UniformSlots.h:35
BOOST_DESCRIBE_STRUCT(PositionComponent,(),(position)) struct ENGINE_API RotationComponent
定义 Camera.h:23
定义 Component.h:13
StaticMeshInstance()
定义 Component.h:18
FCT::StaticMesh< uint32_t > * mesh
定义 Component.h:16
StaticMeshInstance(const std::string &uuid, const std::string &name)
定义 Component.h:20
std::string modelUuid
定义 Component.h:14
void serialize(Archive &ar, const unsigned int version)
定义 Component.h:27
friend class boost::serialization::access
定义 Component.h:24
std::string meshName
定义 Component.h:15