Skip to content

Commit

Permalink
add docs, camelCase, remove temp variables
Browse files Browse the repository at this point in the history
Signed-off-by: ddengster <[email protected]>
  • Loading branch information
ddengster committed Jul 19, 2021
1 parent f6e2f92 commit 1b7602b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 57 deletions.
52 changes: 42 additions & 10 deletions graphics/include/ignition/common/ColladaExporter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,35 @@ namespace ignition
/// Defaults set based on collada 1.4 specifications
struct ColladaLight
{
std::string name; // name of the light
std::string type; // either "point", "directional" or "spot"
math::Vector3d direction; // direction (directional/spot lights only)
math::Vector3d position; // light position (non directional lights only)
math::Color diffuse; // light diffuse color
double constant_attenuation = 1.0; // Constant attentuation
double linear_attenuation = 0.0; // Linear attentuation
double quadratic_attenuation = 0.0; // Quadratic attentuation
double falloff_angle_deg = 180.0; // Falloff angle in degrees
double falloff_exponent = 0.0; // Fallof exponent
/// \brief Name of the light
std::string name;

/// \brief Type of the light. Either "point", "directional" or "spot"
std::string type;

/// \brief Light direction (directional/spot lights only)
math::Vector3d direction;

/// \brief Light position (non directional lights only)
math::Vector3d position;

/// \brief Light diffuse color
math::Color diffuse;

/// \brief Constant attentuation
double constantAttenuation = 1.0;

/// \brief Linear attentuation
double linearAttenuation = 0.0;

/// \brief Quadratic attentuation
double quadraticAttenuation = 0.0;

/// \brief Falloff angle in degrees
double falloffAngleDeg = 180.0;

/// \brief Fallof exponent
double falloffExponent = 0.0;
};

/// \brief Class used to export Collada mesh files
Expand All @@ -66,10 +85,23 @@ namespace ignition
public: virtual void Export(const Mesh *_mesh,
const std::string &_filename, bool _exportTextures = false);

/// \brief Export a mesh to a file
/// \param[in] _mesh Pointer to the mesh to be exported
/// \param[in] _filename Exported file's path and name
/// \param[in] _exportTextures True to export texture images to
/// '../materials/textures' folder
/// \param[in] _submeshToMatrix Matrices of submeshes
public: void Export(const Mesh *_mesh,
const std::string &_filename, bool _exportTextures,
const std::vector<math::Matrix4d> &_submeshToMatrix);

/// \brief Export a mesh to a file
/// \param[in] _mesh Pointer to the mesh to be exported
/// \param[in] _filename Exported file's path and name
/// \param[in] _exportTextures True to export texture images to
/// '../materials/textures' folder
/// \param[in] _submeshToMatrix Matrices of submeshes
/// \param[in] _lights List of lights to export
public: void Export(const Mesh *_mesh,
const std::string &_filename, bool _exportTextures,
const std::vector<math::Matrix4d> &_submeshToMatrix,
Expand Down
10 changes: 5 additions & 5 deletions graphics/src/ColladaExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ void ColladaExporter::Export(const Mesh *_mesh, const std::string &_filename,
attenXml->SetText(str);
lightTypeXml->LinkEndChild(attenXml);
};
attenuation_tag("constant_attenuation", light.constant_attenuation);
attenuation_tag("linear_attenuation", light.linear_attenuation);
attenuation_tag("quadratic_attenuation", light.quadratic_attenuation);
attenuation_tag("constant_attenuation", light.constantAttenuation);
attenuation_tag("linear_attenuation", light.linearAttenuation);
attenuation_tag("quadratic_attenuation", light.quadraticAttenuation);
}

// falloff
Expand All @@ -303,13 +303,13 @@ void ColladaExporter::Export(const Mesh *_mesh, const std::string &_filename,
tinyxml2::XMLElement *falloffAngleXml =
xmlDoc.NewElement("falloff_angle");
char str[100] = { 0 };
snprintf(str, sizeof(str), "%g", light.falloff_angle_deg);
snprintf(str, sizeof(str), "%g", light.falloffAngleDeg);
falloffAngleXml->SetText(str);
lightTypeXml->LinkEndChild(falloffAngleXml);

tinyxml2::XMLElement *falloffExpoXml =
xmlDoc.NewElement("falloff_exponent");
snprintf(str, sizeof(str), "%g", light.falloff_exponent);
snprintf(str, sizeof(str), "%g", light.falloffExponent);
falloffExpoXml->SetText(str);
lightTypeXml->LinkEndChild(falloffExpoXml);
}
Expand Down
68 changes: 26 additions & 42 deletions graphics/src/ColladaExporter_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,21 @@ TEST_F(ColladaExporter, ExportLights)
point.type = "point";
point.position = math::Vector3d(0, 0, 10);
point.diffuse = math::Color(1, 0.5, 1);
point.constant_attenuation = 0.8;
point.linear_attenuation = 0.8;
point.quadratic_attenuation = 0.1;
point.constantAttenuation = 0.8;
point.linearAttenuation = 0.8;
point.quadraticAttenuation = 0.1;
lights.push_back(point);

