bug fix
This commit is contained in:
@@ -2,13 +2,14 @@ import { Line } from "@react-three/drei";
|
|||||||
import { Box3, Vector3 } from "three";
|
import { Box3, Vector3 } from "three";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
|
||||||
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 { points } = useMemo(() => {
|
const { points, size, center } = useMemo(() => {
|
||||||
if (!boundingBox) return { points: [], center: new Vector3() };
|
if (!boundingBox) { return { points: [], center: new Vector3(), size: new Vector3(), }; }
|
||||||
|
|
||||||
const min = boundingBox.min;
|
const min = boundingBox.min;
|
||||||
const max = boundingBox.max;
|
const max = boundingBox.max;
|
||||||
const center = boundingBox.getCenter(new Vector3());
|
const center = boundingBox.getCenter(new Vector3());
|
||||||
|
const size = boundingBox.getSize(new Vector3());
|
||||||
|
|
||||||
const edges: Array<[number, number, number]> = [
|
const edges: Array<[number, number, number]> = [
|
||||||
[min.x, min.y, min.z], [max.x, min.y, min.z],
|
[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],
|
[min.x, max.y, min.z], [min.x, max.y, max.z],
|
||||||
];
|
];
|
||||||
|
|
||||||
return { points: edges, center };
|
return { points: edges, center, size };
|
||||||
}, [boundingBox]);
|
}, [boundingBox]);
|
||||||
|
|
||||||
if (!boundingBox) return null;
|
if (!boundingBox) return null;
|
||||||
@@ -41,6 +42,10 @@ export const AssetBoundingBox = ({ name, boundingBox, color, lineWidth, }: { nam
|
|||||||
color={color}
|
color={color}
|
||||||
lineWidth={lineWidth}
|
lineWidth={lineWidth}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<mesh visible={false} position={center}>
|
||||||
|
<boxGeometry args={[size.x, size.y, size.z]} />
|
||||||
|
</mesh>
|
||||||
</group>
|
</group>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ function WallAssetInstance({ wallAsset }: { wallAsset: WallAsset }) {
|
|||||||
visible={wallAsset.isVisible}
|
visible={wallAsset.isVisible}
|
||||||
userData={wallAsset}
|
userData={wallAsset}
|
||||||
>
|
>
|
||||||
<Subtraction position={[center.x, center.y, center.z]} scale={[size.x, size.y, wall.wallThickness + 0.05]}>
|
<Subtraction position={[center.x, center.y, 0]} scale={[size.x, size.y, wall.wallThickness + 0.05]}>
|
||||||
<Geometry>
|
<Geometry>
|
||||||
<Base geometry={new THREE.BoxGeometry()} />
|
<Base geometry={new THREE.BoxGeometry()} />
|
||||||
</Geometry>
|
</Geometry>
|
||||||
@@ -265,7 +265,7 @@ function WallAssetInstance({ wallAsset }: { wallAsset: WallAsset }) {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let currentObject = e.object as THREE.Object3D;
|
let currentObject = e.object as THREE.Object3D;
|
||||||
while (currentObject) {
|
while (currentObject) {
|
||||||
if (currentObject.name === "Scene") {
|
if (currentObject.userData.wallUuid) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currentObject = currentObject.parent as THREE.Object3D;
|
currentObject = currentObject.parent as THREE.Object3D;
|
||||||
@@ -286,7 +286,7 @@ function WallAssetInstance({ wallAsset }: { wallAsset: WallAsset }) {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let currentObject = e.object as THREE.Object3D;
|
let currentObject = e.object as THREE.Object3D;
|
||||||
while (currentObject) {
|
while (currentObject) {
|
||||||
if (currentObject.name === "Scene") {
|
if (currentObject.userData.wallUuid) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currentObject = currentObject.parent as THREE.Object3D;
|
currentObject = currentObject.parent as THREE.Object3D;
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ function MoveControls3D({
|
|||||||
if (dragOffset) {
|
if (dragOffset) {
|
||||||
const rawBasePosition = new THREE.Vector3().addVectors(intersectionPoint, dragOffset);
|
const rawBasePosition = new THREE.Vector3().addVectors(intersectionPoint, dragOffset);
|
||||||
|
|
||||||
let moveSpeed = keyEvent.includes("Shift") ? 0.25 : 1;
|
let moveSpeed = keyEvent.includes("Shift") ? 0.05 : 1;
|
||||||
|
|
||||||
const initialBasePosition = initialPositions[movedObjects[0].uuid];
|
const initialBasePosition = initialPositions[movedObjects[0].uuid];
|
||||||
const positionDifference = new THREE.Vector3().subVectors(rawBasePosition, initialBasePosition);
|
const positionDifference = new THREE.Vector3().subVectors(rawBasePosition, initialBasePosition);
|
||||||
|
|||||||
Reference in New Issue
Block a user