Skip to content

Commit 55bd14b

Browse files
committed
fix update order to prevent transform & pivot handles size flickering when drastic position changes occur
1 parent 6195c75 commit 55bd14b

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

packages/handle/src/computations/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,9 @@ function projectOntoPlane(
396396
): void {
397397
normalHelper.crossVectors(_axis1, _axis2).normalize()
398398
planeHelper.setFromNormalAndCoplanarPoint(normalHelper, initialWorldPoint)
399+
const angleDifference = worldDirection == null ? 0 : Math.abs(normalHelper.dot(worldDirection))
399400

400-
if (worldDirection == null) {
401+
if (worldDirection == null || angleDifference < 0.01) {
401402
//project point onto plane
402403
planeHelper.projectPoint(worldPoint, worldPoint)
403404
return
@@ -426,7 +427,8 @@ export function projectOntoAxis(
426427
worldPoint: Vector3,
427428
worldDirection: Vector3 | undefined,
428429
): void {
429-
if (worldDirection == null) {
430+
const angleDifference = worldDirection == null ? 0 : 1 - Math.abs(axis.dot(worldDirection))
431+
if (worldDirection == null || angleDifference < 0.001) {
430432
projectPointOntoAxis(worldPoint, initialWorldPoint, axis)
431433
return
432434
}

packages/react/handle/src/handles/pivot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const PivotHandlesContext = forwardRef<Group, PivotHandlesContextProperti
4545
const optionsRef = useRef(options)
4646
optionsRef.current = options
4747
const context = useMemo(() => new HandlesContextImpl(internalRef, () => optionsRef.current), [])
48-
useFrame((state) => context.update(state.clock.getElapsedTime()))
48+
useFrame((state) => context.update(state.clock.getElapsedTime()), -1)
4949
return (
5050
<group {...props} ref={internalRef}>
5151
<HandlesContext.Provider value={context}>{children}</HandlesContext.Provider>

packages/react/handle/src/handles/transform.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const TransformHandlesContext = forwardRef<Group, TransformHandlesContext
7575
if (space !== null) {
7676
context.space = space
7777
}
78-
useFrame((state) => context.update(state.clock.getElapsedTime()))
78+
useFrame((state) => context.update(state.clock.getElapsedTime()), -1)
7979
return (
8080
<group {...props} ref={internalRef}>
8181
<HandlesContext.Provider value={context}>{children}</HandlesContext.Provider>

packages/react/handle/src/hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function useHandle<T>(
2828
() => new HandleStore(target, () => ({ ...getHandleOptionsRef.current?.(), ...optionsRef.current })),
2929
[target],
3030
)
31-
useFrame((state) => store.update(state.clock.getElapsedTime()))
31+
useFrame((state) => store.update(state.clock.getElapsedTime()), -1)
3232
const handleRef = options.handle ?? target
3333
useEffect(() => {
3434
if (options.bind === false) {

0 commit comments

Comments
 (0)