Writing a texture importer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lifelike

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?

:bust_in_silhouette: Reply From: hungrymonkey

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.

follow the jpg module as a guide.

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

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

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:
Import plugins — Godot Engine (3.0) documentation in English
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::_save_stex 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.

lifelike | 2018-04-25 21:43