0 votes

I want to write an importer that can import from an image file format, similar how the built-in importer for PNG-files work (but obviously for a different format), but I can not figure out what type of resource to create or what file extension to use.

My first thought was to create an Image and set all the pixels to what I parse out from the file to be imported, then create an ImageTexture from that Image. But I can not see any way to write out the ImageTexture to file (or what extension it would have)?

Then I looked at what happens when a PNG is imported and I see that the generated file is a StreamTexture with stex extension. But if that is what other image file importers are also supposed to do, I can find very little documentation about what a StreamTexture is or how to create a stex file.

What is the correct way of doing this?

in Engine by (14 points)

1 Answer

0 votes

Resource loader and resource importer are two different things.

Resource loader is something you need so you can call load.

Resource importer goes even farer and allows the editor to make minor modifications to the resource.

https://github.com/godotengine/godot/blob/master/core/io/image_loader.h

https://github.com/godotengine/godot/tree/master/modules/jpg

https://github.com/godotengine/godot/tree/master/drivers/png

follow the jpg module as a guide.

Here is the guide on how to add support to custom formats

http://docs.godotengine.org/en/latest/development/cpp/custom_resource_format_loaders.html

The process is somewhat the same but adding support for an image is just less work overall.

by (427 points)

Not sure how that helps me. Perhaps my question was confusing and did not describe what I was asking for?

Trying to follow the instructions here:
http://docs.godotengine.org/en/3.0/tutorials/plugins/editor/import_plugins.html
but import just a 2D texture.

Managed to get it to work by creating an Image, using that to create an ImageTexture, and using the ResourceSaver to write that to a tres file. I think the answer to my question was to use the ResourceSaver. But my created files are not compressed, so it is not a working solution.

EDIT: It is obvious that when a PNG is imported the created stex-file is compressed, but as I mentioned in the question I can not figure out a way to write to a stex file, or even to create a StreamTexture object with my image data. Perhaps that is not even what I am supposed to do anyway.

EDIT2: The only code I can find that generates a stex-file is ResourceImporterTexture::savestex and there is no obvious way to call that from GDScript(?). Can not figure out a way to make a tres compressed. Not sure what other options there are.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.