Skip to content

Commit

Permalink
[WIP] Infer material from texture name
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed Nov 23, 2024
1 parent 0c45ace commit 63ba5bd
Showing 1 changed file with 175 additions and 0 deletions.
175 changes: 175 additions & 0 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,181 @@ Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, Transparency p_
return materials_for_2d[key];
}

// Values must be written in PascalCase.
// The file name is stripped from its extension, then each component (each word separated by `-`, `_` or `.`)
// is checked individually for a match. Each component will check for the original casing,
// convert to lowercase, then convert the first character to lowercase. This covers the PascalCase,
// camelCase and snake_case file naming conventions.
#
// The order of the keys is important, since we want some material maps to be checked before others (e.g. albedo takes
// priority over metallic, so that `metal_grate_albedo.png` is correctly detected as an albedo map).
#
// Websites used to determine common file names:
#
// - https://polyhaven.com/
// - http://cgbookcase.com/
// - https://ambientcg.com/
Dictionary types = {
// We check for the presence of an ORM texture first when creating the material.
// If one is found, we'll create an ORMMaterial3D. Otherwise, we'll create a StandardMaterial3D.
"orm": PackedStringArray({ "ORM", "ARM" }),

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected '}' before ':' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

could not convert '{"orm"}' from '<brace-enclosed initializer list>' to 'Dictionary'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected '}' before ':' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

could not convert '{"orm"}' from '<brace-enclosed initializer list>' to 'Dictionary'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

expected '}'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: ':'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ';' before '{'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ')' before ';'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'{': missing function header (old-style formal list?)

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: ')'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: ','

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected '}' before ':' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

could not convert '{"orm"}' from '<brace-enclosed initializer list>' to 'Dictionary'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

expected '}'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

could not convert '{"orm"}' from '<brace-enclosed initializer list>' to 'Dictionary'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected ',' or ';' before ':' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected '}' before ':' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

could not convert '{"orm"}' from '<brace-enclosed initializer list>' to 'Dictionary'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: ':'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ';' before '{'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ')' before ';'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'{': missing function header (old-style formal list?)

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: ')'

Check failure on line 2856 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: ','

// Common PBR material texture types, standardized across engines.
"albedo": PackedStringArray({ "Albedo", "BaseColor", "BaseColour", "Base", "Color", "Colour", "Diffuse", "Diff", "C", "D" }),

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: '{'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ';' before '{'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

syntax error: missing ')' before ';'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'{': missing function header (old-style formal list?)

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: '{'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ';' before '{'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

syntax error: missing ')' before ';'

Check failure on line 2859 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'{': missing function header (old-style formal list?)
"normal": PackedStringArray({ "Normal", "NormalGL", "NormalDX", "Local", "Norm", "Nor", "Nor_GL", "Nor_DX", "N" }),

Check failure on line 2860 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2860 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2860 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2860 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2860 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token
"roughness": PackedStringArray({ "Roughness", "Rough", "R" }), // Not used in ORMMaterial3D creation.

Check failure on line 2861 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2861 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2861 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2861 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2861 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token
"metallic": PackedStringArray({ "Metallic", "Metalness", "Metal", "M" }), // Not used in ORMMaterial3D creation.

Check failure on line 2862 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2862 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2862 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2862 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2862 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token
"ao": PackedStringArray({ "AO", "AmbientOcclusion", "Ambient", "Occlusion", "A", "O" }), // Not used in ORMMaterial3D creation.

Check failure on line 2863 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2863 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2863 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2863 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2863 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token
"emission": PackedStringArray({ "Emission", "Emissive", "Glow", "Luma", "E", "G" }),

Check failure on line 2864 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2864 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2864 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2864 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

expected unqualified-id before ')' token

Check failure on line 2864 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token
"height": PackedStringArray({ "Height", "Displacement", "Disp", "H", "Z" }),

Check failure on line 2865 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

expected unqualified-id before ')' token

Check failure on line 2865 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

expected unqualified-id before ')' token

Check failure on line 2865 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

expected unqualified-id before ')' token

Check failure on line 2865 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

expected unqualified-id before ')' token

// Less common and not as standardized across engines.
"rim": PackedStringArray({ "Rim" }),
"clearcoat": PackedStringArray({ "Clearcoat" }),
"anisotropy": PackedStringArray({ "Anisotropy", "Aniso", "Flowmap", "Flow" }),
"subsurf_scatter": PackedStringArray({ "Subsurface", "Subsurf", "Scattering", "Scatter", "SSS" }),
"subsurf_scatter_transmittance": PackedStringArray({ "Transmittance", "Transmission", "Transmissive", "Scatter", "SSS" }),
"backlight": PackedStringArray({ "BackLighting", "Backlight" }),
"refraction": PackedStringArray({ "Refraction", "Refract" }),
"detail_albedo": PackedStringArray({ "Detail" }),
};

Ref<Material> BaseMaterial3D::get_material_from_texture(const String &p_texture_path) const {

Check failure on line 2878 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

out-of-line definition of 'get_material_from_texture' does not match any declaration in 'BaseMaterial3D'

Check failure on line 2878 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

out-of-line definition of 'get_material_from_texture' does not match any declaration in 'BaseMaterial3D'
String path_type;
String found_suffix;
// Read from the last component to the first, so that names like `blue_metal_diff`
// are seen as an albedo (diffuse) texture instead of a metallic map.
PackedStringArray components = p_texture_path.get_basename().get_file().replace("-", "_").replace(" ", "_").replace(".", "_").split("_", false);
components.reverse();

for (const String &component : components) {
if (found_suffix.is_empty()) {
for (const String &type : types) {

Check failure on line 2888 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

invalid range expression of type 'Dictionary'; no viable 'begin' function available

Check failure on line 2888 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

invalid range expression of type 'Dictionary'; no viable 'begin' function available
for (const String &suffix : types[type]) {

Check failure on line 2889 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

invalid range expression of type 'Variant'; no viable 'begin' function available

Check failure on line 2889 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

invalid range expression of type 'Variant'; no viable 'begin' function available
// Check PascalCase, snake_case and camelCase.
for (const String &suffix_casing : PackedStringArray({ suffix, suffix.to_lower(), suffix[0].to_lower() + suffix.substr(1) }) {

Check failure on line 2891 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

member reference base type 'const char32_t' is not a structure or union

Check failure on line 2891 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

expected ')'

Check failure on line 2891 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

member reference base type 'const char32_t' is not a structure or union

Check failure on line 2891 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

expected ')'
if (component == suffix_casing) {
path_type = type;
found_suffix = suffix_casing;
break;
}
}
}

Check failure on line 2898 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

expected statement

Check failure on line 2898 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

expected statement
} else {

Check failure on line 2899 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

expected expression

Check failure on line 2899 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

expected expression
break;
}
}

if (found_suffix) {

Check failure on line 2904 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

value of type 'String' is not contextually convertible to 'bool'

Check failure on line 2904 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

value of type 'String' is not contextually convertible to 'bool'
print_line_rich(vformat("\n[b]%s[/b] is a [color=green][b]%s[/b][/color] texture with suffix [b]%s[/b].", path, path_type, found_suffix));

Check failure on line 2905 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

use of undeclared identifier 'path'; did you mean 'catch'?

Check failure on line 2905 in scene/resources/material.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

use of undeclared identifier 'path'; did you mean 'catch'?
} else {
print_line(vformat("Could not detect material: %s" % path));
return nullptr;
}

Dictionary found_textures;
for (const String &type : types) {
if (type == path_type) {
// We already know this texture's type, since it was the texture originally specified.
found_textures[type] = path;
continue;
}

for (const String &suffix : types[type]) {
for (const String &suffix_casing : PackedStringArray({ suffix, suffix.to_lower(), suffix[0].to_lower() + suffix.substr(1) }))
if (FileAccess::file_exists(p_texture_path.replace(found_suffix, suffix_casing))) {
found_textures[type] = p_texture_path.replace(found_suffix, suffix_casing);
}
}
}

print_line(found_textures);

Ref<BaseMaterial3D> material;

if (found_textures.has("orm")) {
print_line("Creating ORMMaterial3D");
material = memnew(ORMMaterial3D);
material.instantiate();
material->set_texture(BaseMaterial3D::TEXTURE_ORM, ResourceLoader::load(found_textures["orm"]));
material->set_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION, true);
} else {
print_line("Creating StandardMaterial3D");
material = memnew(StandardMaterial3D);
material.instantiate();
if (found_textures.has("roughness")) {
material->set_roughness(1.0);
material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, ResourceLoader::load(found_textures["roughness"]));
} if (found_textures.has("metallic")) {
material->set_metallic(1.0);
material->set_texture(BaseMaterial3D::TEXTURE_METALLIC, ResourceLoader::load(found_textures["metallic"]));
} if (found_textures.has("ao")) {
material->set_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION, true);
material->set_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION, ResourceLoader::load(found_textures["ao"]));
}

