Skip to content
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

Refactor MeshTexture #102028

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

beicause
Copy link
Contributor

@beicause beicause commented Jan 25, 2025

Fixes #101965, fixes #87159, fixes #81213

Makes the mesh draw in the center, and exposes the scale property. In the editor, I limit the scale to -1 to 1 to prevent drawing beyond its own size, but don't limit it in script.

scene/resources/mesh_texture.cpp Outdated Show resolved Hide resolved
doc/classes/MeshTexture.xml Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member

The description is to match Texture2D size but that's not a Vector2i? What do size do you mean? The get_size returns Vector2

Nothing in Texture2D uses Vector2i

@mk56-spn
Copy link

I have tested a bit and found some issues.

  • I can not select by clicking on the area covered by the "selected object orange rectangle" gizmo when image size is negative.

( having created selection systems in my game i think this is probably because areas do not generate properly with negative numbers, but i could be wrong )

-The orange selection rectangle scales appropriately with changes to "image size" but not with the "scale" parameter.

@beicause
Copy link
Contributor Author

I just realize that the type is Vector2 although get_width and get_height are int. I'll change the type back then.

@beicause
Copy link
Contributor Author

I have tested a bit and found some issues.我测试了一些,发现了一些问题。

  • I can not select by clicking on the area covered by the "selected object orange rectangle" gizmo when image size is negative.当图像大小为负数时,我无法通过单击“selected object orange rectangle”(选定对象橙色矩形)gizmo 覆盖的区域进行选择。

( having created selection systems in my game i think this is probably because areas do not generate properly with negative numbers, but i could be wrong )(在我的游戏中创建了选择系统后,我认为这可能是因为区域没有正确生成负数,但我可能是错的)

-The orange selection rectangle scales appropriately with changes to "image size" but not with the "scale" parameter.- 橙色选择矩形会随着 “image size” 的更改而适当缩放,但不会随着 “scale” 参数的更改而缩放。

The image size matches the true size of the texture and the orange selection. Negative size are not allowed. I will make changes to avoid negative numbers.
The scale does not affect size, only applies to the content.

Comment on lines 152 to 123
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "image_size", PROPERTY_HINT_RANGE, "0,16384,1,suffix:px"), "set_image_size", "get_image_size");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "image_size", PROPERTY_HINT_RANGE, "1,16384,1,suffix:px"), "set_image_size", "get_image_size");
Copy link
Contributor Author

@beicause beicause Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range hint seems do not work in editor. I consider replacing it with width and height, the same with gradient texture and noise texture.

Copy link
Contributor Author

@beicause beicause Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the editor issue for now. Keep the image_size for compatibility.

@beicause beicause force-pushed the refactor-meshtexture branch from 94c0c6a to d26590f Compare January 25, 2025 18:58
@beicause
Copy link
Contributor Author

In addition to the scale property, I think offset is also worth adding, but the drawing area cannot be cropped and may exceed the texture size. I wonder if it is allowed for texture2d to draw beyond its size.

Fixes properties changing issue. Makes the mesh draw in the center of this texture. Adds `scale` and `offset` property
@beicause beicause force-pushed the refactor-meshtexture branch from d26590f to 2b605ec Compare January 26, 2025 05:45
@beicause
Copy link
Contributor Author

beicause commented Jan 26, 2025

It cannot be used in 3D, nor can it use get data. Perhaps we can use ViewportTexure internally to render to real texture, which also supports region drawing, but may reduce performance.

@beicause beicause force-pushed the refactor-meshtexture branch 2 times, most recently from 4164197 to 4a17c75 Compare January 26, 2025 14:13
@beicause beicause force-pushed the refactor-meshtexture branch from 4a17c75 to aeb49d0 Compare January 26, 2025 15:18
@mk56-spn
Copy link

mk56-spn commented Jan 26, 2025

Issues with the latest version :

image

  • Viewports are annoying in that they output a texture suited for use with "premultiplied alpha" materials ( note the black border on the left side triangle)

Screenshot from 2025-01-26 16-53-33

  • upon instantiating a new meshtexture the viewport seems to show a region of the screen until you touch a setting that forces an update, this should probably be purged upon initialisation

PS. sorry for being so nitpicky but meshtexture barely gets any love so i think its worth making sure we get it right this time

@beicause
Copy link
Contributor Author

beicause commented Jan 26, 2025

In addition, when using GradientTexture2D as base_texture, change the property of gradient won't update texture in editor, because GradientTexture2D calls emit_changed signal before its texture updates. NoiseTexture2D is OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants