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";
|
import { Cylinder } from "@react-three/drei";
|
||||||
|
|
||||||
export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { name: string; boundingBox: Box3 | null; color: string; lineWidth: number; }) => {
|
export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { name: string; boundingBox: Box3 | null; color: string; lineWidth: number; }) => {
|
||||||
const { edgeCylinders, center, size } = useMemo(() => {
|
const { edgeCylinders, cornerSpheres, center, size } = useMemo(() => {
|
||||||
if (!boundingBox) return { edgeCylinders: [], center: new Vector3(), size: new Vector3() };
|
if (!boundingBox) {
|
||||||
|
return {
|
||||||
|
edgeCylinders: [],
|
||||||
|
cornerSpheres: [],
|
||||||
|
center: new Vector3(),
|
||||||
|
size: new Vector3(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const min = boundingBox.min;
|
const min = boundingBox.min;
|
||||||
const max = boundingBox.max;
|
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]);
|
}, [boundingBox, lineWidth]);
|
||||||
|
|
||||||
if (!boundingBox) return null;
|
if (!boundingBox) return null;
|
||||||
@@ -58,11 +71,18 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
|||||||
return (
|
return (
|
||||||
<group name={name}>
|
<group name={name}>
|
||||||
{edgeCylinders.map(({ key, position, rotation, length, radius }) => (
|
{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} />
|
<meshBasicMaterial color={color} depthWrite={false} />
|
||||||
</Cylinder>
|
</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}>
|
<mesh visible={false} position={center}>
|
||||||
<boxGeometry args={[size.x, size.y, size.z]} />
|
<boxGeometry args={[size.x, size.y, size.z]} />
|
||||||
</mesh>
|
</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 &&
|
{isSelected &&
|
||||||
<AssetBoundingBox name='Asset BBox' boundingBox={boundingBox} color={savedTheme === "dark" ? "#c4abf1" : "#6f42c1"} lineWidth={2.7} />
|
<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) {
|
function getCurrentSpeed(productUuid: string, modelUuid: string) {
|
||||||
const event = getEventByModelUuid(productUuid, modelUuid)
|
const event = getEventByModelUuid(productUuid, modelUuid)
|
||||||
if (event) {
|
if (event) {
|
||||||
if (event.type === 'transfer') {
|
if (event.type === 'transfer' || event.type === 'machine' || event.type === 'storageUnit') {
|
||||||
return event.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type === 'vehicle') {
|
|
||||||
return event.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type === 'machine') {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (event.type === 'vehicle' || event.type === 'roboticArm' || event.type === 'human') {
|
||||||
if (event.type === 'roboticArm') {
|
|
||||||
return event.speed;
|
return event.speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type === 'storageUnit') {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type === 'human') {
|
|
||||||
return event.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import MaterialInstance from './instance/materialInstance'
|
import MaterialInstance from './instance/materialInstance'
|
||||||
import { useSceneContext } from '../../../scene/sceneContext';
|
import { useSceneContext } from '../../../scene/sceneContext';
|
||||||
|
|
||||||
|
|||||||
@@ -173,13 +173,16 @@ const ArmBotUI = () => {
|
|||||||
|
|
||||||
const targetMesh = scene?.getObjectByProperty("uuid", selectedArmBotData?.modelUuid || '');
|
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(
|
const { handlePointerDown } = useDraggableGLTF(
|
||||||
updatePointToState,
|
updatePointToState,
|
||||||
{
|
{
|
||||||
minDistance: targetMesh?.userData?.iks[0]?.minDistance || 1.2,
|
minDistance: firstIK.minDistance ?? 1.2,
|
||||||
maxDistance: targetMesh?.userData?.iks[0]?.maxDistance || 2,
|
maxDistance: firstIK.maxDistance ?? 2,
|
||||||
maxheight: targetMesh?.userData?.iks[0]?.maxheight || 0.6,
|
maxheight: firstIK.maxheight ?? 0.6,
|
||||||
minheight: targetMesh?.userData?.iks[0]?.minheight || 1.9,
|
minheight: firstIK.minheight ?? 1.9,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user