import { Vector3 } from "three";

onmessage = function (e) {
    const { modelUuid, assetPosition, cameraPosition, limitDistance, renderDistance, isRendered, } = e.data;

    const assetVec = new Vector3(assetPosition.x, assetPosition.y, assetPosition.z);
    const cameraVec = new Vector3(cameraPosition.x, cameraPosition.y, cameraPosition.z);
    const distance = assetVec.distanceTo(cameraVec);

    if (limitDistance) {
        if (!isRendered && distance <= renderDistance) {
            postMessage({ shouldRender: true, modelUuid });
        } else if (isRendered && distance > renderDistance) {
            postMessage({ shouldRender: false, modelUuid });
        }
    } else {
        if (!isRendered) {
            postMessage({ shouldRender: true, modelUuid });
        }
    }
};
