2shady4u / godot-kra-psd-importer

GDNative wrapper for importing KRA- and PSD-files (Godot 3.1+)
MIT License
61 stars 4 forks source link
gamedev godot godotengine

Godot KRA/PSD Importer banner

godot-kra-psd-importer

!!!DISCLAIMER !!! WORK IN PROGRESS

GDNative wrapper for Importing KRA- and PSD-files into Godot 3.1+, making it possible to significantly speed up development. Additionally, it does not require any additional compilation or mucking about with build scripts.

Currently the plugin is only able to export to the PNG image format, but other formats might be added in the future.

This plugin is introduced/discussed in this blogpost for the upcoming game Trip the Ark Fantastic. Feel free to check it out if you are interested in Game development asset pipelines.

Supported operating systems:

Not having PSD support on Linux is an unfortunate constraint of the PSD Library SDK, a library that is used to make the PSD part of this plugin work. Efforts to make this library accessible in Linux are ongoing.

Also, an independent version (containing all of the same Kra-functionalities) is being hosted here in the form of a C++ library.

Table Of Contents

Roadmap

installation

Re-building Godot from scratch is NOT required, the proper way of installing this plugin is to either install it through the Asset Library or to just manually download the build files yourself.

Godot Asset Library

The Godot KRA/PSD Importer is available through the official Godot Asset Library, and can be installed in the following way:

Manually

It's also possible to manually download the build files found in the releases tab, extract them on your system and run the supplied demo-project. Make sure that Godot is correctly loading the gdsqlite.gdns-resource and that it is available in the res://-environment.

An example project, named "demo", can also be downloaded from the releases tab.

Usage

After succesful activation of the plugin, an additional panel should have appeared next to the 'Import'-panel.

Import Plugin Editor

Several fields are available:

Path to the *.kra- or *.psd-file that is to be imported into the engine.

Folder to which the exported layers of the *.kra- or *.psd-file, as given by 'Raw File', will be saved.

Crop all layers of the raw file to the size of the canvas, making them the exact same size and removing any content that spills out of the canvas. Alternatively, the canvas size is ignored and the layer sizes are respected, resulting in exported images with possibly different sizes.

IMPORTANT: This option is currently unavailable for *.kra-files and thus their image canvas size will always be ignored.

Creates a mirrored version of the raw file's layer structure. Current implementation is extremely elementary without any respect for groups or other more advanced functionalities.

After setting these fields correctly, the 'import'-button can be used to start the importing process.
Be sure to check console if any errors are spawned that cannot be decyphered by the import dock.

Credits

This plugin makes heavy use of the PSD Library SDK, without which the PSD-component of this plugin would be impossible. Alongside this, both the zlib and libpng repositories are included as submodules to, respectively, unzip the KRA archive and to export the raw data to the PNG image format.

Lastly, the TinyXML-2 project is exploited to significantly simplify the parsing process of the 'maindoc.xml'-file as contained in the KRA archive.

Blatant self-advertisement

This plugin was made by Gamechuck and is actively used during development of Trip the Ark Fantastic, a colourful game about societal and scientific themes set in the fabled Animal Kingdom. Be sure to check it out!

Trip the Ark Fantastic Banner

Advanced usage instructions

For more advanced usage, the binaries can also be called directly from GDScript without using the editor plugin at all. This might be preferred in some more obscure/creative cases and is fully supported by the plugin.

Variables

Path to the .kra- or .psd-file that is to be exported. Both res:// and user:// keywords can be used to define the path.

Folder to which the exported layers of the raw file, as given by raw_file_path, will be saved. Both res:// and user:// keywords can be used to define the folder.

Either crop the layers to the canvas or ignore the canvas size entirely and respect the layer sizes.

If set to true, the importer will emit the "texture_created"-signal whenever a new texture is created. Check the implementation of the 'create_packed_scene.gd'-script for more information.

Setting verbose_mode on true results in an information dump in the Godot console that is handy for debugging purposes.

Functions

Exports the layers of a *.kra- or *.psd-file, as given by raw_file_path, to a target folder, as given by target_folder_path. Exported image format is either PNG or TGA as given by the export_type variable.

Build instructions

Instructions for building the Godot KRA/PSD Importer from scratch are available here.

Additional documentation

The KRA-format is not that well-documented and thus this library attempts to reverse-engineer the format from scratch. A small document discussing the KRA-format and its pecularities is available here.