Fix bounding box position calculations and update distance finding controls for accurate positioning based on geometry. Enhance move controls to correctly handle floor intersections and adjust object positioning accordingly.
This commit is contained in:
@@ -51,7 +51,7 @@ const BoundingBox = ({ boundingBoxRef, isPerAsset = true }: BoundingBoxProps) =>
|
||||
|
||||
return {
|
||||
points: getBoxLines(min, max),
|
||||
position: [position.x, center.y, position.z],
|
||||
position: [position.x, position.y, position.z],
|
||||
rotation: rotation.toArray(),
|
||||
size: size.toArray(),
|
||||
};
|
||||
@@ -93,7 +93,7 @@ const BoundingBox = ({ boundingBoxRef, isPerAsset = true }: BoundingBoxProps) =>
|
||||
color={savedTheme === "dark" ? "#c4abf1" : "#6f42c1"}
|
||||
lineWidth={2.7}
|
||||
segments
|
||||
position={[box.position[0], 0, box.position[2]]}
|
||||
position={[box.position[0], box.position[1], box.position[2]]}
|
||||
quaternion={new THREE.Quaternion(...box.rotation)}
|
||||
/>
|
||||
<mesh
|
||||
|
||||
@@ -189,6 +189,16 @@ const DistanceFindingControls = ({
|
||||
{boundingBoxRef.current && object > 0 && (
|
||||
<group
|
||||
name="DistanceFindingControls"
|
||||
position={
|
||||
boundingBoxRef.current?.geometry.boundingBox
|
||||
? [
|
||||
0,
|
||||
(boundingBoxRef.current.geometry.boundingBox.max.y -
|
||||
boundingBoxRef.current.geometry.boundingBox.min.y) / 2,
|
||||
0,
|
||||
]
|
||||
: [0, 0, 0]
|
||||
}
|
||||
>
|
||||
{renderLabel("textPosX")}
|
||||
{renderLabel("textNegX")}
|
||||
|
||||
@@ -165,10 +165,21 @@ function MoveControls({
|
||||
if (movedObjects.length > 0) {
|
||||
const intersectionPoint = new THREE.Vector3();
|
||||
raycaster.setFromCamera(pointer, camera);
|
||||
const point = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
let point = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
const floorsGroup = scene.getObjectByName("Floors-Group") as Types.Group | null;
|
||||
const floorChildren = floorsGroup?.children ?? [];
|
||||
const floorIntersections = raycaster.intersectObjects([...floorChildren], true);
|
||||
const intersectedFloor = floorIntersections.find((intersect) => intersect.object.name.includes("Floor"));
|
||||
|
||||
if (intersectedFloor && selectedAssets.length === 1) {
|
||||
if (intersectedFloor.object.userData.floorUuid) {
|
||||
point = new THREE.Vector3(intersectedFloor.point.x, intersectedFloor.object.userData.floorDepth, intersectedFloor.point.z);
|
||||
}
|
||||
}
|
||||
|
||||
if (point) {
|
||||
let targetX = point.x;
|
||||
let targetY = point.y;
|
||||
let targetZ = point.z;
|
||||
|
||||
if (keyEvent === "Ctrl") {
|
||||
@@ -192,7 +203,7 @@ function MoveControls({
|
||||
selectionGroup.current.position.lerp(
|
||||
new THREE.Vector3(
|
||||
targetX - (position.x - selectionGroup.current.position.x),
|
||||
selectionGroup.current.position.y,
|
||||
targetY - (position.y - selectionGroup.current.position.y),
|
||||
targetZ - (position.z - selectionGroup.current.position.z)
|
||||
),
|
||||
moveSpeed
|
||||
@@ -230,9 +241,13 @@ function MoveControls({
|
||||
|
||||
movedObjects.forEach(async (obj: THREE.Object3D) => {
|
||||
if (obj && AssetGroup.current) {
|
||||
const worldPosition = new THREE.Vector3();
|
||||
let worldPosition = new THREE.Vector3();
|
||||
obj.getWorldPosition(worldPosition);
|
||||
|
||||
if (worldPosition.y < 0) {
|
||||
worldPosition.y = 0;
|
||||
}
|
||||
|
||||
selectionGroup.current.remove(obj);
|
||||
obj.position.copy(worldPosition);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user