Skip to content

Commit

Permalink
fix update order to prevent transform & pivot handles size flickering…
Browse files Browse the repository at this point in the history
… when drastic position changes occur
  • Loading branch information
bbohlender committed Jan 28, 2025
1 parent 6195c75 commit 55bd14b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/handle/src/computations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,9 @@ function projectOntoPlane(
): void {
normalHelper.crossVectors(_axis1, _axis2).normalize()
planeHelper.setFromNormalAndCoplanarPoint(normalHelper, initialWorldPoint)
const angleDifference = worldDirection == null ? 0 : Math.abs(normalHelper.dot(worldDirection))

if (worldDirection == null) {
if (worldDirection == null || angleDifference < 0.01) {
//project point onto plane
planeHelper.projectPoint(worldPoint, worldPoint)
return
Expand Down Expand Up @@ -426,7 +427,8 @@ export function projectOntoAxis(
worldPoint: Vector3,
worldDirection: Vector3 | undefined,
): void {
if (worldDirection == null) {
const angleDifference = worldDirection == null ? 0 : 1 - Math.abs(axis.dot(worldDirection))
if (worldDirection == null || angleDifference < 0.001) {
projectPointOntoAxis(worldPoint, initialWorldPoint, axis)
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/handle/src/handles/pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PivotHandlesContext = forwardRef<Group, PivotHandlesContextProperti
const optionsRef = useRef(options)
optionsRef.current = options
const context = useMemo(() => new HandlesContextImpl(internalRef, () => optionsRef.current), [])
useFrame((state) => context.update(state.clock.getElapsedTime()))
useFrame((state) => context.update(state.clock.getElapsedTime()), -1)
return (
<group {...props} ref={internalRef}>
<HandlesContext.Provider value={context}>{children}</HandlesContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/handle/src/handles/transform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const TransformHandlesContext = forwardRef<Group, TransformHandlesContext
if (space !== null) {
context.space = space
}
useFrame((state) => context.update(state.clock.getElapsedTime()))
useFrame((state) => context.update(state.clock.getElapsedTime()), -1)
return (
<group {...props} ref={internalRef}>
<HandlesContext.Provider value={context}>{children}</HandlesContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/handle/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useHandle<T>(
() => new HandleStore(target, () => ({ ...getHandleOptionsRef.current?.(), ...optionsRef.current })),
[target],
)
useFrame((state) => store.update(state.clock.getElapsedTime()))
useFrame((state) => store.update(state.clock.getElapsedTime()), -1)
const handleRef = options.handle ?? target
useEffect(() => {
if (options.bind === false) {
Expand Down

0 comments on commit 55bd14b

Please sign in to comment.