Skip to content

Commit 0bf5a99

Browse files
committed
Add a custom import plugin demo
This is a direct port from the Godot 2.1 version of the demo.
1 parent 621abe5 commit 0bf5a99

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tool
2+
extends EditorPlugin
3+
4+
var import_plugin
5+
6+
func _enter_tree():
7+
import_plugin = preload("import_plugin.gd").new()
8+
9+
add_import_plugin(import_plugin)
10+
11+
func _exit_tree():
12+
remove_import_plugin(import_plugin)
13+
import_plugin = null
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[plugin]
2+
3+
name="Silly Material Importer"
4+
description="Imports a 3D Material from an external text file"
5+
author="George Marques"
6+
version="1.0"
7+
script="material_import.gd"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0,0,255

0 commit comments

Comments
 (0)