Skip to content

Commit

Permalink
Account for minimum motion for node clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
chungmin99 committed Sep 29, 2023
1 parent 919a961 commit 5b05e4f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/viser/client/src/SceneTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export function SceneNodeThreeObject(props: {
false;
const [obj, setRef] = React.useState<THREE.Object3D | null>(null);

const dragInfo = React.useRef({
dragging: false,
startClientX: 0,
startClientY: 0,
});

// Create object + children.
//
// For not-fully-understood reasons, wrapping makeObject with useMemo() fixes
Expand Down Expand Up @@ -219,11 +225,20 @@ export function SceneNodeThreeObject(props: {
onPointerDown={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
const state = dragInfo.current;
state.startClientX = e.clientX;
state.startClientY = e.clientY;
setDragged(false);
}}
onPointerMove={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
const state = dragInfo.current;
const deltaX = e.clientX - state.startClientX;
const deltaY = e.clientY - state.startClientY;
// Minimum motion.
console.log(deltaX, deltaY);
if (Math.abs(deltaX) <= 3 && Math.abs(deltaY) <= 3) return;
setDragged(true);
}}
onPointerUp={(e) => {
Expand Down

0 comments on commit 5b05e4f

Please sign in to comment.