Open Brush Docs
  • Home
  • How to get Open Brush
  • Differences between Open Brush and Tilt Brush
  • User Guide
    • Get started with Open Brush
    • Painting with Open Brush
    • The Open Brush UI
      • Admin Panel
        • Settings Panel
        • Labs Panel
      • Tools Panel
        • Selection Options
        • Repaint Options
      • Brushes Panel
      • Extras Panel
        • Environment Panel
        • Lights Panel
        • Backdrop Panel
        • Guides Panel
        • Media Library
        • Camera Paths Panel
        • Snap Settings Panel
        • Transform Panel
        • Layers Panel
      • Experimental Panel
      • UI Differences Between Basic Mode and Advanced Mode
    • Grid and Angle Snapping
    • Repaint Tool and Jitter
    • Selection/Erase Filter
    • Lazy Input
    • Bimanual Input and Revolver
    • World Axis Unlock
    • Saving and sharing your Open Brush sketches
    • Troubleshooting issues with Open Brush
    • Check out Labs features
    • Importing Images, Videos and 3D Models
    • Experimental Mode
    • Make moving creations using audio reactive brushes
    • Using Reference Images on Oculus Quest
    • Remixing and Creative Commons
    • Accessing Autosave Files
    • The Open Brush config file
    • Exporting Open Brush sketches to other apps
      • Exporting to Unreal Engine 5
      • Exporting to Snapchat Lens Studio
      • Configuring Export
    • Plugins
      • Example Plugins
        • Example Pointer Plugins
        • Example Symmetry Plugins
        • Example Tool Plugins
        • Example Background Plugins
      • Writing Plugins
        • Getting Started
        • Tweaking existing plugins
        • Writing a Pointer Plugin
        • Writing a Symmetry Plugin
        • Writing a Tool Plugin
        • Writing a Background Plugin
        • Defining and Drawing Brush Strokes
      • Plugin API Scripting Reference
    • Open Brush Unity SDK
    • Open Brush API
      • Retrieving a preview image
      • API Commands List
    • Cameras and Exporting Video
    • Brushes
      • Brush List
      • Memory limits and brush costs
      • Experimental Brushes
      • Hiding Brushes with Brush Tags
    • Using Open Brush without a VR headset
    • Command Line Arguments
    • Tilt Brush Version 23 Release Notes
  • Get Involved!
    • How to help with Testing
  • Pre-release and Experimental Builds
    • Installing the Beta Release
    • "Experimental Mode" Builds
    • Feature: 3D Shapes Tool
    • Feature: Animation Timeline
    • Feature: Icosa Gallery Support
    • Feature: Brush Editing
    • Feature: Plugin Scripting
    • Feature: Sculpting
    • Combined Testing Build
    • Old or Completed Feature Builds
      • Feature: Polyhedra
      • Feature: Snip Tool
      • Feature: Layers
      • Insominx's (michael-g) Experimental Build
      • XR Framework Beta
      • Feature: Transform Panel and Snap Enhancements
      • Feature: Improved GLTF Importer
      • Feature: Multi-Mirror
      • Feature: New Monoscopic Mode
      • Feature: Improved Import/Export
      • Feature: Multiplayer
  • Case Studies
  • Other Resources
  • Developer Notes
    • UI Elements
    • Unity shader examples
    • Setting up CI for Open Brush using Github Actions
    • Open Brush File Format
    • Previous Github Wiki
      • Brushes
      • BuildingOpenBrush
      • BurstCompiler
      • Comparison
      • MonoscopicMode
      • PseudoCode
      • UserInterface
    • Differences between Standard and Experimental Mode
    • Open Brush AsCanvas Notes
    • Unity Versions
  • Release History
    • v2.10 Multiplayer
    • v2.9 (Maintenance)
    • v2.8 Import/Export
    • v2.7 (Maintenance)
    • v2.6 (Maintenance)
    • v2.5 (Maintenance)
    • v2.4 "Prismatic"
    • v2.2: Settings and Sketches
    • v2.1 Hotfix
    • 🚀v2.0: XR Update
    • v1.0: Happy Birthday to Us!
    • Current Beta Release Notes
  • Docs TODO
  • Contacting Us
