bug fix in ik and code optimization
This commit is contained in:
@@ -3,8 +3,15 @@ import { useMemo } from "react";
|
||||
import { Cylinder } from "@react-three/drei";
|
||||
|
||||
export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { name: string; boundingBox: Box3 | null; color: string; lineWidth: number; }) => {
|
||||
const { edgeCylinders, center, size } = useMemo(() => {
|
||||
if (!boundingBox) return { edgeCylinders: [], center: new Vector3(), size: new Vector3() };
|
||||
const { edgeCylinders, cornerSpheres, center, size } = useMemo(() => {
|
||||
if (!boundingBox) {
|
||||
return {
|
||||
edgeCylinders: [],
|
||||
cornerSpheres: [],
|
||||
center: new Vector3(),
|
||||
size: new Vector3(),
|
||||
};
|
||||
}
|
||||
|
||||
const min = boundingBox.min;
|
||||
const max = boundingBox.max;
|
||||
@@ -50,7 +57,13 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
||||
};
|
||||
});
|
||||
|
||||
return { edgeCylinders, center, size };
|
||||
const cornerSpheres = corners.map((corner, i) => ({
|
||||
key: `corner-sphere-${i}`,
|
||||
position: corner.clone(),
|
||||
radius: radius * 1.5,
|
||||
}));
|
||||
|
||||
return { edgeCylinders, cornerSpheres, center, size };
|
||||
}, [boundingBox, lineWidth]);
|
||||
|
||||
if (!boundingBox) return null;
|
||||
@@ -58,11 +71,18 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
||||
return (
|
||||
<group name={name}>
|
||||
{edgeCylinders.map(({ key, position, rotation, length, radius }) => (
|
||||
<Cylinder key={key} args={[radius, radius, length, 6]} position={position} quaternion={rotation} >
|
||||
<Cylinder key={key} args={[radius, radius, length, 6]} position={position} quaternion={rotation}>
|
||||
<meshBasicMaterial color={color} depthWrite={false} />
|
||||
</Cylinder>
|
||||
))}
|
||||
|
||||
{cornerSpheres.map(({ key, position, radius }) => (
|
||||
<mesh key={key} position={position}>
|
||||
<sphereGeometry args={[radius, 12, 12]} />
|
||||
<meshBasicMaterial color={color} depthWrite={false} />
|
||||
</mesh>
|
||||
))}
|
||||
|
||||
<mesh visible={false} position={center}>
|
||||
<boxGeometry args={[size.x, size.y, size.z]} />
|
||||
</mesh>
|
||||
|
||||
@@ -449,7 +449,11 @@ function Model({ asset, isRendered, loader }: { readonly asset: Asset, isRendere
|
||||
|
||||
</>
|
||||
) : (
|
||||
<AssetBoundingBox name='Asset Fallback' boundingBox={boundingBox} color='gray' lineWidth={2.5} />
|
||||
<>
|
||||
{!isSelected &&
|
||||
<AssetBoundingBox name='Asset Fallback' boundingBox={boundingBox} color='gray' lineWidth={2.5} />
|
||||
}
|
||||
</>
|
||||
)}
|
||||
{isSelected &&
|
||||
<AssetBoundingBox name='Asset BBox' boundingBox={boundingBox} color={savedTheme === "dark" ? "#c4abf1" : "#6f42c1"} lineWidth={2.7} />
|
||||
|
||||
@@ -61,30 +61,12 @@ function MaterialInstance({ material }: { readonly material: MaterialSchema }) {
|
||||
function getCurrentSpeed(productUuid: string, modelUuid: string) {
|
||||
const event = getEventByModelUuid(productUuid, modelUuid)
|
||||
if (event) {
|
||||
if (event.type === 'transfer') {
|
||||
return event.speed;
|
||||
}
|
||||
|
||||
if (event.type === 'vehicle') {
|
||||
return event.speed;
|
||||
}
|
||||
|
||||
if (event.type === 'machine') {
|
||||
if (event.type === 'transfer' || event.type === 'machine' || event.type === 'storageUnit') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (event.type === 'roboticArm') {
|
||||
if (event.type === 'vehicle' || event.type === 'roboticArm' || event.type === 'human') {
|
||||
return event.speed;
|
||||
}
|
||||
|
||||
if (event.type === 'storageUnit') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (event.type === 'human') {
|
||||
return event.speed;
|
||||
}
|
||||
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import MaterialInstance from './instance/materialInstance'
|
||||
import { useSceneContext } from '../../../scene/sceneContext';
|
||||
|
||||
|
||||
@@ -173,13 +173,16 @@ const ArmBotUI = () => {
|
||||
|
||||
const targetMesh = scene?.getObjectByProperty("uuid", selectedArmBotData?.modelUuid || '');
|
||||
|
||||
const iks = targetMesh?.userData?.iks;
|
||||
const firstIK = Array.isArray(iks) && iks.length > 0 ? iks[0] : {};
|
||||
|
||||
const { handlePointerDown } = useDraggableGLTF(
|
||||
updatePointToState,
|
||||
{
|
||||
minDistance: targetMesh?.userData?.iks[0]?.minDistance || 1.2,
|
||||
maxDistance: targetMesh?.userData?.iks[0]?.maxDistance || 2,
|
||||
maxheight: targetMesh?.userData?.iks[0]?.maxheight || 0.6,
|
||||
minheight: targetMesh?.userData?.iks[0]?.minheight || 1.9,
|
||||
minDistance: firstIK.minDistance ?? 1.2,
|
||||
maxDistance: firstIK.maxDistance ?? 2,
|
||||
maxheight: firstIK.maxheight ?? 0.6,
|
||||
minheight: firstIK.minheight ?? 1.9,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user