Add user ID to selected user state and update related components
This commit is contained in:
@@ -42,6 +42,7 @@ const Header: React.FC = () => {
|
|||||||
setSelectedUser({
|
setSelectedUser({
|
||||||
color: getAvatarColor(index, user.userName),
|
color: getAvatarColor(index, user.userName),
|
||||||
name: user.userName,
|
name: user.userName,
|
||||||
|
id: user.id,
|
||||||
location: { position, rotation, target },
|
location: { position, rotation, target },
|
||||||
});
|
});
|
||||||
setCamMode("FollowPerson");
|
setCamMode("FollowPerson");
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const CamModelsGroup = () => {
|
|||||||
const { setActiveUsers } = useActiveUsers();
|
const { setActiveUsers } = useActiveUsers();
|
||||||
const { socket } = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
const { activeModule } = useModuleStore();
|
const { activeModule } = useModuleStore();
|
||||||
const { selectedUser } = useSelectedUserStore();
|
const { selectedUser, setSelectedUser } = useSelectedUserStore();
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
const loader = new GLTFLoader();
|
const loader = new GLTFLoader();
|
||||||
@@ -126,6 +126,18 @@ const CamModelsGroup = () => {
|
|||||||
)
|
)
|
||||||
return;
|
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) => ({
|
setModels((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[data.data.userId]: {
|
[data.data.userId]: {
|
||||||
@@ -221,6 +233,28 @@ const CamModelsGroup = () => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// collide validate
|
||||||
|
const collisionThreshold = 0.001;
|
||||||
|
|
||||||
|
const collidedCamUUIDs = new Set<string>();
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<group ref={groupRef} name="Cam-Model-Group">
|
<group ref={groupRef} name="Cam-Model-Group">
|
||||||
{cams.map((cam, index) => (
|
{cams.map((cam, index) => (
|
||||||
@@ -249,6 +283,7 @@ const CamModelsGroup = () => {
|
|||||||
<CollabUserIcon
|
<CollabUserIcon
|
||||||
userImage={cam.userData.userImage ?? ""}
|
userImage={cam.userData.userImage ?? ""}
|
||||||
userName={cam.userData.userName}
|
userName={cam.userData.userName}
|
||||||
|
id={cam.userData._id}
|
||||||
color={getAvatarColor(index, cam.userData.userName)}
|
color={getAvatarColor(index, cam.userData.userName)}
|
||||||
position={cam.position}
|
position={cam.position}
|
||||||
rotation={cam.rotation}
|
rotation={cam.rotation}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface CollabUserIconProps {
|
|||||||
userName: string;
|
userName: string;
|
||||||
userImage?: string;
|
userImage?: string;
|
||||||
color: string;
|
color: string;
|
||||||
|
id: string,
|
||||||
position?: {
|
position?: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
@@ -27,6 +28,7 @@ interface CollabUserIconProps {
|
|||||||
const CollabUserIcon: React.FC<CollabUserIconProps> = ({
|
const CollabUserIcon: React.FC<CollabUserIconProps> = ({
|
||||||
userImage,
|
userImage,
|
||||||
userName,
|
userName,
|
||||||
|
id,
|
||||||
color,
|
color,
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
@@ -42,6 +44,7 @@ const CollabUserIcon: React.FC<CollabUserIconProps> = ({
|
|||||||
if (!position || !rotation || !target) return;
|
if (!position || !rotation || !target) return;
|
||||||
// Set the selected user in the store
|
// Set the selected user in the store
|
||||||
setSelectedUser({
|
setSelectedUser({
|
||||||
|
id: id,
|
||||||
color: color,
|
color: color,
|
||||||
name: userName,
|
name: userName,
|
||||||
location: { position, rotation, target },
|
location: { position, rotation, target },
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { create } from 'zustand';
|
|||||||
interface SelectedUser {
|
interface SelectedUser {
|
||||||
color: string;
|
color: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
id: string,
|
||||||
location?: {
|
location?: {
|
||||||
position: {
|
position: {
|
||||||
x: number;
|
x: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user