Powered by GitBook
On this page
Edit on GitHub
Export as PDF
  1. User Guide
  2. Plugins
  3. Writing Plugins

Writing a Pointer Plugin

PreviousTweaking existing pluginsNextWriting a Symmetry Plugin

Last updated 5 months ago

Pointer Plugins can modify the pointer position and/or rotation every frame. You can get the current position and rotation so you can simply add an offset to those - or you could create an entirely new position or rotation based on any of the other context variables that are available to the script.

Name a Pointer Script with the prefix "PointerScript". For example: PointerScript.MyPlugin.lua

Assuming your script is valid (i.e. it has no syntax errors) then giving it a valid prefix is all you need for it to appear in the Scripts Panel.

By default a Pointer Script returns a which represents how the pointer moves relative to it's normal position (which in this case is wherever the user moves their brush hand)

The simplest possible pointer plugin would be something like this:

function Main()
    return Transform.identity
end

This does nothing at all. It returns a transform called "identity" which means "no change at all". There are several other ways to express the same thing:

-- Explicitly returns zero for position, rotation and scale.
return Transform:New(Vector3.zero, Rotation.zero, 0)

-- If you miss out rotation and/or scale they are assumed to be zero
return Transform:New(Vector3.zero)

-- Vector3.zero is itself shorthand for this:
return Transform:New(Vector3:New(0,0,0))

-- You can create a transform with only a position in a slightly shorter way:
return Transform:Position(0,0,0)

There's no difference between these - it's just sometimes more convenient or clearer to write things in different ways.

So - a plugin script that does nothing isn't much fun. Let's change it so it does something.

function Main()
    return Transform:New(0,1,0)
end

-- or

function Main()
    return Transform:Vector3.up
end

Vector3.up is another shorthand - this time it's shorthand for Vector3:New(0, 1, 0) this is a vector with:

x is 0 (no change in the left/right direction) y is 1 (a shift of 1 in the up direction) z is 0 (meaning "no change in the forward/back direction")

So - this plugin tells Open Brush "the user's pointer should be moved up by 1 unit from whereever they are painting". If you try it you should see your pointer is about 10cm above wherever you move your brush hand.

So this is not very useful - but we at least we can see we are changing something now.

Let's try something slightly more interesting.

function Main()
    return Transform:Position(0, App.time, 0)
end

This plugin script will result in your strokes being painted somewhere way higher than the user's brush hand. How high depends on how long since they opened the app! Let's rein things in a bit.

function Main()
    return Transform:Position(0, Waveform:Triangle(App.time, 1), 0)
end

That single return line is getting a bit complicated. Let's split things over two lines to make it easier to read:

function Main()
    y = Waveform:Triangle(App.time, 1)
    return Transform:Position(0, y, 0)
end

If you've done any programming or scripting before, you should recognise what we've done here. "y" is a variable. We chose "y" as the variable name but we could call it anything we want.

So we now have a plugin that moves the pointer up and down over time. You can change the second parameter to control the speed.

Let's go one step further - allow the user the control the speed without needing to edit the plugin script:

Parameters = {
    frequency={label="Frequency", type="float", min=0.01, max=10, default=2}
}

function Main()
    y = Waveform:Triangle(App.time, Parameters.frequency)
    return Transform:Position(0, y, 0)
end

App.time is a property of the class where you can access various properties of Open Brush app itself. As you might have guessed App.time measures time - specifically the number of seconds since you launched Open Brush.

We've assigned a value to "y" which is the result of calculating a

The output of the Waveform:Triangle method takes two parameters as input time and frequency. It returns a value that varies between -1 and +1. If you've configured your editor as explained in then you should have seen a hint pop up when you typed the first open bracket:

We've now told Open Brush that this plugin should show a slider in it's which changes the frequency that the pointer moves.

Transform
App
waveform shaped like a triangle
Getting Started
Parameters popup