@@ -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
0 commit comments