0 votes

Hi,

I am having some trouble cropping images around a node (colo[u]rRect) for a PBR material painting tool (just trying to implement drawing on a flat canvas right now).

I have looked at the gdpaint demo, tested it, and it worked, so I used similar code, however it gave me a segment of the colo[u]rRect, as well as a grey strip (the bg) on the side/top, depending on the scale of the window.

my code is:

onready var IMAGE_SIZE = Vector2(500, 500) # the size of the colourRect

func _save_img(path):
    yield(VisualServer, "frame_post_draw")
    var img = get_viewport().get_texture().get_data()
    img = img.get_rect(Rect2(canvas.get_global_rect().position, IMAGE_SIZE))
    img.flip_y()
    img.save_png(path)

All I need to work out is how to crop the screenshot to a ColourRect.

Godot version 3.3.1
in Engine by (272 points)
edited by

1 Answer

0 votes
Best answer

Okay, so I found the answer. Here it is in case someone needs it. You can get it by saving a viewport with the nodes you want inside it to an imagetexture, and then save it to disk.

by (272 points)
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.