🚀 Auto-deploy: melhoria no snap e medição AR em 04/08/2026 20:55:34
This commit is contained in:
@@ -16,6 +16,8 @@ interface XRGrabbableProps {
|
||||
lockedActive?: boolean;
|
||||
/** Called the first time the user grabs (e.g. to exit placement mode) */
|
||||
onGrabStart?: () => void;
|
||||
/** Optional callback to sync transforms to local state instead of store */
|
||||
onSync?: (pos: THREE.Vector3, quat: THREE.Quaternion, scale: THREE.Vector3) => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ const _tmpQuat = new THREE.Quaternion();
|
||||
* segurar ambos os botões de Grip (L+R) e mover as mãos em direções opostas (giro) ou
|
||||
* afastar/aproximar as mãos (zoom).
|
||||
*/
|
||||
export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabStart, children }: XRGrabbableProps) {
|
||||
export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabStart, onSync, children }: XRGrabbableProps) {
|
||||
const groupRef = useRef<THREE.Group>(null);
|
||||
const grab = useControllerGrab();
|
||||
const session = useXR((s) => s.session);
|
||||
@@ -88,6 +90,20 @@ export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabSta
|
||||
const group = groupRef.current;
|
||||
if (!group) return;
|
||||
|
||||
if (onSync) {
|
||||
const finalPos = new THREE.Vector3();
|
||||
const finalQuat = new THREE.Quaternion();
|
||||
const finalScale = new THREE.Vector3();
|
||||
group.matrixWorld.decompose(finalPos, finalQuat, finalScale);
|
||||
|
||||
group.position.set(0, 0, 0);
|
||||
group.quaternion.identity();
|
||||
group.scale.set(1, 1, 1);
|
||||
|
||||
onSync(finalPos, finalQuat, finalScale);
|
||||
return;
|
||||
}
|
||||
|
||||
const state = useModelStore.getState();
|
||||
const activeModelId = state.activeModelId;
|
||||
if (!activeModelId) return;
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
Hand,
|
||||
} from "lucide-react";
|
||||
import { Suspense } from "react";
|
||||
import { XRGrabbable } from "@/components/three/XRGrabbable";
|
||||
|
||||
/**
|
||||
* ============================================================
|
||||
@@ -167,6 +168,22 @@ const CubeControlado = ({
|
||||
});
|
||||
|
||||
return (
|
||||
<XRGrabbable
|
||||
allowScale={true}
|
||||
lockedActive={lockedRef.current}
|
||||
onSync={(pos, quat, scale) => {
|
||||
posRef.current.x = pos.x;
|
||||
posRef.current.y = Math.max(0.5, pos.y);
|
||||
posRef.current.z = pos.z;
|
||||
|
||||
const euler = new THREE.Euler().setFromQuaternion(quat, 'YXZ');
|
||||
rotRef.current.x = euler.x;
|
||||
rotRef.current.y = euler.y;
|
||||
rotRef.current.z = euler.z;
|
||||
|
||||
scaleRef.current = scale.x;
|
||||
}}
|
||||
>
|
||||
<mesh
|
||||
ref={meshRef}
|
||||
castShadow
|
||||
@@ -197,6 +214,7 @@ const CubeControlado = ({
|
||||
<primitive attach={`material-${i}`} object={m} key={i} />
|
||||
))}
|
||||
</mesh>
|
||||
</XRGrabbable>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user