Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom models: ignore invalid envmap material #3785

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions common/util/gltf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,19 +684,12 @@ bool material_has_envmap(const tinygltf::Material& mat) {
return mat.extensions.contains("KHR_materials_specular");
}

bool envmap_is_valid(const tinygltf::Material& mat, bool die) {
bool envmap_is_valid(const tinygltf::Material& mat) {
if (material_has_envmap(mat) && mat.pbrMetallicRoughness.metallicRoughnessTexture.index < 0) {
std::string error = fmt::format(
"Material \"{}\" has specular property set, but is missing a metallic roughness texture! "
"Check "
"that the Specular IOR level for the material is at the default of 0.5 if this is "
"unintended.",
mat.name);
if (die) {
lg::die(error);
} else {
lg::error(error);
}
lg::warn(fmt::format(
"Material \"{}\" has specular property set, but is missing a metallic roughness texture, "
"ignoring envmap!",
mat.name));
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion common/util/gltf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct EnvmapSettings {

EnvmapSettings envmap_settings_from_gltf(const tinygltf::Material& mat);
bool material_has_envmap(const tinygltf::Material& mat);
bool envmap_is_valid(const tinygltf::Material& mat, bool die);
bool envmap_is_valid(const tinygltf::Material& mat);

/*!
* Find the index of the skin for this model. Returns nullopt if there is no skin, the index of the
Expand Down
8 changes: 3 additions & 5 deletions decompiler/level_extractor/merc_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void extract(const std::string& name,
std::map<int, tfrag3::MercDraw> draw_by_material;
int mesh_count = 0;
int prim_count = 0;
bool has_envmaps = false;
int joints = 3;
auto skin_idx = find_single_skin(model, all_nodes);
if (skin_idx) {
Expand Down Expand Up @@ -80,6 +79,7 @@ void extract(const std::string& name,

tfrag3::MercEffect e;
tfrag3::MercEffect envmap_eff;
envmap_eff.has_envmap = false;
out.new_model.name = name;
out.new_model.max_bones = joints;
out.new_model.max_draws = 0;
Expand Down Expand Up @@ -161,11 +161,9 @@ void extract(const std::string& name,

for (const auto& [mat_idx, d_] : draw_by_material) {
const auto& mat = model.materials[mat_idx];
if (!material_has_envmap(mat)) {
if (!material_has_envmap(mat) || !envmap_is_valid(mat)) {
process_normal_draw(e, mat_idx, d_);
} else {
envmap_is_valid(mat, true);
has_envmaps = true;
envmap_eff.has_envmap = true;
process_envmap_draw(envmap_eff, mat_idx, d_);
}
Expand All @@ -175,7 +173,7 @@ void extract(const std::string& name,
if (!e.all_draws.empty()) {
out.new_model.effects.push_back(e);
}
if (has_envmaps) {
if (envmap_eff.has_envmap) {
out.new_model.effects.push_back(envmap_eff);
}

Expand Down
8 changes: 3 additions & 5 deletions goalc/build_actor/common/MercExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void extract(const std::string& name,
std::map<int, tfrag3::MercDraw> draw_by_material;
int mesh_count = 0;
int prim_count = 0;
bool has_envmaps = false;
int joints = 3;
auto skin_idx = find_single_skin(model, all_nodes);
if (skin_idx) {
Expand Down Expand Up @@ -92,6 +91,7 @@ void extract(const std::string& name,

tfrag3::MercEffect e;
tfrag3::MercEffect envmap_eff;
envmap_eff.has_envmap = false;
out.new_model.name = name;
out.new_model.max_bones = joints;
out.new_model.max_draws = 0;
Expand Down Expand Up @@ -173,11 +173,9 @@ void extract(const std::string& name,

for (const auto& [mat_idx, d_] : draw_by_material) {
const auto& mat = model.materials[mat_idx];
if (!gltf_util::material_has_envmap(mat)) {
if (!gltf_util::material_has_envmap(mat) || !gltf_util::envmap_is_valid(mat)) {
process_normal_draw(e, mat_idx, d_);
} else {
gltf_util::envmap_is_valid(mat, false);
has_envmaps = true;
envmap_eff.has_envmap = true;
process_envmap_draw(envmap_eff, mat_idx, d_);
}
Expand All @@ -187,7 +185,7 @@ void extract(const std::string& name,
if (!e.all_draws.empty()) {
out.new_model.effects.push_back(e);
}
if (has_envmaps) {
if (envmap_eff.has_envmap) {
out.new_model.effects.push_back(envmap_eff);
}

Expand Down
Loading