refactor: remove unnecessary setIsPaused calls in ComparisonScene and CompareLayOut; improve wall visibility logic in hideWalls

This commit is contained in:
Jerald-Golden-B 2025-06-12 12:07:28 +05:30
parent 8f0e005200
commit b3c4f9eb65
4 changed files with 28 additions and 22 deletions

View File

@ -24,7 +24,6 @@ function ComparisonScene() {
const product = products.find((product) => product.productName === option); const product = products.find((product) => product.productName === option);
if (product) { if (product) {
setComparisonProduct(product.productUuid, product.productName); setComparisonProduct(product.productUuid, product.productName);
setIsPaused(true);
} }
}; };
return ( return (

View File

@ -1,4 +1,4 @@
import React from "react"; import React, { useEffect } from "react";
import { import {
useLoadingProgress, useLoadingProgress,
useRenameModeStore, useRenameModeStore,
@ -42,7 +42,7 @@ function MainScene() {
const { setMainProduct } = useMainProduct(); const { setMainProduct } = useMainProduct();
const { selectedProductStore } = useProductContext(); const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore(); const { selectedProduct } = selectedProductStore();
const { isVersionSaved } = useSaveVersion(); const { isVersionSaved, setIsVersionSaved } = useSaveVersion();
const { activeModule } = useModuleStore(); const { activeModule } = useModuleStore();
const { selectedUser } = useSelectedUserStore(); const { selectedUser } = useSelectedUserStore();
const { loadingProgress } = useLoadingProgress(); const { loadingProgress } = useLoadingProgress();
@ -52,11 +52,19 @@ function MainScene() {
const { visualizationSocket } = useSocketStore(); const { visualizationSocket } = useSocketStore();
const { selectedZone } = useSelectedZoneStore(); const { selectedZone } = useSelectedZoneStore();
const { setFloatingWidget } = useFloatingWidget(); const { setFloatingWidget } = useFloatingWidget();
const { comparisonProduct } = useComparisonProduct(); const { clearComparisonProduct } = useComparisonProduct();
const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem(); const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem();
const { setName } = useAssetsStore(); const { setName } = useAssetsStore();
const { projectId } = useParams() const { projectId } = useParams()
const { isRenameMode, setIsRenameMode } = useRenameModeStore(); const { isRenameMode, setIsRenameMode } = useRenameModeStore();
useEffect(() => {
if (activeModule !== 'simulation') {
clearComparisonProduct();
setIsVersionSaved(false);
}
}, [activeModule])
const handleSelectLayout = (option: string) => { const handleSelectLayout = (option: string) => {
const product = products.find((product) => product.productName === option); const product = products.find((product) => product.productName === option);
if (product) { if (product) {
@ -99,10 +107,10 @@ function MainScene() {
{activeModule !== "market" && !isPlaying && !isVersionSaved && ( {activeModule !== "market" && !isPlaying && !isVersionSaved && (
<Tools /> <Tools />
)} )}
{(isPlaying || comparisonProduct !== null) && {(isPlaying) &&
activeModule === "simulation" && activeModule === "simulation" &&
loadingProgress == 0 && <SimulationPlayer />} loadingProgress == 0 && <SimulationPlayer />}
{(isPlaying || comparisonProduct !== null) && {(isPlaying) &&
activeModule !== "simulation" && <ControlsPlayer />} activeModule !== "simulation" && <ControlsPlayer />}
{isRenameMode && selectedFloorItem?.userData.modelName && <RenameTooltip name={selectedFloorItem?.userData.modelName} onSubmit={handleObjectRename} />} {isRenameMode && selectedFloorItem?.userData.modelName && <RenameTooltip name={selectedFloorItem?.userData.modelName} onSubmit={handleObjectRename} />}

View File

@ -118,7 +118,6 @@ const CompareLayOut = () => {
if (product) { if (product) {
setComparisonProduct(product.productUuid, product.productName); setComparisonProduct(product.productUuid, product.productName);
setLoadingProgress(1); setLoadingProgress(1);
setIsPaused(true);
} }
}; };

View File

@ -1,5 +1,4 @@
import * as THREE from 'three'; import * as THREE from 'three';
import * as Types from "../../../../types/world/worldTypes"; import * as Types from "../../../../types/world/worldTypes";
function hideWalls( function hideWalls(
@ -7,21 +6,24 @@ function hideWalls(
scene: THREE.Scene, scene: THREE.Scene,
camera: THREE.Camera camera: THREE.Camera
): void { ): void {
const wallNormal = new THREE.Vector3();
////////// Altering the visibility of the Walls when the world direction of the wall is facing the camera ////////// const cameraToWall = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
const v = new THREE.Vector3();
const u = new THREE.Vector3();
if (visibility === true) { if (visibility === true) {
for (const children of scene.children) { for (const children of scene.children) {
if (children.name === "Walls" && children.children[0]?.children.length > 0) { if (children.name === "Walls" && children.children[0]?.children.length > 0) {
children.children[0].children.forEach((child: any) => { children.children[0].children.forEach((child: any) => {
if (child.children[0]?.userData.WallType === "RoomWall") { if (child.children[0]?.userData.WallType === "RoomWall") {
child.children[0].getWorldDirection(v); const wallMesh = child.children[0];
camera.getWorldDirection(u); wallMesh.getWorldDirection(wallNormal);
if (child.children[0].material) { cameraToWall.copy(wallMesh.position).sub(camera.position).normalize();
child.children[0].material.visible = (2 * v.dot(u)) >= -0.5; camera.getWorldDirection(cameraDirection);
const isFacingCamera = wallNormal.dot(cameraToWall) > 0;
const isInFrontOfCamera = cameraDirection.dot(cameraToWall) > -0.3;
if (wallMesh.material) {
wallMesh.material.visible = isFacingCamera && isInFrontOfCamera;
} }
} }
}); });
@ -31,10 +33,8 @@ function hideWalls(
for (const children of scene.children) { for (const children of scene.children) {
if (children.name === "Walls" && children.children[0]?.children.length > 0) { if (children.name === "Walls" && children.children[0]?.children.length > 0) {
children.children[0].children.forEach((child: any) => { children.children[0].children.forEach((child: any) => {
if (child.children[0]?.userData.WallType === "RoomWall") { if (child.children[0]?.userData.WallType === "RoomWall" && child.children[0].material) {
if (child.children[0].material) { child.children[0].material.visible = true;
child.children[0].material.visible = true;
}
} }
}); });
} }
@ -42,4 +42,4 @@ function hideWalls(
} }
} }
export default hideWalls; export default hideWalls;