EditorScenePostImport: added get_source_folder() and get_source_file() methods
This commit is contained in:
parent
10cab25f72
commit
48e3ff0c8a
3 changed files with 62 additions and 2 deletions
|
@ -1,20 +1,56 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<class name="EditorScenePostImport" inherits="Reference" category="Core" version="3.1">
|
<class name="EditorScenePostImport" inherits="Reference" category="Core" version="3.1">
|
||||||
<brief_description>
|
<brief_description>
|
||||||
|
Post process scenes after import
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
|
The imported scene can be automatically modified right after import by specifying a 'custom script' that inherits from this class. The [method post_import]-method receives the imported scene's root-node and returns the modified version of the scene
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
|
http://docs.godotengine.org/en/latest/learning/workflow/assets/importing_scenes.html?highlight=post%20import
|
||||||
</tutorials>
|
</tutorials>
|
||||||
<demos>
|
<demos>
|
||||||
|
[codeblock]
|
||||||
|
tool # needed so it runs in editor
|
||||||
|
extends EditorScenePostImport
|
||||||
|
|
||||||
|
# This sample changes all node names
|
||||||
|
|
||||||
|
# get called right after the scene is imported and gets the root-node
|
||||||
|
func post_import(scene):
|
||||||
|
# change all node names to "modified_[oldnodename]"
|
||||||
|
iterate(scene)
|
||||||
|
return scene # remember to return the imported scene
|
||||||
|
|
||||||
|
func iterate(node):
|
||||||
|
if node!=null:
|
||||||
|
node.name = "modified_"+node.name
|
||||||
|
for child in node.get_children():
|
||||||
|
iterate(child)
|
||||||
|
[/codeblock]
|
||||||
</demos>
|
</demos>
|
||||||
<methods>
|
<methods>
|
||||||
|
<method name="get_source_file" qualifiers="const">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the source-file-path which got imported (e.g. [code]res://scene.dae[/code] )
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_source_folder" qualifiers="const">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the resource-folder the imported scene-file is located in
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="post_import" qualifiers="virtual">
|
<method name="post_import" qualifiers="virtual">
|
||||||
<return type="void">
|
<return type="Object">
|
||||||
</return>
|
</return>
|
||||||
<argument index="0" name="scene" type="Object">
|
<argument index="0" name="scene" type="Object">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Gets called after the scene got imported and has to return the modified version of the scene
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
|
|
|
@ -130,7 +130,9 @@ void EditorSceneImporter::_bind_methods() {
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
void EditorScenePostImport::_bind_methods() {
|
void EditorScenePostImport::_bind_methods() {
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("post_import", PropertyInfo(Variant::OBJECT, "scene")));
|
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "post_import", PropertyInfo(Variant::OBJECT, "scene")));
|
||||||
|
ClassDB::bind_method(D_METHOD("get_source_folder"), &EditorScenePostImport::get_source_folder);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *EditorScenePostImport::post_import(Node *p_scene) {
|
Node *EditorScenePostImport::post_import(Node *p_scene) {
|
||||||
|
@ -141,6 +143,21 @@ Node *EditorScenePostImport::post_import(Node *p_scene) {
|
||||||
return p_scene;
|
return p_scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String EditorScenePostImport::get_source_folder() const {
|
||||||
|
|
||||||
|
return source_folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
String EditorScenePostImport::get_source_file() const {
|
||||||
|
|
||||||
|
return source_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorScenePostImport::init(const String &p_source_folder, const String &p_source_file) {
|
||||||
|
source_folder = p_source_folder;
|
||||||
|
source_file = p_source_file;
|
||||||
|
}
|
||||||
|
|
||||||
EditorScenePostImport::EditorScenePostImport() {
|
EditorScenePostImport::EditorScenePostImport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1346,6 +1363,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post_import_script.is_valid()) {
|
if (post_import_script.is_valid()) {
|
||||||
|
post_import_script->init(base_path, p_source_file);
|
||||||
scene = post_import_script->post_import(scene);
|
scene = post_import_script->post_import(scene);
|
||||||
if (!scene) {
|
if (!scene) {
|
||||||
EditorNode::add_io_error(TTR("Error running post-import script:") + " " + post_import_script_path);
|
EditorNode::add_io_error(TTR("Error running post-import script:") + " " + post_import_script_path);
|
||||||
|
|
|
@ -75,11 +75,17 @@ class EditorScenePostImport : public Reference {
|
||||||
|
|
||||||
GDCLASS(EditorScenePostImport, Reference);
|
GDCLASS(EditorScenePostImport, Reference);
|
||||||
|
|
||||||
|
String source_folder;
|
||||||
|
String source_file;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
String get_source_folder() const;
|
||||||
|
String get_source_file() const;
|
||||||
virtual Node *post_import(Node *p_scene);
|
virtual Node *post_import(Node *p_scene);
|
||||||
|
virtual void init(const String &p_scene_folder, const String &p_scene_path);
|
||||||
EditorScenePostImport();
|
EditorScenePostImport();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue