21 Json[
"name"] = NameComponent.
Name;
26 Json[
"scale"] = TransformComponent.
Scale;
27 Json[
"angles"] = TransformComponent.
Angles;
28 Json[
"position"] = TransformComponent.
Position;
34 Json[
"is_primary"] = CameraComponent.
IsPrimary;
52 Json[
"color"] = PointLightComponent.
Color;
53 Json[
"strength"] = PointLightComponent.
Strength;
54 Json[
"constant_attitution"] = PointLightComponent.
Constant;
55 Json[
"linear_attitution"] = PointLightComponent.
Linear;
56 Json[
"quafratic_attitution"] = PointLightComponent.
Quadratic;
61 Json[
"color"] = DirectionalLightComponent.
Color;
62 Json[
"strength"] = DirectionalLightComponent.
Strength;
63 Json[
"is_casting_shadows"] = DirectionalLightComponent.
GetIsShadow();
64 Json[
"projection_box_size"] = DirectionalLightComponent.
GetBoxSize();
65 Json[
"projection_box_depth"] = DirectionalLightComponent.
GetBoxDepth();
72 Json[
"color"] = SpotLightComponent.
Color;
73 Json[
"strength"] = SpotLightComponent.
Strength;
80 const auto &name = Json.find(
"name");
81 if (name == Json.end())
return false;
83 NameComponent.
Name = name->get<std::string>();
89 const auto &scale = Json.find(
"scale");
90 const auto &angles = Json.find(
"angles");
91 const auto &position = Json.find(
"position");
93 if (scale != Json.end()) TransformComponent.
SetScale(scale->get<
vec3>());
94 if (angles != Json.end()) TransformComponent.
SetAngles(angles->get<
vec3>());
95 if (position != Json.end()) TransformComponent.
SetPosition(position->get<
vec3>());
101 const auto &is_primary = Json.find(
"is_primary");
102 const auto &projection_type = Json.find(
"projection_type");
103 const auto &fov = Json.find(
"fov");
104 const auto &position = Json.find(
"position");
105 const auto &focus_point = Json.find(
"focus_point");
106 const auto &up_direction = Json.find(
"up_direction");
107 const auto &viewport_width = Json.find(
"viewport_width");
108 const auto &viewport_height = Json.find(
"viewport_height");
111 if (is_primary != Json.end()) CameraComponent.
IsPrimary = is_primary->get<
bool>();
120 const auto &effects = Json.find(
"effects");
121 if (effects != Json.end())
123 const auto &effects_is_hdr = effects->find(
"is_hdr");
124 const auto &effects_exposure = effects->find(
"exposure");
125 const auto &effects_is_bloom = effects->find(
"is_bloom");
126 const auto &effects_bloom_amount = effects->find(
"bloom_amount");
128 if (effects_is_hdr != effects->end())
camera.
Effects.
HDR = effects_is_hdr->get<
bool>();
130 if (effects_is_bloom != effects->end())
camera.
Effects.
Bloom = effects_is_bloom->get<
bool>();
138 const auto &
color = Json.find(
"color");
139 const auto &strength = Json.find(
"strength");
140 const auto &constant_attitution = Json.find(
"constant_attitution");
141 const auto &linear_attitution = Json.find(
"linear_attitution");
142 const auto &quadratic_attitution = Json.find(
"quafratic_attitution");
145 if (strength != Json.end()) PointLightComponent.
Strength = strength->get<
float>();
146 if (constant_attitution != Json.end()) PointLightComponent.
Constant = constant_attitution->get<
float>();
147 if (linear_attitution != Json.end()) PointLightComponent.
Linear = linear_attitution->get<
float>();
148 if (quadratic_attitution != Json.end()) PointLightComponent.
Quadratic = quadratic_attitution->get<
float>();
154 const auto &
color = Json.find(
"color");
155 const auto &strength = Json.find(
"strength");
156 const auto &is_casting_shadows = Json.find(
"is_casting_shadows");
157 const auto &projection_box_size = Json.find(
"projection_box_size");
158 const auto &projection_box_depth = Json.find(
"projection_box_depth");
159 const auto &shadow_map_width = Json.find(
"shadow_map_width");
160 const auto &shadow_map_height = Json.find(
"shadow_map_height");
163 if (strength != Json.end()) DirectionalLightComponent.
Strength = strength->get<
float>();
164 if (is_casting_shadows != Json.end()) DirectionalLightComponent.
SetIsShadows(is_casting_shadows->get<
bool>());
165 if (projection_box_size != Json.end()) DirectionalLightComponent.
SetBoxSize(projection_box_size->get<
float>());
166 if (projection_box_depth != Json.end()) DirectionalLightComponent.
SetBoxDepth(projection_box_depth->get<
float>());
167 if (shadow_map_width != Json.end()) DirectionalLightComponent.
SetShadowMapWidth(shadow_map_width->get<
int>());
168 if (shadow_map_height != Json.end()) DirectionalLightComponent.
SetShadowMapHeight(shadow_map_height->get<
int>());
174 const auto &
color = Json.find(
"color");
175 const auto &strength = Json.find(
"strength");
176 const auto &inner_cutoff_angle = Json.find(
"inner_cutoff_angle");
177 const auto &outer_cutoff_angle = Json.find(
"outer_cutoff_angle");
180 if (strength != Json.end()) SpotLightComponent.
Strength = strength->get<
float>();
181 if (inner_cutoff_angle != Json.end()) SpotLightComponent.
SetInnerCutoff(inner_cutoff_angle->get<
float>());
182 if (outer_cutoff_angle != Json.end()) SpotLightComponent.
SetOuterCutoff(outer_cutoff_angle->get<
float>());
186void scl::scene_serializer::SerializeObject(
json &Json,
const scene_object &SceneObject)
188 SerializeComponent<name_component>(Json, SceneObject);
189 SerializeComponent<transform_component>(Json, SceneObject);
190 SerializeComponent<camera_component>(Json, SceneObject);
191 SerializeComponent<point_light_component>(Json, SceneObject);
192 SerializeComponent<directional_light_component>(Json, SceneObject);
193 SerializeComponent<spot_light_component>(Json, SceneObject);
196void scl::scene_serializer::DeserializeObject(
const json &Json, scene_object &SceneObject)
198 DeserializeComponent<transform_component>(Json, SceneObject);
199 DeserializeComponent<camera_component>(Json, SceneObject);
200 DeserializeComponent<point_light_component>(Json, SceneObject);
201 DeserializeComponent<directional_light_component>(Json, SceneObject);
202 DeserializeComponent<spot_light_component>(Json, SceneObject);
210 Scene->Registry.each([&](
auto Entity)
216 SerializeObject(j,
object);
217 objects_json.push_back(j);
222 {
"is_gui_enabled", application::Get().GuiEnabled },
231 {
"viewport_id", Scene->GetViewportId(), },
232 {
"enviroment_ambient", Scene->GetEnviromentAmbient(), }
234 {
"objects", objects_json }
237 SCL_CORE_INFO(
"Scene saved to file \"{}\".", OutFileName.string());
243 const json root_json = json::parse(root_json_string);
245 const auto &gui_json = root_json.find(
"gui");
246 const auto &render_json = root_json.find(
"render");
247 const auto &scene_data_json = root_json.find(
"scene_data");
248 const auto &objects_json = root_json.find(
"objects");
250 if (gui_json != root_json.end())
252 const auto &is_gui_enabled = gui_json->find(
"is_gui_enabled");
253 const auto &is_dockspace = gui_json->find(
"is_dockspace");
255 if (is_gui_enabled != gui_json->end()) application::Get().GuiEnabled = is_gui_enabled->get<
bool>();
256 if (is_dockspace != gui_json->end())
gui::IsDockspace = is_dockspace->get<
bool>();
258 if (render_json != root_json.end())
260 const auto &clear_color = render_json->find(
"clear_color");
261 const auto &is_wireframe = render_json->find(
"is_wireframe");
262 const auto &is_vsync = render_json->find(
"is_vsync");
268 if (scene_data_json != root_json.end())
270 const auto &viewport_id = scene_data_json->find(
"viewport_id");
271 const auto &enviroment_ambient = scene_data_json->find(
"enviroment_ambient");
273 if (viewport_id != scene_data_json->end()) Scene->SetViewportId(viewport_id->get<
int>());
274 if (enviroment_ambient != scene_data_json->end()) Scene->SetEnviromentAmbient(enviroment_ambient->get<
vec3>());
276 if (objects_json != root_json.end())
278 for (
const auto &object_json : *objects_json)
281 const auto &name_json = object_json.find(
typeid(
name_component).name());
282 if (name_json == object_json.end())
284 object = Scene->CreateObject();
289 from_json(*name_json, object_name_component);
290 object = Scene->CreaetOrGetObject(object_name_component.Name);
293 DeserializeObject(object_json,
object);
const vec3 & GetUpDirection() const
int GetViewportWidth() const
const vec3 & GetFocus() const
camera_projection_type GetProjectionType() const
void SetProjectionType(camera_projection_type ProjectionType)
void SetFieldOfView(float FieldOfView)
float GetFieldOfView() const
void SetViewportHeight(int ViewportHeight)
const vec3 & GetPosition() const
int GetViewportHeight() const
void SetPosition(const vec3 &Position)
void SetUpDirection(const vec3 &UpDirection)
void SetViewportWidth(int ViewportWidth)
void SetFocus(const vec3 &Focus)
static void SetVSync(bool VSync)
static void SetClearColor(const vec4 &ClearColor)
static void SetWireframeMode(bool IsWireframe)
static const vec4 & GetClearColor()
static bool GetWireframeMode()
static void Serialize(const shared< scene > &Scene, const std::filesystem::path &OutFileName)
static void Deserialize(shared< scene > &Scene, const std::filesystem::path &InFileName)
#define SCL_CORE_INFO(...)
void SaveFile(const std::string &Data, const std::filesystem::path &FilePath)
std::string LoadFile(const std::filesystem::path &FilePath)
std::shared_ptr< T > shared
void to_json(json &Json, const name_component &NameComponent)
bool from_json(const json &Json, name_component &NameComponent)
Render bridge class implementation module. Static class for making calls to low-level render api,...
Scene serializer (also could perform deserialization) class definition module.
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.
int GetShadowMapHeight() const
void SetBoxSize(float BoxSize)
void SetBoxDepth(float BoxDepth)
float GetBoxDepth() const
void SetIsShadows(bool IsShadows)
void SetShadowMapWidth(int ShadowMapWidth)
void SetShadowMapHeight(int ShadowMapHeight)
int GetShadowMapWidth() const
float GetOuterCutoff() const
float GetInnerCutoff() const
void SetOuterCutoff(degrees Angle)
void SetInnerCutoff(degrees Angle)