Refactor and enhance zone and wall item management:
- Update zone handling in ZoneGroup to include selected zone visibility. - Improve camera transition speed in ZoneCentreTarget. - Add clearSelectedZone functionality in useZoneStore. - Integrate clearSelectedZone in KeyPressListener for ESCAPE key action. - Adjust sidebar and module toggle positioning for better UI layout. - Clean up unused code and comments in Project component.
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
import { getZonesApi } from "../../../services/factoryBuilder/zones/getZonesApi";
|
||||
|
||||
import * as CONSTANTS from "../../../types/world/worldConstants";
|
||||
import { useSelectedZoneStore } from "../../../store/visualization/useZoneStore";
|
||||
|
||||
const ZoneGroup: React.FC = () => {
|
||||
const { camera, pointer, gl, raycaster, scene, controls } = useThree();
|
||||
@@ -24,6 +25,7 @@ const ZoneGroup: React.FC = () => {
|
||||
const { zones, setZones } = useZones();
|
||||
const { zonePoints, setZonePoints } = useZonePoints();
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const { selectedZone } = useSelectedZoneStore();
|
||||
const [draggedSphere, setDraggedSphere] = useState<THREE.Vector3 | null>(
|
||||
null
|
||||
);
|
||||
@@ -308,7 +310,7 @@ const ZoneGroup: React.FC = () => {
|
||||
true
|
||||
);
|
||||
|
||||
if (intersects.length > 0 && toolMode === 'move') {
|
||||
if (intersects.length > 0 && toolMode === "move") {
|
||||
const clickedObject = intersects[0].object;
|
||||
const sphereIndex = zonePoints.findIndex((point: any) =>
|
||||
point.equals(clickedObject.position)
|
||||
@@ -326,7 +328,7 @@ const ZoneGroup: React.FC = () => {
|
||||
if (evt.button === 0 && !drag && !isDragging && !deletePointOrLine) {
|
||||
isLeftMouseDown = false;
|
||||
|
||||
if (!startPoint && toolMode !== 'move') {
|
||||
if (!startPoint && toolMode !== "move") {
|
||||
raycaster.setFromCamera(pointer, camera);
|
||||
const intersectionPoint = new THREE.Vector3();
|
||||
const point = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
@@ -334,7 +336,7 @@ const ZoneGroup: React.FC = () => {
|
||||
setStartPoint(point);
|
||||
setEndPoint(null);
|
||||
}
|
||||
} else if (startPoint && toolMode !== 'move') {
|
||||
} else if (startPoint && toolMode !== "move") {
|
||||
raycaster.setFromCamera(pointer, camera);
|
||||
const intersectionPoint = new THREE.Vector3();
|
||||
const point = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
@@ -436,7 +438,8 @@ const ZoneGroup: React.FC = () => {
|
||||
intersects.length > 0 &&
|
||||
intersects[0].object.name.includes("point")
|
||||
) {
|
||||
gl.domElement.style.cursor = toolMode === 'move' ? "pointer" : "default";
|
||||
gl.domElement.style.cursor =
|
||||
toolMode === "move" ? "pointer" : "default";
|
||||
} else {
|
||||
gl.domElement.style.cursor = "default";
|
||||
}
|
||||
@@ -476,7 +479,7 @@ const ZoneGroup: React.FC = () => {
|
||||
setEndPoint(null);
|
||||
};
|
||||
|
||||
if (toolMode === "Zone" || deletePointOrLine || toolMode === 'move') {
|
||||
if (toolMode === "Zone" || deletePointOrLine || toolMode === "move") {
|
||||
canvasElement.addEventListener("mousedown", onMouseDown);
|
||||
canvasElement.addEventListener("mouseup", onMouseUp);
|
||||
canvasElement.addEventListener("mousemove", onMouseMove);
|
||||
@@ -526,7 +529,11 @@ const ZoneGroup: React.FC = () => {
|
||||
<group ref={groupsRef} name="zoneGroup">
|
||||
<group name="zones" visible={!toggleView}>
|
||||
{zones.map((zone: any) => (
|
||||
<group key={zone.zoneId} name={zone.zoneName} visible={false}>
|
||||
<group
|
||||
key={zone.zoneId}
|
||||
name={zone.zoneName}
|
||||
visible={zone.zoneName === selectedZone.zoneName}
|
||||
>
|
||||
{zone.points
|
||||
.slice(0, -1)
|
||||
.map((point: [number, number, number], index: number) => {
|
||||
@@ -545,7 +552,7 @@ const ZoneGroup: React.FC = () => {
|
||||
const midpoint = new THREE.Vector3(
|
||||
(point1.x + point2.x) / 2,
|
||||
CONSTANTS.zoneConfig.height / 2 +
|
||||
(zone.layer - 1) * CONSTANTS.zoneConfig.height,
|
||||
(zone.layer - 1) * CONSTANTS.zoneConfig.height,
|
||||
(point1.z + point2.z) / 2
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user