import * as THREE from 'three';
import * as Types from "../../../../types/world/worldTypes";
import * as CONSTANTS from '../../../../types/world/worldConstants';

function updateLines(
    floorPlanGroupLine: Types.RefGroup,
    affectedLines: Types.NumberArray
): void {

    ////////// Updating the positions for the affected lines only based on the updated positions //////////

    affectedLines.forEach((lineIndex) => {
        const mesh = floorPlanGroupLine.current.children[lineIndex] as Types.Mesh;
        const linePoints = mesh.userData.linePoints as Types.Line;
        if (linePoints) {
            const newPositions = linePoints.map(([pos]) => pos);
            const newPath = new THREE.CatmullRomCurve3(newPositions);
            mesh.geometry.dispose();
            mesh.geometry = new THREE.TubeGeometry(newPath, CONSTANTS.lineConfig.tubularSegments, CONSTANTS.lineConfig.radius, CONSTANTS.lineConfig.radialSegments, false);
        }
    });
}

export default updateLines;