mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
Overhaul silly material creator plugin demo (#1261)
This commit is contained in:
@@ -1,38 +1,46 @@
|
||||
# A simple (and silly) material resource plugin. Allows you to make a really simple material
|
||||
# from a custom dock, that you can save and load, and apply to selected MeshInstances.
|
||||
#
|
||||
# SPECIAL NOTE: This technically should be using EditorImportPlugin and EditorExportPlugin
|
||||
# to handle the input and output of the silly material. However, currently you cannot export
|
||||
# custom resources in Godot, so instead we're using JSON files instead.
|
||||
#
|
||||
# This example should be replaced when EditorImportPlugin and EditorExportPlugin are both
|
||||
# fully working and you can save custom resources.
|
||||
|
||||
## A simple (and silly) material resource plugin. Allows you to make a really
|
||||
## simple material from a custom dock, which can be applied to meshes,
|
||||
## saved to files, loaded from files, imported from files, and more.
|
||||
##
|
||||
## See the documentation in the `README.md` file for more information,
|
||||
## and also the documentation in each class (Ctrl+Click on these in Godot):
|
||||
## - SillyMaterialResource
|
||||
## - ImportSillyMatAsSillyMaterialResource
|
||||
## - ImportSillyMatAsStandardMaterial3D
|
||||
## - SillyMatFormatLoader
|
||||
## - SillyMatFormatSaver
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
var io_material_dialog: Panel
|
||||
var _loader: SillyMatFormatLoader
|
||||
var _saver: SillyMatFormatSaver
|
||||
|
||||
var _material_creator_dock: Panel
|
||||
var _silly_mat_loader := SillyMatFormatLoader.new()
|
||||
var _silly_mat_saver := SillyMatFormatSaver.new()
|
||||
var _import_as_silly_mat_res := ImportSillyMatAsSillyMaterialResource.new()
|
||||
var _import_as_standard_mat := ImportSillyMatAsStandardMaterial3D.new()
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
_loader = SillyMatFormatLoader.new()
|
||||
_saver = SillyMatFormatSaver.new()
|
||||
ResourceLoader.add_resource_format_loader(_loader)
|
||||
ResourceSaver.add_resource_format_saver(_saver)
|
||||
|
||||
io_material_dialog = preload("res://addons/material_creator/material_dock.tscn").instantiate()
|
||||
io_material_dialog.editor_interface = get_editor_interface()
|
||||
add_control_to_dock(DOCK_SLOT_LEFT_UL, io_material_dialog)
|
||||
# Set up the loader and saver.
|
||||
ResourceLoader.add_resource_format_loader(_silly_mat_loader)
|
||||
ResourceSaver.add_resource_format_saver(_silly_mat_saver)
|
||||
# Set up the importers.
|
||||
add_import_plugin(_import_as_silly_mat_res)
|
||||
add_import_plugin(_import_as_standard_mat)
|
||||
# Set up the silly material creator dock.
|
||||
const dock_scene: PackedScene = preload("res://addons/material_creator/editor/material_dock.tscn")
|
||||
_material_creator_dock = dock_scene.instantiate()
|
||||
_material_creator_dock.editor_interface = get_editor_interface()
|
||||
var dock_scale: float = EditorInterface.get_editor_scale() * 0.85
|
||||
_material_creator_dock.custom_minimum_size *= dock_scale
|
||||
for child in _material_creator_dock.find_children("*", "Control"):
|
||||
child.custom_minimum_size *= dock_scale
|
||||
add_control_to_dock(DOCK_SLOT_LEFT_UL, _material_creator_dock)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
remove_control_from_docks(io_material_dialog)
|
||||
|
||||
if _loader:
|
||||
ResourceLoader.remove_resource_format_loader(_loader)
|
||||
_loader = null
|
||||
if _saver:
|
||||
ResourceSaver.remove_resource_format_saver(_saver)
|
||||
_saver = null
|
||||
remove_control_from_docks(_material_creator_dock)
|
||||
ResourceLoader.remove_resource_format_loader(_silly_mat_loader)
|
||||
ResourceSaver.remove_resource_format_saver(_silly_mat_saver)
|
||||
remove_import_plugin(_import_as_silly_mat_res)
|
||||
remove_import_plugin(_import_as_standard_mat)
|
||||
|
||||
Reference in New Issue
Block a user