PatchesModule

The PatchesModule module allows interop between JS scripting and the AR Studio patches visual scripting system.

Example

//==============================================================================
// The following example demonstrates how to send and receive values between the
// Patch Editor and script.
//
// Project setup:
// - Insert text
// - With your script selected in the Assets, in the Inspector:
//   - Select 'Boolean' from the + menu of 'From Script' and name it 'myBoolean'
//   - Select 'Create' next to 'Producer Patch' to add it to the Patch Editor
//   - Select 'String' from the + menu of 'To Script' and name it 'myString'
//   - Select the arrow next to 'myString' to add it to the Patch Editor
// - Add an 'If Then Else' patch setting it's 'Type' to 'Text'
// - Add two strings to the 'Then' and 'Else' values of the 'If Then Else' patch
// - Connect the 'myBoolean' value to the 'Condidition' value
// - Connect the 'If Then Else' patch output value to the 'myString' value
//==============================================================================

// Load in the required modules
const Patches = require('Patches');
const Scene = require('Scene');

// Enable async/await in JS [part 1]
(async function() {
  // Locate the text in the Scene
  const [text] = await Promise.all([
    Scene.root.findFirst('text0')
  ]);

  // Create a boolean variable
  const myBoolean = true;

  // Send the boolean value to the Patch Editor under the name 'myBoolean'
  await Patches.inputs.setBoolean('myBoolean', myBoolean);

  // Get the 'myString' string value from the Patch Editor
  const myString = await Patches.outputs.getString('myString');

  // Update the text with the string value
  text.text = myString;
// Enable async/await in JS [part 2]
})();

Properties

PropertyDescription
inputs
(get) inputs: PatchesInputs
(set) (Not Available)


Returns an object encapsulating all input setters for the Patch Editor patches.
outputs
(get) outputs: PatchesOutputs
(set) (Not Available)


Returns an object encapsulating all outputs getters for the Patch Editor patches.

Methods

MethodDescription
getBooleanValue
getBooleanValue(name: String): BoolSignal


Returns a BoolSignal that is exported with name from the Patch Editor.
getColorValue
getColorValue(name: String): RgbaSignal


Returns a RgbaSignal that is exported with name from the Patch Editor.
getPoint2DValue
getPoint2DValue(name: String): Point2DSignal


Returns a Point2DSignal that is exported with name from the Patch Editor.
getPointValue
getPointValue(name: String): PointSignal


Returns a PointSignal that is exported with name from the Patch Editor.
getPulseValue
getPulseValue(name: String): EventSource


Returns a pulse EventSource that wrapps a pulse that is exported with name from the Patch Editor.
getScalarValue
getScalarValue(name: String): ScalarSignal


Returns a ScalarSignal that is exported with name from the Patch Editor.
getStringValue
getStringValue(name: String): StringSignal


Returns a StringSignal that is exported with name from the Patch Editor.
getVectorValue
getVectorValue(name: String): VectorSignal


Returns a VectorSignal that is exported with name from the Patch Editor.
setBooleanValue
setBooleanValue(name: String, signal: BoolSignal): void


Sends a BoolSignal that is imported with name into the Patch Editor.
setColorValue
setColorValue(name: String, signal: ColorSignal): void


Sends a ColorSignal that is imported with name into the Patch Editor.
setPoint2DValue
setPoint2DValue(name: String, signal: Point2DSignal): void


Sends a Point2DSignal that is imported with name into the Patch Editor.
setPointValue
setPointValue(name: String, signal: PointSignal): void


Sends a PointSignal that is imported with name into the Patch Editor.
setPulseValue
setPulseValue(name: String, signal: EventSource): void


Sends an EventSource that is imported with name into the Patch Editor.

Note: The Reactive.once() method can be used to return an EventSource that emits an empty event as soon as possible.
setScalarValue
setScalarValue(name: String, signal: ScalarSignal): void


Sends a ScalarSignal that is imported with name into the Patch Editor.
setStringValue
setStringValue(name: String, signal: StringSignal): void


Sends a StringSignal that is imported with name into the Patch Editor.
setVectorValue
setVectorValue(name: String, signal: VectorSignal): void


Sends a VectorSignal that is imported with name into the Patch Editor.

Classes

ClassDescription
PatchesInputsThe PatchesInputs class encapsulates methods for setting inputs to the Patch Editor.
PatchesOutputsThe PatchesOutputs class encapsulates methods for getting outputs of the Patch Editor.