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} />
|
||||
|
||||
Reference in New Issue
Block a user