Skip to content

Commit dabd28c

Browse files
authored
Merge pull request #192 from vnen/import-plugin
Add a proper import plugin demo
2 parents e182dd7 + 0bf5a99 commit dabd28c

File tree

9 files changed

+104
-27
lines changed

9 files changed

+104
-27
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
tool
2+
extends EditorImportPlugin
3+
4+
enum Presets { PRESET_DEFAULT }
5+
6+
func get_importer_name():
7+
return "demos.sillymaterial"
8+
9+
func get_visible_name():
10+
return "Silly Material"
11+
12+
func get_recognized_extensions():
13+
return ["mtxt"]
14+
15+
func get_save_extension():
16+
return "res"
17+
18+
func get_resource_type():
19+
return "Material"
20+
21+
func get_preset_count():
22+
return 1
23+
24+
func get_preset_name(preset):
25+
match preset:
26+
PRESET_DEFAULT: return "Default"
27+
_ : return "Unknown"
28+
29+
func get_import_options(preset):
30+
match preset:
31+
PRESET_DEFAULT:
32+
return [{
33+
"name": "use_red_anyway",
34+
"default_value": false
35+
}]
36+
_: return []
37+
38+
func get_option_visibility(option, options):
39+
return true
40+
41+
func import(source_file, save_path, options, r_platform_variants, r_gen_files):
42+
var file = File.new()
43+
var err = file.open(source_file, File.READ)
44+
if (err != OK):
45+
return err
46+
47+
var line = file.get_line()
48+
49+
file.close()
50+
51+
var channels = line.split(",")
52+
if channels.size() != 3:
53+
return ERR_PARSE_ERROR
54+
55+
var color = Color8(int(channels[0]), int(channels[1]), int(channels[2]))
56+
var material = SpatialMaterial.new()
57+
58+
if options.use_red_anyway:
59+
color = Color8(255, 0, 0)
60+
61+
material.albedo_color = color
62+
63+
return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], material)
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
# A simple (and silly) material resource plugin. Allows you to make a really simple material
2-
# from a custom dock, that you can save and load, and apply to selected MeshInstances.
3-
#
4-
# SPECIAL NOTE: This technically should be using EditorImportPlugin and EditorExportPlugin
5-
# to handle the input and output of the silly material. However, currently you cannot export
6-
# custom resources in Godot, so instead we're using JSON files instead.
7-
# |
8-
# This example should be replaced when EditorImportPlugin and EditorExportPlugin are both
9-
# fully working and you can save custom resources.
10-
111
tool
122
extends EditorPlugin
133

14-
var io_material_dialog;
4+
var import_plugin
155

166
func _enter_tree():
17-
18-
io_material_dialog = preload("res://addons/custom_import_plugin/Custom_material_dock.tscn").instance()
19-
io_material_dialog.editor_interface = get_editor_interface();
20-
21-
add_control_to_dock( DOCK_SLOT_LEFT_UL, io_material_dialog )
7+
import_plugin = preload("import_plugin.gd").new()
8+
9+
add_import_plugin(import_plugin)
2210

2311
func _exit_tree():
24-
remove_control_from_docks(io_material_dialog)
12+
remove_import_plugin(import_plugin)
13+
import_plugin = null
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
[plugin]
22

3-
name="Silly Spatial Material Importer/Exporter"
4-
description="Imports and exports a 3D Material from an external text file"
5-
author="TwistedTwigleg"
3+
name="Silly Material Importer"
4+
description="Imports a 3D Material from an external text file"
5+
author="George Marques"
66
version="1.0"
77
script="material_import.gd"
8-
9-
10-
11-
12-
13-
14-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0,0,255
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# A simple (and silly) material resource plugin. Allows you to make a really simple material
2+
# from a custom dock, that you can save and load, and apply to selected MeshInstances.
3+
#
4+
# SPECIAL NOTE: This technically should be using EditorImportPlugin and EditorExportPlugin
5+
# to handle the input and output of the silly material. However, currently you cannot export
6+
# custom resources in Godot, so instead we're using JSON files instead.
7+
# |
8+
# This example should be replaced when EditorImportPlugin and EditorExportPlugin are both
9+
# fully working and you can save custom resources.
10+
11+
tool
12+
extends EditorPlugin
13+
14+
var io_material_dialog;
15+
16+
func _enter_tree():
17+
18+
io_material_dialog = preload("res://addons/custom_import_plugin/Custom_material_dock.tscn").instance()
19+
io_material_dialog.editor_interface = get_editor_interface();
20+
21+
add_control_to_dock( DOCK_SLOT_LEFT_UL, io_material_dialog )
22+
23+
func _exit_tree():
24+
remove_control_from_docks(io_material_dialog)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[plugin]
2+
3+
name="Silly Spatial Material Creator"
4+
description="Loads and saves a 3D Material from an external text file"
5+
author="TwistedTwigleg"
6+
version="1.0"
7+
script="material_import.gd"

0 commit comments

Comments
 (0)