EditorImportPlugin

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

EditorImportPlugins provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers.

EditorImportPlugins work by associating with specific file extensions and a resource type. See GetRecognizedExtensions and GetResourceType. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the .godot/imported directory (see ProjectSettings "application/config/use_hidden_project_data_directory").

Below is an example EditorImportPlugin that imports a Mesh from a file with the extension ".special" or ".spec":

package main

import (
	"graphics.gd/classdb/ArrayMesh"
	"graphics.gd/classdb/EditorImportPlugin"
	"graphics.gd/classdb/FileAccess"
	"graphics.gd/classdb/ResourceSaver"
)

type MySpecialPlugin struct {
	EditorImportPlugin.Extension[MySpecialPlugin]
}

func (m *MySpecialPlugin) GetImporterName() string              { return "my.special.plugin" }
func (m *MySpecialPlugin) GetVisibleName() string               { return "Special Mesh" }
func (m *MySpecialPlugin) GetRecognizedExtensions() []string    { return []string{"special", "spec"} }
func (m *MySpecialPlugin) GetSaveExtension() string             { return "mesh" }
func (m *MySpecialPlugin) GetResourceType() string              { return "Mesh" }
func (m *MySpecialPlugin) GetPresetCount() int                  { return 1 }
func (m *MySpecialPlugin) GetPresetName(presetIndex int) string { return "Default" }
func (m *MySpecialPlugin) GetImportOptions(path string, presetIndex int) []map[any]any {
	return []map[any]any{
		{
			"name":          "my_option",
			"default_value": false,
		},
	}
}
func (m *MySpecialPlugin) Import(sourceFile, savePath string, options map[any]any, platformVariants, genFiles []string) error {
	var file = FileAccess.Open(sourceFile, FileAccess.Read)
	if err := file.GetError(); err != nil {
		return err
	}
	var mesh = ArrayMesh.New()
	// Fill the Mesh with data read in "file", left as an exercise to the reader.
	var filename = savePath + "." + m.GetSaveExtension()
	return ResourceSaver.Save(mesh.AsResource(), filename, 0)
}

To use EditorImportPlugin, register it using the EditorPlugin.AddImportPlugin method first.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsEditorImportPlugin() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.

func (*Extension[T]) AsEditorImportPlugin

func (self *Extension[T]) AsEditorImportPlugin() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResourceImporter

func (self *Extension[T]) AsResourceImporter() ResourceImporter.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.EditorImportPlugin

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AppendImportExternalResource

func (self Instance) AppendImportExternalResource(path string) error

This function can only be called during the Import callback and it allows manually importing resources from it. This is useful when the imported file generates external resources that require importing (as example, images). Custom parameters for the ".import" file can be passed via the 'custom_options'. Additionally, in cases where multiple importers can handle a file, the 'custom_importer' can be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. 'generator_parameters' defines optional extra metadata which will be stored as generator_parameters in the remap section of the .import file, for example to store a md5 hash of the source data.

func (Instance) AsEditorImportPlugin

func (self Instance) AsEditorImportPlugin() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResourceImporter

func (self Instance) AsResourceImporter() ResourceImporter.Instance

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interface

