From 4d08c612620c4c8e9925b3a81c0d9f30b4eeb2b6 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Wed, 7 May 2025 16:31:59 +0530 Subject: [PATCH] Add user ID to selected user state and update related components --- .../components/layout/sidebarRight/Header.tsx | 1 + .../collaboration/camera/collabCams.tsx | 37 ++++++++++++++++++- .../collaboration/camera/collabUserIcon.tsx | 3 ++ app/src/store/useCollabStore.ts | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/components/layout/sidebarRight/Header.tsx b/app/src/components/layout/sidebarRight/Header.tsx index 02917b4..3684157 100644 --- a/app/src/components/layout/sidebarRight/Header.tsx +++ b/app/src/components/layout/sidebarRight/Header.tsx @@ -42,6 +42,7 @@ const Header: React.FC = () => { setSelectedUser({ color: getAvatarColor(index, user.userName), name: user.userName, + id: user.id, location: { position, rotation, target }, }); setCamMode("FollowPerson"); diff --git a/app/src/modules/collaboration/camera/collabCams.tsx b/app/src/modules/collaboration/camera/collabCams.tsx index a3e4eb4..d4bc69e 100644 --- a/app/src/modules/collaboration/camera/collabCams.tsx +++ b/app/src/modules/collaboration/camera/collabCams.tsx @@ -20,7 +20,7 @@ const CamModelsGroup = () => { const { setActiveUsers } = useActiveUsers(); const { socket } = useSocketStore(); const { activeModule } = useModuleStore(); - const { selectedUser } = useSelectedUserStore(); + const { selectedUser, setSelectedUser } = useSelectedUserStore(); // eslint-disable-next-line react-hooks/exhaustive-deps const loader = new GLTFLoader(); @@ -126,6 +126,18 @@ const CamModelsGroup = () => { ) return; + if (selectedUser && selectedUser?.id === data.data.userId) { + setSelectedUser({ + color: selectedUser.color, + name: selectedUser.name, + id: selectedUser.id, + location: { + position: data.data.position, + rotation: data.data.rotation, + target: data.data.target, + }, + }); + } setModels((prev) => ({ ...prev, [data.data.userId]: { @@ -221,6 +233,28 @@ const CamModelsGroup = () => { }); }, []); + // collide validate + const collisionThreshold = 0.001; + + const collidedCamUUIDs = new Set(); + + for (let i = 0; i < cams.length; i++) { + for (let j = i + 1; j < cams.length; j++) { + const posA = cams[i].position; + const posB = cams[j].position; + + const distSquared = + Math.pow(posA.x - posB.x, 2) + + Math.pow(posA.y - posB.y, 2) + + Math.pow(posA.z - posB.z, 2); + + if (distSquared < collisionThreshold ** 2) { + collidedCamUUIDs.add(cams[i].uuid); + collidedCamUUIDs.add(cams[j].uuid); + } + } + } + return ( {cams.map((cam, index) => ( @@ -249,6 +283,7 @@ const CamModelsGroup = () => { = ({ userImage, userName, + id, color, position, rotation, @@ -42,6 +44,7 @@ const CollabUserIcon: React.FC = ({ if (!position || !rotation || !target) return; // Set the selected user in the store setSelectedUser({ + id: id, color: color, name: userName, location: { position, rotation, target }, diff --git a/app/src/store/useCollabStore.ts b/app/src/store/useCollabStore.ts index 3bc5077..499e857 100644 --- a/app/src/store/useCollabStore.ts +++ b/app/src/store/useCollabStore.ts @@ -3,6 +3,7 @@ import { create } from 'zustand'; interface SelectedUser { color: string; name: string; + id: string, location?: { position: { x: number;