cod eoptimization
This commit is contained in:
@@ -30,8 +30,7 @@ import material4NormalMap from "../../../../../assets/textures/floor/tex3/metal_
|
||||
function FloorInstance({ floor }: { floor: Floor }) {
|
||||
const { togglView } = useToggleView();
|
||||
const { activeModule } = useModuleStore();
|
||||
const { selectedFloor, setSelectedFloor, setSelectedDecal } =
|
||||
useBuilderStore();
|
||||
const { selectedFloor, setSelectedFloor, setSelectedDecal } = useBuilderStore();
|
||||
const savedTheme = localStorage.getItem("theme");
|
||||
|
||||
const materials: Record<
|
||||
@@ -44,12 +43,8 @@ function FloorInstance({ floor }: { floor: Floor }) {
|
||||
textureTileScale?: [number, number];
|
||||
}
|
||||
> = {
|
||||
"Default Material": {
|
||||
map: savedTheme === "dark" ? texturePathDark : texturePath,
|
||||
},
|
||||
"Material 1": {
|
||||
map: material1,
|
||||
},
|
||||
"Default Material": { map: savedTheme === "dark" ? texturePathDark : texturePath, },
|
||||
"Material 1": { map: material1 },
|
||||
"Material 2": {
|
||||
map: material2Map,
|
||||
roughnessMap: material2MetalicRoughnessMap,
|
||||
@@ -74,9 +69,7 @@ function FloorInstance({ floor }: { floor: Floor }) {
|
||||
|
||||
const shape = useMemo(() => {
|
||||
const shape = new Shape();
|
||||
const points = floor.points.map(
|
||||
(p) => new Vector2(p.position[0], p.position[2])
|
||||
);
|
||||
const points = floor.points.map((p) => new Vector2(p.position[0], p.position[2]));
|
||||
if (points.length < 3) return null;
|
||||
shape.moveTo(points[0].x, points[0].y);
|
||||
for (let i = 1; i < points.length; i++) {
|
||||
@@ -94,9 +87,7 @@ function FloorInstance({ floor }: { floor: Floor }) {
|
||||
const roughnessMap = material.roughnessMap || null;
|
||||
const metalnessMap = material.metalnessMap || null;
|
||||
|
||||
return [materialMap, normalMap, roughnessMap, metalnessMap].filter(
|
||||
(texture): texture is string => texture !== null
|
||||
);
|
||||
return [materialMap, normalMap, roughnessMap, metalnessMap].filter((texture): texture is string => texture !== null);
|
||||
}
|
||||
|
||||
// Default material map
|
||||
@@ -113,16 +104,10 @@ function FloorInstance({ floor }: { floor: Floor }) {
|
||||
// Use loader to load top and side textures
|
||||
const [topTexture, topNormalTexture, topRoughnessTexture, topMetalicTexture] = useLoader(TextureLoader, topTexturesList);
|
||||
|
||||
const [
|
||||
sideTexture,
|
||||
sideNormalTexture,
|
||||
sideRoughnessTexture,
|
||||
sideMetalicTexture,
|
||||
] = useLoader(TextureLoader, sideTexturesList);
|
||||
const [sideTexture, sideNormalTexture, sideRoughnessTexture, sideMetalicTexture] = useLoader(TextureLoader, sideTexturesList);
|
||||
|
||||
// Early exit if materials are missing
|
||||
if (!materials[floor.topMaterial] || !materials[floor.sideMaterial])
|
||||
return null;
|
||||
if (!materials[floor.topMaterial] || !materials[floor.sideMaterial]) return null;
|
||||
|
||||
// Combine and pair textures with their corresponding material
|
||||
const textureMaterialMap = [
|
||||
@@ -183,18 +168,14 @@ function FloorInstance({ floor }: { floor: Floor }) {
|
||||
}
|
||||
}}
|
||||
onPointerMissed={() => {
|
||||
if (
|
||||
selectedFloor &&
|
||||
selectedFloor.userData.floorUuid === floor.floorUuid
|
||||
) {
|
||||
if (selectedFloor && selectedFloor.userData.floorUuid === floor.floorUuid) {
|
||||
setSelectedFloor(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Extrude
|
||||
name={`Floor-${floor.floorUuid}`}
|
||||
args={[
|
||||
shape,
|
||||
args={[shape,
|
||||
{
|
||||
depth: !floor.isBeveled ? floor.floorDepth : floor.floorDepth - 0.1,
|
||||
bevelEnabled: floor.isBeveled,
|
||||
|
||||
Reference in New Issue
Block a user