SPARK AR Patch to Script

This example is provided by Andrey Staroseltsev Facebook post that shows how to use the Spark AR Patch to Script editor.

Below are some useful examples :


Patch Editor / JavaScript Interoperability

————————————————————

AR Studio v38 now has an ability to have shared context between the Script and the Patch Editor.

It is now possible to read & write JavaScript signal variables from the Patch Editor and vice versa.

————————————————————

AR STUDIO SIDE:

From the Script Inspector of AR Studio it is now possible to declare variables to be used in both Script & the Patch Editor for reading as well as writing.

– “From Script” variables allow to get (read) JS signals inside the Patch Editor by having a Producer patch.
– “To Script” variables allow to set (write) JS signals inside the Patch Editor by having a Consumer patch

Check out a video 🎬 attached to see this in action

————————————————————

SCRIPT SIDE:

Import the newly added Patches module in your script:

var P = require(‘Patches’);

Write to signals:

// Set a signal:
P.setBooleanValue(“boolVar”, boolSignal);
P.setScalarValue(“scaleVar”, scalarSignal);
P.setVectorValue(“vectorVar”, vectorSignal);
P.setPulseValue(“triggerVar”, eventSource);

// Or set a constant:
P.setBooleanValue(“boolVar”, false);
P.setScalarValue(“scaleVar”, 0.75);
P.setVectorValue(“vectorVar”, R.vector(-10, 20, -10));
P.setPulseValue(“triggerVar”, R.once());

Read from signals:

// Get a signal
var boolSignal = P.getBooleanValue(“boolVar”);
var scaleSignal = P.getScalarValue(“scaleVar”);
var vectorSignal = P.getVectorValue(“vectorVar”);
var eventSource = P.getPulseValue(“triggerVar”);

Full module documentation available here:
https://developers.facebook.com/…/api…/classes/patchesmodule

Advertisements

Published by hamdanbasri

Games | Simulation in VR & AR

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: