Skip to content

Commit

Permalink
Match materials in project
Browse files Browse the repository at this point in the history
This will see if there is a material at the path indicated by
"material_name" and if there is, load the material.
  • Loading branch information
Jonny K authored and Jonny K committed Jan 8, 2025
1 parent a659548 commit 7e3417a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion modules/gltf/editor/editor_scene_importer_blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
parameters_map["export_materials"] = "PLACEHOLDER";
} else if (exports == BLEND_MATERIAL_EXPORT_EXPORT) {
parameters_map["export_materials"] = "EXPORT";
} else if (exports == BLEND_MATERIAL_EXPORT_MATCH) {
parameters_map["export_materials"] = "MATCH";
}
} else {
parameters_map["export_materials"] = "PLACEHOLDER";
Expand Down Expand Up @@ -371,7 +373,7 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li
ADD_OPTION_ENUM("blender/meshes/skins", "None,4 Influences (Compatible),All Influences", BLEND_BONE_INFLUENCES_ALL);
ADD_OPTION_BOOL("blender/meshes/export_bones_deforming_mesh_only", false);
ADD_OPTION_BOOL("blender/materials/unpack_enabled", true);
ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export", BLEND_MATERIAL_EXPORT_EXPORT);
ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export,Match", BLEND_MATERIAL_EXPORT_EXPORT);
ADD_OPTION_BOOL("blender/animation/limit_playback", true);
ADD_OPTION_BOOL("blender/animation/always_sample", true);
ADD_OPTION_BOOL("blender/animation/group_tracks", true);
Expand Down
3 changes: 2 additions & 1 deletion modules/gltf/editor/editor_scene_importer_blend.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class EditorSceneFormatImporterBlend : public EditorSceneFormatImporter {
};
enum {
BLEND_MATERIAL_EXPORT_PLACEHOLDER,
BLEND_MATERIAL_EXPORT_EXPORT
BLEND_MATERIAL_EXPORT_EXPORT,
BLEND_MATERIAL_EXPORT_MATCH
};
enum {
BLEND_MODIFIERS_NONE,
Expand Down
9 changes: 8 additions & 1 deletion modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4669,7 +4669,14 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> p_state) {
Ref<StandardMaterial3D> material;
material.instantiate();
if (material_dict.has("name") && !String(material_dict["name"]).is_empty()) {
material->set_name(material_dict["name"]);
if(ResourceLoader::exists("res://" + (String)material_dict["name"] + ".tres")){
Ref<Material> cached_material = ResourceLoader::load("res://" + (String)material_dict["name"] + ".tres", "Material");
cached_material->set_name(material_dict["name"]);
p_state->materials.push_back(cached_material);
continue;
}

material->set_name(material_dict["name"]);
} else {
material->set_name(vformat("material_%s", itos(i)));
}
Expand Down

0 comments on commit 7e3417a

Please sign in to comment.