human assembly rotation and movement bug fixed
This commit is contained in:
@@ -34,6 +34,9 @@ function HumanAnimator({ path, handleCallBack, currentPhase, human, reset, start
|
|||||||
if (currentPhase === 'init-pickup' && path.length > 0) {
|
if (currentPhase === 'init-pickup' && path.length > 0) {
|
||||||
setCurrentPath(path);
|
setCurrentPath(path);
|
||||||
setObjectRotation(human.point.action.pickUpPoint?.rotation ?? null)
|
setObjectRotation(human.point.action.pickUpPoint?.rotation ?? null)
|
||||||
|
} else if (currentPhase === 'init_assembly' && path.length > 0) {
|
||||||
|
setObjectRotation(human.point.action?.assemblyPoint?.rotation ?? null)
|
||||||
|
setCurrentPath(path);
|
||||||
} else if (currentPhase === 'pickup-drop' && path.length > 0) {
|
} else if (currentPhase === 'pickup-drop' && path.length > 0) {
|
||||||
setObjectRotation(human.point.action?.dropPoint?.rotation ?? null)
|
setObjectRotation(human.point.action?.dropPoint?.rotation ?? null)
|
||||||
setCurrentPath(path);
|
setCurrentPath(path);
|
||||||
|
|||||||
@@ -123,8 +123,17 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
|||||||
if (!human.point.action.assemblyPoint || human.point.action.actionType === 'worker') return;
|
if (!human.point.action.assemblyPoint || human.point.action.actionType === 'worker') return;
|
||||||
|
|
||||||
if (!human.isActive && human.state === 'idle' && currentPhase === 'init') {
|
if (!human.isActive && human.state === 'idle' && currentPhase === 'init') {
|
||||||
|
const toPickupPath = computePath(
|
||||||
|
new THREE.Vector3(human?.position[0], human?.position[1], human?.position[2]),
|
||||||
|
new THREE.Vector3(
|
||||||
|
human?.point?.action?.assemblyPoint?.position?.[0] ?? 0,
|
||||||
|
human?.point?.action?.assemblyPoint?.position?.[1] ?? 0,
|
||||||
|
human?.point?.action?.assemblyPoint?.position?.[2] ?? 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
setPath(toPickupPath);
|
||||||
setHumanState(human.modelUuid, 'idle');
|
setHumanState(human.modelUuid, 'idle');
|
||||||
setCurrentPhase('waiting');
|
setCurrentPhase('init_assembly');
|
||||||
setHumanActive(human.modelUuid, false);
|
setHumanActive(human.modelUuid, false);
|
||||||
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
|
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
|
||||||
humanStatus(human.modelUuid, 'Human is waiting for material in assembly');
|
humanStatus(human.modelUuid, 'Human is waiting for material in assembly');
|
||||||
@@ -293,6 +302,13 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
|||||||
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
|
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
|
||||||
humanStatus(human.modelUuid, 'Reached pickup point, waiting for material');
|
humanStatus(human.modelUuid, 'Reached pickup point, waiting for material');
|
||||||
setPath([]);
|
setPath([]);
|
||||||
|
} if (currentPhase === 'init_assembly') {
|
||||||
|
setCurrentPhase('waiting');
|
||||||
|
setHumanState(human.modelUuid, 'idle');
|
||||||
|
setHumanActive(human.modelUuid, false);
|
||||||
|
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
|
||||||
|
humanStatus(human.modelUuid, 'Reached assembly point, waiting for material');
|
||||||
|
setPath([]);
|
||||||
} else if (currentPhase === 'pickup-drop') {
|
} else if (currentPhase === 'pickup-drop') {
|
||||||
setCurrentPhase('dropping');
|
setCurrentPhase('dropping');
|
||||||
setHumanState(human.modelUuid, 'idle');
|
setHumanState(human.modelUuid, 'idle');
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ function HumanUi() {
|
|||||||
const { updateEvent } = productStore();
|
const { updateEvent } = productStore();
|
||||||
const [startPosition, setStartPosition] = useState<[number, number, number]>([0, 1, 0]);
|
const [startPosition, setStartPosition] = useState<[number, number, number]>([0, 1, 0]);
|
||||||
const [endPosition, setEndPosition] = useState<[number, number, number]>([0, 1, 0]);
|
const [endPosition, setEndPosition] = useState<[number, number, number]>([0, 1, 0]);
|
||||||
|
const [assemblyPosition, setAssemblyPosition] = useState<[number, number, number]>([0, 1, 0]);
|
||||||
const [startRotation, setStartRotation] = useState<[number, number, number]>([0, Math.PI, 0]);
|
const [startRotation, setStartRotation] = useState<[number, number, number]>([0, Math.PI, 0]);
|
||||||
const [assemblyRotation, setAssemblyRotation] = useState<[number, number, number]>([0, 0, 0]);
|
const [assemblyRotation, setAssemblyRotation] = useState<[number, number, number]>([0, 0, 0]);
|
||||||
const [endRotation, setEndRotation] = useState<[number, number, number]>([0, 0, 0]);
|
const [endRotation, setEndRotation] = useState<[number, number, number]>([0, 0, 0]);
|
||||||
@@ -88,40 +89,44 @@ function HumanUi() {
|
|||||||
|
|
||||||
const action = selectedHuman.point.action;
|
const action = selectedHuman.point.action;
|
||||||
|
|
||||||
if (action.pickUpPoint?.position && outerGroup.current) {
|
if (isAssembly) {
|
||||||
const worldPos = new Vector3(...action.pickUpPoint.position);
|
if (action.assemblyPoint?.position && outerGroup.current) {
|
||||||
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
|
const worldPos = new Vector3(...action.assemblyPoint.position);
|
||||||
setStartPosition([localPosition.x, 1, localPosition.z]);
|
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
|
||||||
setStartRotation(action.pickUpPoint.rotation || [0, 0, 0]);
|
setAssemblyPosition([localPosition.x, 1, localPosition.z]);
|
||||||
|
setAssemblyRotation(action.assemblyPoint.rotation || [0, 0, 0]);
|
||||||
|
} else {
|
||||||
|
setAssemblyPosition([0, 1, 0]);
|
||||||
|
setAssemblyRotation([0, 0, 0]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setStartPosition([0, 1, 0]);
|
if (action.pickUpPoint?.position && outerGroup.current) {
|
||||||
setStartRotation([0, Math.PI, 0]);
|
const worldPos = new Vector3(...action.pickUpPoint.position);
|
||||||
}
|
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
|
||||||
|
setStartPosition([localPosition.x, 1, localPosition.z]);
|
||||||
|
setStartRotation(action.pickUpPoint.rotation || [0, 0, 0]);
|
||||||
|
} else {
|
||||||
|
setStartPosition([0, 1, 0]);
|
||||||
|
setStartRotation([0, Math.PI, 0]);
|
||||||
|
}
|
||||||
|
|
||||||
if (action.dropPoint?.position && outerGroup.current) {
|
if (action.dropPoint?.position && outerGroup.current) {
|
||||||
const worldPos = new Vector3(...action.dropPoint.position);
|
const worldPos = new Vector3(...action.dropPoint.position);
|
||||||
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
|
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
|
||||||
setEndPosition([localPosition.x, 1, localPosition.z]);
|
setEndPosition([localPosition.x, 1, localPosition.z]);
|
||||||
setEndRotation(action.dropPoint.rotation || [0, Math.PI, 0]);
|
setEndRotation(action.dropPoint.rotation || [0, Math.PI, 0]);
|
||||||
} else {
|
} else {
|
||||||
setEndPosition([0, 1, 0]);
|
setEndPosition([0, 1, 0]);
|
||||||
setEndRotation([0, 0, 0]);
|
setEndRotation([0, 0, 0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.assemblyPoint?.rotation) {
|
|
||||||
setAssemblyRotation(action.assemblyPoint.rotation);
|
|
||||||
} else {
|
|
||||||
setAssemblyRotation([0, 0, 0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, [selectedEventSphere, outerGroup.current, selectedAction, humans]);
|
}, [selectedEventSphere, outerGroup.current, selectedAction, humans]);
|
||||||
|
|
||||||
const handlePointerDown = (
|
const handlePointerDown = (
|
||||||
e: any,
|
e: any,
|
||||||
state: "start" | "end",
|
state: "start" | "end" | "assembly",
|
||||||
rotation: "start" | "end"
|
rotation: "start" | "end" | "assembly"
|
||||||
) => {
|
) => {
|
||||||
if (isAssembly) return;
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const intersection = new Vector3();
|
const intersection = new Vector3();
|
||||||
const pointer = new Vector2((e.clientX / window.innerWidth) * 2 - 1, -(e.clientY / window.innerHeight) * 2 + 1);
|
const pointer = new Vector2((e.clientX / window.innerWidth) * 2 - 1, -(e.clientY / window.innerHeight) * 2 + 1);
|
||||||
@@ -144,7 +149,10 @@ function HumanUi() {
|
|||||||
if (outerGroup.current) {
|
if (outerGroup.current) {
|
||||||
localPoint = outerGroup.current.worldToLocal(intersection.clone());
|
localPoint = outerGroup.current.worldToLocal(intersection.clone());
|
||||||
}
|
}
|
||||||
const marker = state === "start" ? startMarker.current : endMarker.current;
|
const marker =
|
||||||
|
state === "start" ? startMarker.current :
|
||||||
|
state === "end" ? endMarker.current :
|
||||||
|
assemblyMarker.current;
|
||||||
if (marker && localPoint) {
|
if (marker && localPoint) {
|
||||||
const markerPos = new Vector3().copy(marker.position);
|
const markerPos = new Vector3().copy(marker.position);
|
||||||
dragOffset.current.copy(markerPos.sub(localPoint));
|
dragOffset.current.copy(markerPos.sub(localPoint));
|
||||||
@@ -154,7 +162,6 @@ function HumanUi() {
|
|||||||
if (controls) (controls as any).enabled = false;
|
if (controls) (controls as any).enabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handlePointerUp = () => {
|
const handlePointerUp = () => {
|
||||||
(controls as any).enabled = true;
|
(controls as any).enabled = true;
|
||||||
setIsDragging(null);
|
setIsDragging(null);
|
||||||
@@ -165,14 +172,18 @@ function HumanUi() {
|
|||||||
const selectedHuman = getHumanById(selectedEventSphere.userData.modelUuid);
|
const selectedHuman = getHumanById(selectedEventSphere.userData.modelUuid);
|
||||||
if (!selectedHuman || !outerGroup.current) return;
|
if (!selectedHuman || !outerGroup.current) return;
|
||||||
|
|
||||||
const isAssembly = selectedHuman.point?.action?.actionType === 'assembly';
|
|
||||||
|
|
||||||
let updatedAction;
|
let updatedAction;
|
||||||
|
|
||||||
if (isAssembly) {
|
if (isAssembly) {
|
||||||
|
if (!assemblyMarker.current) return;
|
||||||
|
|
||||||
|
const worldPosAssembly = new Vector3(...assemblyPosition);
|
||||||
|
const globalAssemblyPosition = outerGroup.current.localToWorld(worldPosAssembly.clone());
|
||||||
|
|
||||||
updatedAction = {
|
updatedAction = {
|
||||||
...selectedHuman.point.action,
|
...selectedHuman.point.action,
|
||||||
assemblyPoint: {
|
assemblyPoint: {
|
||||||
|
position: [globalAssemblyPosition.x, globalAssemblyPosition.y, globalAssemblyPosition.z] as [number, number, number],
|
||||||
rotation: assemblyRotation
|
rotation: assemblyRotation
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -221,7 +232,7 @@ function HumanUi() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (isAssembly || !isDragging || !plane.current || !raycaster || !outerGroup.current) return;
|
if (!isDragging || !plane.current || !raycaster || !outerGroup.current) return;
|
||||||
const intersectPoint = new Vector3();
|
const intersectPoint = new Vector3();
|
||||||
const intersects = raycaster.ray.intersectPlane(plane.current, intersectPoint);
|
const intersects = raycaster.ray.intersectPlane(plane.current, intersectPoint);
|
||||||
if (!intersects) return;
|
if (!intersects) return;
|
||||||
@@ -232,6 +243,8 @@ function HumanUi() {
|
|||||||
setStartPosition([localPoint.x, 1, localPoint.z]);
|
setStartPosition([localPoint.x, 1, localPoint.z]);
|
||||||
} else if (isDragging === "end") {
|
} else if (isDragging === "end") {
|
||||||
setEndPosition([localPoint.x, 1, localPoint.z]);
|
setEndPosition([localPoint.x, 1, localPoint.z]);
|
||||||
|
} else if (isDragging === "assembly") {
|
||||||
|
setAssemblyPosition([localPoint.x, 1, localPoint.z]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -240,28 +253,34 @@ function HumanUi() {
|
|||||||
const currentPointerX = state.pointer.x;
|
const currentPointerX = state.pointer.x;
|
||||||
const deltaX = currentPointerX - prevMousePos.current.x;
|
const deltaX = currentPointerX - prevMousePos.current.x;
|
||||||
prevMousePos.current.x = currentPointerX;
|
prevMousePos.current.x = currentPointerX;
|
||||||
const marker = isRotating === "start" ? isAssembly ? assemblyMarker.current : startMarker.current : isAssembly ? assemblyMarker.current : endMarker.current;
|
|
||||||
|
const marker =
|
||||||
|
isRotating === "start" ? startMarker.current :
|
||||||
|
isRotating === "end" ? endMarker.current :
|
||||||
|
assemblyMarker.current;
|
||||||
|
|
||||||
if (marker) {
|
if (marker) {
|
||||||
const rotationSpeed = 10;
|
const rotationSpeed = 10;
|
||||||
marker.rotation.y += deltaX * rotationSpeed;
|
marker.rotation.y += deltaX * rotationSpeed;
|
||||||
if (isAssembly && isRotating === "start") {
|
|
||||||
setAssemblyRotation([
|
if (isRotating === "start") {
|
||||||
marker.rotation.x,
|
|
||||||
marker.rotation.y,
|
|
||||||
marker.rotation.z,
|
|
||||||
]);
|
|
||||||
} else if (isRotating === "start") {
|
|
||||||
setStartRotation([
|
setStartRotation([
|
||||||
marker.rotation.x,
|
marker.rotation.x,
|
||||||
marker.rotation.y,
|
marker.rotation.y,
|
||||||
marker.rotation.z,
|
marker.rotation.z,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else if (isRotating === "end") {
|
||||||
setEndRotation([
|
setEndRotation([
|
||||||
marker.rotation.x,
|
marker.rotation.x,
|
||||||
marker.rotation.y,
|
marker.rotation.y,
|
||||||
marker.rotation.z,
|
marker.rotation.z,
|
||||||
]);
|
]);
|
||||||
|
} else {
|
||||||
|
setAssemblyRotation([
|
||||||
|
marker.rotation.x,
|
||||||
|
marker.rotation.y,
|
||||||
|
marker.rotation.z,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -281,7 +300,7 @@ function HumanUi() {
|
|||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("pointerup", handleGlobalPointerUp);
|
window.removeEventListener("pointerup", handleGlobalPointerUp);
|
||||||
};
|
};
|
||||||
}, [isDragging, isRotating, startPosition, startRotation, endPosition, endRotation, assemblyRotation]);
|
}, [isDragging, isRotating, startPosition, startRotation, endPosition, endRotation, assemblyPosition, assemblyRotation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -295,16 +314,13 @@ function HumanUi() {
|
|||||||
<primitive
|
<primitive
|
||||||
ref={assemblyMarker}
|
ref={assemblyMarker}
|
||||||
object={assemblyScene}
|
object={assemblyScene}
|
||||||
position={[0, 1, 0]}
|
position={assemblyPosition}
|
||||||
rotation={assemblyRotation}
|
rotation={assemblyRotation}
|
||||||
onPointerDown={(e: any) => {
|
onPointerDown={(e: any) => {
|
||||||
if (e.object.parent.name === "handle") {
|
if (e.object.parent.name === "handle") {
|
||||||
e.stopPropagation();
|
handlePointerDown(e, "assembly", "assembly");
|
||||||
const normalizedX = (e.clientX / window.innerWidth) * 2 - 1;
|
} else {
|
||||||
prevMousePos.current.x = normalizedX;
|
handlePointerDown(e, "assembly", "assembly");
|
||||||
setIsRotating("start");
|
|
||||||
setIsDragging(null);
|
|
||||||
if (controls) (controls as any).enabled = false;
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onPointerMissed={() => {
|
onPointerMissed={() => {
|
||||||
@@ -322,8 +338,11 @@ function HumanUi() {
|
|||||||
position={startPosition}
|
position={startPosition}
|
||||||
rotation={startRotation}
|
rotation={startRotation}
|
||||||
onPointerDown={(e: any) => {
|
onPointerDown={(e: any) => {
|
||||||
e.stopPropagation();
|
if (e.object.parent.name === "handle") {
|
||||||
handlePointerDown(e, "start", "start");
|
handlePointerDown(e, "start", "start");
|
||||||
|
} else {
|
||||||
|
handlePointerDown(e, "start", "start");
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onPointerMissed={() => {
|
onPointerMissed={() => {
|
||||||
setIsDragging(null);
|
setIsDragging(null);
|
||||||
@@ -339,8 +358,11 @@ function HumanUi() {
|
|||||||
position={endPosition}
|
position={endPosition}
|
||||||
rotation={endRotation}
|
rotation={endRotation}
|
||||||
onPointerDown={(e: any) => {
|
onPointerDown={(e: any) => {
|
||||||
e.stopPropagation();
|
if (e.object.parent.name === "handle") {
|
||||||
handlePointerDown(e, "end", "end");
|
handlePointerDown(e, "end", "end");
|
||||||
|
} else {
|
||||||
|
handlePointerDown(e, "end", "end");
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onPointerMissed={() => {
|
onPointerMissed={() => {
|
||||||
setIsDragging(null);
|
setIsDragging(null);
|
||||||
@@ -356,4 +378,4 @@ function HumanUi() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HumanUi
|
export default HumanUi;
|
||||||
@@ -203,8 +203,8 @@ export const useSelectedAnimation = create<SelectedAnimationState>()(
|
|||||||
);
|
);
|
||||||
|
|
||||||
interface IsDraggingState {
|
interface IsDraggingState {
|
||||||
isDragging: "start" | "end" | null;
|
isDragging: "start" | "end" | "assembly" | null;
|
||||||
setIsDragging: (state: "start" | "end" | null) => void;
|
setIsDragging: (state: "start" | "end" | "assembly" | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useIsDragging = create<IsDraggingState>()(
|
export const useIsDragging = create<IsDraggingState>()(
|
||||||
@@ -219,8 +219,8 @@ export const useIsDragging = create<IsDraggingState>()(
|
|||||||
);
|
);
|
||||||
|
|
||||||
interface IsRotatingState {
|
interface IsRotatingState {
|
||||||
isRotating: "start" | "end" | null;
|
isRotating: "start" | "end" | "assembly" | null;
|
||||||
setIsRotating: (state: "start" | "end" | null) => void;
|
setIsRotating: (state: "start" | "end" | "assembly" | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useIsRotating = create<IsRotatingState>()(
|
export const useIsRotating = create<IsRotatingState>()(
|
||||||
|
|||||||
4
app/src/types/simulationTypes.d.ts
vendored
4
app/src/types/simulationTypes.d.ts
vendored
@@ -75,7 +75,7 @@ interface HumanAction {
|
|||||||
actionType: "worker" | "assembly";
|
actionType: "worker" | "assembly";
|
||||||
processTime?: number;
|
processTime?: number;
|
||||||
swapMaterial?: string;
|
swapMaterial?: string;
|
||||||
assemblyPoint?: { rotation: [number, number, number] | null; }
|
assemblyPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||||
pickUpPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
pickUpPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||||
dropPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
dropPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||||
loadCapacity: number;
|
loadCapacity: number;
|
||||||
@@ -306,4 +306,4 @@ type IK = {
|
|||||||
maxDistance?: number;
|
maxDistance?: number;
|
||||||
maxheight?: number;
|
maxheight?: number;
|
||||||
minheight?: number;
|
minheight?: number;
|
||||||
} ;
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user