added wall asset visiblity toggle and code optimization

This commit is contained in:
2025-08-23 12:26:45 +05:30
parent 8b01372d08
commit 21cd12b518
15 changed files with 172 additions and 89 deletions

View File

@@ -17,9 +17,9 @@ import material1 from '../../../../../assets/textures/floor/factory wall texture
function Wall({ wall }: { readonly wall: Wall }) {
const { wallStore, wallAssetStore } = useSceneContext();
const { walls, addDecal } = wallStore();
const { wallAssets, getAssetsByWall } = wallAssetStore();
const assets = getAssetsByWall(wall.wallUuid);
const { walls } = wallStore();
const { wallAssets, getWallAssetsByWall, setVisibility } = wallAssetStore();
const assets = getWallAssetsByWall(wall.wallUuid);
const { selectedWall, setSelectedWall, setSelectedDecal } = useBuilderStore();
const { togglView } = useToggleView();
const { activeModule } = useModuleStore();
@@ -28,6 +28,7 @@ function Wall({ wall }: { readonly wall: Wall }) {
const { getWallType, isWallFlipped } = useWallClassification(walls);
const [visible, setVisible] = useState(true);
const meshRef = useRef<any>();
const prevVisibleRef = useRef<boolean | null>(null);
const wallType = getWallType(wall);
const wallFlipped = isWallFlipped(wall);
@@ -89,15 +90,23 @@ function Wall({ wall }: { readonly wall: Wall }) {
const v = new THREE.Vector3();
const u = new THREE.Vector3();
if (!wallVisibility && wallType.type === 'room') {
let nextVisible = true;
if (!wallVisibility && wallType.type === "room") {
meshRef.current.getWorldDirection(v);
camera.getWorldDirection(u);
if (!u || !v) return;
setVisible((2 * v.dot(u)) <= 0.1);
} else {
setVisible(true);
nextVisible = (2 * v.dot(u)) <= 0.1;
}
})
if (prevVisibleRef.current !== nextVisible) {
prevVisibleRef.current = nextVisible;
setVisible(nextVisible);
assets.forEach((asset) => {
setVisibility(asset.modelUuid, nextVisible);
})
}
});
return (
<mesh
@@ -107,7 +116,7 @@ function Wall({ wall }: { readonly wall: Wall }) {
key={wall.wallUuid}
userData={wall}
>
{(assets.length > 0 || (walls[0].wallUuid === wall.wallUuid && wallAssets.length > 0)) ?
{(assets.length > 0 || (walls[0].wallUuid === wall.wallUuid && wallAssets.length > 0)) && visible ?
<Base
castShadow
receiveShadow