bug fix
This commit is contained in:
@@ -2,13 +2,14 @@ import { Line } from "@react-three/drei";
|
||||
import { Box3, Vector3 } from "three";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { name: string; boundingBox: Box3 | null; color: string; lineWidth: number; }) => {
|
||||
const { points } = useMemo(() => {
|
||||
if (!boundingBox) return { points: [], center: new Vector3() };
|
||||
export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth }: { name: string; boundingBox: Box3 | null; color: string; lineWidth: number; }) => {
|
||||
const { points, size, center } = useMemo(() => {
|
||||
if (!boundingBox) { return { points: [], center: new Vector3(), size: new Vector3(), }; }
|
||||
|
||||
const min = boundingBox.min;
|
||||
const max = boundingBox.max;
|
||||
const center = boundingBox.getCenter(new Vector3());
|
||||
const size = boundingBox.getSize(new Vector3());
|
||||
|
||||
const edges: Array<[number, number, number]> = [
|
||||
[min.x, min.y, min.z], [max.x, min.y, min.z],
|
||||
@@ -27,7 +28,7 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
||||
[min.x, max.y, min.z], [min.x, max.y, max.z],
|
||||
];
|
||||
|
||||
return { points: edges, center };
|
||||
return { points: edges, center, size };
|
||||
}, [boundingBox]);
|
||||
|
||||
if (!boundingBox) return null;
|
||||
@@ -41,6 +42,10 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
||||
color={color}
|
||||
lineWidth={lineWidth}
|
||||
/>
|
||||
|
||||
<mesh visible={false} position={center}>
|
||||
<boxGeometry args={[size.x, size.y, size.z]} />
|
||||
</mesh>
|
||||
</group>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user