Overhaul silly material creator plugin demo (#1261)

This commit is contained in:
Aaron Franke
2025-10-11 03:22:04 -07:00
committed by GitHub
parent 0343cedd48
commit 0ae09b7e5a
56 changed files with 897 additions and 493 deletions

View 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.

View 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()])

View File

@@ -0,0 +1 @@
uid://2krbk6m5bjtg

View 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"

View 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

View File

@@ -0,0 +1 @@
uid://rhenxy50b2ma

View File

@@ -0,0 +1 @@
0,0,255

View 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