davidfig / pixi-cull

a library to visibly cull objects designed to work with pixi.js
MIT License
109 stars 14 forks source link

How to handle local coordinates? #24

Open KKzLEO opened 2 years ago

KKzLEO commented 2 years ago

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?

davidfig commented 2 years ago

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.

ArthurTimofey commented 2 months ago

@KKzLEO were you able to come to a solution?