import * as Types from "../../../../types/world/worldTypes";

let lastUpdateTime = 0;

export default function assetVisibility(
    itemsGroup: Types.RefGroup,
    cameraPosition: Types.Vector3,
    renderDistance: Types.Number,
    throttleTime = 100
): void {
    const now = performance.now();
    if (now - lastUpdateTime < throttleTime) return;
    lastUpdateTime = now;

    if (!itemsGroup?.current || !cameraPosition) return;

    itemsGroup.current.children.forEach((child) => {
        const Distance = cameraPosition.distanceTo(child.position);
        if (Distance <= renderDistance) {
            child.visible = true;
        } else {
            child.visible = false;
        }
    });
}
