- Added ArmBot component to manage ArmBot instances in the simulation. - Created ArmBotInstances component to render individual ArmBot models. - Developed IKAnimationController for handling inverse kinematics during animations. - Introduced IkInstances component to load and manage IK-enabled arm models. - Defined simulation types for ArmBot events and connections in TypeScript. - Enhanced type definitions for better clarity and maintainability.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import React, { useEffect, useState } from "react";
|
|
import { useThree } from "@react-three/fiber";
|
|
import useModuleStore from "../../../store/useModuleStore";
|
|
import { useSimulationStates } from "../../../store/store";
|
|
import * as SimulationTypes from '../../../types/simulation';
|
|
import { ArmbotInstances } from "./ArmBotInstances";
|
|
|
|
interface ArmBotState {
|
|
uuid: string;
|
|
position: [number, number, number];
|
|
rotation: [number, number, number];
|
|
status: string;
|
|
material: string;
|
|
triggerId: string;
|
|
connections: any
|
|
}
|
|
|
|
const ArmBot: React.FC = () => {
|
|
const { activeModule } = useModuleStore();
|
|
const { scene } = useThree();
|
|
const { simulationStates } = useSimulationStates();
|
|
const [armBots, setArmBots] = useState<ArmBotState[]>([]);
|
|
|
|
useEffect(() => {
|
|
const filtered = simulationStates.filter((s): s is SimulationTypes.ArmBotEventsSchema => s.type === "ArmBot");
|
|
const initialStates: ArmBotState[] = filtered.map(bot => ({
|
|
uuid: bot.modeluuid,
|
|
position: bot.position,
|
|
rotation: bot.rotation,
|
|
status: "idle",
|
|
material: "default",
|
|
triggerId: '',
|
|
connections: bot.points.connections
|
|
}));
|
|
setArmBots(initialStates);
|
|
}, [simulationStates]);
|
|
|
|
useEffect(() => {
|
|
armBots.forEach((bot) => {
|
|
const object = scene.getObjectByProperty("uuid", bot.uuid);
|
|
if (object) {
|
|
object.visible = activeModule !== "simulation";
|
|
}
|
|
});
|
|
}, [scene, activeModule, armBots]);
|
|
|
|
return (
|
|
<>
|
|
{activeModule === "simulation" &&
|
|
armBots.map((bot, i) => (
|
|
<ArmbotInstances
|
|
key={i}
|
|
index={i}
|
|
armBot={bot}
|
|
setArmBots={setArmBots}
|
|
/>
|
|
))}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ArmBot;
|