Skip to content

Commit

Permalink
Add Blender install autodetection and configuration.
Browse files Browse the repository at this point in the history
This PR is a continuation to godotengine#54886

* Changed Blender path editor setting from binary to installation.
* Add a class to query whether the format is supported.
* This class allows to create proper editors to configure support.

**NOTE**: This PR only provides autodetection on Linux. Code needs to be added for Windows and MacOS to autodetect the Blender installation.
  • Loading branch information
reduz committed Mar 31, 2022
1 parent 155a94f commit 152c572
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 23 deletions.
2 changes: 2 additions & 0 deletions doc/classes/AcceptDialog.xml
Expand Up @@ -61,6 +61,8 @@
<member name="dialog_autowrap" type="bool" setter="set_autowrap" getter="has_autowrap" default="false">
Sets autowrapping for the text in the dialog.
</member>
<member name="dialog_close_on_escape" type="bool" setter="set_close_on_escape" getter="get_close_on_escape" default="true">
</member>
<member name="dialog_hide_on_ok" type="bool" setter="set_hide_on_ok" getter="get_hide_on_ok" default="true">
If [code]true[/code], the dialog is hidden when the OK button is pressed. You can set it to [code]false[/code] if you want to do e.g. input validation when receiving the [signal confirmed] signal, and handle hiding the dialog in your own logic.
[b]Note:[/b] Some nodes derived from this class can have a different default value, and potentially their own built-in logic overriding this setting. For example [FileDialog] defaults to [code]false[/code], and has its own input validation code that is called when you press OK, which eventually hides the dialog if the input is valid. As such, this property can't be used in [FileDialog] to disable hiding the dialog when pressing OK.
Expand Down
31 changes: 31 additions & 0 deletions doc/classes/EditorFileSystemImportFormatSupportQuery.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorFileSystemImportFormatSupportQuery" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Used to query and configure import format support.
</brief_description>
<description>
This class is used to query and configure a certain import format. It is used in conjuntion with asset format import plugins.
</description>
<tutorials>
</tutorials>
<methods>
<method name="_get_file_extensions" qualifiers="virtual const">
<return type="PackedStringArray" />
<description>
Return the file extensions supported.
</description>
</method>
<method name="_is_active" qualifiers="virtual const">
<return type="bool" />
<description>
Return whether this importer is active.
</description>
</method>
<method name="_query" qualifiers="virtual const">
<return type="bool" />
<description>
Query support. Return false if import must not continue.
</description>
</method>
</methods>
</class>
4 changes: 2 additions & 2 deletions doc/classes/ProjectSettings.xml
Expand Up @@ -553,9 +553,9 @@
<member name="editor/script/templates_search_path" type="String" setter="" getter="" default="&quot;res://script_templates&quot;">
Search path for project-specific script templates. Godot will search for script templates both in the editor-specific path and in this project-specific path.
</member>
<member name="filesystem/import/blend/enabled" type="bool" setter="" getter="" default="true">
<member name="filesystem/import/blender/enabled" type="bool" setter="" getter="" default="true">
If [code]true[/code], Blender 3D scene files with the [code].blend[/code] extension will be imported by converting them to glTF 2.0.
This requires configuring a path to a Blender executable in the editor settings at [code]filesystem/import/blend/blender_path[/code]. Blender 3.0 or later is required.
This requires configuring a path to a Blender executable in the editor settings at [code]filesystem/import/blender/blender3_path[/code]. Blender 3.0 or later is required.
</member>
<member name="filesystem/import/fbx/enabled" type="bool" setter="" getter="" default="true">
If [code]true[/code], Autodesk FBX 3D scene files with the [code].fbx[/code] extension will be imported by converting them to glTF 2.0.
Expand Down
55 changes: 54 additions & 1 deletion editor/editor_file_system.cpp
Expand Up @@ -520,6 +520,45 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
return false; //nothing changed
}

bool EditorFileSystem::_scan_import_support(Vector<String> reimports) {
if (import_support_queries.size() == 0) {
return false;
}
Map<String, int> import_support_test;
Vector<bool> import_support_tested;
import_support_tested.resize(import_support_queries.size());
for (int i = 0; i < import_support_queries.size(); i++) {
import_support_tested.write[i] = false;
if (import_support_queries[i]->is_active()) {
Vector<String> extensions = import_support_queries[i]->get_file_extensions();
for (int j = 0; j < extensions.size(); j++) {
import_support_test.insert(extensions[j], i);
}
}
}

if (import_support_test.size() == 0) {
return false; //well nothing to do
}

for (int i = 0; i < reimports.size(); i++) {
Map<String, int>::Element *E = import_support_test.find(reimports[i].get_extension());
if (E) {
import_support_tested.write[E->get()] = true;
}
}

for (int i = 0; i < import_support_tested.size(); i++) {
if (import_support_tested[i]) {
if (import_support_queries.write[i]->query()) {
return true;
}
}
}

return false;
}

