diff --git a/plugins/custom_import_plugin/import_plugin.gd b/plugins/custom_import_plugin/import_plugin.gd new file mode 100644 index 00000000..ce719d9d --- /dev/null +++ b/plugins/custom_import_plugin/import_plugin.gd @@ -0,0 +1,63 @@ +tool +extends EditorImportPlugin + +enum Presets { PRESET_DEFAULT } + +func get_importer_name(): + return "demos.sillymaterial" + +func get_visible_name(): + return "Silly Material" + +func get_recognized_extensions(): + return ["mtxt"] + +func get_save_extension(): + return "res" + +func get_resource_type(): + return "Material" + +func get_preset_count(): + return 1 + +func get_preset_name(preset): + match preset: + PRESET_DEFAULT: return "Default" + _ : return "Unknown" + +func get_import_options(preset): + match preset: + PRESET_DEFAULT: + return [{ + "name": "use_red_anyway", + "default_value": false + }] + _: return [] + +func get_option_visibility(option, options): + return true + +func import(source_file, save_path, options, r_platform_variants, r_gen_files): + var file = File.new() + var err = file.open(source_file, File.READ) + if (err != OK): + return err + + var line = file.get_line() + + file.close() + + 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 = SpatialMaterial.new() + + if options.use_red_anyway: + color = Color8(255, 0, 0) + + material.albedo_color = color + + return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], material) diff --git a/plugins/custom_import_plugin/material_import.gd b/plugins/custom_import_plugin/material_import.gd index a952315a..0f98a026 100644 --- a/plugins/custom_import_plugin/material_import.gd +++ b/plugins/custom_import_plugin/material_import.gd @@ -1,24 +1,13 @@ -# 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. - tool extends EditorPlugin -var io_material_dialog; +var import_plugin func _enter_tree(): - - io_material_dialog = preload("res://addons/custom_import_plugin/Custom_material_dock.tscn").instance() - io_material_dialog.editor_interface = get_editor_interface(); - - add_control_to_dock( DOCK_SLOT_LEFT_UL, io_material_dialog ) + import_plugin = preload("import_plugin.gd").new() + + add_import_plugin(import_plugin) func _exit_tree(): - remove_control_from_docks(io_material_dialog) \ No newline at end of file + remove_import_plugin(import_plugin) + import_plugin = null diff --git a/plugins/custom_import_plugin/plugin.cfg b/plugins/custom_import_plugin/plugin.cfg index 246b07f5..cc36e53f 100644 --- a/plugins/custom_import_plugin/plugin.cfg +++ b/plugins/custom_import_plugin/plugin.cfg @@ -1,14 +1,7 @@ [plugin] -name="Silly Spatial Material Importer/Exporter" -description="Imports and exports a 3D Material from an external text file" -author="TwistedTwigleg" +name="Silly Material Importer" +description="Imports a 3D Material from an external text file" +author="George Marques" version="1.0" script="material_import.gd" - - - - - - - diff --git a/plugins/custom_import_plugin/test.mtxt b/plugins/custom_import_plugin/test.mtxt new file mode 100644 index 00000000..546ea2af --- /dev/null +++ b/plugins/custom_import_plugin/test.mtxt @@ -0,0 +1 @@ +0,0,255 diff --git a/plugins/custom_import_plugin/Custom_material_dock.tscn b/plugins/custom_material_creator/Custom_material_dock.tscn similarity index 100% rename from plugins/custom_import_plugin/Custom_material_dock.tscn rename to plugins/custom_material_creator/Custom_material_dock.tscn diff --git a/plugins/custom_import_plugin/Silly_material_creator.gd b/plugins/custom_material_creator/Silly_material_creator.gd similarity index 100% rename from plugins/custom_import_plugin/Silly_material_creator.gd rename to plugins/custom_material_creator/Silly_material_creator.gd diff --git a/plugins/custom_import_plugin/Silly_material_resource.gd b/plugins/custom_material_creator/Silly_material_resource.gd similarity index 100% rename from plugins/custom_import_plugin/Silly_material_resource.gd rename to plugins/custom_material_creator/Silly_material_resource.gd diff --git a/plugins/custom_material_creator/material_import.gd b/plugins/custom_material_creator/material_import.gd new file mode 100644 index 00000000..a952315a --- /dev/null +++ b/plugins/custom_material_creator/material_import.gd @@ -0,0 +1,24 @@ +# 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. + +tool +extends EditorPlugin + +var io_material_dialog; + +func _enter_tree(): + + io_material_dialog = preload("res://addons/custom_import_plugin/Custom_material_dock.tscn").instance() + io_material_dialog.editor_interface = get_editor_interface(); + + add_control_to_dock( DOCK_SLOT_LEFT_UL, io_material_dialog ) + +func _exit_tree(): + remove_control_from_docks(io_material_dialog) \ No newline at end of file diff --git a/plugins/custom_material_creator/plugin.cfg b/plugins/custom_material_creator/plugin.cfg new file mode 100644 index 00000000..9961a157 --- /dev/null +++ b/plugins/custom_material_creator/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Silly Spatial Material Creator" +description="Loads and saves a 3D Material from an external text file" +author="TwistedTwigleg" +version="1.0" +script="material_import.gd"