Finger Drawing

Topology
SHARED AUTHORITY

This addon lets users draw with the fingers of their tracked hands:

It reuses the pen based drawing of those addons: the finger becomes a pen tip placed on the network hands of the user's network rig. If you are learning Fusion, read the Overview and "How it works", then "Fusion patterns in this addon" at the end.

Overview

Finger tools on the network hands

XRShared splits each user into a hardware rig (the local tracked devices, not networked) and a network rig (spawned for each user, following the hardware rig of its owner). The finger tool prefabs, holding NetworkBehaviours, are placed under each network hand of the network rig: FingerTexturePen (drawing on surfaces) and FingerLineDrawer (drawing in the air). They only act for the local user, and follow the local hardware hand (through XRShared's LocalHardwareHandTracker): its index tip, its pinch, its pinch point and its grabbers.

They require tracked hands on the hardware rig: XR Hands hands (XRShared hardware rig), or the Meta building blocks rig with hand tracking. While the user holds controllers, the finger tools are inactive, and the drawing menu actions are not available.

Drawing on surfaces

The FingerTexturePen prefab combines a FingerTip (the index tip as a tip touching Blocking Contact surfaces) with the Texture Drawing TexturePen and TextureDrawer. The TexturePen reads the contact of the finger as it reads the one of a pen's BlockableTip, through the Blocking Contact ISurfaceContactTip interface:

  • the contact with a surface only starts when the finger comes from the front of the surface, and is kept until the finger goes too deep, moves back or leaves the surface,
  • during a contact, the network hand display is held on the surface: the local user sees their finger resting on it, while the actual finger keeps going. Remote users see the actual finger go through the surface (see "Fusion patterns in this addon"),
  • the drawing pressure follows the finger depth, and the drawing point is smoothed (One Euro filter) to remove the hand tracking jitter,
  • no contact is possible while the hand pinches: grabbing a sticky note does not draw on it.

Before the contact, a ring (FingerHoverCursor) shows on the surface where the finger will land, in the drawing color.

The TexturePen converts each contact to a texture point and hands it to the TextureDrawer, which draws it locally at once and sends it, in FixedUpdateNetwork, to the networked TextureDrawing of the surface: this is how the ink reaches the other users.

Drawing in the air

The FingerLineDrawer prefab draws a 3D line while the user pinches:

  • a pinch started while an object is in reach of the hand grabber is left to the grabbing, and a stroke is cancelled if the hand grabs something,
  • a pinch made while the back of the hand faces the headset (looking at a watch, ...) does not draw: the thumb and index are hidden behind the hand, and the hand tracking may predict them closed,
  • a stroke ends when the thumb and index stay clearly apart, further than the pinch threshold, for a short delay: when the hand turns during a stroke, the estimated fingers drift slightly apart, and the hand tracking sometimes loses the index for a few frames, while a release keeps the fingers open. During the delay, the line follows the wrist and is only shown and sent if the pinch comes back,
  • the line follows the pinch point, between the thumb and index tips, when the hand provides it (IPinchPointProvider: XR Hands and Meta building blocks hands), otherwise the index tip,
  • a local preview line follows the fingers without delay, while the points are sent slightly later, once the stroke is confirmed: the end of the stroke, following the opening fingers, is dropped at the release,
  • strokes made close in time are grouped in the same drawing.

Vocabulary: a stroke is one pinch, drawn as a line of the Line Drawing addon; a drawing is a NetworkLineDrawing, a networked object spawned by the first confirmed point, holding the lines made close in time. It replicates its lines to the other users, and is finished (its handle appears) when no stroke follows.

Drawing mode and color

The finger tools find in their parents (on the network rig) the drawing color, an IColorProvider (a NetworkColorSelection), and the drawing mode, an IHandDrawingModeProvider. Without them, the finger drawing is always enabled, in the default color of each tool (black).

To control them from a menu, HandDrawingMode works alongside the scene NamedActionManager (usually driven by a Watch Menu): the scene UI cannot reference the network rig, spawned at runtime, so for the local user the rig registers two named actions, toggling the drawing (it is the IHandDrawingModeProvider of the rig) and changing the color (routed to the NetworkColorSelection of the rig). They are only available with hand tracking, and provide the drawing state and the current color to the UI (for instance Watch Menu radial menu buttons). To control the drawing mode differently (gesture, application state, ...), call HandDrawingMode.SetDrawingEnabled, or implement IHandDrawingModeProvider on the network rig instead.

HandDrawingTipDot displays a dot of the drawing color at the index tips, after each mode or color change (or always).

How it works

Where the components sit

Plain Old Text

Network rig (NetworkObject): NetworkColorSelection, HandDrawingMode, HandDrawingTipDot, NetworkFingerDrawingSetup (all optional)
    Network left hand (INetworkHand)
        LeftFingerTexturePen: FingerTip, TexturePen, TextureDrawer, FingerHoverCursor
        LeftFingerLineDrawer: FingerLineDrawer, LineDrawingSettingsListener, FingerDrawingCountdown
    Network right hand: the same tools

The finger tool prefabs have no NetworkObject: their NetworkBehaviours belong to the NetworkObject of the rig.

Frame timing

The network hand of the local user does not wait for the network: every rendered frame, it is moved to the pose of the local hardware hand (the rig "extrapolation"), either during Fusion Render or later, during Unity Application.onBeforeRender, depending on the rig (some hand tracking stacks update the hands just before rendering). The network hand then applies its position modifiers, like the FingerTip holding it on a surface.

The displayed finger and the drawn point must come from the same finger position, otherwise they disagree by a frame. So FingerTip updates in the same frame phase as the hand display, just before it, and the TexturePen reads the contact just after. Execution orders, lower first: FingerTip 90, network rig 100, network hands 100 (Render) or 110 (onBeforeRender), TexturePen 130. [DefaultExecutionOrder] orders Fusion Render, [BeforeRenderOrder] orders onBeforeRender (where a method without it runs at order 0).

FingerLineDrawer does not move the hand display: it simply reads the hand once per frame, in Render.

A finger touching a board

  1. FingerTip (UpdateFinger): the finger gets less than hoverDistance in front of the board, the state goes from Free to Hovering, and FingerHoverCursor shows the ring.
  2. The finger reaches the front face of the board: the state goes to Touching.
  3. The network hand applies the FingerTip position modification: its display rests on the board.
  4. The TexturePen reads the contact (TryGetContact) and hands the point to the TextureDrawer, which sends it to the TextureDrawing.
  5. The finger goes too deep, back in front of the board, or out of its bounds: the contact ends, and the TexturePen sends a stop point.

A stroke in the air

  1. FingerLineDrawer: the pinch starts (state Unconfirmed), a local preview line follows the fingers.
  2. After confirmationDelay and confirmationDistance (state Drawing), the points older than the commit delay are sent: the first one spawns the NetworkLineDrawing.
  3. The pinch is released: the thumb and index stay further apart than strokeReleaseDistance for releaseGraceDelay. The points not sent yet are dropped, and the line is closed.
  4. No new stroke during drawingGroupingDelay (FingerDrawingCountdown shows it): the drawing is finished, its handle appears.

Setup

Basic setup

In your network rig prefab, place the FingerTexturePen and/or the FingerLineDrawer prefab under each network hand: the hands draw.

They have to be in the prefab, at edit time: Fusion registers the NetworkBehaviours of a NetworkObject with its prefab, and they cannot be added to a spawned rig.

To draw on surfaces, the scene needs drawing surfaces: a TextureDrawing with a BlockingSurface collider on the layer the finger detects (the "Board" layer by default, see FingerTip blockingLayers and additionalBlockingLayerName). Drawing in the air needs nothing in the scene.

Options

  • Drawing color: a NetworkColorSelection on the network rig. It gives both tools of both hands the same color, synchronized. Without it, each tool draws in its own color, black by default.
  • Grabbing: a GrabbingSetup on the hardware rig, so that each hand has a Grabber. A pinch started with a grabbable in reach is then left to the grabbing, instead of drawing in the air.
  • Drawing mode and color from a menu: a HandDrawingMode on the network rig, and a NamedActionManager in the scene, for its actions (HandDrawingMode.ToggleDrawingActionName, HandDrawingMode.NextColorActionName). Then UI buttons triggering those actions, for instance Watch Menu RadialMenu named action entries (the color one as a press button).
  • Color feedback: a HandDrawingTipDot on the network rig.
  • Feedback inside the tool prefabs, which can be removed: the hover ring (FingerHoverCursor, FingerTexturePen) and the drawing countdown (FingerDrawingCountdown, FingerLineDrawer).
  • Sounds: see Sounds.

Setup in one click

NetworkFingerDrawingSetup does the basic setup and adds the rig options. Add it on the network rig prefab, in prefab edit mode, then click its "Setup finger drawing" button (also in its context menu). It adds, when missing:

  • the finger tool prefabs under each network hand: the prefabs with the "FingerDrawingTool" asset label (FingerTexturePen and FingerLineDrawer; add this label to your own finger tools to include them). The first setup fills the fingerToolPrefabs list of the component with them: edit it to choose the tools, or clear it to look up the labeled prefabs again,
  • a NetworkColorSelection, a HandDrawingMode and a HandDrawingTipDot on the rig.

It then warns if the project has no layer for the finger to detect the drawing surfaces, and logs the named action names for the menu buttons. The scene requirements (drawing surfaces, NamedActionManager, hardware rig GrabbingSetup) are not checked: the rig prefab is edited without its scenes. See "Basic setup" and "Options" above.

Sounds

The finger tools play no sound by default: the addon does not depend on an audio system. To add sounds, place an IFeedbackHandler on each finger tool object (the Feedback addon Feedback component, for instance), and set the audio types:

  • FingerTexturePen: the TexturePen audioType, played while the finger draws on a surface,
  • FingerLineDrawer: drawingAudioType and drawingFinishedAudioType, played during a stroke and when the drawing is finished.

Give each finger tool its own AudioSource: the end of a stroke stops the handler's audio source, and the Feedback component otherwise falls back to the shared SoundManager source, cutting the other sounds played on it.

Class details

Core components

FingerTip

The index tip of the local hardware hand, as a tip touching drawing surfaces: its IndexTipFollowerTransform on the Meta building blocks rig, its IndexTipMarker otherwise (XR Hands and simulated hands).

Its State, computed once per frame, is:

  • Unavailable: remote user's rig (always), hand not tracked or pinching, or drawing disabled,
  • Free: no surface close in front of the finger,
  • Hovering: the finger is less than hoverDistance in front of a surface (Surface, HoverPoint, HoverDistanceToSurface),
  • Touching: the finger reached the front face of the hovered surface (its contact threshold, BlockingSurface.negativeProximityThresholds.z, 1 mm in front by default).

During a contact, it provides the contact to the TexturePen (ISurfaceContactTip), and holds the network hand display on the surface (IRigPartPositionModifier). Without haptic feedback, users push their finger several centimeters through a board: the contact is kept until the finger goes deeper than releaseDepth. The finger distances (hoverDistance, releaseDepth, liftTolerance, pressureDepth) are in world units, whatever the surface scale. The hover and contact points are kept in the surface coordinates: they follow a surface moving after the finger update (a sticky note held in the other hand).

FingerLineDrawer

A Line Drawing NetworkLineDrawer driven by the pinch of the hand. Main settings:

  • confirmationDelay and confirmationDistance: a stroke is sent only after this duration and move,
  • hiddenPinchMaxAngle (30° by default, 0 to disable): until its stroke is confirmed, a pinch is ignored until released if the back of the hand faces the headset within this angle. The angle is measured with the wrist up axis, which leaves the back of the hand for XR Hands hands. In our Meta Quest recordings, the default value separates the pinches made while looking at a watch (29° at most) from deliberate ones (37° at least),
  • strokeReleaseDistance (3 cm by default, 0 to use the hand pinch): a confirmed stroke ends when the thumb and index tips are further apart than this distance, instead of the hand pinch threshold (2 cm for XR Hands hands). In our Meta Quest recordings, the fingers estimated behind a turned hand drift to 2 to 2.2 cm during a stroke, while a release opens them beyond 3 cm within one or two frames. Hands without pinch point end the stroke with their pinch,
  • releaseGraceDelay (0.1 s by default): the fingers must stay apart (strokeReleaseDistance) for this delay to end a confirmed stroke, as the hand tracking sometimes loses the index for a few frames during a pinch. During the delay, the stroke point is the last pinch point carried by the wrist, which the hand tracking keeps following. Those points are neither shown nor sent (the preview stops where the fingers got apart): they are shown and sent if the pinch comes back, dropped otherwise, and the stroke then ends where the fingers got apart. A new pinch within this delay continues the same stroke: a longer delay mends longer index losses, but also continues the previous stroke when a new one starts soon after a release,
  • commitDelay and pinchPointCommitDelay: delay before a point is sent, at the index tip or at the pinch point (the points of the last delay are dropped at the release),
  • drawingGroupingDelay: strokes closer in time are grouped in the same drawing, which is then finished (its handle appears),
  • drawingAudioType and drawingFinishedAudioType: see Sounds.

With the Line Drawing LineDrawingSettingsListener on the prefab, the spawned drawing prefab follows the scene LineDrawingSettings (without it in the scene, the drawer keeps its own drawingPrefab).

LineRendererShapes

Static helper drawing the local visuals (stroke preview, hover ring, countdown arc, tip dot) with LineRenderers.

Optional components

FingerHoverCursor

In the FingerTexturePen prefab: a ring on the surface hovered by the FingerTip, shrinking as the finger gets closer, in the color of the TexturePen.

FingerDrawingCountdown

In the FingerLineDrawer prefab: after a stroke, a ring at the center of the drawing, where its handle will appear, empties until the drawing is finished. It takes the drawing color and faces the user. It only appears after startDelay, so that a short pause between strokes shows nothing. As a new point hides it, the drawing does not change while the ring is shown: its center is computed once, when it appears.

HandDrawingMode

Network rig component working alongside a NamedActionManager: it registers, for the local user, the named actions toggling the hand drawing and routing the color changes to the NetworkColorSelection of the rig. It is the IHandDrawingModeProvider of the rig (IsHandDrawingEnabled, also set from code with SetDrawingEnabled), read by the finger tools and the tip dot. IsHandDrawingEnabled is the user's choice, IsHandDrawingAvailable tells whether a tracked hand can draw (the actions are only available then).

HandDrawingTipDot

Network rig component: a dot of the drawing color at the index tips of the local user's tracked hands, displayed always or after a change (displayDuration).

NetworkFingerDrawingSetup

Edit time setup of a network rig for finger drawing (see "Setup in one click").

Fusion patterns in this addon

The finger tools are NetworkBehaviours of the network rig prefab, present on every user's rig, but they only act where Object.HasStateAuthority is true: in shared mode, each user has the state authority over their own rig. The plain components rely on the other side of it: only the local user's rig has a local hardware hand (FingerHoverCursor, HandDrawingTipDot), or a drawing in progress (FingerDrawingCountdown).

Not everything needs to be networked. HandDrawingMode has no networked property: it is a NetworkBehaviour only to know, in Spawned, whether its rig is the local one, and the drawing mode stays local (the strokes carry their color). Next to it, the NetworkColorSelection color is networked, and only the state authority changes it.

The displayed state can differ from the networked state. FingerTip is an IRigPartPositionModifier: the network hand applies its modification when it places its display, at the rig extrapolation timing (see Frame timing). The networked hand pose, written in FixedUpdateNetwork, is the actual tracked one: the hand held on the surface is a local display, and remote users see the actual finger go through the surface.

The local user sees their action at once, and the network data follows. FingerLineDrawer shows a local preview line immediately, and only sends confirmed points, a short delay later, to the networked NetworkLineDrawing. An unconfirmed pinch spawns no network object.

Hand tracking is a frame-rate input. FingerLineDrawer writes its points to the networked drawing from Render: in shared mode, the state authority may change the networked state outside FixedUpdateNetwork, and it is sent with the next tick. The TextureDrawer draws locally at once and writes to the network in FixedUpdateNetwork. Both rely on shared mode: this addon does not use NetworkInput.

NetworkBehaviours are part of the prefab. Fusion registers the NetworkBehaviours of a NetworkObject with its prefab, so they cannot be added to a spawned rig, and the network hands collect their position modifiers at Awake. Hence the edit time setup.

Finally, the networked drawing itself comes from the Texture Drawing and Line Drawing addons (TexturePen, NetworkLineDrawer): this addon only provides a new input, the hand (ISurfaceContactTip, a NetworkLineDrawer subclass).

Dependencies

Demo

A demo scene, DemoFingerDrawing, can be found in the Demo/Scenes folder of the addon. The network rig of the Cross-Platform XR Starter sample is also set up for finger drawing.

Download

This addon latest version is included into the XR Addons project

Supported topologies

  • shared mode

Changelog

  • Version 1.1.1: releaseGraceDelay default value 0.1 s (0.35 s continued the previous stroke when a new one started soon after a release)
  • Version 1.1.0: FingerLineDrawer pinch filtering
    • hiddenPinchMaxAngle (30°): a pinch started while the back of the hand faces the headset does not draw (looking at a watch: the hidden fingers may be predicted closed)
    • strokeReleaseDistance (3 cm): a confirmed stroke ends when the thumb and index tips are further apart than this distance, read from the hand joints, instead of the 2 cm pinch threshold
    • releaseGraceDelay (0.35 s): the fingers must stay apart for this delay to end a stroke; meanwhile the stroke point follows the wrist, and is shown and sent only if the pinch comes back
  • Version 1.0.0: First release
    • FingerTexturePen prefab: draws on TextureDrawing surfaces with the index finger. FingerTip (hover and contact detection, pressure following the finger, network hand blocked on the surface) and FingerHoverCursor (where the finger will land)
    • FingerLineDrawer prefab: draws LineDrawing 3D lines with a pinch, except when the hand can grab something. Optional stroke and drawing finished sounds (IFeedbackHandler), FingerDrawingCountdown (ring at the future handle position, showing when the drawing will be finished)
    • HandDrawingMode: drawing mode toggle and color actions for a NamedActionManager menu (usually a WatchMenu), available while a local hand is tracked. IHandDrawingModeProvider for custom drawing modes
    • HandDrawingTipDot: dot of the drawing color at the local user's index tips
    • NetworkFingerDrawingSetup: edit time setup of a network rig (finger tools under each network hand, NetworkColorSelection, HandDrawingMode, HandDrawingTipDot)

Last updated on

Back to top