mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
Overhaul silly material creator plugin demo (#1261)
This commit is contained in:
9
plugins/addons/simple_import_plugin/README.md
Normal file
9
plugins/addons/simple_import_plugin/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Material Import Plugin Demo
|
||||
|
||||
This plugin demo shows how a custom import system can
|
||||
be added to the editor. In this case, it imports a material.
|
||||
For more information, see this documentation article:
|
||||
https://docs.godotengine.org/en/latest/tutorials/plugins/editor/import_plugins.html
|
||||
|
||||
In the editor, try opening `test.mtxt`. Godot will recognize
|
||||
it and import it as a material because of this plugin.
|
||||
76
plugins/addons/simple_import_plugin/import.gd
Normal file
76
plugins/addons/simple_import_plugin/import.gd
Normal file
@@ -0,0 +1,76 @@
|
||||
@tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
enum Preset {
|
||||
PRESET_DEFAULT,
|
||||
}
|
||||
|
||||
|
||||
func _get_importer_name() -> String:
|
||||
return "demos.mtxt"
|
||||
|
||||
|
||||
func _get_visible_name() -> String:
|
||||
return "Silly Material"
|
||||
|
||||
|
||||
func _get_recognized_extensions() -> PackedStringArray:
|
||||
return ["mtxt"]
|
||||
|
||||
|
||||
func _get_save_extension() -> String:
|
||||
return "res"
|
||||
|
||||
|
||||
func _get_resource_type() -> String:
|
||||
return "Material"
|
||||
|
||||
|
||||
func _get_preset_count() -> int:
|
||||
return Preset.size()
|
||||
|
||||
|
||||
func _get_preset_name(preset: Preset) -> String:
|
||||
match preset:
|
||||
Preset.PRESET_DEFAULT:
|
||||
return "Default"
|
||||
_:
|
||||
return "Unknown"
|
||||
|
||||
|
||||
func _get_import_options(_path: String, preset: Preset) -> Array[Dictionary]:
|
||||
match preset:
|
||||
Preset.PRESET_DEFAULT:
|
||||
return [{
|
||||
"name": "use_red_anyway",
|
||||
"default_value": false,
|
||||
}]
|
||||
_:
|
||||
return []
|
||||
|
||||
|
||||
func _get_import_order() -> int:
|
||||
return ResourceImporter.IMPORT_ORDER_DEFAULT
|
||||
|
||||
|
||||
func _get_option_visibility(path: String, option: StringName, options: Dictionary) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func _import(source_file: String, save_path: String, options: Dictionary, r_platform_variants: Array[String], r_gen_files: Array[String]) -> Error:
|
||||
var file := FileAccess.open(source_file, FileAccess.READ)
|
||||
var line := file.get_line()
|
||||
|
||||
var channels := line.split(",")
|
||||
if channels.size() != 3:
|
||||
return ERR_PARSE_ERROR
|
||||
|
||||
var color := Color8(int(channels[0]), int(channels[1]), int(channels[2]))
|
||||
var material := StandardMaterial3D.new()
|
||||
|
||||
if options.use_red_anyway:
|
||||
color = Color8(255, 0, 0)
|
||||
|
||||
material.albedo_color = color
|
||||
|
||||
return ResourceSaver.save(material, "%s.%s" % [save_path, _get_save_extension()])
|
||||
1
plugins/addons/simple_import_plugin/import.gd.uid
Normal file
1
plugins/addons/simple_import_plugin/import.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://2krbk6m5bjtg
|
||||
7
plugins/addons/simple_import_plugin/plugin.cfg
Normal file
7
plugins/addons/simple_import_plugin/plugin.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="Simple Importer Plugin Demo"
|
||||
description="Imports a 3D Material from an external text file"
|
||||
author="George Marques"
|
||||
version="1.0"
|
||||
script="plugin.gd"
|
||||
14
plugins/addons/simple_import_plugin/plugin.gd
Normal file
14
plugins/addons/simple_import_plugin/plugin.gd
Normal file
@@ -0,0 +1,14 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
var import_plugin: EditorImportPlugin
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
import_plugin = preload("import.gd").new()
|
||||
add_import_plugin(import_plugin)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
remove_import_plugin(import_plugin)
|
||||
import_plugin = null
|
||||
1
plugins/addons/simple_import_plugin/plugin.gd.uid
Normal file
1
plugins/addons/simple_import_plugin/plugin.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://rhenxy50b2ma
|
||||
1
plugins/addons/simple_import_plugin/test.mtxt
Normal file
1
plugins/addons/simple_import_plugin/test.mtxt
Normal file
@@ -0,0 +1 @@
|
||||
0,0,255
|
||||
15
plugins/addons/simple_import_plugin/test.mtxt.import
Normal file
15
plugins/addons/simple_import_plugin/test.mtxt.import
Normal file
@@ -0,0 +1,15 @@
|
||||
[remap]
|
||||
|
||||
importer="demos.mtxt"
|
||||
type="Material"
|
||||
uid="uid://bqja7mgxfmfqa"
|
||||
path="res://.godot/imported/test.mtxt-cc369242bc971647fccdadd6e971f1d0.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/simple_import_plugin/test.mtxt"
|
||||
dest_files=["res://.godot/imported/test.mtxt-cc369242bc971647fccdadd6e971f1d0.res"]
|
||||
|
||||
[params]
|
||||
|
||||
use_red_anyway=false
|
||||
Reference in New Issue
Block a user