You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
implement individual mesh transform for meshlibrary items
(cherry picked from commit 70108fd850)
This commit is contained in:
@@ -47,23 +47,25 @@ void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_mesh_library) {
|
||||
}
|
||||
}
|
||||
|
||||
void MeshLibraryEditor::_menu_confirm() {
|
||||
void MeshLibraryEditor::_menu_remove_confirm() {
|
||||
switch (option) {
|
||||
case MENU_OPTION_REMOVE_ITEM: {
|
||||
mesh_library->remove_item(to_erase);
|
||||
} break;
|
||||
case MENU_OPTION_UPDATE_FROM_SCENE: {
|
||||
String existing = mesh_library->get_meta("_editor_source_scene");
|
||||
ERR_FAIL_COND(existing == "");
|
||||
_import_scene_cbk(existing);
|
||||
|
||||
} break;
|
||||
default: {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) {
|
||||
void MeshLibraryEditor::_menu_update_confirm(bool p_apply_xforms) {
|
||||
cd_update->hide();
|
||||
apply_xforms = p_apply_xforms;
|
||||
String existing = mesh_library->get_meta("_editor_source_scene");
|
||||
ERR_FAIL_COND(existing == "");
|
||||
_import_scene_cbk(existing);
|
||||
}
|
||||
|
||||
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge, bool p_apply_xforms) {
|
||||
if (!p_merge) {
|
||||
p_library->clear();
|
||||
}
|
||||
@@ -108,6 +110,13 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
|
||||
}
|
||||
|
||||
p_library->set_item_mesh(id, mesh);
|
||||
|
||||
if (p_apply_xforms) {
|
||||
p_library->set_item_mesh_transform(id, mi->get_transform());
|
||||
} else {
|
||||
p_library->set_item_mesh_transform(id, Transform());
|
||||
}
|
||||
|
||||
mesh_instances[id] = mi;
|
||||
|
||||
Vector<MeshLibrary::ShapeData> collisions;
|
||||
@@ -197,15 +206,16 @@ void MeshLibraryEditor::_import_scene_cbk(const String &p_str) {
|
||||
|
||||
ERR_FAIL_COND_MSG(!scene, "Cannot create an instance from PackedScene '" + p_str + "'.");
|
||||
|
||||
_import_scene(scene, mesh_library, option == MENU_OPTION_UPDATE_FROM_SCENE);
|
||||
_import_scene(scene, mesh_library, option == MENU_OPTION_UPDATE_FROM_SCENE, apply_xforms);
|
||||
|
||||
memdelete(scene);
|
||||
mesh_library->set_meta("_editor_source_scene", p_str);
|
||||
|
||||
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), false);
|
||||
}
|
||||
|
||||
Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge) {
|
||||
_import_scene(p_base_scene, ml, p_merge);
|
||||
Error MeshLibraryEditor::update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge, bool p_apply_xforms) {
|
||||
_import_scene(p_base_scene, ml, p_merge, p_apply_xforms);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -219,23 +229,29 @@ void MeshLibraryEditor::_menu_cbk(int p_option) {
|
||||
String p = editor->get_inspector()->get_selected_path();
|
||||
if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/") >= 3) {
|
||||
to_erase = p.get_slice("/", 3).to_int();
|
||||
cd->set_text(vformat(TTR("Remove item %d?"), to_erase));
|
||||
cd->popup_centered(Size2(300, 60));
|
||||
cd_remove->set_text(vformat(TTR("Remove item %d?"), to_erase));
|
||||
cd_remove->popup_centered(Size2(300, 60));
|
||||
}
|
||||
} break;
|
||||
case MENU_OPTION_IMPORT_FROM_SCENE: {
|
||||
apply_xforms = false;
|
||||
file->popup_centered_ratio();
|
||||
} break;
|
||||
case MENU_OPTION_IMPORT_FROM_SCENE_APPLY_XFORMS: {
|
||||
apply_xforms = true;
|
||||
file->popup_centered_ratio();
|
||||
} break;
|
||||
case MENU_OPTION_UPDATE_FROM_SCENE: {
|
||||
cd->set_text(vformat(TTR("Update from existing scene?:\n%s"), String(mesh_library->get_meta("_editor_source_scene"))));
|
||||
cd->popup_centered(Size2(500, 60));
|
||||
cd_update->set_text(vformat(TTR("Update from existing scene?:\n%s"), String(mesh_library->get_meta("_editor_source_scene"))));
|
||||
cd_update->popup_centered(Size2(500, 60));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void MeshLibraryEditor::_bind_methods() {
|
||||
ClassDB::bind_method("_menu_cbk", &MeshLibraryEditor::_menu_cbk);
|
||||
ClassDB::bind_method("_menu_confirm", &MeshLibraryEditor::_menu_confirm);
|
||||
ClassDB::bind_method("_menu_remove_confirm", &MeshLibraryEditor::_menu_remove_confirm);
|
||||
ClassDB::bind_method("_menu_update_confirm", &MeshLibraryEditor::_menu_update_confirm);
|
||||
ClassDB::bind_method("_import_scene_cbk", &MeshLibraryEditor::_import_scene_cbk);
|
||||
}
|
||||
|
||||
@@ -261,16 +277,22 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) {
|
||||
menu->get_popup()->add_item(TTR("Add Item"), MENU_OPTION_ADD_ITEM);
|
||||
menu->get_popup()->add_item(TTR("Remove Selected Item"), MENU_OPTION_REMOVE_ITEM);
|
||||
menu->get_popup()->add_separator();
|
||||
menu->get_popup()->add_item(TTR("Import from Scene"), MENU_OPTION_IMPORT_FROM_SCENE);
|
||||
menu->get_popup()->add_item(TTR("Import from Scene (Ignore Transforms)"), MENU_OPTION_IMPORT_FROM_SCENE);
|
||||
menu->get_popup()->add_item(TTR("Import from Scene (Apply Transforms)"), MENU_OPTION_IMPORT_FROM_SCENE_APPLY_XFORMS);
|
||||
menu->get_popup()->add_item(TTR("Update from Scene"), MENU_OPTION_UPDATE_FROM_SCENE);
|
||||
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), true);
|
||||
menu->get_popup()->connect("id_pressed", this, "_menu_cbk");
|
||||
menu->hide();
|
||||
|
||||
editor = p_editor;
|
||||
cd = memnew(ConfirmationDialog);
|
||||
add_child(cd);
|
||||
cd->get_ok()->connect("pressed", this, "_menu_confirm");
|
||||
cd_remove = memnew(ConfirmationDialog);
|
||||
add_child(cd_remove);
|
||||
cd_remove->get_ok()->connect("pressed", this, "_menu_remove_confirm");
|
||||
cd_update = memnew(ConfirmationDialog);
|
||||
add_child(cd_update);
|
||||
cd_update->get_ok()->set_text("Apply without Transforms");
|
||||
cd_update->get_ok()->connect("pressed", this, "_menu_update_confirm", varray(false));
|
||||
cd_update->add_button("Apply with Transforms")->connect("pressed", this, "_menu_update_confirm", varray(true));
|
||||
}
|
||||
|
||||
void MeshLibraryEditorPlugin::edit(Object *p_node) {
|
||||
|
||||
Reference in New Issue
Block a user