feat: improve fist grab depth tracking
This commit is contained in:
@@ -76,15 +76,17 @@ class HandTracker:
|
|||||||
result.hand_landmarks,
|
result.hand_landmarks,
|
||||||
result.handedness,
|
result.handedness,
|
||||||
):
|
):
|
||||||
index_tip = landmarks[8]
|
palm_center = self._average_points(
|
||||||
|
[landmarks[0], landmarks[5], landmarks[9], landmarks[13], landmarks[17]],
|
||||||
|
)
|
||||||
is_fist = self._is_fist(landmarks)
|
is_fist = self._is_fist(landmarks)
|
||||||
handedness = handedness_categories[0]
|
handedness = handedness_categories[0]
|
||||||
|
|
||||||
hands.append(
|
hands.append(
|
||||||
HandData(
|
HandData(
|
||||||
x=index_tip.x,
|
x=palm_center["x"],
|
||||||
y=index_tip.y,
|
y=palm_center["y"],
|
||||||
z=index_tip.z,
|
z=palm_center["z"],
|
||||||
landmarks=[
|
landmarks=[
|
||||||
{"x": point.x, "y": point.y, "z": point.z}
|
{"x": point.x, "y": point.y, "z": point.z}
|
||||||
for point in landmarks
|
for point in landmarks
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export function GrabbableObject({
|
|||||||
const rbRef = useRef<RapierRigidBody>(null);
|
const rbRef = useRef<RapierRigidBody>(null);
|
||||||
const isHolding = useRef(false);
|
const isHolding = useRef(false);
|
||||||
const isHandHolding = useRef(false);
|
const isHandHolding = useRef(false);
|
||||||
|
const handHoldDistance = useRef<number | null>(null);
|
||||||
|
|
||||||
useDebugFolder("GrabbableObject", (folder) => {
|
useDebugFolder("GrabbableObject", (folder) => {
|
||||||
folder
|
folder
|
||||||
@@ -123,17 +124,23 @@ export function GrabbableObject({
|
|||||||
: [];
|
: [];
|
||||||
|
|
||||||
isHandHolding.current = isObjectInRange && hits.length > 0;
|
isHandHolding.current = isObjectInRange && hits.length > 0;
|
||||||
|
handHoldDistance.current = isHandHolding.current
|
||||||
|
? hits[0].distance
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
isHandHolding.current = false;
|
isHandHolding.current = false;
|
||||||
|
handHoldDistance.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHolding.current && !isHandHolding.current) return;
|
if (!isHolding.current && !isHandHolding.current) return;
|
||||||
|
|
||||||
if (fistHand && isHandHolding.current) {
|
if (fistHand && isHandHolding.current) {
|
||||||
|
const holdDistance = handHoldDistance.current ?? params.holdDistance;
|
||||||
|
|
||||||
_holdTarget
|
_holdTarget
|
||||||
.copy(_cameraPos)
|
.copy(_cameraPos)
|
||||||
.addScaledVector(_handDirection, params.holdDistance);
|
.addScaledVector(_handDirection, holdDistance);
|
||||||
} else {
|
} else {
|
||||||
camera.getWorldDirection(_holdTarget);
|
camera.getWorldDirection(_holdTarget);
|
||||||
_holdTarget.multiplyScalar(params.holdDistance).add(camera.position);
|
_holdTarget.multiplyScalar(params.holdDistance).add(camera.position);
|
||||||
|
|||||||
Reference in New Issue
Block a user