Skip to content

Commit 5b05e4f

Browse files
committed
Account for minimum motion for node clicks
1 parent 919a961 commit 5b05e4f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/viser/client/src/SceneTree.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ export function SceneNodeThreeObject(props: {
113113
false;
114114
const [obj, setRef] = React.useState<THREE.Object3D | null>(null);
115115

116+
const dragInfo = React.useRef({
117+
dragging: false,
118+
startClientX: 0,
119+
startClientY: 0,
120+
});
121+
116122
// Create object + children.
117123
//
118124
// For not-fully-understood reasons, wrapping makeObject with useMemo() fixes
@@ -219,11 +225,20 @@ export function SceneNodeThreeObject(props: {
219225
onPointerDown={(e) => {
220226
if (!isDisplayed()) return;
221227
e.stopPropagation();
228+
const state = dragInfo.current;
229+
state.startClientX = e.clientX;
230+
state.startClientY = e.clientY;
222231
setDragged(false);
223232
}}
224233
onPointerMove={(e) => {
225234
if (!isDisplayed()) return;
226235
e.stopPropagation();
236+
const state = dragInfo.current;
237+
const deltaX = e.clientX - state.startClientX;
238+
const deltaY = e.clientY - state.startClientY;
239+
// Minimum motion.
240+
console.log(deltaX, deltaY);
241+
if (Math.abs(deltaX) <= 3 && Math.abs(deltaY) <= 3) return;
227242
setDragged(true);
228243
}}
229244
onPointerUp={(e) => {

0 commit comments

Comments
 (0)