Skip to content

Commit dd6f181

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 9282ed3 commit dd6f181

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
@@ -1617,6 +1617,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
16171617
}
16181618
if (!mat_id.is_empty() && p_material_data.has(mat_id)) {
16191619
Dictionary matdata = p_material_data[mat_id];
1620+
// Old style material, keep for compatibility.
16201621
if (matdata.has("use_external/enabled") && bool(matdata["use_external/enabled"]) && matdata.has("use_external/path")) {
16211622
String path = matdata["use_external/path"];
16221623
Ref<Material> external_mat = ResourceLoader::load(path);
@@ -1642,6 +1643,13 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
16421643
matdata["use_external/fallback_path"] = external_mat->get_path();
16431644
}
16441645
}
1646+
// New style custom material
1647+
if (matdata.has("custom")) {
1648+
Ref<Material> external_mat = matdata["custom"];
1649+
if (external_mat.is_valid()) {
1650+
m->set_surface_material(i, external_mat);
1651+
}
1652+
}
16451653
}
16461654
}
16471655
}
@@ -2168,9 +2176,11 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
21682176
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,1,degrees"), 20.0f));
21692177
} break;
21702178
case INTERNAL_IMPORT_CATEGORY_MATERIAL: {
2171-
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
2172-
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/path", PROPERTY_HINT_FILE, "*.material,*.res,*.tres"), ""));
2173-
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/fallback_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), ""));
2179+
// Compatibility (hidden) settings.
2180+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), false));
2181+
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/path", PROPERTY_HINT_FILE, "*.material,*.res,*.tres", PROPERTY_USAGE_NONE), ""));
2182+
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "use_external/fallback_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), ""));
2183+
r_options->push_back(ImportOption(PropertyInfo(Variant::OBJECT, "custom", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), Ref<Material>()));
21742184
} break;
21752185
case INTERNAL_IMPORT_CATEGORY_ANIMATION: {
21762186
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "settings/loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Pingpong"), 0));

0 commit comments

Comments
 (0)