mirror of
https://github.com/godotengine/godot.git
synced 2024-12-29 06:13:24 +00:00
Fix import order, so scenes are imported after textures.
Also fix bugs when meshes are always generated.
This commit is contained in:
parent
71e4fae3a1
commit
423ca9bcaf
@ -87,6 +87,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
|
||||
path_found = true; //first match must have priority
|
||||
} else if (assign == "type") {
|
||||
r_path_and_type.type = value;
|
||||
} else if (assign == "importer") {
|
||||
r_path_and_type.importer = value;
|
||||
} else if (assign == "valid") {
|
||||
if (r_valid) {
|
||||
*r_valid = value;
|
||||
@ -184,6 +186,29 @@ bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
|
||||
return ResourceFormatLoader::recognize_path(p_path);
|
||||
}
|
||||
|
||||
int ResourceFormatImporter::get_import_order(const String &p_path) const {
|
||||
|
||||
Ref<ResourceImporter> importer;
|
||||
|
||||
if (FileAccess::exists(p_path + ".import")) {
|
||||
|
||||
PathAndType pat;
|
||||
Error err = _get_path_and_type(p_path, pat);
|
||||
|
||||
if (err == OK) {
|
||||
importer = get_importer_by_name(pat.importer);
|
||||
}
|
||||
} else {
|
||||
|
||||
importer = get_importer_by_extension(p_path.get_extension().to_lower());
|
||||
}
|
||||
|
||||
if (importer.is_valid())
|
||||
return importer->get_import_order();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ResourceFormatImporter::handles_type(const String &p_type) const {
|
||||
|
||||
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
|
||||
@ -291,7 +316,7 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
|
||||
return ResourceLoader::get_dependencies(pat.path, p_dependencies, p_add_types);
|
||||
}
|
||||
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) {
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
|
||||
|
||||
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
|
||||
if (E->get()->get_importer_name() == p_name) {
|
||||
@ -315,7 +340,7 @@ void ResourceFormatImporter::get_importers_for_extension(const String &p_extensi
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) {
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
|
||||
|
||||
Ref<ResourceImporter> importer;
|
||||
float priority = 0;
|
||||
|
@ -38,6 +38,7 @@ class ResourceFormatImporter : public ResourceFormatLoader {
|
||||
struct PathAndType {
|
||||
String path;
|
||||
String type;
|
||||
String importer;
|
||||
};
|
||||
|
||||
Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const;
|
||||
@ -58,14 +59,15 @@ public:
|
||||
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
|
||||
|
||||
virtual bool can_be_imported(const String &p_path) const;
|
||||
virtual int get_import_order(const String &p_path) const;
|
||||
|
||||
String get_internal_resource_path(const String &p_path) const;
|
||||
void get_internal_resource_path_list(const String &p_path, List<String> *r_paths);
|
||||
|
||||
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
|
||||
void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
|
||||
Ref<ResourceImporter> get_importer_by_name(const String &p_name);
|
||||
Ref<ResourceImporter> get_importer_by_extension(const String &p_extension);
|
||||
Ref<ResourceImporter> get_importer_by_name(const String &p_name) const;
|
||||
Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const;
|
||||
void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers);
|
||||
|
||||
String get_import_base_path(const String &p_for_file) const;
|
||||
@ -82,6 +84,7 @@ public:
|
||||
virtual String get_save_extension() const = 0;
|
||||
virtual String get_resource_type() const = 0;
|
||||
virtual float get_priority() const { return 1.0; }
|
||||
virtual int get_import_order() const { return 0; }
|
||||
|
||||
struct ImportOption {
|
||||
PropertyInfo option;
|
||||
|
@ -308,6 +308,31 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l
|
||||
}
|
||||
}
|
||||
|
||||
int ResourceLoader::get_import_order(const String &p_path) {
|
||||
|
||||
String path = _path_remap(p_path);
|
||||
|
||||
String local_path;
|
||||
if (path.is_rel_path())
|
||||
local_path = "res://" + path;
|
||||
else
|
||||
local_path = ProjectSettings::get_singleton()->localize_path(path);
|
||||
|
||||
for (int i = 0; i < loader_count; i++) {
|
||||
|
||||
if (!loader[i]->recognize_path(local_path))
|
||||
continue;
|
||||
/*
|
||||
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
|
||||
continue;
|
||||
*/
|
||||
|
||||
return loader[i]->get_import_order(p_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ResourceLoader::is_import_valid(const String &p_path) {
|
||||
|
||||
String path = _path_remap(p_path);
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
|
||||
virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map) { return OK; }
|
||||
virtual bool is_import_valid(const String &p_path) const { return true; }
|
||||
virtual int get_import_order(const String &p_path) const { return 0; }
|
||||
|
||||
virtual ~ResourceFormatLoader() {}
|
||||
};
|
||||
@ -110,6 +111,7 @@ public:
|
||||
static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
|
||||
static Error rename_dependencies(const String &p_path, const Map<String, String> &p_map);
|
||||
static bool is_import_valid(const String &p_path);
|
||||
static int get_import_order(const String &p_path);
|
||||
|
||||
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
|
||||
|
||||
|
@ -1918,7 +1918,7 @@ void Collada::_parse_animation(XMLParser &parser) {
|
||||
for (int j = 0; j < key_count; j++) {
|
||||
track.keys[j].data.resize(output_len);
|
||||
for (int k = 0; k < output_len; k++)
|
||||
track.keys[j].data[k] = output[l + j * stride + k]; //super weird but should work
|
||||
track.keys[j].data[k] = output[l + j * stride + k]; //super weird but should work:
|
||||
}
|
||||
|
||||
if (sampler.has("INTERPOLATION")) {
|
||||
|
@ -1498,10 +1498,22 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
|
||||
|
||||
importing = true;
|
||||
EditorProgress pr("reimport", TTR("(Re)Importing Assets"), p_files.size());
|
||||
for (int i = 0; i < p_files.size(); i++) {
|
||||
pr.step(p_files[i].get_file(), i);
|
||||
|
||||
_reimport_file(p_files[i]);
|
||||
Vector<ImportFile> files;
|
||||
|
||||
for (int i = 0; i < p_files.size(); i++) {
|
||||
ImportFile ifile;
|
||||
ifile.path = p_files[i];
|
||||
ifile.order = ResourceFormatImporter::get_singleton()->get_import_order(p_files[i]);
|
||||
files.push_back(ifile);
|
||||
}
|
||||
|
||||
files.sort();
|
||||
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
pr.step(files[i].path.get_file(), i);
|
||||
|
||||
_reimport_file(files[i].path);
|
||||
}
|
||||
|
||||
_save_filesystem_cache();
|
||||
|
@ -206,6 +206,14 @@ class EditorFileSystem : public Node {
|
||||
|
||||
Vector<String> _get_dependencies(const String &p_path);
|
||||
|
||||
struct ImportFile {
|
||||
String path;
|
||||
int order;
|
||||
bool operator<(const ImportFile &p_if) const {
|
||||
return order < p_if.order;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
@ -381,6 +381,9 @@ Error ColladaImport::_create_material(const String &p_target) {
|
||||
String texfile = effect.get_texture_path(effect.diffuse.texture, collada);
|
||||
if (texfile != "") {
|
||||
|
||||
if (texfile.begins_with("/")) {
|
||||
texfile = texfile.replace_first("/", "res://");
|
||||
}
|
||||
Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
|
||||
if (texture.is_valid()) {
|
||||
|
||||
@ -402,6 +405,10 @@ Error ColladaImport::_create_material(const String &p_target) {
|
||||
String texfile = effect.get_texture_path(effect.specular.texture, collada);
|
||||
if (texfile != "") {
|
||||
|
||||
if (texfile.begins_with("/")) {
|
||||
texfile = texfile.replace_first("/", "res://");
|
||||
}
|
||||
|
||||
Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
|
||||
if (texture.is_valid()) {
|
||||
material->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture);
|
||||
@ -425,6 +432,10 @@ Error ColladaImport::_create_material(const String &p_target) {
|
||||
String texfile = effect.get_texture_path(effect.emission.texture, collada);
|
||||
if (texfile != "") {
|
||||
|
||||
if (texfile.begins_with("/")) {
|
||||
texfile = texfile.replace_first("/", "res://");
|
||||
}
|
||||
|
||||
Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
|
||||
if (texture.is_valid()) {
|
||||
|
||||
@ -451,6 +462,10 @@ Error ColladaImport::_create_material(const String &p_target) {
|
||||
String texfile = effect.get_texture_path(effect.bump.texture, collada);
|
||||
if (texfile != "") {
|
||||
|
||||
if (texfile.begins_with("/")) {
|
||||
texfile = texfile.replace_first("/", "res://");
|
||||
}
|
||||
|
||||
Ref<Texture> texture = ResourceLoader::load(texfile, "Texture");
|
||||
if (texture.is_valid()) {
|
||||
material->set_feature(SpatialMaterial::FEATURE_NORMAL_MAPPING, true);
|
||||
|
@ -114,7 +114,7 @@ bool ResourceImporterScene::get_option_visibility(const String &p_option, const
|
||||
}
|
||||
|
||||
int ResourceImporterScene::get_preset_count() const {
|
||||
return 6;
|
||||
return PRESET_MAX;
|
||||
}
|
||||
String ResourceImporterScene::get_preset_name(int p_idx) const {
|
||||
|
||||
@ -954,10 +954,10 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
|
||||
script_ext_hint += "*." + E->get();
|
||||
}
|
||||
|
||||
bool materials_out = p_preset == PRESET_SEPARATE_MATERIALS || p_preset == PRESET_SEPARATE_MESHES_AND_MATERIALS || p_preset == PRESET_MULTIPLE_SCENES_AND_MATERIALS || p_preset == PRESET_SEPARATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
bool meshes_out = p_preset == PRESET_SEPARATE_MESHES || p_preset == PRESET_SEPARATE_MESHES_AND_MATERIALS || PRESET_SEPARATE_MESHES_AND_ANIMATIONS || PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
bool materials_out = p_preset == PRESET_SEPARATE_MATERIALS || p_preset == PRESET_SEPARATE_MESHES_AND_MATERIALS || p_preset == PRESET_MULTIPLE_SCENES_AND_MATERIALS || p_preset == PRESET_SEPERATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPERATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
bool meshes_out = p_preset == PRESET_SEPARATE_MESHES || p_preset == PRESET_SEPARATE_MESHES_AND_MATERIALS || p_preset == PRESET_SEPARATE_MESHES_AND_ANIMATIONS || p_preset == PRESET_SEPERATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
bool scenes_out = p_preset == PRESET_MULTIPLE_SCENES || p_preset == PRESET_MULTIPLE_SCENES_AND_MATERIALS;
|
||||
bool animations_out = p_preset == PRESET_SEPARATE_ANIMATIONS || PRESET_SEPARATE_MESHES_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
bool animations_out = p_preset == PRESET_SEPERATE_ANIMATIONS || p_preset == PRESET_SEPARATE_MESHES_AND_ANIMATIONS || p_preset == PRESET_SEPERATE_MATERIALS_AND_ANIMATIONS || p_preset == PRESET_SEPERATE_MESHES_MATERIALS_AND_ANIMATIONS;
|
||||
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/custom_script", PROPERTY_HINT_FILE, script_ext_hint), ""));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "nodes/storage", PROPERTY_HINT_ENUM, "Single Scene,Instanced Sub-Scenes"), scenes_out ? 1 : 0));
|
||||
@ -966,7 +966,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "materials/keep_on_reimport"), materials_out ? true : false));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/compress"), true));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/storage", PROPERTY_HINT_ENUM, "Built-In,Files"), meshes_out ? true : false));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/storage", PROPERTY_HINT_ENUM, "Built-In,Files"), meshes_out ? 1 : 0));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "external_files/store_in_subdir"), false));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
|
||||
r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15));
|
||||
|
@ -96,6 +96,7 @@ class ResourceImporterScene : public ResourceImporter {
|
||||
|
||||
PRESET_MULTIPLE_SCENES,
|
||||
PRESET_MULTIPLE_SCENES_AND_MATERIALS,
|
||||
PRESET_MAX
|
||||
};
|
||||
|
||||
void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
|
||||
@ -118,6 +119,7 @@ public:
|
||||
|
||||
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
|
||||
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||
virtual int get_import_order() const { return 100; } //after everything
|
||||
|
||||
void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_animations, bool p_make_materials, bool p_keep_materials, bool p_make_meshes, Map<Ref<Animation>, Ref<Animation> > &p_animations, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user