void EditorSceneImportDialog::popup_import(const String &p_from) { popup_centered(Size2(700,500)); if (p_from!="") { Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from); if (rimd.is_null()) return; int flags = rimd->get_option("flags"); for(int i=0;i<scene_flags.size();i++) { int md = scene_flags[i]->get_metadata(0); scene_flags[i]->set_checked(0,flags&md); } texture_options->set_flags(rimd->get_option("texture_flags")); texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("texture_format")))); texture_options->set_quality(rimd->get_option("texture_quality")); animation_options->set_flags(rimd->get_option("animation_flags")); script_path->set_text(rimd->get_option("post_import_script")); save_path->set_text(p_from.get_base_dir()); import_path->set_text(EditorImportPlugin::expand_source_path(rimd->get_source_path(0))); } }
void EditorSceneImportDialog::_choose_file(const String& p_path) { #if 0 StringName sn = EditorImportDB::get_singleton()->find_source_path(p_path); if (sn!=StringName()) { EditorImportDB::ImportScene isc; if (EditorImportDB::get_singleton()->get_scene(sn,isc)==OK) { save_path->set_text(String(sn).get_base_dir()); texture_options->set_flags( isc.image_flags ); texture_options->set_quality( isc.image_quality ); texture_options->set_format( isc.image_format ); animation_options->set_flags( isc.anim_flags ); script_path->set_text( isc.import_script ); uint32_t f = isc.flags; for(int i=0;i<scene_flags.size();i++) { scene_flags[i]->set_checked(0,f&(1<<i)); } } } else { #endif save_path->set_text(""); //save_path->set_text(p_path.get_file().basename()+".scn"); #if 0 } #endif import_path->set_text(p_path); }
void EditorTextureImportDialog::popup_import(const String& p_from) { popup_centered(Size2(400,400)); if (p_from!="") { Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from); ERR_FAIL_COND(!rimd.is_valid()); save_path->set_text(p_from.get_base_dir()); texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("format")))); texture_options->set_flags(rimd->get_option("flags")); texture_options->set_quality(rimd->get_option("quality")); String src = ""; for(int i=0;i<rimd->get_source_count();i++) { if (i>0) src+=","; src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i)); } import_path->set_text(src); } }
void EditorSceneImportDialog::_import(bool p_and_open) { wip_open=p_and_open; //' ImportMonitorBlock imb; if (import_path->get_text()=="") { error_dialog->set_text("Source path is empty."); error_dialog->popup_centered(Size2(200,100)); return; } if (save_path->get_text()=="") { error_dialog->set_text("Target path is empty."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path; if (texture_action->get_selected()==0) dst_path=save_path->get_text();//.get_base_dir(); else dst_path=Globals::get_singleton()->get("import/shared_textures"); uint32_t flags=0; for(int i=0;i<scene_flags.size();i++) { if (scene_flags[i]->is_checked(0)) { int md = scene_flags[i]->get_metadata(0); flags|=md; } } Ref<EditorScenePostImport> pi; if (script_path->get_text()!="") { Ref<Script> scr = ResourceLoader::load(script_path->get_text()); if (!scr.is_valid()) { error_dialog->set_text("Couldn't load Post-Import Script."); error_dialog->popup_centered(Size2(200,100)); return; } pi = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) ); pi->set_script(scr.get_ref_ptr()); if (!pi->get_script_instance()) { error_dialog->set_text("Invalid/Broken Script for Post-Import."); error_dialog->popup_centered(Size2(200,100)); return; } } String save_file = save_path->get_text().plus_file(import_path->get_text().get_file().basename()+".scn"); print_line("Saving to: "+save_file); Node *scene=NULL; Ref<ResourceImportMetadata> rim = memnew( ResourceImportMetadata ); rim->add_source(EditorImportPlugin::validate_source_path(import_path->get_text())); rim->set_option("flags",flags); rim->set_option("texture_flags",texture_options->get_flags()); rim->set_option("texture_format",texture_options->get_format()); rim->set_option("texture_quality",texture_options->get_quality()); rim->set_option("animation_flags",animation_options->get_flags()); rim->set_option("post_import_script",script_path->get_text()!=String()?EditorImportPlugin::validate_source_path(script_path->get_text()):String()); rim->set_option("reimport",true); List<String> missing; Error err = plugin->import1(rim,&scene,&missing); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } if (missing.size()) { missing_files->clear(); for(List<String>::Element *E=missing.front();E;E=E->next()) { missing_files->add_text(E->get()); missing_files->add_newline(); } wip_import=scene; wip_rimd=rim; wip_save_file=save_file; confirm_import->popup_centered_ratio(); return; } else { err = plugin->import2(scene,save_file,rim); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } if (wip_open) EditorNode::get_singleton()->load_scene(save_file); } hide(); /* editor->clear_scene(); Error err = EditorImport::import_scene(import_path->get_text(),save_file,dst_path,flags,texture_options->get_format(),compression,texture_options->get_flags(),texture_options->get_quality(),animation_options->get_flags(), &scene,pi); if (err) { error_dialog->set_text("Error importing scene."); error_dialog->popup_centered(Size2(200,100)); return; } editor->save_import_export(); if (scene) editor->set_edited_scene(scene); hide(); */ };
void EditorTextureImportDialog::_import() { // ImportMonitorBlock imb; Vector<String> files=import_path->get_text().split(","); if (!files.size()) { error_dialog->set_text("Please specify some files!"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path=save_path->get_text(); if (save_path->get_text().strip_edges()=="") { error_dialog->set_text("Target path is empty."); error_dialog->popup_centered_minsize(); return; } if (!save_path->get_text().begins_with("res://")) { error_dialog->set_text("Target path must be full resource path."); error_dialog->popup_centered_minsize(); return; } if (!atlas && !large && !DirAccess::exists(save_path->get_text())) { error_dialog->set_text("Target path must exist."); error_dialog->popup_centered_minsize(); return; } if (atlas) { //atlas if (files.size()==0) { error_dialog->set_text("At least one file needed for Atlas."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",true); imd->set_option("atlas_size",int(size->get_val())); imd->set_option("large",false); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else if (large) { //atlas if (files.size()!=1) { error_dialog->set_text("Only one file is required for large texture"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); imd->set_option("large",true); imd->set_option("large_cell_size",int(size->get_val())); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else { for(int i=0;i<files.size();i++) { String dst_file = dst_path.plus_file(files[i].get_file()); dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); imd->add_source(EditorImportPlugin::validate_source_path(files[i])); imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); imd->set_option("large",false); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } } hide(); }
void EditorTextureImportDialog::_import() { // ImportMonitorBlock imb; Vector<String> files=import_path->get_text().split(","); if (!files.size()) { error_dialog->set_text("Please specify some files!"); error_dialog->popup_centered(Size2(200,100)); return; } String dst_path=save_path->get_text(); if (dst_path.empty()) { error_dialog->set_text("Please specify a valid target import path!"); error_dialog->popup_centered(Size2(200,100)); return; } if (atlas) { //atlas if (files.size()==0) { error_dialog->set_text("At least one file needed for Atlas."); error_dialog->popup_centered(Size2(200,100)); return; } String dst_file = dst_path; //dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); for(int i=0;i<files.size();i++) { imd->add_source(EditorImportPlugin::validate_source_path(files[i])); } imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",true); imd->set_option("crop",crop_source->is_pressed()); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } else { for(int i=0;i<files.size();i++) { String dst_file = dst_path.plus_file(files[i].get_file()); dst_file=dst_file.basename()+".tex"; Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); //imd->set_editor(); imd->add_source(EditorImportPlugin::validate_source_path(files[i])); imd->set_option("format",texture_options->get_format()); imd->set_option("flags",texture_options->get_flags()); imd->set_option("quality",texture_options->get_quality()); imd->set_option("atlas",false); Error err = plugin->import(dst_file,imd); if (err) { error_dialog->set_text("Error importing: "+dst_file.get_file()); error_dialog->popup_centered(Size2(200,100)); return; } } } hide(); }