import * as THREE from 'three';

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

function TempLoader(
    intersectPoint: Types.Vector3,
    isTempLoader: Types.RefBoolean,
    tempLoader: Types.RefMesh,
    itemsGroup: Types.RefGroup
): void {

    //////////  Temporary Loader that indicates the gltf is being loaded  //////////

    //////////  Bug:  Can't Load More than one TempLoader if done, it won't leave the scene  //////////

    if (tempLoader.current) {
        itemsGroup.current.remove(tempLoader.current);
    }
    if (isTempLoader.current) {
        const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
        const cubeMaterial = new THREE.MeshBasicMaterial({ color: "white" });
        tempLoader.current = new THREE.Mesh(cubeGeometry, cubeMaterial);
        tempLoader.current.position.set(intersectPoint.x, 0.5 + intersectPoint.y, intersectPoint.z);
        itemsGroup.current.add(tempLoader.current);
        isTempLoader.current = false;
    }
}

export default TempLoader;