if (found_textures.has("albedo")) {
material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, ResourceLoader::load(found_textures["albedo"]));
}

if (found_textures.has("normal")) {
material->set_feature(BaseMaterial3D::FEATURE_NORMAL_MAPPING, true);
material->set_texture(BaseMaterial3D::TEXTURE_NORMAL, ResourceLoader::load(found_textures["normal"]));
}

if (found_textures.has("emission")) {
material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true);
material->set_texture(BaseMaterial3D::TEXTURE_EMISSION, ResourceLoader::load(found_textures["emission"]));
}

if (found_textures.has("height")) {
material->set_feature(BaseMaterial3D::FEATURE_HEIGHT_MAPPING, true);
material->set_texture(BaseMaterial3D::TEXTURE_HEIGHTMAP, ResourceLoader::load(found_textures["height"]));
}

if (found_textures.has("rim")) {
material->set_feature(BaseMaterial3D::FEATURE_RIM, true);
material->set_texture(BaseMaterial3D::TEXTURE_RIM, ResourceLoader::load(found_textures["rim"]));
}

if (found_textures.has("clearcoat")) {
material->set_feature(BaseMaterial3D::FEATURE_CLEARCOAT, true);
material->set_texture(BaseMaterial3D::TEXTURE_CLEARCOAT, ResourceLoader::load(found_textures["clearcoat"]));
}

if (found_textures.has("anisotropy")) {
material->set_feature(BaseMaterial3D::FEATURE_ANISOTROPY, true);
material->set_texture(BaseMaterial3D::TEXTURE_FLOWMAP, ResourceLoader::load(found_textures["anisotropy"]));
}

if (found_textures.has("subsurf_scatter")) {
material->set_feature(BaseMaterial3D::FEATURE_SUBSURFACE_SCATTERING, true);
material->set_texture(BaseMaterial3D::TEXTURE_SUBSURFACE_SCATTERING, ResourceLoader::load(found_textures["subsurf_scatter"]));
}

if (found_textures.has("subsurf_scatter_transmittance")) {
material->set_feature(BaseMaterial3D::FEATURE_SUBSURFACE_TRANSMITTANCE, true);
material->set_texture(BaseMaterial3D::TEXTURE_SUBSURFACE_TRANSMITTANCE, ResourceLoader::load(found_textures["subsurf_scatter_transmittance"]));
}

if (found_textures.has("backlight")) {
material->set_feature(BaseMaterial3D::FEATURE_BACKLIGHT, true);
material->set_texture(BaseMaterial3D::TEXTURE_BACKLIGHT, ResourceLoader::load(found_textures["backlight"]));
}

if (found_textures.has("refraction")) {
material->set_feature(BaseMaterial3D::FEATURE_REFRACTION, true);
material->set_texture(BaseMaterial3D::TEXTURE_REFRACTION, ResourceLoader::load(found_textures["refraction"]));
}

if (found_textures.has("detail_albedo")) {
material->set_feature(BaseMaterial3D::FEATURE_DETAIL, true);
material->set_texture(BaseMaterial3D::TEXTURE_DETAIL_ALBEDO, ResourceLoader::load(found_textures["detail_albedo"]));
}

return material;
}

void BaseMaterial3D::set_on_top_of_alpha() {
set_transparency(TRANSPARENCY_DISABLED);
set_render_priority(RENDER_PRIORITY_MAX);
Expand Down

0 comments on commit 63ba5bd

Please sign in to comment.