feat: Log camera update response data for debugging purposes; adjust user position parameter in findEnvironment function
This commit is contained in:
parent
58d82da349
commit
c5d4507400
|
@ -12,39 +12,54 @@ import CollabUserIcon from "./collabUserIcon";
|
||||||
import { getAvatarColor } from "./users/functions/getAvatarColor";
|
import { getAvatarColor } from "./users/functions/getAvatarColor";
|
||||||
|
|
||||||
const CamModelsGroup = () => {
|
const CamModelsGroup = () => {
|
||||||
let navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const groupRef = useRef<THREE.Group>(null);
|
const groupRef = useRef<THREE.Group>(null);
|
||||||
const email = localStorage.getItem("email");
|
const email = localStorage.getItem("email");
|
||||||
const { activeUsers, setActiveUsers } = useActiveUsers();
|
const { activeUsers, setActiveUsers } = useActiveUsers();
|
||||||
const { socket } = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
|
|
||||||
const loader = new GLTFLoader();
|
const loader = new GLTFLoader();
|
||||||
const dracoLoader = new DRACOLoader();
|
const dracoLoader = new DRACOLoader();
|
||||||
const [cams, setCams] = useState<any[]>([]);
|
|
||||||
const [models, setModels] = useState<Record<string, { targetPosition: THREE.Vector3; targetRotation: THREE.Euler }>>({});
|
|
||||||
|
|
||||||
dracoLoader.setDecoderPath("three/examples/jsm/libs/draco/gltf/");
|
dracoLoader.setDecoderPath("three/examples/jsm/libs/draco/gltf/");
|
||||||
loader.setDRACOLoader(dracoLoader);
|
loader.setDRACOLoader(dracoLoader);
|
||||||
|
|
||||||
|
const [cams, setCams] = useState<any[]>([]);
|
||||||
|
const [models, setModels] = useState<Record<string, { targetPosition: THREE.Vector3; targetRotation: THREE.Euler }>>({});
|
||||||
|
|
||||||
|
const dedupeCams = (cams: any[]) => {
|
||||||
|
const seen = new Set();
|
||||||
|
return cams.filter((cam) => {
|
||||||
|
if (seen.has(cam.uuid)) return false;
|
||||||
|
seen.add(cam.uuid);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const dedupeUsers = (users: any[]) => {
|
||||||
|
const seen = new Set();
|
||||||
|
return users.filter((user) => {
|
||||||
|
if (seen.has(user._id)) return false;
|
||||||
|
seen.add(user._id);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!email) {
|
if (!email) navigate("/");
|
||||||
navigate("/");
|
|
||||||
}
|
|
||||||
if (!socket) return;
|
if (!socket) return;
|
||||||
const organization = email!.split("@")[1].split(".")[0];
|
const organization = email!.split("@")[1].split(".")[0];
|
||||||
|
|
||||||
socket.on("userConnectResponse", (data: any) => {
|
socket.on("userConnectResponse", (data: any) => {
|
||||||
if (!groupRef.current) return;
|
if (!groupRef.current) return;
|
||||||
if (data.data.userData.email === email) return;
|
if (data.data.userData.email === email) return;
|
||||||
if (socket.id === data.socketId || organization !== data.organization)
|
if (socket.id === data.socketId || organization !== data.organization) return;
|
||||||
return;
|
|
||||||
|
|
||||||
const model = groupRef.current.getObjectByProperty(
|
const model = groupRef.current.getObjectByProperty("uuid", data.data.userData._id);
|
||||||
"uuid",
|
|
||||||
data.data.userData._id
|
|
||||||
);
|
|
||||||
if (model) {
|
if (model) {
|
||||||
groupRef.current.remove(model);
|
groupRef.current.remove(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.load(camModel, (gltf) => {
|
loader.load(camModel, (gltf) => {
|
||||||
const newModel = gltf.scene.clone();
|
const newModel = gltf.scene.clone();
|
||||||
newModel.uuid = data.data.userData._id;
|
newModel.uuid = data.data.userData._id;
|
||||||
|
@ -59,25 +74,23 @@ const CamModelsGroup = () => {
|
||||||
data.data.rotation.z
|
data.data.rotation.z
|
||||||
);
|
);
|
||||||
newModel.userData = data.data.userData;
|
newModel.userData = data.data.userData;
|
||||||
setCams((prev) => [...prev, newModel]);
|
|
||||||
setActiveUsers([...activeUsers, data.data.userData]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// socket.on("users:online", (data: any) => {
|
setCams((prev) => dedupeCams([...prev, newModel]));
|
||||||
// console.log('users online: ', data);
|
setActiveUsers((prev: any) =>
|
||||||
// })
|
dedupeUsers([...prev, data.data.userData])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
socket.on("userDisConnectResponse", (data: any) => {
|
socket.on("userDisConnectResponse", (data: any) => {
|
||||||
if (!groupRef.current) return;
|
if (!groupRef.current) return;
|
||||||
if (socket.id === data.socketId || organization !== data.organization)
|
if (socket.id === data.socketId || organization !== data.organization) return;
|
||||||
return;
|
|
||||||
|
|
||||||
setCams((prev) =>
|
setCams((prev) =>
|
||||||
prev.filter((cam) => cam.uuid !== data.data.userData._id)
|
prev.filter((cam) => cam.uuid !== data.data.userData._id)
|
||||||
);
|
);
|
||||||
setActiveUsers(
|
setActiveUsers((prev: any) =>
|
||||||
activeUsers.filter((user: any) => user._id !== data.data.userData._id)
|
prev.filter((user: any) => user._id !== data.data.userData._id)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -107,21 +120,12 @@ const CamModelsGroup = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.off("userConnectRespones");
|
socket.off("userConnectResponse");
|
||||||
socket.off("userDisConnectRespones");
|
socket.off("userDisConnectResponse");
|
||||||
socket.off("cameraUpdateResponse");
|
socket.off("cameraUpdateResponse");
|
||||||
};
|
};
|
||||||
}, [socket]);
|
}, [socket]);
|
||||||
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// console.log(activeUsers);
|
|
||||||
// }, [activeUsers])
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// console.log(models);
|
|
||||||
// }, [models])
|
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (!groupRef.current) return;
|
if (!groupRef.current) return;
|
||||||
Object.keys(models).forEach((uuid) => {
|
Object.keys(models).forEach((uuid) => {
|
||||||
|
@ -130,53 +134,35 @@ const CamModelsGroup = () => {
|
||||||
|
|
||||||
const { targetPosition, targetRotation } = models[uuid];
|
const { targetPosition, targetRotation } = models[uuid];
|
||||||
model.position.lerp(targetPosition, 0.1);
|
model.position.lerp(targetPosition, 0.1);
|
||||||
model.rotation.x = THREE.MathUtils.lerp(
|
model.rotation.x = THREE.MathUtils.lerp(model.rotation.x, targetRotation.x, 0.1);
|
||||||
model.rotation.x,
|
model.rotation.y = THREE.MathUtils.lerp(model.rotation.y, targetRotation.y, 0.1);
|
||||||
targetRotation.x,
|
model.rotation.z = THREE.MathUtils.lerp(model.rotation.z, targetRotation.z, 0.1);
|
||||||
0.1
|
|
||||||
);
|
|
||||||
model.rotation.y = THREE.MathUtils.lerp(
|
|
||||||
model.rotation.y,
|
|
||||||
targetRotation.y,
|
|
||||||
0.1
|
|
||||||
);
|
|
||||||
model.rotation.z = THREE.MathUtils.lerp(
|
|
||||||
model.rotation.z,
|
|
||||||
targetRotation.z,
|
|
||||||
0.1
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!groupRef.current) return;
|
if (!groupRef.current) return;
|
||||||
const organization = email!.split("@")[1].split(".")[0];
|
const organization = email!.split("@")[1].split(".")[0];
|
||||||
|
|
||||||
getActiveUsersData(organization).then((data) => {
|
getActiveUsersData(organization).then((data) => {
|
||||||
const filteredData = data.cameraDatas.filter(
|
const filteredData = data.cameraDatas.filter(
|
||||||
(camera: any) => camera.userData.email !== email
|
(camera: any) => camera.userData.email !== email
|
||||||
);
|
);
|
||||||
let a: any = [];
|
|
||||||
if (filteredData.length > 0) {
|
if (filteredData.length > 0) {
|
||||||
loader.load(camModel, (gltf) => {
|
loader.load(camModel, (gltf) => {
|
||||||
const newCams = filteredData.map((cam: any) => {
|
const newCams = filteredData.map((cam: any) => {
|
||||||
const newModel = gltf.scene.clone();
|
const newModel = gltf.scene.clone();
|
||||||
newModel.uuid = cam.userData._id;
|
newModel.uuid = cam.userData._id;
|
||||||
newModel.position.set(
|
newModel.position.set(cam.position.x, cam.position.y, cam.position.z);
|
||||||
cam.position.x,
|
newModel.rotation.set(cam.rotation.x, cam.rotation.y, cam.rotation.z);
|
||||||
cam.position.y,
|
|
||||||
cam.position.z
|
|
||||||
);
|
|
||||||
newModel.rotation.set(
|
|
||||||
cam.rotation.x,
|
|
||||||
cam.rotation.y,
|
|
||||||
cam.rotation.z
|
|
||||||
);
|
|
||||||
newModel.userData = cam.userData;
|
newModel.userData = cam.userData;
|
||||||
a.push(cam.userData);
|
|
||||||
return newModel;
|
return newModel;
|
||||||
});
|
});
|
||||||
setActiveUsers(a);
|
|
||||||
setCams((prev) => [...prev, ...newCams]);
|
const users = filteredData.map((cam: any) => cam.userData);
|
||||||
|
setActiveUsers((prev: any) => dedupeUsers([...prev, ...users]));
|
||||||
|
setCams((prev) => dedupeCams([...prev, ...newCams]));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -185,7 +171,7 @@ const CamModelsGroup = () => {
|
||||||
return (
|
return (
|
||||||
<group ref={groupRef} name="Cam-Model-Group">
|
<group ref={groupRef} name="Cam-Model-Group">
|
||||||
{cams.map((cam, index) => (
|
{cams.map((cam, index) => (
|
||||||
<primitive key={index} object={cam}>
|
<primitive key={cam.uuid} object={cam}>
|
||||||
<Html
|
<Html
|
||||||
as="div"
|
as="div"
|
||||||
center
|
center
|
||||||
|
|
|
@ -20,7 +20,24 @@ const CollabUserIcon: React.FC<CollabUserIconProps> = ({
|
||||||
{userImage ? (
|
{userImage ? (
|
||||||
<img className="user-image" src={userImage} alt={userName} />
|
<img className="user-image" src={userImage} alt={userName} />
|
||||||
) : (
|
) : (
|
||||||
<CustomAvatar name={userName} index={index} />
|
<CustomAvatar name={userName} index={index} color={color} />
|
||||||
|
// <div
|
||||||
|
// className="user-image"
|
||||||
|
// style={{
|
||||||
|
// lineHeight: "30px",
|
||||||
|
// textTransform: "uppercase",
|
||||||
|
// textAlign: "center",
|
||||||
|
// fontSize: "16px",
|
||||||
|
// borderRadius: "50%",
|
||||||
|
// backgroundColor: color,
|
||||||
|
// overflow: "hidden",
|
||||||
|
// backgroundSize: "cover",
|
||||||
|
// backgroundPosition: "center",
|
||||||
|
// color: "white",
|
||||||
|
// fontWeight: "bold",
|
||||||
|
// }}>
|
||||||
|
// {userName[0]}
|
||||||
|
// </div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="user-name" style={{ backgroundColor: color }}>
|
<div className="user-name" style={{ backgroundColor: color }}>
|
||||||
|
|
|
@ -233,7 +233,7 @@ export default function SocketResponses({
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (data.message === "Model updated successfully") {
|
} else if (data.message === "Model updated successfully") {
|
||||||
itemsGroup.current.children.forEach((item: THREE.Group) => {
|
itemsGroup.current?.children.forEach((item: THREE.Group) => {
|
||||||
if (item.uuid === data.data.modeluuid) {
|
if (item.uuid === data.data.modeluuid) {
|
||||||
item.position.set(...data.data.position as [number, number, number]);
|
item.position.set(...data.data.position as [number, number, number]);
|
||||||
item.rotation.set(data.data.rotation.x, data.data.rotation.y, data.data.rotation.z);
|
item.rotation.set(data.data.rotation.x, data.data.rotation.y, data.data.rotation.z);
|
||||||
|
|
|
@ -7,6 +7,7 @@ interface AvatarProps {
|
||||||
size?: number;
|
size?: number;
|
||||||
index?: number;
|
index?: number;
|
||||||
textColor?: string;
|
textColor?: string;
|
||||||
|
color?: string; // Optional color prop for future use
|
||||||
}
|
}
|
||||||
|
|
||||||
const CustomAvatar: React.FC<AvatarProps> = ({
|
const CustomAvatar: React.FC<AvatarProps> = ({
|
||||||
|
@ -14,6 +15,7 @@ const CustomAvatar: React.FC<AvatarProps> = ({
|
||||||
size = 100,
|
size = 100,
|
||||||
index = 0,
|
index = 0,
|
||||||
textColor = "#ffffff",
|
textColor = "#ffffff",
|
||||||
|
color, // Optional color prop for future use
|
||||||
}) => {
|
}) => {
|
||||||
const [imageSrc, setImageSrc] = useState<string | null>(null);
|
const [imageSrc, setImageSrc] = useState<string | null>(null);
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ const CustomAvatar: React.FC<AvatarProps> = ({
|
||||||
const initials = getInitials(name); // Convert name to initials if needed
|
const initials = getInitials(name); // Convert name to initials if needed
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
ctx.fillStyle = getAvatarColor(index);
|
ctx.fillStyle = color || getAvatarColor(index); // Use color prop or generate color based on index
|
||||||
ctx.fillRect(0, 0, size, size);
|
ctx.fillRect(0, 0, size, size);
|
||||||
|
|
||||||
// Draw initials
|
// Draw initials
|
||||||
|
@ -40,7 +42,7 @@ const CustomAvatar: React.FC<AvatarProps> = ({
|
||||||
const dataURL = canvas.toDataURL("image/png");
|
const dataURL = canvas.toDataURL("image/png");
|
||||||
setImageSrc(dataURL);
|
setImageSrc(dataURL);
|
||||||
}
|
}
|
||||||
}, [name, size, textColor]);
|
}, [name, size, textColor, index]);
|
||||||
|
|
||||||
if (!imageSrc) {
|
if (!imageSrc) {
|
||||||
return null; // Return null while the image is being generated
|
return null; // Return null while the image is being generated
|
||||||
|
@ -53,6 +55,18 @@ const CustomAvatar: React.FC<AvatarProps> = ({
|
||||||
alt="User Avatar"
|
alt="User Avatar"
|
||||||
style={{ width: "100%", height: "100%" }}
|
style={{ width: "100%", height: "100%" }}
|
||||||
/>
|
/>
|
||||||
|
// <div
|
||||||
|
// className="user-image"
|
||||||
|
// style={{
|
||||||
|
// width: size,
|
||||||
|
// height: size,
|
||||||
|
// borderRadius: "50%",
|
||||||
|
// overflow: "hidden",
|
||||||
|
// backgroundSize: "cover",
|
||||||
|
// backgroundPosition: "center",
|
||||||
|
// }}>
|
||||||
|
// {name[0]}
|
||||||
|
// </div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const findEnvironment = async (organization: string, userId: string) => {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
0,
|
40,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
return userpos;
|
return userpos;
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||||
const socket = io(
|
const socket = io(
|
||||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/Builder`,
|
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/Builder`,
|
||||||
{
|
{
|
||||||
reconnection: false,
|
reconnection: true,
|
||||||
auth: { email, organization },
|
auth: { email, organization },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,7 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||||
const visualizationSocket = io(
|
const visualizationSocket = io(
|
||||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/Visualization`,
|
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/Visualization`,
|
||||||
{
|
{
|
||||||
reconnection: false,
|
reconnection: true,
|
||||||
auth: { email, organization },
|
auth: { email, organization },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -302,7 +302,13 @@ export const useDrieTemp = create<any>((set: any) => ({
|
||||||
|
|
||||||
export const useActiveUsers = create<any>((set: any) => ({
|
export const useActiveUsers = create<any>((set: any) => ({
|
||||||
activeUsers: [],
|
activeUsers: [],
|
||||||
setActiveUsers: (x: any) => set({ activeUsers: x }),
|
setActiveUsers: (callback: (prev: any[]) => any[] | any[]) =>
|
||||||
|
set((state: { activeUsers: any[] }) => ({
|
||||||
|
activeUsers:
|
||||||
|
typeof callback === "function"
|
||||||
|
? callback(state.activeUsers)
|
||||||
|
: callback,
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useDrieUIValue = create<any>((set: any) => ({
|
export const useDrieUIValue = create<any>((set: any) => ({
|
||||||
|
|
Loading…
Reference in New Issue