boundary.worker.js 1.77 KB
const _worker_getMaxMinZValue = `
getMaxMinZValue = (position, matrix) => {
    const e = matrix.elements;
    let xMin = yMin = zMin = Infinity;
    let xMax = yMax = zMax = -Infinity;
    let x, y, z, w;
    let cx, cy, cz;
    let i = position.array.length / 3 - 1;
    while (i >= 0) {
        x = position.array[ i * 3 + 0];
        y = position.array[ i * 3 + 1];
        z = position.array[ i * 3 + 2];
        w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
        cx = ( e[0] * x + e[4] * y + e[8] * z + e[12] ) * w;
		cy = ( e[1] * x + e[5] * y + e[9] * z + e[13] ) * w;
        cz = ( e[2] * x + e[6] * y + e[10] * z + e[14]) * w;

        xMin = Math.min(cx, xMin);
        yMin = Math.min(cy, yMin);
        zMin = Math.min(cz, zMin);

        xMax = Math.max(cx, xMax);
        yMax = Math.max(cy, yMax);
        zMax = Math.max(cz, zMax);
        --i;
    }
    return {
        xMax, yMax, zMax, xMin, yMin, zMin
    };
};

getMaxMinZValues = (positions,matrixs) => {
    let vxMin = vyMin = vzMin = Infinity;
    let vxMax = vyMax = vzMax = -Infinity;
    positions.forEach((el , index) => {
        const { xMax, yMax, zMax, xMin, yMin, zMin } = this.getMaxMinZValue(el, matrixs[index]);

        vxMin = Math.min(xMin, vxMin);
        vyMin = Math.min(yMin, vyMin);
        vzMin = Math.min(zMin, vzMin);

        vxMax = Math.max(xMax, vxMax);
        vyMax = Math.max(yMax, vyMax);
        vzMax = Math.max(zMax, vzMax);
    });
    return {
        min: { x: vxMin, y: vyMin, z: vzMin },
        max: { x: vxMax, y: vyMax, z: vzMax }
    };
};

onmessage = (e) => {
    const {id , positions , matrixs } = e.data;
    const { max, min } = this.getMaxMinZValues(positions, matrixs);
    postMessage({ id: id, response: { max, min } });
    close();
};
`;

export { _worker_getMaxMinZValue };