Skip to content

Commit

Permalink
fix: parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 19, 2024
1 parent d8457ef commit 67cd00f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 28 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# # Specify build type if not set
# if(NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
# endif()

# # Set debug-specific flags
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(CMAKE_CXX_FLAGS_DEBUG "-g")
# set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
# endif()

# Dependencies
include(FetchContent)

Expand Down Expand Up @@ -77,4 +88,4 @@ target_link_libraries(cg-engine PUBLIC
GLU
CustomImgui
glm
)
)
79 changes: 52 additions & 27 deletions engine/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,39 +211,64 @@ void parseModels(rapidxml::xml_node<>* modelsNode, Group& group) {
return;
}
rapidxml::xml_node<>* color = modelNode->first_node("color");
/*
<color>
<diffuse R="200" G="200" B="200" />
<ambient R="50" G="50" B="50" />
<specular R="0" G="0" B="0" />
<emissive R="0" G="0" B="0" />
<shininess value="0" />
</color>
*/
//Set the vector for diffuse, ambient, specular and emissive based on the above example
glm::vec4 diffuse_vec = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f);
glm::vec4 ambient_vec = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
glm::vec4 specular_vec = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 emission_vec = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
float shininess_val = 0.0f;

if (color) {

rapidxml::xml_node<>* diffuse = color->first_node("diffuse");
glm::vec4 diffuse_vec = glm::vec4(
std::stof(diffuse->first_attribute("R")->value()) / 255.0f,
std::stof(diffuse->first_attribute("G")->value()) / 255.0f,
std::stof(diffuse->first_attribute("B")->value()) / 255.0f, 1.0f);
if(diffuse) {
diffuse_vec = glm::vec4(
std::stof(diffuse->first_attribute("R")->value()) / 255.0f,
std::stof(diffuse->first_attribute("G")->value()) / 255.0f,
std::stof(diffuse->first_attribute("B")->value()) / 255.0f, 1.0f);
}

rapidxml::xml_node<>* ambient = color->first_node("ambient");
glm::vec4 ambient_vec = glm::vec4(
std::stof(ambient->first_attribute("R")->value()) / 255.0f,
std::stof(ambient->first_attribute("G")->value()) / 255.0f,
std::stof(ambient->first_attribute("B")->value()) / 255.0f, 1.0f);
if (ambient) {
ambient_vec = glm::vec4(
std::stof(ambient->first_attribute("R")->value()) / 255.0f,
std::stof(ambient->first_attribute("G")->value()) / 255.0f,
std::stof(ambient->first_attribute("B")->value()) / 255.0f, 1.0f);
}

rapidxml::xml_node<>* specular = color->first_node("specular");
glm::vec4 specular_vec = glm::vec4(
std::stof(specular->first_attribute("R")->value()) / 255.0f,
std::stof(specular->first_attribute("G")->value()) / 255.0f,
std::stof(specular->first_attribute("B")->value()) / 255.0f, 1.0f);
if (specular) {
specular_vec = glm::vec4(
std::stof(specular->first_attribute("R")->value()) / 255.0f,
std::stof(specular->first_attribute("G")->value()) / 255.0f,
std::stof(specular->first_attribute("B")->value()) / 255.0f, 1.0f);
}

rapidxml::xml_node<>* emissive = color->first_node("emissive");
glm::vec4 emission_vec = glm::vec4(
std::stof(emissive->first_attribute("R")->value()) / 255.0f,
std::stof(emissive->first_attribute("G")->value()) / 255.0f,
std::stof(emissive->first_attribute("B")->value()) / 255.0f, 1.0f);
if (emissive) {
emission_vec = glm::vec4(
std::stof(emissive->first_attribute("R")->value()) / 255.0f,
std::stof(emissive->first_attribute("G")->value()) / 255.0f,
std::stof(emissive->first_attribute("B")->value()) / 255.0f, 1.0f);
}

rapidxml::xml_node<>* shininess = color->first_node("shininess");
float shininess_val =
std::stof(shininess->first_attribute("value")->value());

model.material = createMaterial(diffuse_vec, ambient_vec, specular_vec,
emission_vec, shininess_val);
} else {
model.material = createMaterial(glm::vec4(0.2f, 0.2f, 0.2f, 1.0f),
glm::vec4(0.8f, 0.8f, 0.8f, 1.0f),
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), 0.0f);
}
if (shininess) {
shininess_val = std::stof(shininess->first_attribute("value")->value());
}
}

Material material = createMaterial(ambient_vec, diffuse_vec, specular_vec, emission_vec, shininess_val);
model.material = material;

group.models.push_back(model);
modelNode = modelNode->next_sibling("model");
Expand Down

0 comments on commit 67cd00f

Please sign in to comment.