2 years ago
#77512
Vincent
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 ?
godot
0 Answers
Your Answer