Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node3D
- var http_request = HTTPRequest.new()
- var url="https://upload.wikimedia.org/wikipedia/commons/8/85/%22_Shot_From_The_Sky%22_Army_Show_1945_Oak_Ridge_%2824971013612%29.jpg"
- func _ready():
- http_request = HTTPRequest.new()
- print(http_request.get_http_client_status ())
- add_child(http_request)
- #http_request.request_resolving.connect(self.reso)
- http_request.request_completed.connect(self._http_request_completed)
- var error = http_request.request(url)
- if error != OK:
- push_error("An error occurred in the HTTP request.")
- print(http_request.get_http_client_status ())
- func _http_request_completed(result, response_code, headers, body):
- print(http_request.get_http_client_status ())
- if result != HTTPRequest.RESULT_SUCCESS:
- push_error("Image couldn't be downloaded. Try a different image.")
- var image = Image.new()
- var error = image.load_jpg_from_buffer(body)
- if error != OK:
- push_error("Couldn't load the image.")
- var texture = ImageTexture.create_from_image(image)
- $TextureRect.texture = texture
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement