rotation added
This commit is contained in:
parent
713738520b
commit
60b778ff3d
|
@ -30,14 +30,13 @@ interface ProductionCapacityProps {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
onContextMenu?: (event: React.MouseEvent) => void;
|
onContextMenu?: (event: React.MouseEvent) => void;
|
||||||
// onPointerDown:any
|
// onPointerDown:any
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductionCapacity: React.FC<ProductionCapacityProps> = ({ id, type, position, onContextMenu }) => {
|
const ProductionCapacity: React.FC<ProductionCapacityProps> = ({ id, type, position, rotation, onContextMenu }) => {
|
||||||
|
|
||||||
const { selectedChartId, setSelectedChartId } = useWidgetStore();
|
const { selectedChartId, setSelectedChartId } = useWidgetStore();
|
||||||
|
|
||||||
const { measurements: chartMeasurements, duration: chartDuration, name: widgetName } = useChartStore();
|
const { measurements: chartMeasurements, duration: chartDuration, name: widgetName } = useChartStore();
|
||||||
const [measurements, setmeasurements] = useState<any>({});
|
const [measurements, setmeasurements] = useState<any>({});
|
||||||
const [duration, setDuration] = useState("1h")
|
const [duration, setDuration] = useState("1h")
|
||||||
|
@ -177,15 +176,43 @@ const ProductionCapacity: React.FC<ProductionCapacityProps> = ({ id, type, posit
|
||||||
}
|
}
|
||||||
, [chartMeasurements, chartDuration, widgetName])
|
, [chartMeasurements, chartDuration, widgetName])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
|
||||||
|
console.log('rotation: ', rotation);
|
||||||
|
}, [rotation])
|
||||||
|
const rotationDegrees = {
|
||||||
|
x: (rotation[0] * 180) / Math.PI,
|
||||||
|
y: (rotation[1] * 180) / Math.PI,
|
||||||
|
z: (rotation[2] * 180) / Math.PI,
|
||||||
|
};
|
||||||
|
|
||||||
|
const transformStyle = {
|
||||||
|
transform: `rotateX(${rotationDegrees.x}deg) rotateY(${rotationDegrees.y}deg) rotateZ(${rotationDegrees.z}deg)`,
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Html position={[position[0], position[1], position[2]]}
|
<Html position={position}
|
||||||
scale={[0.5, 0.5, 0.5]}
|
scale={[0.5, 0.5, 0.5]}
|
||||||
zIndexRange={[1, 0]}
|
|
||||||
transform
|
transform
|
||||||
sprite>
|
sprite
|
||||||
|
zIndexRange={[1,0]}
|
||||||
|
// center
|
||||||
|
// distanceFactor={10} // Adjusted for visual balance
|
||||||
|
style={{
|
||||||
|
transform: transformStyle.transform,
|
||||||
|
transformStyle: 'preserve-3d',
|
||||||
|
transition: 'transform 0.1s ease-out'
|
||||||
|
|
||||||
|
}}>
|
||||||
<div className="productionCapacity-wrapper card"
|
<div className="productionCapacity-wrapper card"
|
||||||
onClick={() => setSelectedChartId({ id: id, type: type })}
|
onClick={() => setSelectedChartId({ id: id, type: type })}
|
||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
|
style={{
|
||||||
|
width: '300px', // Original width
|
||||||
|
height: '300px', // Original height
|
||||||
|
transform: transformStyle.transform,
|
||||||
|
transformStyle: 'preserve-3d'
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="headeproductionCapacityr-wrapper">
|
<div className="headeproductionCapacityr-wrapper">
|
||||||
<div className="header">Production Capacity</div>
|
<div className="header">Production Capacity</div>
|
||||||
|
|
|
@ -239,14 +239,13 @@ export const DraggableWidget = ({
|
||||||
onReorder(fromIndex, toIndex); // Call the reorder function passed as a prop
|
onReorder(fromIndex, toIndex); // Call the reorder function passed as a prop
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log("widget.type", widget.type);
|
|
||||||
|
|
||||||
// useClickOutside(chartWidget, () => {
|
// useClickOutside(chartWidget, () => {
|
||||||
// setSelectedChartId(null);
|
// setSelectedChartId(null);
|
||||||
// });
|
// });
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
|
||||||
console.log('isPanelHidden: ', isPanelHidden);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useThree } from "@react-three/fiber";
|
import { useThree } from "@react-three/fiber";
|
||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
import { useAsset3dWidget, useSocketStore, useWidgetSubOption } from "../../../store/store";
|
import { useAsset3dWidget, useSocketStore, useWidgetSubOption } from "../../../store/store";
|
||||||
import useModuleStore from "../../../store/useModuleStore";
|
import useModuleStore from "../../../store/useModuleStore";
|
||||||
import { ThreeState } from "../../../types/world/worldTypes";
|
import { ThreeState } from "../../../types/world/worldTypes";
|
||||||
|
@ -16,6 +16,14 @@ import { use3DWidget } from "../../../store/useDroppedObjectsStore";
|
||||||
import { useLeftData, useRightClickSelected, useRightSelected, useTopData, useZoneWidgetStore } from "../../../store/useZone3DWidgetStore";
|
import { useLeftData, useRightClickSelected, useRightSelected, useTopData, useZoneWidgetStore } from "../../../store/useZone3DWidgetStore";
|
||||||
import { useWidgetStore } from "../../../store/useWidgetStore";
|
import { useWidgetStore } from "../../../store/useWidgetStore";
|
||||||
import EditWidgetOption from "../menu/EditWidgetOption";
|
import EditWidgetOption from "../menu/EditWidgetOption";
|
||||||
|
type WidgetData = {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation?: [number, number, number];
|
||||||
|
tempPosition?: [number, number, number];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function Dropped3dWidgets() {
|
export default function Dropped3dWidgets() {
|
||||||
const { widgetSelect } = useAsset3dWidget();
|
const { widgetSelect } = useAsset3dWidget();
|
||||||
|
@ -23,22 +31,22 @@ export default function Dropped3dWidgets() {
|
||||||
const { raycaster, gl, scene, mouse, camera }: ThreeState = useThree();
|
const { raycaster, gl, scene, mouse, camera }: ThreeState = useThree();
|
||||||
const { widgetSubOption } = useWidgetSubOption();
|
const { widgetSubOption } = useWidgetSubOption();
|
||||||
const { selectedZone } = useSelectedZoneStore();
|
const { selectedZone } = useSelectedZoneStore();
|
||||||
const { top, setTop } = useTopData()
|
const { top, setTop } = useTopData();
|
||||||
const { left, setLeft } = useLeftData()
|
const { left, setLeft } = useLeftData();
|
||||||
const { rightSelect, setRightSelect } = useRightSelected()
|
const { rightSelect, setRightSelect } = useRightSelected();
|
||||||
|
|
||||||
// ✅ Use Zustand Store instead of useState
|
const { zoneWidgetData, setZoneWidgetData, addWidget, updateWidgetPosition, updateWidgetRotation } = useZoneWidgetStore();
|
||||||
const { zoneWidgetData, setZoneWidgetData, addWidget, updateWidgetPosition } = useZoneWidgetStore();
|
|
||||||
const { setWidgets3D } = use3DWidget();
|
const { setWidgets3D } = use3DWidget();
|
||||||
const { visualizationSocket } = useSocketStore();
|
const { visualizationSocket } = useSocketStore();
|
||||||
const { rightClickSelected, setRightClickSelected } = useRightClickSelected()
|
const { rightClickSelected, setRightClickSelected } = useRightClickSelected();
|
||||||
|
|
||||||
const plane = useRef(new THREE.Plane(new THREE.Vector3(0, 1, 0), 0)); // Floor plane for horizontal move
|
const plane = useRef(new THREE.Plane(new THREE.Vector3(0, 1, 0), 0)); // Floor plane for horizontal move
|
||||||
const verticalPlane = useRef(new THREE.Plane(new THREE.Vector3(0, 0, 1), 0)); // Vertical plane for vertical move
|
const verticalPlane = useRef(new THREE.Plane(new THREE.Vector3(0, 0, 1), 0)); // Vertical plane for vertical move
|
||||||
const planeIntersect = useRef(new THREE.Vector3());
|
const planeIntersect = useRef(new THREE.Vector3());
|
||||||
// let [verticalPlane, setFloorPlanesVertical] = useState(
|
// const plane = useRef(new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
|
||||||
// new THREE.Plane(new THREE.Vector3(0, 1, 0))
|
// const verticalPlane = useRef(new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
|
||||||
// );
|
// const planeIntersect = useRef(new THREE.Vector3());
|
||||||
|
const rotationStartRef = useRef<[number, number, number]>([0, 0, 0]);
|
||||||
|
const mouseStartRef = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeModule !== "visualization") return;
|
if (activeModule !== "visualization") return;
|
||||||
|
@ -48,14 +56,14 @@ export default function Dropped3dWidgets() {
|
||||||
const organization = email?.split("@")[1]?.split(".")[0];
|
const organization = email?.split("@")[1]?.split(".")[0];
|
||||||
|
|
||||||
async function get3dWidgetData() {
|
async function get3dWidgetData() {
|
||||||
let result = await get3dWidgetZoneData(selectedZone.zoneId, organization);
|
const result = await get3dWidgetZoneData(selectedZone.zoneId, organization);
|
||||||
|
|
||||||
setWidgets3D(result);
|
setWidgets3D(result);
|
||||||
|
|
||||||
const formattedWidgets = result.map((widget: any) => ({
|
const formattedWidgets = result.map((widget: WidgetData) => ({
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
type: widget.type,
|
type: widget.type,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
|
rotation: widget.rotation || [0, 0, 0],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setZoneWidgetData(selectedZone.zoneId, formattedWidgets);
|
setZoneWidgetData(selectedZone.zoneId, formattedWidgets);
|
||||||
|
@ -91,28 +99,24 @@ export default function Dropped3dWidgets() {
|
||||||
|
|
||||||
if (intersects.length > 0) {
|
if (intersects.length > 0) {
|
||||||
const { x, y, z } = intersects[0].point;
|
const { x, y, z } = intersects[0].point;
|
||||||
const newWidget = {
|
const newWidget: WidgetData = {
|
||||||
id: generateUniqueId(),
|
id: generateUniqueId(),
|
||||||
type: widgetSelect,
|
type: widgetSelect,
|
||||||
position: [x, y, z] as [number, number, number],
|
position: [x, y, z],
|
||||||
|
rotation: [0, 0, 0],
|
||||||
};
|
};
|
||||||
|
|
||||||
let add3dWidget = {
|
const add3dWidget = {
|
||||||
organization: organization,
|
organization: organization,
|
||||||
widget: newWidget,
|
widget: newWidget,
|
||||||
zoneId: selectedZone.zoneId
|
zoneId: selectedZone.zoneId
|
||||||
}
|
};
|
||||||
|
|
||||||
if (visualizationSocket) {
|
if (visualizationSocket) {
|
||||||
visualizationSocket.emit("v2:viz-3D-widget:add", add3dWidget)
|
visualizationSocket.emit("v2:viz-3D-widget:add", add3dWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
// let response = await adding3dWidgets(selectedZone.zoneId, organization, newWidget);
|
|
||||||
//
|
|
||||||
|
|
||||||
// if (response.message === "Widget created successfully") {
|
|
||||||
addWidget(selectedZone.zoneId, newWidget);
|
addWidget(selectedZone.zoneId, newWidget);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,63 +132,76 @@ export default function Dropped3dWidgets() {
|
||||||
if (!rightClickSelected) return;
|
if (!rightClickSelected) return;
|
||||||
const email = localStorage.getItem("email") || "";
|
const email = localStorage.getItem("email") || "";
|
||||||
const organization = email?.split("@")[1]?.split(".")[0];
|
const organization = email?.split("@")[1]?.split(".")[0];
|
||||||
|
|
||||||
if (rightSelect === "Duplicate") {
|
if (rightSelect === "Duplicate") {
|
||||||
const widgetToDuplicate = activeZoneWidgets.find(w => w.id === rightClickSelected);
|
const widgetToDuplicate = activeZoneWidgets.find((w: WidgetData) => w.id === rightClickSelected);
|
||||||
if (!widgetToDuplicate) return;
|
if (!widgetToDuplicate) return;
|
||||||
const newWidget = {
|
const newWidget: WidgetData = {
|
||||||
id: generateUniqueId(),
|
id: generateUniqueId(),
|
||||||
type: widgetToDuplicate.type,
|
type: widgetToDuplicate.type,
|
||||||
position: [
|
position: [
|
||||||
widgetToDuplicate.position[0] + 0.5, // Slightly shift position
|
widgetToDuplicate.position[0] + 0.5,
|
||||||
widgetToDuplicate.position[1],
|
widgetToDuplicate.position[1],
|
||||||
widgetToDuplicate.position[2] + 0.5,
|
widgetToDuplicate.position[2] + 0.5,
|
||||||
] as [number, number, number],
|
],
|
||||||
|
rotation: widgetToDuplicate.rotation || [0, 0, 0],
|
||||||
};
|
};
|
||||||
let add3dWidget = {
|
|
||||||
|
const add3dWidget = {
|
||||||
organization,
|
organization,
|
||||||
widget: newWidget,
|
widget: newWidget,
|
||||||
zoneId: selectedZone.zoneId
|
zoneId: selectedZone.zoneId
|
||||||
};
|
};
|
||||||
// if (visualizationSocket) {
|
|
||||||
// visualizationSocket.emit("v2:viz-3D-widget:add", add3dWidget);
|
|
||||||
// }
|
|
||||||
addWidget(selectedZone.zoneId, newWidget);
|
addWidget(selectedZone.zoneId, newWidget);
|
||||||
setRightSelect(null);
|
setRightSelect(null);
|
||||||
setRightClickSelected(null);
|
setRightClickSelected(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rightSelect === "Delete") {
|
if (rightSelect === "Delete") {
|
||||||
let deleteWidget = {
|
const deleteWidget = {
|
||||||
organization,
|
organization,
|
||||||
widgetId: rightClickSelected,
|
widgetId: rightClickSelected,
|
||||||
zoneId: selectedZone.zoneId
|
zoneId: selectedZone.zoneId
|
||||||
};
|
};
|
||||||
// if (visualizationSocket) {
|
|
||||||
// visualizationSocket.emit("v2:viz-3D-widget:delete", deleteWidget);
|
setZoneWidgetData(
|
||||||
// }
|
selectedZone.zoneId,
|
||||||
setZoneWidgetData(selectedZone.zoneId, activeZoneWidgets.filter(w => w.id !== rightClickSelected));
|
activeZoneWidgets.filter((w: WidgetData) => w.id !== rightClickSelected)
|
||||||
|
);
|
||||||
setRightClickSelected(null);
|
setRightClickSelected(null);
|
||||||
setRightSelect(null);
|
setRightSelect(null);
|
||||||
}
|
}
|
||||||
if (rightSelect === "Horizontal Move") {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (rightSelect === "Vertical Move") {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}, [rightSelect, rightClickSelected]);
|
}, [rightSelect, rightClickSelected]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleMouseMove = (event: MouseEvent) => {
|
const handleMouseDown = (event: MouseEvent) => {
|
||||||
if (!rightClickSelected || !rightSelect) return;
|
if (!rightClickSelected || !rightSelect) return;
|
||||||
|
|
||||||
|
if (rightSelect === "RotateX" || rightSelect === "RotateY") {
|
||||||
|
mouseStartRef.current = { x: event.clientX, y: event.clientY };
|
||||||
|
|
||||||
const selectedZone = Object.keys(zoneWidgetData).find(zoneId =>
|
const selectedZone = Object.keys(zoneWidgetData).find((zoneId: string) =>
|
||||||
zoneWidgetData[zoneId].some(widget => widget.id === rightClickSelected)
|
zoneWidgetData[zoneId].some((widget: WidgetData) => widget.id === rightClickSelected)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!selectedZone) return;
|
||||||
|
|
||||||
|
const selectedWidget = zoneWidgetData[selectedZone].find((widget: WidgetData) => widget.id === rightClickSelected);
|
||||||
|
if (selectedWidget) {
|
||||||
|
rotationStartRef.current = selectedWidget.rotation || [0, 0, 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = (event: MouseEvent) => {
|
||||||
|
if (!rightClickSelected || !rightSelect) return;
|
||||||
|
const selectedZone = Object.keys(zoneWidgetData).find((zoneId: string) =>
|
||||||
|
zoneWidgetData[zoneId].some((widget: WidgetData) => widget.id === rightClickSelected)
|
||||||
);
|
);
|
||||||
if (!selectedZone) return;
|
if (!selectedZone) return;
|
||||||
|
|
||||||
const selectedWidget = zoneWidgetData[selectedZone].find(widget => widget.id === rightClickSelected);
|
const selectedWidget = zoneWidgetData[selectedZone].find((widget: WidgetData) => widget.id === rightClickSelected);
|
||||||
if (!selectedWidget) return;
|
if (!selectedWidget) return;
|
||||||
|
|
||||||
const rect = gl.domElement.getBoundingClientRect();
|
const rect = gl.domElement.getBoundingClientRect();
|
||||||
|
@ -194,31 +211,67 @@ export default function Dropped3dWidgets() {
|
||||||
raycaster.setFromCamera(mouse, camera);
|
raycaster.setFromCamera(mouse, camera);
|
||||||
|
|
||||||
if (rightSelect === "Horizontal Move" && raycaster.ray.intersectPlane(plane.current, planeIntersect.current)) {
|
if (rightSelect === "Horizontal Move" && raycaster.ray.intersectPlane(plane.current, planeIntersect.current)) {
|
||||||
|
const newPosition: [number, number, number] = [
|
||||||
updateWidgetPosition(selectedZone, rightClickSelected, [
|
|
||||||
planeIntersect.current.x,
|
planeIntersect.current.x,
|
||||||
selectedWidget.position[1],
|
selectedWidget.position[1],
|
||||||
planeIntersect.current.z
|
planeIntersect.current.z
|
||||||
]);
|
];
|
||||||
|
updateWidgetPosition(selectedZone, rightClickSelected, newPosition);
|
||||||
|
console.log('Horizontal Move - Final Position:', newPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rightSelect === "Vertical Move") {
|
if (rightSelect === "Vertical Move") {
|
||||||
if (raycaster.ray.intersectPlane(verticalPlane.current, planeIntersect.current)) {
|
if (raycaster.ray.intersectPlane(verticalPlane.current, planeIntersect.current)) {
|
||||||
updateWidgetPosition(selectedZone, rightClickSelected, [
|
updateWidgetPosition(selectedZone, rightClickSelected, [
|
||||||
selectedWidget.position[0],
|
selectedWidget.position[0],
|
||||||
planeIntersect.current.y, // Ensure Y value updates correctly
|
planeIntersect.current.y,
|
||||||
selectedWidget.position[2]
|
selectedWidget.position[2]
|
||||||
]);
|
]);
|
||||||
} else {
|
|
||||||
console.log("No Intersection with Vertical Plane");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rightSelect === "RotateX") {
|
||||||
|
const deltaX = event.clientX - mouseStartRef.current.x;
|
||||||
|
const rotationSpeed = 0.03;
|
||||||
|
const newRotation: [number, number, number] = [
|
||||||
|
rotationStartRef.current[0] + deltaX * rotationSpeed,
|
||||||
|
rotationStartRef.current[1],
|
||||||
|
rotationStartRef.current[2]
|
||||||
|
];
|
||||||
|
updateWidgetRotation(selectedZone, rightClickSelected, newRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rightSelect === "RotateY") {
|
||||||
|
const deltaY = event.clientY - mouseStartRef.current.y;
|
||||||
|
const rotationSpeed = 0.03;
|
||||||
|
const newRotation: [number, number, number] = [
|
||||||
|
rotationStartRef.current[0],
|
||||||
|
rotationStartRef.current[1] + deltaY * rotationSpeed,
|
||||||
|
rotationStartRef.current[2]
|
||||||
|
];
|
||||||
|
updateWidgetRotation(selectedZone, rightClickSelected, newRotation);
|
||||||
|
}
|
||||||
|
if (rightSelect === "RotateZ") {
|
||||||
|
const deltaX = event.movementX;
|
||||||
|
const rotationSpeed = 0.03;
|
||||||
|
const currentRotation = selectedWidget.rotation || [0, 0, 0];
|
||||||
|
const newRotation: [number, number, number] = [
|
||||||
|
currentRotation[0],
|
||||||
|
currentRotation[1],
|
||||||
|
currentRotation[2] + deltaX * rotationSpeed
|
||||||
|
];
|
||||||
|
updateWidgetRotation(selectedZone, rightClickSelected, newRotation);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseUp = () => {
|
const handleMouseUp = () => {
|
||||||
|
if (rightClickSelected && (
|
||||||
if (rightClickSelected && (rightSelect === "Horizontal Move" || rightSelect === "Vertical Move")) {
|
rightSelect === "Horizontal Move" ||
|
||||||
|
rightSelect === "Vertical Move" ||
|
||||||
|
rightSelect === "RotateX" ||
|
||||||
|
rightSelect === "RotateY" || rightSelect === "RotateZ"
|
||||||
|
)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setRightClickSelected(null);
|
setRightClickSelected(null);
|
||||||
setRightSelect(null);
|
setRightSelect(null);
|
||||||
|
@ -226,40 +279,81 @@ export default function Dropped3dWidgets() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Attach events to window instead of gl.domElement
|
window.addEventListener("mousedown", handleMouseDown);
|
||||||
window.addEventListener("mousemove", handleMouseMove);
|
window.addEventListener("mousemove", handleMouseMove);
|
||||||
window.addEventListener("mouseup", handleMouseUp);
|
window.addEventListener("mouseup", handleMouseUp);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
window.removeEventListener("mousedown", handleMouseDown);
|
||||||
window.removeEventListener("mousemove", handleMouseMove);
|
window.removeEventListener("mousemove", handleMouseMove);
|
||||||
window.removeEventListener("mouseup", handleMouseUp);
|
window.removeEventListener("mouseup", handleMouseUp);
|
||||||
};
|
};
|
||||||
}, [rightClickSelected, rightSelect, zoneWidgetData, gl]);
|
}, [rightClickSelected, rightSelect, zoneWidgetData, gl]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{activeZoneWidgets.map(({ id, type, position }) => {
|
{activeZoneWidgets.map(({ id, type, position, rotation = [0, 0, 0] }: WidgetData) => {
|
||||||
const handleRightClick = (event: React.MouseEvent) => {
|
const handleRightClick = (event: React.MouseEvent, id: string) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setRightClickSelected(id)
|
const canvasElement = document.getElementById("real-time-vis-canvas");
|
||||||
|
if (!canvasElement) throw new Error("Canvas element not found");
|
||||||
|
const canvasRect = canvasElement.getBoundingClientRect();
|
||||||
|
const relativeX = event.clientX - canvasRect.left;
|
||||||
|
const relativeY = event.clientY - canvasRect.top;
|
||||||
|
setRightClickSelected(id);
|
||||||
|
setTop(relativeY);
|
||||||
|
setLeft(relativeX);
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "ui-Widget 1":
|
case "ui-Widget 1":
|
||||||
return <ProductionCapacity key={id} id={id} type={type} position={position} onContextMenu={handleRightClick} />;
|
return (
|
||||||
|
<ProductionCapacity
|
||||||
|
key={id}
|
||||||
|
id={id}
|
||||||
|
type={type}
|
||||||
|
position={position}
|
||||||
|
rotation={rotation}
|
||||||
|
onContextMenu={(e) => handleRightClick(e, id)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "ui-Widget 2":
|
case "ui-Widget 2":
|
||||||
return <ReturnOfInvestment key={id} id={id} type={type} position={position} onContextMenu={handleRightClick} />;
|
return (
|
||||||
|
<ReturnOfInvestment
|
||||||
|
key={id}
|
||||||
|
id={id}
|
||||||
|
type={type}
|
||||||
|
position={position}
|
||||||
|
// rotation={rotation}
|
||||||
|
onContextMenu={(e) => handleRightClick(e, id)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "ui-Widget 3":
|
case "ui-Widget 3":
|
||||||
return <StateWorking key={id} id={id} type={type} position={position} onContextMenu={handleRightClick} />;
|
return (
|
||||||
|
<StateWorking
|
||||||
|
key={id}
|
||||||
|
id={id}
|
||||||
|
type={type}
|
||||||
|
position={position}
|
||||||
|
// rotation={rotation}
|
||||||
|
onContextMenu={(e) => handleRightClick(e, id)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
case "ui-Widget 4":
|
case "ui-Widget 4":
|
||||||
return <Throughput key={id} id={id} type={type} position={position} onContextMenu={handleRightClick} />;
|
return (
|
||||||
|
<Throughput
|
||||||
|
key={id}
|
||||||
|
id={id}
|
||||||
|
type={type}
|
||||||
|
position={position}
|
||||||
|
// rotation={rotation}
|
||||||
|
onContextMenu={(e) => handleRightClick(e, id)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})}
|
})}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -197,7 +197,6 @@ const RealTimeVisulization: React.FC = () => {
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleRightClickSel(){}
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
|
@ -234,8 +233,8 @@ const RealTimeVisulization: React.FC = () => {
|
||||||
{activeModule === "visualization" && selectedZone.zoneName !== "" && <DroppedObjects />}
|
{activeModule === "visualization" && selectedZone.zoneName !== "" && <DroppedObjects />}
|
||||||
{activeModule === "visualization" && <SocketRealTimeViz />}
|
{activeModule === "visualization" && <SocketRealTimeViz />}
|
||||||
|
|
||||||
{activeModule === "visualization" && widgetSubOption === "3D" && rightClickSelected && <EditWidgetOption
|
{activeModule === "visualization" && rightClickSelected && <EditWidgetOption
|
||||||
options={["Duplicate", "Vertical Move", "Horizontal Move", "Delete"]}
|
options={["Duplicate", "Vertical Move", "Horizontal Move", "RotateX", "RotateY", "RotateZ", "Delete"]}
|
||||||
/>}
|
/>}
|
||||||
|
|
||||||
{activeModule === "visualization" && (
|
{activeModule === "visualization" && (
|
||||||
|
|
|
@ -17,7 +17,15 @@ const EditWidgetOption: React.FC<EditWidgetOptionProps> = ({ options }) => {
|
||||||
}, [top, left])
|
}, [top, left])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="editWidgetOptions-wrapper" style={{ top: top + "px", left: left + "px" }}>
|
<div className="editWidgetOptions-wrapper"
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: `${top}px`,
|
||||||
|
left: `${left}px`,
|
||||||
|
zIndex: 10000,
|
||||||
|
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div className="editWidgetOptions">
|
<div className="editWidgetOptions">
|
||||||
{options.map((option, index) => (
|
{options.map((option, index) => (
|
||||||
<div className="option" key={index} onClick={(e) => setRightSelect(option)}>
|
<div className="option" key={index} onClick={(e) => setRightSelect(option)}>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
type WidgetData = {
|
type WidgetData = {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
|
rotation?: [number, number, number];
|
||||||
tempPosition?: [number, number, number];
|
tempPosition?: [number, number, number];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,38 +13,59 @@ type ZoneWidgetStore = {
|
||||||
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) => void;
|
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) => void;
|
||||||
addWidget: (zoneId: string, widget: WidgetData) => void;
|
addWidget: (zoneId: string, widget: WidgetData) => void;
|
||||||
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) => void;
|
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) => void;
|
||||||
|
updateWidgetRotation: (zoneId: string, widgetId: string, newRotation: [number, number, number]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useZoneWidgetStore = create<ZoneWidgetStore>((set) => ({
|
export const useZoneWidgetStore = create<ZoneWidgetStore>((set) => ({
|
||||||
zoneWidgetData: {},
|
zoneWidgetData: {},
|
||||||
|
|
||||||
setZoneWidgetData: (zoneId, widgets) =>
|
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) =>
|
||||||
set((state) => ({
|
set((state: ZoneWidgetStore) => ({
|
||||||
zoneWidgetData: { ...state.zoneWidgetData, [zoneId]: widgets },
|
zoneWidgetData: { ...state.zoneWidgetData, [zoneId]: widgets },
|
||||||
})),
|
})),
|
||||||
|
|
||||||
addWidget: (zoneId, widget) =>
|
addWidget: (zoneId: string, widget: WidgetData) =>
|
||||||
set((state) => ({
|
set((state: ZoneWidgetStore) => ({
|
||||||
zoneWidgetData: {
|
zoneWidgetData: {
|
||||||
...state.zoneWidgetData,
|
...state.zoneWidgetData,
|
||||||
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), widget],
|
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), { ...widget, rotation: widget.rotation || [0, 0, 0] }],
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
|
|
||||||
updateWidgetPosition: (zoneId, widgetId, newPosition) =>
|
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) =>
|
||||||
set((state) => {
|
set((state: ZoneWidgetStore) => {
|
||||||
const widgets = state.zoneWidgetData[zoneId] || [];
|
const widgets = state.zoneWidgetData[zoneId] || [];
|
||||||
return {
|
return {
|
||||||
zoneWidgetData: {
|
zoneWidgetData: {
|
||||||
...state.zoneWidgetData,
|
...state.zoneWidgetData,
|
||||||
[zoneId]: widgets.map((widget) =>
|
[zoneId]: widgets.map((widget: WidgetData) =>
|
||||||
widget.id === widgetId ? { ...widget, position: newPosition } : widget
|
widget.id === widgetId ? { ...widget, position: newPosition } : widget
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
updateWidgetRotation: (zoneId: string, widgetId: string, newRotation: [number, number, number]) =>
|
||||||
|
set((state: ZoneWidgetStore) => {
|
||||||
|
const widgets = state.zoneWidgetData[zoneId] || [];
|
||||||
|
return {
|
||||||
|
zoneWidgetData: {
|
||||||
|
...state.zoneWidgetData,
|
||||||
|
[zoneId]: widgets.map((widget: WidgetData) =>
|
||||||
|
widget.id === widgetId ? { ...widget, rotation: newRotation } : widget
|
||||||
|
),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// export type WidgetData = {
|
||||||
|
// id: string;
|
||||||
|
// type: string;
|
||||||
|
// position: [number, number, number];
|
||||||
|
// rotation?: [number, number, number];
|
||||||
|
// tempPosition?: [number, number, number];
|
||||||
|
// };
|
||||||
|
|
||||||
interface RightClickStore {
|
interface RightClickStore {
|
||||||
rightClickSelected: string | null;
|
rightClickSelected: string | null;
|
||||||
|
|
Loading…
Reference in New Issue