3D & 2D drawing

Topology
SHARED AUTHORITY

This addon shows how to draw on boards: pens touching a board create drawings that all users see on the board, and that can be moved afterwards.

The drawings are lines synchronized by the Line Drawing addon, which also provides the 3D drawings made in the air.

3D drawing

The 3D drawing of this addon (3D Drawer and 3D Draw prefabs) is kept for existing projects. For new 3D drawings, use the Line Drawing addon directly.

Board drawing

Principle

A board drawing is a real 3D line, created on the board surface, on the BoardPenLine layer that the users' cameras do not render. A camera of the board sees only those lines, and renders them into a texture displayed by the board material: users feel they are drawing on the board.

Since the drawing is a real object, its pin can move it, and the board camera captures it again at its new place.

Rendering the board camera has a cost: the camera is disabled, and a board only renders for a moment after being activated. A drawing activates its board when new points are drawn, when the drawing moves, and when it is despawned. Each user renders their own board texture from the synchronized drawings.

Synchronization

The Draw component, on the 2D Draw prefab, is a NetworkLineDrawing of the Line Drawing addon: the points are synchronized with a ring buffer, and late joiners receive the whole drawing.

The author of a drawing is its state authority while drawing (the pin can only be grabbed once the drawing is finished), then whoever grabs it.

Note that in this prototyping code, all data is stored on Fusion networked properties, or synched through reliable transfer API. In real-life scenarios, including in regards to persistence, Fusion should be used for real time synchronization, while a third-party storage service should be used for the long term data persistence.

Pens

A pen (Drawer component, 2D Drawer prefab) draws while its tip touches a board, with a pressure (the line width) that follows the depth of the contact.

The contact comes from the pen's ISurfaceContactTip, usually its BlockableTip from the Blocking Contact addon, which also stops the pen at the board surface. The board is found through the BlockingSurface that the tip touches. A stroke continues while the pen slightly lifts, and each drawing stays on one board.

The pen needs a Rigidbody, since its BlockableTip detects the boards with trigger messages.

Boards

Start from the Board or LargeBoard prefab (in Drawing/Prefabs), which contain everything below.

A Board requires:

  • a NetworkObject, spawned in the session: the drawings reference their board,
  • a BlockingSurface: the pens detect the board with it; its negative proximity threshold on z (-0.005 in the prefabs) must match the 5 mm the pen can lift without breaking the stroke,
  • the Board layer on the BlockingSurface object (the prefabs apply it at runtime with a LayerSetter): the board pens only detect this layer,
  • a flat mesh in the local XY plane (a Quad, not a Plane), with its MeshRenderer and MeshFilter, on the board object,
  • a child Camera with a target RenderTexture, which gives the texture format,
  • Board and BoardPenLine layers in the project (Tags and Layers settings).

The users' cameras must not render the BoardPenLine layer, otherwise the lines would also float where they were drawn (a CullingMaskSetter removes it, as in the demo scene). The board logs an error or a warning when one of those is missing.

With fitCameraToBoard (enabled by default), the board camera (orthographic) and its texture fit the board size, so boards of any size can be used. pixelsPerMeter sets the texture resolution. Uncheck fitCameraToBoard to keep a camera and a render texture set by hand.

Color Selection

The ColorSelection component of the pens changes the pen color with the joystick of the controller holding the pen. It is a subclass of XRShared's GrabbableColorSelection, which synchronizes the color and tints the pen renderers.

The pen reads it as its color provider: a color change starts a new line. If the pen has an InteractiveMenu (the tips explaining how to change the color), it is hidden after a few color changes.

Upgrading from 2.1.0

Drawing 2.2.0 relies on the Line Drawing addon. Script and prefab GUIDs are kept, and the values saved with 2.1.0 are loaded. However:

  • Draw, Drawer and ColorSelection now derive from Line Drawing and XRShared classes: some public members were removed or renamed, a few remain as obsolete,
  • a custom draw prefab must be a variant of 2D Draw (or have a LineDrawing component and a finishedHandler),
  • boards fit their camera to the board size: uncheck Board.fitCameraToBoard to keep a hand-tuned camera.

Dependencies

  • XRShared addon (2.1.18 or newer)
  • Line Drawing addon (2.1.5 or newer), and the DataSyncHelpers addon, which it requires
  • Blocking Contact addon (2.1.2 or newer)
  • Feedback addon (pen sounds and haptics)
  • Interactive Menu addon (color change tips)

Demo

A demo scene can be found in the Samples/Drawing/Scenes folder of the addon.

Fusion Industries 2D Drawing
Fusion Industries 2D Drawing

The scene contains a square board and two large boards, with three board pens that can change color.

When a drawing is finished, a pin appears, allowing players to move it.

Fusion Industries 3D Drawing
Fusion Industries 3D Drawing

The scene also contains two 3D pens. When the pen is released, a handle appears, allowing players to move the 3D lines.

Download

This addon latest version is included into the XR Addons project

Supported topologies

  • shared mode

Changelog

  • Version 2.2.0:
    • Drawing now relies on the LineDrawing add-on. Script and prefab GUIDs are kept, and the values saved with 2.1.0 are loaded
    • Board drawings work on boards of any size, and their projection no longer jumps while they are moved
    • Board pens detect the boards with their BlockableTip. A stroke continues while the pen slightly lifts
    • Clear errors for a missing setup (board without BlockingSurface or NetworkObject, missing BoardPenLine layer, pen without contact tip or Rigidbody)
    • 3D drawing (3D Drawer, 3D Draw) is kept for existing projects: use the LineDrawing add-on for new 3D drawings
    • Fix a board drawing not shown on its board for late joiners
    • Demo scene: the three board pens can change color
    • Upgrading from 2.1.0:
      • Draw, Drawer and ColorSelection now derive from LineDrawing and XRShared classes: some public members were removed or renamed, a few remain as obsolete
      • A custom Draw prefab must be a variant of 2D Draw (or have a LineDrawing component and a finishedHandler)
      • Boards fit their camera to the board size: uncheck Board.fitCameraToBoard to keep a hand-tuned camera
  • Version 2.1.0: Update to support new XRShared architecture
  • Version 2.0.12: Modifications for Asset Store
  • Version 2.0.11: Modification for Asset Store
  • Version 2.0.10: Adapt to Unity 2022.3.47f1
  • Version 2.0.9: Update to match latest XRShared interfaces
  • Version 2.0.8: Update ColorSelcection to implement IColorProvider interface
  • Version 2.0.7: User layer tools to automatically set the proper layer for 2D projection
  • Version 2.0.6:
    • Fix to ensure compatibility with VisionOSHelpers addon.
    • Fix issue with force use.
  • Version 2.0.5: ColorSelection KeyboardBindings are added at runtime
  • Version 2.0.4: Drawer: Use virtual variables & add verification+ Draw: fix lastDrawingTipPosition
  • Version 2.0.3: Fix because of feedback namespace modification
  • Version 2.0.2: Add LargeBoard with visual prefab
  • Version 2.0.1: Add demo scene + prefabs update + add namespace
  • Version 2.0.0: First release

Last updated on

Back to top