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