simulation-arm #62

Merged
Vishnu merged 4 commits from simulation-arm into main 2025-04-14 04:15:07 +00:00
3 changed files with 15 additions and 13 deletions
Showing only changes of commit 737094848f - Show all commits

View File

@@ -11,6 +11,7 @@ import { MultiGLTFInstances } from "./MultiGLTFInstances";
// impory model from model folder // impory model from model folder
import armModel from "../../../assets/gltf-glb/rigged/ik_arm_4.glb"; import armModel from "../../../assets/gltf-glb/rigged/ik_arm_4.glb";
import { Vector3 } from "three";
// Main component to include the logic // Main component to include the logic
const ArmReplace: React.FC = () => { const ArmReplace: React.FC = () => {
@@ -19,10 +20,10 @@ const ArmReplace: React.FC = () => {
const { scene } = useThree(); // Access the Three.js scene from the React Fiber context const { scene } = useThree(); // Access the Three.js scene from the React Fiber context
// State to store positions, rotations, and count // State to store positions, rotations, and count
const [positions, setPositions] = React.useState<[number, number, number][]>( const [positions, setPositions] = React.useState<Vector3[]>(
[] []
); );
const [rotations, setRotations] = React.useState<[number, number, number][]>( const [rotations, setRotations] = React.useState<Vector3[]>(
[] []
); );
const [count, setCount] = React.useState<string[]>([]); const [count, setCount] = React.useState<string[]>([]);

View File

@@ -1,12 +1,14 @@
import { useLoader } from "@react-three/fiber"; import { useLoader } from "@react-three/fiber";
import { Vector3 } from "three";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader"; import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { clone } from "three/examples/jsm/utils/SkeletonUtils"; import { clone } from "three/examples/jsm/utils/SkeletonUtils";
interface MultiGLTFInstancesProps { interface MultiGLTFInstancesProps {
index: number; index: number;
modelUrl: string; modelUrl: string;
position: [number, number, number]; position: Vector3;
rotation: [number, number, number]; rotation: Vector3;
visibility?: boolean; visibility?: boolean;
} }
@@ -25,8 +27,7 @@ export const MultiGLTFInstances: React.FC<MultiGLTFInstancesProps> = ({
); );
loader.setDRACOLoader(draco); loader.setDRACOLoader(draco);
}); });
const cloned = originalGltf.scene.clone(); const cloned = clone(originalGltf.scene);
console.log(index);
return ( return (
<> <>
{visibility && ( {visibility && (

View File

@@ -1,19 +1,19 @@
import { Object3D } from "three"; import { Object3D, Vector3 } from "three";
// Function to find objects named 'link_0' and update positions, rotations, and count // Function to find objects named 'link_0' and update positions, rotations, and count
export const findLinkObjects = ( export const findLinkObjects = (
scene: Object3D, scene: Object3D,
setPositions: React.Dispatch< setPositions: React.Dispatch<
React.SetStateAction<[number, number, number][]> React.SetStateAction<Vector3[]>
>, >,
setRotations: React.Dispatch< setRotations: React.Dispatch<
React.SetStateAction<[number, number, number][]> React.SetStateAction<Vector3[]>
>, >,
setCount: React.Dispatch<React.SetStateAction<string[]>>, setCount: React.Dispatch<React.SetStateAction<string[]>>,
visibility: boolean visibility: boolean
) => { ) => {
const positions: [number, number, number][] = []; const positions: Vector3[] = [];
const rotations: [number, number, number][] = []; const rotations: Vector3[] = [];
const count: string[] = []; const count: string[] = [];
let i = 0; let i = 0;
@@ -28,10 +28,10 @@ export const findLinkObjects = (
i++; i++;
// Save the position and rotation of the parent object // Save the position and rotation of the parent object
const { x: px, y: py, z: pz } = object.parent.position; const { x: px, y: py, z: pz } = object.parent.position;
positions.push([px, py, pz]); positions.push(new Vector3(px, py, pz));
const { x: rx, y: ry, z: rz } = object.parent.rotation; const { x: rx, y: ry, z: rz } = object.parent.rotation;
rotations.push([rx, ry, rz]); rotations.push(new Vector3(rx, ry, rz));
// Change visibility of the object // Change visibility of the object
object.visible = visibility; object.visible = visibility;