common::ColladaLight spot;
spot.name = "torch";
spot.type = "spot";
spot.position = math::Vector3d(0, 10, 10);
spot.diffuse = math::Color(1, 0.5, 1);
spot.constant_attenuation = 0.8;
spot.linear_attenuation = 0.8;
spot.quadratic_attenuation = 0.1;
spot.falloff_angle_deg = 90.0;
spot.falloff_exponent = 0.125;
spot.constantAttenuation = 0.8;
spot.linearAttenuation = 0.8;
spot.quadraticAttenuation = 0.1;
spot.falloffAngleDeg = 90.0;
spot.falloffExponent = 0.125;
lights.push_back(spot);
}

Expand All @@ -382,48 +382,35 @@ TEST_F(ColladaExporter, ExportLights)
const char* light_name_cstr = light_ele->Attribute("name");
ASSERT_TRUE(light_name_cstr);
std::string light_name = light_name_cstr;

auto technique = light_ele->FirstChildElement("technique_common");
EXPECT_TRUE(technique);

if (light_name == "sun")
{
auto technique = light_ele->FirstChildElement("technique_common");
EXPECT_TRUE(technique);
auto directional = technique->FirstChildElement("directional");
EXPECT_TRUE(directional);
auto color = directional->FirstChildElement("color");
EXPECT_TRUE(color);
EXPECT_TRUE(directional->FirstChildElement("color"));
}
else if (light_name == "lamp")
{
auto technique = light_ele->FirstChildElement("technique_common");
EXPECT_TRUE(technique);
auto point = technique->FirstChildElement("point");
EXPECT_TRUE(point);
auto color = point->FirstChildElement("color");
EXPECT_TRUE(color);
auto catt = point->FirstChildElement("constant_attenuation");
EXPECT_TRUE(catt);
auto latt = point->FirstChildElement("linear_attenuation");
EXPECT_TRUE(latt);
auto qatt = point->FirstChildElement("quadratic_attenuation");
EXPECT_TRUE(qatt);
EXPECT_TRUE(point->FirstChildElement("color"));
EXPECT_TRUE(point->FirstChildElement("constant_attenuation"));
EXPECT_TRUE(point->FirstChildElement("linear_attenuation"));
EXPECT_TRUE(point->FirstChildElement("quadratic_attenuation"));
}
else if (light_name == "torch")
{
auto technique = light_ele->FirstChildElement("technique_common");
EXPECT_TRUE(technique);
auto spot = technique->FirstChildElement("spot");
EXPECT_TRUE(spot);
auto color = spot->FirstChildElement("color");
EXPECT_TRUE(color);
auto catt = spot->FirstChildElement("constant_attenuation");
EXPECT_TRUE(catt);
auto latt = spot->FirstChildElement("linear_attenuation");
EXPECT_TRUE(latt);
auto qatt = spot->FirstChildElement("quadratic_attenuation");
EXPECT_TRUE(qatt);
auto falloff_angle = spot->FirstChildElement("falloff_angle");
EXPECT_TRUE(falloff_angle);
auto falloff_expo = spot->FirstChildElement("falloff_exponent");
EXPECT_TRUE(falloff_expo);
EXPECT_TRUE(spot->FirstChildElement("color"));
EXPECT_TRUE(spot->FirstChildElement("constant_attenuation"));
EXPECT_TRUE(spot->FirstChildElement("linear_attenuation"));
EXPECT_TRUE(spot->FirstChildElement("quadratic_attenuation"));
EXPECT_TRUE(spot->FirstChildElement("falloff_angle"));
EXPECT_TRUE(spot->FirstChildElement("falloff_exponent"));
}
else
ASSERT_TRUE(0); // Invalid light name given
Expand All @@ -447,12 +434,9 @@ TEST_F(ColladaExporter, ExportLights)
std::string node_name = node_name_cstr;
if (node_name == "sun" || node_name == "lamp" || node_name == "torch")
{
auto inst_light = node_ele->FirstChildElement("instance_light");
EXPECT_TRUE(inst_light);
auto translate = node_ele->FirstChildElement("translate");
EXPECT_TRUE(translate);
auto rotate = node_ele->FirstChildElement("rotate");
EXPECT_TRUE(rotate);
EXPECT_TRUE(node_ele->FirstChildElement("instance_light"));
EXPECT_TRUE(node_ele->FirstChildElement("translate"));
EXPECT_TRUE(node_ele->FirstChildElement("rotate"));

++node_with_light_count;
}
Expand Down

0 comments on commit 1b7602b

Please sign in to comment.