-
-
Notifications
You must be signed in to change notification settings - Fork 21k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not hydrate an image from data and load into a TextureRect #42346
Comments
GDScript doesn't allow exposing static methods in built-in classes (unless they're singletons, in which case they appear to be static but aren't). |
Ok, update time, I dug through the code and found a reference to Method 1: func _on_ImageTexture1_pressed():
var image = Image.new()
image.load_png_from_buffer(Marshalls.base64_to_raw(ref_data))
print(str(image))
$Icon.set_texture(image)
print("TextRect Texture is: " + str($Icon.get_texture()))
$Sprite.texture = image
print("Sprite Texture is: "+ str($Sprite.get_texture())) which results in
So there appears to be difficulty setting the texture from an Image variant, which I though maybe should have worked. (Jury is still out if this should work in the first place) Method 2: func _on_ImageTexture2_pressed():
var image = Image.new()
image.load_png_from_buffer(Marshalls.base64_to_raw(ref_data))
var it = ImageTexture.new()
var texture = it.create_from_image(image)
it.set_data(image)
print(str(it))
print(str(texture))
$Icon.set_texture(texture)
print("Texture is: " + str($Icon.get_texture()))
$Sprite.texture = it
print("Sprite Texture is: "+ str($Sprite.get_texture())) This results in
Interestingly calling BUT If we Open problems:
Updated repo project: BrokenImportv2.zip |
Back again, the working call isn't A working call is var image = Image.new()
image.load_png_from_buffer(Marshalls.base64_to_raw(ref_data))
var texture = ImageTexture.new()
texture.create_from_image(image)
$Icon.set_texture(texture)
print("Texture is: " + str($Icon.get_texture())) |
Yes, this is expected, the And please lets not rename The current documentation seems to be explicit about this, but likely just lacks examples for those common conversion operations.
If I understand correctly, Godot follows single-responsibility principle for methods, see example discussions in #30628 and #33926. It would just return the current texture (
I think I've seen a bug report/enhancement proposal for this, yes. It also depends, if you embed the |
@Xrayez the new documentation you posted clearly closes out method 1 as invalid, and clarifies that the This leaves Lastly, if you happen to update the docs for create_from_image
I think this is what threw me expecting a new object to be returned from the call instead of listening to the plainly explain just above that it returns |
In Godot
Yes, I suspected that this wording is what lead to the confusion. 🙂 I've looked up godot/scene/resources/texture.cpp Lines 161 to 178 in cc62eaf
The implementation is somewhat different when comparing to godot/scene/resources/texture.cpp Lines 197 to 211 in 9047731
So, this can be documented as:
I think this shouldn't matter much because those are implementation details. Sounds good? |
Thanks for reminding me to look at the code. We can see in 3.2 that This probably implies that we should annotate the 3.2 |
Documentation updates in #42412 resolve this issue |
Godot version:
v3.2.3.stable.flathub
OS/device including version:
Linux Ubuntu (PopOS)
Issue description:
I'm trying to replace the image used in a
TextureRect
with a Image that has been created fromImage.new()
(which has been regurgitated from from a json file containing a base64 encoded png data (similar to #25571 (comment)).Proof the data isn't corrupt
We can prove the image data is fine if we marshal the data to disk, however this is only usable if the engine editor is brought back into focus to do "some magic" with the file (the first call to write and read the image from a
res://
will always fail)Method 1: try to attach an image to the TextureRect
I figured I'd give it a shot with whatever magic the editor does for us. I know its most likely is wrong, but raises no errors so 🤷
Method 2: try some version of creating an ImageTexture and attaching that
you can create a new ImageTexture and do an
set_data()
on it directly or callingcreate_from_image()
neither seem to work. Also as an aside why do you have to instanceImageTexture
just to create a new one from an image??I've tried some other ways like spawning other texture resources, but they result in errors similar to #23574 which gives no context to the error or how to avoid it other than "use load()"
Steps to reproduce:
Minimal reproduction project:
BrokenImport.zip
The text was updated successfully, but these errors were encountered: