codecat / godot-tbloader

TrenchBroom Loader for Godot 4. (Alternative to Qodot)
MIT License
240 stars 30 forks source link

Additional Texture Formats/Extensions Support #25

Closed TDCRanila closed 2 years ago

TDCRanila commented 2 years ago

Heya!

I was messing around with the tool, but noticed that textures other then '.png' were not supported. From what I can gather from the code, this is just because the texture file format when loading is hard-coded to '.png'. Changing the extension to '.tga', for instance, worked perfectly fine. So because of this, I have added support for other file extensions.

I decided to let the user control the array of strings/extensions, so that they order, remove, or add the ones they needed for their map. (Not sure if this really needed though and I am not convinced that is the greatest UI/UX experience, however, it works fine.) Alternatively, we could:

Anyhow, this is how you can use it in the editor.

https://user-images.githubusercontent.com/38665664/190424509-b89a3c4c-18bd-4736-8d01-6482ae7cf41d.mp4

I have also made a change regarding "texture_from_name" so that we don't have to; check for file extensions, check if it exists, and then call the load function for every texture. (This would be done twice for setting the texture size and then later for the mesh building.) It now fetches the resource from "m_loaded_map_textures" dictionary, which gets filled once at the start of map load.

Of course, feel free to suggest anything and let me know what you think. :)

codecat commented 2 years ago

Thanks for the PR! 🎉

I like the idea of using Godot's supported texture list for this! We would need to check if all those texture formats are actually supported by TrenchBroom, too. I guess depending on that we can decide if we want to hardcode a specific supported set, or just use whatever Godot tells us it can use.

TDCRanila commented 2 years ago

Alrighty, I did some research,

"The 'image' format can be used to load a wide array of image formats such as tga, pcx, jpeg, and so on. TrenchBroom uses the FreeImage Library to load these images and supports any file type supported by this library."

FreeImage Library Supported Formats freeimage-supported-formats

So theoretically, that would mean that all supported texture formats/extensions overlap besides tres, res, ctex, and svg, and thus means that whatever you are able to use in Trenchbroom, Godot will also be able to load it - using directory-based texture collections of course.

As for the PR, I would then indeed just use the Godot's supported extension list and then remove all the bits with the exposed property. If we want to be more explicit with the extension list, it could be hardcoded, but I don't see much value in that since that Godot function exist albeit with extensions that Trenchbroom can't load.

On a sidenote, if we want to support more texture formats/extensions in the workflow, the 'textures' field in GameConfig.cfg that is provided with TBLoader, would have to be updated as well to accommodate this.

codecat commented 2 years ago

Thanks for taking the time to look into this!

I think I would have a preference for hardcoding the list to take into account the (unlikely?) scenario that Godot adds another format that is unsupported by Trenchbroom, or one that could be something other than an image (like tres). Then if someone needs another format we could just add it on request, since that would probably be a rare occasion as well.

And yes indeed, the default GameConfig.cfg would have to be updated as well. Since we don't generate this file yet, hardcoding the supported extensions also makes more sense to me.

TDCRanila commented 2 years ago

Yeah, no problem! ^^

I have removed the 'Texture Import Extensions' property entirely and replaced it with a hardcoded list instead like we talked about.

Let me know if there is anything else that could be improved or changed.

TDCRanila commented 2 years ago

Alrighty, I have made the adjustments and have amended the commit, so that should be it. 🎉

codecat commented 2 years ago

Looks good to me! Thank you! 🎉