pixi-cull icon indicating copy to clipboard operation
pixi-cull copied to clipboard

How to handle local coordinates?

Open KKzLEO opened this issue 4 years ago • 2 comments

Hi, thanks for creating this library, it's awesome. I encountered an issue is that my coordinate system is based on container, so the structure will be like image

the coordinate of my graphics object is a local coordinate(relative to the parent container), and I wanna do culling so I add the children of the container to cull object, it will be like

const collectChildren = (viewport: Viewport) => {
  return _flatten((viewport.children as Container[]).map(({ children }) => children));
};

cull.addList(collectChildren(viewport));
cull.cull(viewport.getVisibleBounds());

seems the cull method is to use the x and y of the object directly instead of worldTransforms.x to do a comparison, it will cull some objects that are still in my view unexpectedly, is there any direction I can try?

KKzLEO avatar Oct 05 '21 09:10 KKzLEO

When I wrote this library, I ran into a bunch of problems with pixi's getBounds implementation. I ended up rolling a simpler version that, regrettably, assumes it shares a coordinate system with the viewport. An update to the library using getLocalBounds relative to a set parent (like the viewport) would fix the issue. I'm happy to accept a PR if you have the time. Otherwise you can extends SpatialHash or Simple to change the updateObject function with this type of functionality.

davidfig avatar Oct 05 '21 16:10 davidfig

@KKzLEO were you able to come to a solution?

ArthurTimofey avatar Apr 25 '24 11:04 ArthurTimofey