Skip to content

Commit 72c5e2d

Browse files
lyumareduz
andcommitted
Improved 3D Asset Import Dialog material editing
Implements [7238](godotengine/godot-proposals#7238) (for the most part). * Ability to select nodes, meshes or materials by clicking. * Moved mesh/material previews to the inspector area. * Ability to override materials and edit them directly in the inspector. * By default, shows overridden materials in the imported scene, with a button to disable them and show original materials. * Keeps compatibility with the old override format. Co-authored-by: Juan Linietsky <[email protected]>
1 parent fc523ec commit 72c5e2d

14 files changed

+458
-117
lines changed

core/math/triangle_mesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const {
107107
void TriangleMesh::create(const Vector<Vector3> &p_faces, const Vector<int32_t> &p_surface_indices) {
108108
valid = false;
109109

110-
ERR_FAIL_COND(p_surface_indices.size() && p_surface_indices.size() != p_faces.size());
111-
112110
int fc = p_faces.size();
113111
ERR_FAIL_COND(!fc || ((fc % 3) != 0));
114112
fc /= 3;
115113
triangles.resize(fc);
116114

115+
ERR_FAIL_COND(p_surface_indices.size() && p_surface_indices.size() != triangles.size());
116+
117117
bvh.resize(fc * 3); //will never be larger than this (todo make better)
118118
BVH *bw = bvh.ptrw();
119119

editor/editor_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ void EditorNode::save_resource(const Ref<Resource> &p_resource) {
15751575
if (path.is_resource_file() && !FileAccess::exists(path + ".import")) {
15761576
save_resource_in_path(p_resource, p_resource->get_path());
15771577
} else {
1578-
save_resource_as(p_resource);
1578+
save_resource_as(p_resource, "");
15791579
}
15801580
}
15811581

editor/icons/MaterialSelect.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

editor/icons/MeshSelect.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/icons/NodeSelect.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/import/3d/resource_importer_scene.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
15381538
post_importer_plugins.write[j]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MATERIAL, p_root, p_node, mat, matdata);
15391539
}
15401540

1541+
// Old style material, keep for compatibility.
15411542
if (matdata.has("use_external/enabled") && bool(matdata["use_external/enabled"]) && matdata.has("use_external/path")) {
15421543
String path = matdata["use_external/path"];
15431544
Ref<Material> external_mat = ResourceLoader::load(path);
@@ -1563,6 +1564,13 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
15631564
matdata["use_external/fallback_path"] = external_mat->get_path();
15641565
}
15651566
}
1567+
// New style custom material
1568+
if (matdata.has("custom")) {
1569+
Ref<Material> external_mat = matdata["custom"];
1570+
if (external_mat.is_valid()) {
1571+
m->set_surface_material(i, external_mat);
1572+
}
1573+
}
15661574
}
15671575
}
15681576
}
@@ -2082,9 +2090,11 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
20822090
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,1,degrees"), 20.0f));
20832091
} break;
20842092
case INTERNAL_IMPORT_CATEGORY_MATERIAL: {
2085-
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
2086-
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/path", PROPERTY_HINT_FILE, "*.material,*.res,*.tres"), ""));
2087-
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/fallback_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), ""));
2093+
// Compatibility (hidden) settings.
2094+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), false));
2095+
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/path", PROPERTY_HINT_FILE, "*.material,*.res,*.tres", PROPERTY_USAGE_NONE), ""));
2096+
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/fallback_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), ""));
2097+
r_options->push_back(ImportOption(PropertyInfo(Variant::OBJECT, "custom", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), Ref<Material>()));
20882098
} break;
20892099
case INTERNAL_IMPORT_CATEGORY_ANIMATION: {
20902100
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "settings/loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Pingpong"), 0));

0 commit comments

Comments
 (0)