bool EditorFileSystem::_update_scan_actions() {
sources_changed.clear();

Expand Down Expand Up @@ -612,7 +651,7 @@ bool EditorFileSystem::_update_scan_actions() {
if (_scan_extensions()) {
//needs editor restart
//extensions also may provide filetypes to be imported, so they must run before importing
if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save&Restart"), TTR("Continue"))) {
if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save & Restart"), TTR("Continue"))) {
if (!first_scan) {
EditorNode::get_singleton()->save_all_scenes();
}
Expand All @@ -621,7 +660,12 @@ bool EditorFileSystem::_update_scan_actions() {
return true;
}
}

if (reimports.size()) {
if (_scan_import_support(reimports)) {
return true;
}

reimport_files(reimports);
} else {
//reimport files will update the uid cache file so if nothing was reimported, update it manually
Expand Down Expand Up @@ -2274,6 +2318,7 @@ static void _scan_extensions_dir(EditorFileSystemDirectory *d, Set<String> &exte
bool EditorFileSystem::_scan_extensions() {
EditorFileSystemDirectory *d = get_filesystem();
Set<String> extensions;

_scan_extensions_dir(d, extensions);

//verify against loaded extensions
Expand Down Expand Up @@ -2374,6 +2419,14 @@ void EditorFileSystem::_update_extensions() {
}
}

void EditorFileSystem::add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
ERR_FAIL_COND(import_support_queries.find(p_query) != -1);
import_support_queries.push_back(p_query);
}
void EditorFileSystem::remove_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
import_support_queries.erase(p_query);
}

EditorFileSystem::EditorFileSystem() {
ResourceLoader::import = _resource_import;
reimport_on_missing_imported_files = GLOBAL_DEF("editor/import/reimport_missing_imported_files", true);
Expand Down
36 changes: 36 additions & 0 deletions editor/editor_file_system.h
Expand Up @@ -109,6 +109,37 @@ class EditorFileSystemDirectory : public Object {
~EditorFileSystemDirectory();
};

class EditorFileSystemImportFormatSupportQuery : public RefCounted {
GDCLASS(EditorFileSystemImportFormatSupportQuery, RefCounted);

protected:
GDVIRTUAL0RC(bool, _is_active)
GDVIRTUAL0RC(Vector<String>, _get_file_extensions)
GDVIRTUAL0RC(bool, _query)
static void _bind_methods() {
GDVIRTUAL_BIND(_is_active);
GDVIRTUAL_BIND(_get_file_extensions);
GDVIRTUAL_BIND(_query);
}

public:
virtual bool is_active() const {
bool ret = false;
GDVIRTUAL_REQUIRED_CALL(_is_active, ret);
return ret;
}
virtual Vector<String> get_file_extensions() const {
Vector<String> ret;
GDVIRTUAL_REQUIRED_CALL(_get_file_extensions, ret);
return ret;
}
virtual bool query() {
bool ret = false;
GDVIRTUAL_REQUIRED_CALL(_query, ret);
return ret;
}
};

class EditorFileSystem : public Node {
GDCLASS(EditorFileSystem, Node);

Expand Down Expand Up @@ -257,6 +288,9 @@ class EditorFileSystem : public Node {
static ResourceUID::ID _resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate);

bool _scan_extensions();
bool _scan_import_support(Vector<String> reimports);

Vector<Ref<EditorFileSystemImportFormatSupportQuery>> import_support_queries;

protected:
void _notification(int p_what);
Expand Down Expand Up @@ -289,6 +323,8 @@ class EditorFileSystem : public Node {

static bool _should_skip_directory(const String &p_path);

void add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query);
void remove_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query);
EditorFileSystem();
~EditorFileSystem();
};
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.cpp
Expand Up @@ -3920,6 +3920,7 @@ void EditorNode::register_editor_types() {
GDREGISTER_CLASS(EditorScriptPicker);

GDREGISTER_ABSTRACT_CLASS(FileSystemDock);
GDREGISTER_VIRTUAL_CLASS(EditorFileSystemImportFormatSupportQuery);

GDREGISTER_CLASS(EditorScenePostImport);
GDREGISTER_CLASS(EditorCommandPalette);
Expand Down
4 changes: 2 additions & 2 deletions modules/gltf/doc_classes/EditorSceneFormatImporterBlend.xml
Expand Up @@ -5,8 +5,8 @@
</brief_description>
<description>
Imports Blender scenes in the [code].blend[/code] file format through the glTF 2.0 3D import pipeline. This importer requires Blender to be installed by the user, so that it can be used to export the scene as glTF 2.0.
The location of the Blender binary is set via the [code]filesystem/import/blend/blender_path[/code] editor setting.
This importer is only used if [member ProjectSettings.filesystem/import/blend/enabled] is enabled, otherwise [code].blend[/code] files present in the project folder are not imported.
The location of the Blender binary is set via the [code]filesystem/import/blender/blender3_path[/code] editor setting.
This importer is only used if [member ProjectSettings.filesystem/import/blender/enabled] is enabled, otherwise [code].blend[/code] files present in the project folder are not imported.
Blend import requires Blender 3.0.
Internally, the EditorSceneFormatImporterBlend uses the Blender glTF "Use Original" mode to reference external textures.
</description>
Expand Down

0 comments on commit 152c572

Please sign in to comment.