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

MultiMeshInstance2D can cull early #54854

Closed
reikken opened this issue Nov 10, 2021 · 4 comments
Closed

MultiMeshInstance2D can cull early #54854

reikken opened this issue Nov 10, 2021 · 4 comments

Comments

@reikken
Copy link

reikken commented Nov 10, 2021

Godot version

3.4.stable

System information

Windows10, GLES3

Issue description

I encountered this for MultiMeshInstance2Ds generated at runtime.
This node can be culled from drawing before all instances are off screen. It seems to cull as soon as the center of the node is off screen.

Resizing the window seems to fix the issue for any existing instances, and ones generated entirely in a _ready() function or premade in a packed scene do not seem to have this issue.

Steps to reproduce

Create a new multimesh but do not set the instances until some amount of time after adding it to the scene tree. Then pan the camera until the multimesh is halfway offscreen, and it will disappear.

Minimal reproduction project

MM2DTEST.zip

@Calinou
Copy link
Member

Calinou commented Nov 10, 2021

For reference, this issue was cross-posted on the Godot Q&A: https://godotengine.org/qa/120419/multimeshinstance2d-culling-before-going-fully-offscreen

If we can't calculate its visibility rect automatically, it's possible that MultiMeshInstance2D may need a property to set its visibility rect manually (like GPU-based Particles2D).

@reikken
Copy link
Author

reikken commented Nov 11, 2021

It does seem like it is being calculated correctly when it does get calculated, but isn't always up to date

@kleonc
Copy link
Member

kleonc commented Nov 11, 2021

If we can't calculate its visibility rect automatically, it's possible that MultiMeshInstance2D may need a property to set its visibility rect manually (like GPU-based Particles2D).

For MultiMeshInstance (3D) GeometryInstance::set_custom_aabb() can be used.
For MultiMeshInstance2D seems like there's indeed no counterpart method allowing to set custom rect. But it should be doable using VisualServer::canvas_item_set_custom_rect():

var mmi: MultiMeshInstance2D = ...
var rect: Rect2 = ...
VisualServer.canvas_item_set_custom_rect(mmi.get_canvas_item(), true, rect)

Also it seems that MultiMesh::get_aabb() recalculates its AABB if it's dirty (in fact it triggers updating AABBs of all dirty multimeshes). So as of now this should work to manually update MultiMeshInstance2D's visibility rect:

var mmi: MultiMeshInstance2D = ...
var aabb: AABB = mmi.multimesh.get_aabb()
var rect := Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y)
VisualServer.canvas_item_set_custom_rect(mmi.get_canvas_item(), true, rect)

@akien-mga
Copy link
Member

Fixed by #54899.

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

No branches or pull requests

4 participants