Dwinzo_dev/app/src/modules/duplicate/duplicateBuilder/duplicateWall/wallMeshDuplicate.tsx

69 lines
2.6 KiB
TypeScript

import * as THREE from "three";
import * as Types from "../../../../types/world/worldTypes";
import * as CONSTANTS from "../../../../types/world/worldConstants";
import { Base } from "@react-three/csg";
import { MeshDiscardMaterial } from "@react-three/drei";
import React, { useEffect } from "react";
import objectLinesToArray from "../../../builder/geomentries/lines/lineConvertions/objectLinesToArray";
import loadWalls from "../../../builder/geomentries/walls/loadWalls";
import texturePath from "../../../../assets/textures/floor/wall-tex.png";
import { getLines } from "../../../../services/factoryBuilder/lines/getLinesApi";
const WallsMeshDuplicate = ({ projectId, walls, setWalls, lines }: any) => {
useEffect(() => {
const email = localStorage.getItem("email");
const organization = email!.split("@")[1].split(".")[0];
getLines(organization, projectId).then((data) => {
const Lines: Types.Lines = objectLinesToArray(data);
if (Lines) {
lines.current = Lines;
loadWalls(lines, setWalls);
}
});
}, []);
const wallTexture = React.useMemo(() => {
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load(texturePath);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(0.1, 0.1);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}, []);
return (
<>
{walls.map((wall: Types.Wall, index: number) => (
<mesh key={index} renderOrder={1}>
<Base
name={`Wall${index + 1}`}
geometry={wall[0]}
rotation={wall[1]}
position={wall[2]}
userData={{ WallType: wall[3], Layer: wall[4] }}
>
<meshStandardMaterial
side={THREE.DoubleSide}
color={CONSTANTS.wallConfig.defaultColor}
map={wallTexture}
/>
</Base>
<mesh
castShadow
geometry={wall[0]}
rotation={wall[1]}
position={wall[2]}
name={`WallRaycastReference_${index + 1}`}
>
<MeshDiscardMaterial />
</mesh>
</mesh>
))}
</>
);
};
export default WallsMeshDuplicate;