type Interface interface {
	// Gets the unique name of the importer.
	GetImporterName() string
	// Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
	GetVisibleName() string
	// Gets the number of initial presets defined by the plugin. Use [GetImportOptions] to get the default options for the preset and [GetPresetName] to get the name of the preset.
	//
	// [GetImportOptions]: https://pkg.go.dev/graphics.gd/classdb/EditorImportPlugin#Interface
	// [GetPresetName]: https://pkg.go.dev/graphics.gd/classdb/EditorImportPlugin#Interface
	GetPresetCount() int
	// Gets the name of the options preset at this index.
	GetPresetName(preset_index int) string
	// Gets the list of file extensions to associate with this loader (case-insensitive). e.g. ["obj"].
	GetRecognizedExtensions() []string
	// Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: name, default_value, property_hint (optional), hint_string (optional), usage (optional).
	GetImportOptions(path string, preset_index int) [][]struct {
		Name         string      "gd:\"name\""
		DefaultValue interface{} "gd:\"default_value\""
		PropertyHint int         "gd:\"property_hint\""
		HintString   string      "gd:\"hint_string\""
		Usage        int         "gd:\"usage\""
	}
	// Gets the extension used to save this resource in the .godot/imported directory (see [ProjectSettings] "application/config/use_hidden_project_data_directory").
	//
	// [ProjectSettings]: https://pkg.go.dev/graphics.gd/classdb/ProjectSettings
	GetSaveExtension() string
	// Gets the Godot resource type associated with this loader. e.g. "Mesh" or "Animation".
	GetResourceType() string
	// Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is 1.0.
	GetPriority() Float.X
	// Gets the order of this importer to be run when importing resources. Importers with lower import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is 0 unless overridden by a specific importer. See [ResourceImporter.ImportOrder] for some predefined values.
	GetImportOrder() int
	// Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources.
	GetFormatVersion() int
	// Gets whether the import option specified by 'option_name' should be visible in the Import dock. The default implementation always returns true, making all options visible. This is mainly useful for hiding options that depend on others if one of them is disabled.
	//
	//
	//
	// [gdscript]
	//
	// func _get_option_visibility(path, option_name, options):
	//
	// 	# Only show the lossy quality setting if the compression mode is set to "Lossy".
	//
	// 	if option_name == "compress/lossy_quality" and options.has("compress/mode"):
	//
	// 		return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set
	//
	//
	//
	// 	return true
	//
	// [/gdscript]
	//
	// [csharp]
	//
	// public override bool _GetOptionVisibility(string path, StringName optionName, Godot.Collections.Dictionary options)
	//
	// {
	//
	// 	// Only show the lossy quality setting if the compression mode is set to "Lossy".
	//
	// 	if (optionName == "compress/lossy_quality" && options.ContainsKey("compress/mode"))
	//
	// 	{
	//
	// 		return (int)options["compress/mode"] == CompressLossy; // This is a constant you set
	//
	// 	}
	//
	//
	//
	// 	return true;
	//
	// }
	//
	// [/csharp]
	//
	//
	GetOptionVisibility(path string, option_name string, options map[string]interface{}) bool
	// Imports 'source_file' with the import 'options' specified. Should return [@Globalscope.Ok] if the import is successful, other values indicate failure.
	//
	// The imported resource is expected to be saved to save_path + "." + _get_save_extension(). If a different variant is preferred for a [feature tag], save the variant to save_path + "." + tag + "." + _get_save_extension() and add the feature tag to 'platform_variants'.
	//
	// If additional resource files are generated in the resource filesystem (res://), add their full path to 'gen_files' so that the editor knows they depend on 'source_file'.
	//
	// This method must be overridden to do the actual importing work. See this class' description for an example of overriding this method.
	//
	// [feature tag]: https://docs.godotengine.org/tutorials/export/feature_tags.html
	Import(source_file string, save_path string, options map[string]interface{}, platform_variants []string, gen_files []string) error
	// Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time.
	//
	// If this method is not overridden, it will return false by default.
	//
	// If this importer's implementation is thread-safe and can be run in parallel, override this with true to optimize for concurrency.
	CanImportThreaded() bool
}

type MoreArgs

type MoreArgs [1]gdclass.EditorImportPlugin

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) AppendImportExternalResource

func (self MoreArgs) AppendImportExternalResource(path string, custom_options map[string]interface{}, custom_importer string, generator_parameters any) error

This function can only be called during the Import callback and it allows manually importing resources from it. This is useful when the imported file generates external resources that require importing (as example, images). Custom parameters for the ".import" file can be passed via the 'custom_options'. Additionally, in cases where multiple importers can handle a file, the 'custom_importer' can be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. 'generator_parameters' defines optional extra metadata which will be stored as generator_parameters in the remap section of the .import file, for example to store a md5 hash of the source data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL