Skip to content
0.2.0-dev Download ZIP
75 lines ·2.5 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="EditorScenePostImport" inherits="RefCounted" api_type="editor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Post-processes scenes after import.
5 </brief_description>
6 <description>
7 Imported scenes can be automatically modified right after import by setting their [b]Custom Script[/b] Import property to a [code]tool[/code] script that inherits from this class.
8 The [method _post_import] callback receives the imported scene's root node and returns the modified version of the scene:
9 [codeblocks]
10 [gdscript]
11 @tool # Needed so it runs in editor.
12 extends EditorScenePostImport
13
14 # This sample changes all node names.
15 # Called right after the scene is imported and gets the root node.
16 func _post_import(scene):
17 # Change all node names to "modified_[oldnodename]"
18 iterate(scene)
19 return scene # Remember to return the imported scene
20
21 func iterate(node):
22 if node != null:
23 node.name = "modified_" + node.name
24 for child in node.get_children():
25 iterate(child)
26 [/gdscript]
27 [csharp]
28 using Godot;
29
30 // This sample changes all node names.
31 // Called right after the scene is imported and gets the root node.
32 [Tool]
33 public partial class NodeRenamer : EditorScenePostImport
34 {
35 public override GodotObject _PostImport(Node scene)
36 {
37 // Change all node names to "modified_[oldnodename]"
38 Iterate(scene);
39 return scene; // Remember to return the imported scene
40 }
41
42 public void Iterate(Node node)
43 {
44 if (node != null)
45 {
46 node.Name = $"modified_{node.Name}";
47 foreach (Node child in node.GetChildren())
48 {
49 Iterate(child);
50 }
51 }
52 }
53 }
54 [/csharp]
55 [/codeblocks]
56 </description>
57 <tutorials>
58 <link title="Importing 3D scenes: Configuration: Using import scripts for automation">$DOCS_URL/tutorials/assets_pipeline/importing_3d_scenes/import_configuration.html#using-import-scripts-for-automation</link>
59 </tutorials>
60 <methods>
61 <method name="_post_import" qualifiers="virtual">
62 <return type="Object" />
63 <param index="0" name="scene" type="Node" />
64 <description>
65 Called after the scene was imported. This method must return the modified version of the scene.
66 </description>
67 </method>
68 <method name="get_source_file" qualifiers="const">
69 <return type="String" />
70 <description>
71 Returns the source file path which got imported (e.g. [code]res://scene.dae[/code]).
72 </description>
73 </method>
74 </methods>
75</class>