Skip to content

Commit 7df7ddc

Browse files
committed
Added materials
1 parent b2dcdef commit 7df7ddc

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Engine/include/SceneData/SceneExporterLayout.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ void to_json(json& j, std::shared_ptr<Node> n) {
295295
j["farPlane"] = light->type().farPlane.x;
296296
j["shadow"] = light->hasShadow();
297297
j["intensity"] = light->intensity();
298+
} else if (std::dynamic_pointer_cast<Light<LightType::LightSpot>>(n)) {
299+
j["type"] = "LIGHT_SPOT";
300+
auto light = std::dynamic_pointer_cast<Light<LightType::LightSpot>>(n);
301+
j["position"] = {light->type().position.x, light->type().position.y, light->type().position.z};
302+
j["diffuse"] = {light->type().diffuse.x, light->type().diffuse.y, light->type().diffuse.z};
303+
j["specular"] = {light->type().specular.x, light->type().specular.y, light->type().specular.z};
304+
j["direction"] = {light->type().direction.x, light->type().direction.y, light->type().direction.z};
305+
j["innerCutoff"] = light->type().innerCutoff;
306+
j["outerCutoff"] = light->type().outerCutoff;
307+
j["intensity"] = light->intensity();
298308
}
299309

300310
std::vector<std::pair<std::string, json>> componentJson;
@@ -338,6 +348,8 @@ void from_json(json& j, std::shared_ptr<Node> n) {
338348
child = std::make_shared<Light<LightType::LightDir>>();
339349
} else if (childJson["type"] == "LIGHT_OMNI") {
340350
child = std::make_shared<Light<LightType::LightOmni>>();
351+
}else if (childJson["type"] == "LIGHT_SPOT") {
352+
child = std::make_shared<Light<LightType::LightSpot>>();
341353
} else if (childJson["type"] == "MESH_ANIMATE") {
342354
child = std::make_shared<AnimatedMesh>();
343355
}
@@ -531,6 +543,19 @@ void from_json(json& j, std::shared_ptr<Node> n) {
531543
float intensity = 1;
532544
j.at("intensity").get_to(intensity);
533545
light->intensity(intensity);
546+
} else if (type == "LIGHT_SPOT") {
547+
auto light = std::dynamic_pointer_cast<Light<LightType::LightSpot>>(n);
548+
LightType::LightSpot lightType;
549+
lightType.position = glm::vec4(j.at("position").get<std::vector<float>>().at(0), j.at("position").get<std::vector<float>>().at(1), j.at("position").get<std::vector<float>>().at(2), 1.0);
550+
lightType.diffuse = glm::vec4(j.at("diffuse").get<std::vector<float>>().at(0), j.at("diffuse").get<std::vector<float>>().at(1), j.at("diffuse").get<std::vector<float>>().at(2), 1.0);
551+
lightType.specular = glm::vec4(j.at("specular").get<std::vector<float>>().at(0), j.at("specular").get<std::vector<float>>().at(1), j.at("specular").get<std::vector<float>>().at(2), 1.0);
552+
lightType.direction = glm::vec4(j.at("direction").get<std::vector<float>>().at(0), j.at("direction").get<std::vector<float>>().at(1), j.at("direction").get<std::vector<float>>().at(2), 1.0);
553+
lightType.innerCutoff = j.at("innerCutoff").get<float>();
554+
lightType.outerCutoff = j.at("outerCutoff").get<float>();
555+
float intensity = 1;
556+
j.at("intensity").get_to(intensity);
557+
light->type(lightType);
558+
light->intensity(intensity);
534559
} else if (type == "MESH_ANIMATE") {
535560
auto mesh = std::dynamic_pointer_cast<AnimatedMesh>(n);
536561
// Deserialize textures

Engine/src/SceneData/SceneLoader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ std::shared_ptr<Prisma::Scene> Prisma::SceneLoader::loadScene(std::string scene,
4545
auto isMesh = std::dynamic_pointer_cast<Mesh>(node);
4646
auto isLightDir = std::dynamic_pointer_cast<Light<LightType::LightDir>>(node);
4747
auto isLightOmni = std::dynamic_pointer_cast<Light<LightType::LightOmni>>(node);
48+
auto isLightSpot = std::dynamic_pointer_cast<Light<LightType::LightSpot>>(node);
4849
if (isAnimateMesh) {
4950
m_scene->animateMeshes.push_back(isAnimateMesh);
5051
} else if (isMesh) {
@@ -53,7 +54,10 @@ std::shared_ptr<Prisma::Scene> Prisma::SceneLoader::loadScene(std::string scene,
5354
m_scene->dirLights.push_back(isLightDir);
5455
} else if (isLightOmni) {
5556
m_scene->omniLights.push_back(isLightOmni);
57+
} else if (isLightSpot) {
58+
m_scene->spotLights.push_back(isLightSpot);
5659
}
60+
5761
});
5862

5963
return m_scene;
@@ -126,6 +130,7 @@ std::shared_ptr<Prisma::Scene> Prisma::SceneLoader::hasFinish() {
126130
auto isMesh = std::dynamic_pointer_cast<Mesh>(node);
127131
auto isLightDir = std::dynamic_pointer_cast<Light<LightType::LightDir>>(node);
128132
auto isLightOmni = std::dynamic_pointer_cast<Light<LightType::LightOmni>>(node);
133+
auto isLightSpot = std::dynamic_pointer_cast<Light<LightType::LightSpot>>(node);
129134
if (isAnimateMesh) {
130135
m_scene->animateMeshes.push_back(isAnimateMesh);
131136
} else if (isMesh) {
@@ -134,7 +139,10 @@ std::shared_ptr<Prisma::Scene> Prisma::SceneLoader::hasFinish() {
134139
m_scene->dirLights.push_back(isLightDir);
135140
} else if (isLightOmni) {
136141
m_scene->omniLights.push_back(isLightOmni);
142+
}else if (isLightSpot) {
143+
m_scene->spotLights.push_back(isLightSpot);
137144
}
145+
138146
});
139147
return m_scene;
140148
}

0 commit comments

Comments
 (0)