@@ -295,20 +295,15 @@ 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::LightArea>>(n)) {
299- j[" type" ] = " LIGHT_AREA" ;
300- auto light = std::dynamic_pointer_cast<Light<LightType::LightArea>>(n);
301- j[" position" ][0 ] = {light->type ().position [0 ].x , light->type ().position [0 ].y ,
302- light->type ().position [0 ].z };
303- j[" position" ][1 ] = {light->type ().position [1 ].x , light->type ().position [1 ].y ,
304- light->type ().position [1 ].z };
305- j[" position" ][2 ] = {light->type ().position [2 ].x , light->type ().position [2 ].y ,
306- light->type ().position [2 ].z };
307- j[" position" ][3 ] = {light->type ().position [3 ].x , light->type ().position [3 ].y ,
308- light->type ().position [3 ].z };
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 };
309302 j[" diffuse" ] = {light->type ().diffuse .x , light->type ().diffuse .y , light->type ().diffuse .z };
310- j[" doubleSide" ] = light->type ().doubleSide ;
311- j[" shadow" ] = light->hasShadow ();
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 ;
312307 j[" intensity" ] = light->intensity ();
313308 }
314309
@@ -353,8 +348,8 @@ void from_json(json& j, std::shared_ptr<Node> n) {
353348 child = std::make_shared<Light<LightType::LightDir>>();
354349 } else if (childJson[" type" ] == " LIGHT_OMNI" ) {
355350 child = std::make_shared<Light<LightType::LightOmni>>();
356- } else if (childJson[" type" ] == " LIGHT_AREA " ) {
357- child = std::make_shared<Light<LightType::LightArea >>();
351+ }else if (childJson[" type" ] == " LIGHT_SPOT " ) {
352+ child = std::make_shared<Light<LightType::LightSpot >>();
358353 } else if (childJson[" type" ] == " MESH_ANIMATE" ) {
359354 child = std::make_shared<AnimatedMesh>();
360355 }
@@ -548,36 +543,18 @@ void from_json(json& j, std::shared_ptr<Node> n) {
548543 float intensity = 1 ;
549544 j.at (" intensity" ).get_to (intensity);
550545 light->intensity (intensity);
551- } else if (type == " LIGHT_AREA" ) {
552- auto light = std::dynamic_pointer_cast<Light<LightType::LightArea>>(n);
553- LightType::LightArea lightType;
554- lightType.position [0 ] = glm::vec4 (j.at (" position" ).at (0 ).get <std::vector<float >>().at (0 ),
555- j.at (" position" ).at (0 ).get <std::vector<float >>().at (1 ),
556- j.at (" position" ).at (0 ).get <std::vector<float >>().at (2 ), 1.0 );
557- lightType.position [1 ] = glm::vec4 (j.at (" position" ).at (1 ).get <std::vector<float >>().at (0 ),
558- j.at (" position" ).at (1 ).get <std::vector<float >>().at (1 ),
559- j.at (" position" ).at (1 ).get <std::vector<float >>().at (2 ), 1.0 );
560- lightType.position [2 ] = glm::vec4 (j.at (" position" ).at (2 ).get <std::vector<float >>().at (0 ),
561- j.at (" position" ).at (2 ).get <std::vector<float >>().at (1 ),
562- j.at (" position" ).at (2 ).get <std::vector<float >>().at (2 ), 1.0 );
563- lightType.position [3 ] = glm::vec4 (j.at (" position" ).at (3 ).get <std::vector<float >>().at (0 ),
564- j.at (" position" ).at (3 ).get <std::vector<float >>().at (1 ),
565- j.at (" position" ).at (3 ).get <std::vector<float >>().at (2 ), 1.0 );
566- lightType.diffuse = glm::vec4 (j.at (" diffuse" ).get <std::vector<float >>().at (0 ),
567- j.at (" diffuse" ).get <std::vector<float >>().at (1 ),
568- j.at (" diffuse" ).get <std::vector<float >>().at (2 ), 1.0 );
569-
570- bool hasShadow = false ;
571- j.at (" shadow" ).get_to (hasShadow);
572-
573- int doubleSide = 0 ;
574-
575- j.at (" doubleSide" ).get_to (doubleSide);
576- lightType.doubleSide = doubleSide;
577- light->hasShadow (hasShadow);
578- light->type (lightType);
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 >();
579555 float intensity = 1 ;
580556 j.at (" intensity" ).get_to (intensity);
557+ light->type (lightType);
581558 light->intensity (intensity);
582559 } else if (type == " MESH_ANIMATE" ) {
583560 auto mesh = std::dynamic_pointer_cast<AnimatedMesh>(n);
0 commit comments