Godot Version
4.3.stable
Question
How can I split a single image resource into multiple textures at runtime? I am essentially using a tilemap texture for a 3D object and trying to apply each tile to a different surface. Obviously I could just have each tile be a unique file, but I'm trying to avoid that. Atlastexture doesn't seem to work when used as a texture for a standardmaterial3D, and I have no clue if a texture2Darray is right for this
You’ll have to manipulate UVs of each object to map to different parts of the texture.
1 Like
Is there no way to separate one texture into multiple local resources?
That would be the same as using multiple textures. You can separate it using an image editing app.
I’m trying to use a single texture and split it at runtime for the sake of file management, not for optimization
You can use Godot’s Image class to manipulate texture images. Create multiple smaller images of adequate size, use Image::blit_rect() to transfer data from the original image, and then turn images into textures using ImageTexture::create_from_image().
I wouldn’t recommend doing this at runtime (or even at all) for several reasons. It’s always better to just do this as a pre-processing step and maintain multiple files. For easier management simply use file system folders and good naming conventions.
2 Likes
You use Material Maker to apply the textures and then import the output into your Godot game.
As a follow-up, Material Maker was specifically made to solve your problem, and has even been highlighted by the Godot team. Like @normalized said, you can do image manipulation, but as someone who has spent a lot of time trying to do that I can tell you it’s very painful, even if you are used to writing code in other languages to manipulate images.
1 Like
Interesting, I’ll look into it!
1 Like