Topic was automatically imported from the old Question2Answer platform.
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.
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.