+1 vote

Hi!
I need send a texture from a server to a client.

var t0 = Main.crate_image(temp[1])
var t1 = t0.get_data()
var t2:PoolByteArray = t1.get_data()
var t3 = t2.compress(1)
var t4:Array = [temp[1],t3]
Servidor.get_peer(id).put_var(t4)

Main.GDScript

func crate_image(path):
    var img = Image.new()
    img.load(path)
    var img_tex: = ImageTexture.new()
    img_tex.create_from_image(img)
    return img_tex

temp is one Array received from client. [order type,texture path]

t0 = ImageTexture
t1 = Image
t2 = PoolByteArray
and t3 is t2 compressed (without this, client has returned: is too big for it to
process.)

The client received this, but I can't transform this PoolByteArray in texture

var t0:PoolByteArray = dados_temp[1].decompress(1,1)
var image = Image.new()
image.load_png_from_buffer(t0)
var _t1 = image.save_png(dados_temp[0])

I have tried several things... Decompress dont work... I didn't find anything about buffer_size()... Let alone other ideas.
Even that didn't help me:

https://www.reddit.com/r/godot/comments/gilgpo/attempted_guide_on_how_to_transmit_images_over_a/

in Engine by (211 points)

I solved my problem.

Server

var t0 = Main.crate_image(temp[1])
var t1 = t0.get_data()
var dic:Dictionary = t1.data
dic.erase("data")
var t2:PoolByteArray = t1.get_data()
var t3 = t2.compress(3)
var t4:Array = [temp[1],t3,dic]
Servidor.get_peer(id).put_var(t4)

Client

var t0:Dictionary = dados_temp[2]
var t1:PoolByteArray = dados_temp[1].decompress(2048000,3)
var image = Image.new()
image.create_from_data(t0["width"],t0["height"],t0["mipmaps"],5,t1)
var _t1 = image.save_png(dados_temp[0])

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.