Refactor PointsCreator and RoboticArmInstance: remove unused hooks and clean up code; comment out scene.add(helper) in IKInstance; streamline imports in ArmBotUI.

This commit is contained in:
Jerald-Golden-B 2025-05-03 10:45:36 +05:30
parent 846350728f
commit c198a90ac6
4 changed files with 7 additions and 41 deletions

View File

@ -7,8 +7,6 @@ import { detectModifierKeys } from "../../../../../utils/shortcutkeys/detectModi
import { import {
useSelectedEventSphere, useSelectedEventSphere,
useSelectedEventData, useSelectedEventData,
useIsDragging,
useIsRotating,
} from "../../../../../store/simulation/useSimulationStore"; } from "../../../../../store/simulation/useSimulationStore";
import { useThree } from "@react-three/fiber"; import { useThree } from "@react-three/fiber";
@ -21,9 +19,7 @@ function PointsCreator() {
const [transformMode, setTransformMode] = useState<"translate" | "rotate" | null>(null); const [transformMode, setTransformMode] = useState<"translate" | "rotate" | null>(null);
const sphereRefs = useRef<{ [key: string]: THREE.Mesh }>({}); const sphereRefs = useRef<{ [key: string]: THREE.Mesh }>({});
const { selectedEventSphere, setSelectedEventSphere, clearSelectedEventSphere, } = useSelectedEventSphere(); const { selectedEventSphere, setSelectedEventSphere, clearSelectedEventSphere, } = useSelectedEventSphere();
const { selectedEventData,setSelectedEventData, clearSelectedEventData } = useSelectedEventData(); const { selectedEventData, setSelectedEventData, clearSelectedEventData } = useSelectedEventData();
const { isDragging } = useIsDragging();
const { isRotating } = useIsRotating();
useEffect(() => { useEffect(() => {
if (selectedEventSphere) { if (selectedEventSphere) {
@ -59,24 +55,11 @@ function PointsCreator() {
const updatePointToState = (selectedEventSphere: THREE.Mesh) => { const updatePointToState = (selectedEventSphere: THREE.Mesh) => {
let point = JSON.parse( let point = JSON.parse(
JSON.stringify( JSON.stringify(getPointByUuid(selectedEventSphere.userData.modelUuid, selectedEventSphere.userData.pointUuid))
getPointByUuid(
selectedEventSphere.userData.modelUuid,
selectedEventSphere.userData.pointUuid
)
)
); );
if (point) { if (point) {
point.position = [ point.position = [selectedEventSphere.position.x, selectedEventSphere.position.y, selectedEventSphere.position.z,];
selectedEventSphere.position.x, updatePoint(selectedEventSphere.userData.modelUuid, selectedEventSphere.userData.pointUuid, point);
selectedEventSphere.position.y,
selectedEventSphere.position.z,
];
updatePoint(
selectedEventSphere.userData.modelUuid,
selectedEventSphere.userData.pointUuid,
point
);
} }
}; };
@ -139,7 +122,7 @@ function PointsCreator() {
key={i} key={i}
position={new THREE.Vector3(...event.position)} position={new THREE.Vector3(...event.position)}
> >
{event.points.map((point, j) => ( {event.points.map((point) => (
<mesh <mesh
name="Event-Sphere" name="Event-Sphere"
uuid={point.uuid} uuid={point.uuid}
@ -150,13 +133,6 @@ function PointsCreator() {
sphereRefs.current[point.uuid] sphereRefs.current[point.uuid]
); );
}} }}
onPointerMissed={() => {
if (selectedEventData?.data.type !== 'vehicle') {
// clearSelectedEventSphere();
}
setTransformMode(null);
}}
key={`${i}-${j}`}
position={new THREE.Vector3(...point.position)} position={new THREE.Vector3(...point.position)}
userData={{ userData={{
modelUuid: event.modelUuid, modelUuid: event.modelUuid,
@ -212,9 +188,6 @@ function PointsCreator() {
sphereRefs.current[event.point.uuid] sphereRefs.current[event.point.uuid]
); );
}} }}
onPointerMissed={() => {
setTransformMode(null);
}}
position={new THREE.Vector3(...event.point.position)} position={new THREE.Vector3(...event.point.position)}
userData={{ userData={{
modelUuid: event.modelUuid, modelUuid: event.modelUuid,
@ -242,10 +215,6 @@ function PointsCreator() {
sphereRefs.current[event.point.uuid] sphereRefs.current[event.point.uuid]
); );
}} }}
onPointerMissed={() => {
// clearSelectedEventSphere();
setTransformMode(null);
}}
position={new THREE.Vector3(...event.point.position)} position={new THREE.Vector3(...event.point.position)}
userData={{ userData={{
modelUuid: event.modelUuid, modelUuid: event.modelUuid,

View File

@ -5,7 +5,6 @@ import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '..
import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore'; import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore';
import armModel from "../../../../../assets/gltf-glb/rigged/ik_arm_4.glb"; import armModel from "../../../../../assets/gltf-glb/rigged/ik_arm_4.glb";
import { useThree } from "@react-three/fiber"; import { useThree } from "@react-three/fiber";
import { useFloorItems } from '../../../../../store/store';
import useModuleStore from '../../../../../store/useModuleStore'; import useModuleStore from '../../../../../store/useModuleStore';
import * as THREE from "three"; import * as THREE from "three";
import { useSelectedAction, useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useSelectedAction, useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
@ -26,9 +25,8 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
let startTime: number; let startTime: number;
//zustand //zustand
const { addCurrentAction, setArmBotActive, setArmBotState, removeCurrentAction } = useArmBotStore(); const { addCurrentAction, setArmBotActive, setArmBotState, removeCurrentAction } = useArmBotStore();
const { products, getActionByUuid } = useProductStore(); const { getActionByUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { floorItems } = useFloorItems();
const { activeModule } = useModuleStore(); const { activeModule } = useModuleStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { isReset, setReset } = useResetButtonStore(); const { isReset, setReset } = useResetButtonStore();

View File

@ -71,7 +71,7 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, armBot, groupRef }: IKIns
setSelectedArm(OOI.Target_Bone); setSelectedArm(OOI.Target_Bone);
scene.add(helper) // scene.add(helper);
}, [gltf]); }, [gltf]);

View File

@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useSelectedAction, useSelectedEventData, useSelectedProduct } from '../../../../store/simulation/useSimulationStore'; import { useSelectedAction, useSelectedEventData, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
import { useGLTF } from '@react-three/drei'; import { useGLTF } from '@react-three/drei';
import { useThree } from '@react-three/fiber'; import { useThree } from '@react-three/fiber';
import { useProductStore } from '../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../store/simulation/useProductStore';