Skip to content

Commit

Permalink
Account for minimum motion for node clicks (nerfstudio-project#109)
Browse files Browse the repository at this point in the history
* Account for minimum motion for node clicks

* Remove stale useref
  • Loading branch information
chungmin99 authored Sep 29, 2023
1 parent f2b6056 commit 9a428df
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 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 @@ -200,7 +206,6 @@ export function SceneNodeThreeObject(props: {
50
);
const [hovered, setHovered] = React.useState(false);
const [dragged, setDragged] = React.useState(false);
useCursor(hovered);
if (!clickable && hovered) setHovered(false);

Expand All @@ -219,17 +224,27 @@ export function SceneNodeThreeObject(props: {
onPointerDown={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
setDragged(false);
const state = dragInfo.current;
state.startClientX = e.clientX;
state.startClientY = e.clientY;
state.dragging = false;
}}
onPointerMove={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
setDragged(true);
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;
state.dragging = true;
}}
onPointerUp={(e) => {
if (!isDisplayed()) return;
e.stopPropagation();
if (dragged) return;
const state = dragInfo.current;
if (state.dragging) return;
sendClicksThrottled({
type: "SceneNodeClickedMessage",
name: props.name,
Expand Down

0 comments on commit 9a428df

Please sign in to comment.