Best way to generate a Texture.tres 's data by code available in the editor

I want to have MyTexture.tres to generate the Image, and be able to visualise it both at run time and in the editor.

The goal is to have my own Texture type as a Resource file, that can be used like NoiseTexture, GradientTexture, etc, and to use it in the editor (on a Sprite, as a shader uniform...) and NOT to save any image data in project folder.

tool
extends ImageTexture
export var width := 100
export var height := 100
func _init(): var image := Image.new() # ... # Generate the image data array # ... create_from_image(image)

Using the tool keyword, it works but the Image data is automatically saved into MyTexture.tres, so it break the best advantage that is to save a lot of space.

I assign a script to the .tres file trying inheriting both ImageTexture and ProxyTexture, but the result is the same once I call create_from_image() it saves it to the file.

[sub_resource type="Image" id=3]
data = {
"data": PoolByteArray( 127, 119, 254, 131, 131, 119, 25, ... ) <-----
"format": "RGBA8",
"height": 512,
"mipmaps": false,
"width": 512
}

May be I will try inheriting ViewportTexture but even if it works it seem wrong, that require accessing the SceneTree to instanciate the Viewport (from a Resource script), may be is there a clean way ?

3 Related questions 6 Is it possible to 'manually' create image data for OpenGL texture use? 1 Texture Coordinate Generation 4 create texture from memory directx Related questions 6 Is it possible to 'manually' create image data for OpenGL texture use? 1 Texture Coordinate Generation 4 create texture from memory directx 4 Creating Texture Programmatically DirectX 0 Generate texture coordinates for procedural texturing 2 How do I create a texture 3d programatically? 1 Creating raw OpenGL texture data (C++) 4 OpenGL texture format, create image/texture data for OpenGL 0 Creating Texture with initial data DirectX 11 1 How would I randomly generate a 3d world in Godot? Load 7 more related questions Show fewer related questions Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like