Blocks allow you to save and export sections of a project in Spark AR Studio, to be reused in other projects and shared with other creators.
You can create a block for most things you need to repeat or reuse. Combinations of objects, assets, patches, materials and texture settings are all supported.
Follow this step-by-step tutorial to create a block that adds snow to your effect.
To create a block:
The block will be listed in the Assets panel. When it's selected you can rename it if you want to:
To build and edit a block:
This will open the block in a new window, so you can make changes to it:
In the new window, the block will be listed in the Scene panel as Block Root. Simply add the objects and assets you want to include in the block as a child of Block Root.
When you save a block, it will automatically update in all projects that use the block. You'll see this message in Spark AR Studio to remind you:
The quickest way to add a block to your scene is to simply click and drag it from the Assets panel to the Scene panel. Alternatively:
The block will be listed in both the Scene panel and the Assets panel:
Below, we've added a block to the Scene panel. We've used it to create an effect with a particle system that looks like snow:
In the Scene panel, Snow is the instance of the Block. You'd use the options under Inputs in the Inspector to customize how the block behaves in the effect. In the Assets panel, Snow is the master block.
You can instantiate the same block more than once.
Learn how we made this block.
Inputs and outputs pass information to and from blocks, into your projects. You'll use them to set default values for the block's properties, allowing you to customize the block.
Supported data types for inputs and outputs are:
To create an input or output, make sure the block is open, by right-clicking on the box in the Assets panel and selecting Edit. Then:
You'll see a list of options that you can edit to configure the input or output, depending on the data type you select:
To reorder inputs and outputs, just click and drag them in the properties window. For example, you could place blockInput0 below blockInput1.
Alternatively, you can create input and output ports using patches in the Patch Editor. To do this:
Using inputs in a block
Use inputs to customize your patch graph inside a block:
Alternatively, drag the block scene object from the Scene panel into the Patch Editor.
Using outputs in a block
Use outputs to pass information from the block, into your project. For example to a patch outside the block.
In the opened block:
A consumer patch will be created:
All the inputs you've added to a Block will be listed under Inputs in the Inspector, when you select the block in the Scene panel:
You can change the values of the inputs in the Inspector, to change how the block behaves in your effect. Or, click the arrow next to the input to create a consumer patch that can be connected to the rest of your graph:
You can also drag the block from the Scene panel into the Patch Editor.
Once you've defined the outputs of the block, drag it from the Scene panel into the Patch Editor to create a patch:
You can set the values of inputs and get the values of outputs in a script by using the methods of the
BlockSceneRoot class after accessing your block in the scene by name.
// Load in the scene module const Scene = require('Scene'); // Locate a block in the scene const myBlock = Scene.root.find('myBlock'); // Set a scalar input (signals also accepted) myBlock.setScalarInput('blockInput', 5); // Get a scalar output const blockOutput = myBlock.getScalarOutput('blockOutput');
It's a good idea to add descriptions to your blocks. This will help any creators you share the block with understand what it does, and help you keep track too.
To add a description:
When you select the block in the Assets panel, you'll see the description in the Inspector:
It is also possible to create blocks within blocks.
Let’s reuse the block with the particle system that looks like snow:
To add another block inside SnowBlock:
The second-level block will be listed as block0 in the Assets panel.
Editing the second-level block
To edit the second-level block:
Instantiate the second-level block
You need to instantiate the second-level block so the contents also appears in the first-level block. To do so:
The contents of both blocks will now be visible in the first-level window.
The contents of both blocks will also be visible in the main project. In our example, both particle systems are visible in the Viewport and Simulator:
Blocks allow you to structure your project, to use parts of it again and again. They can contain scene objects, assets and patches.
Patch Assets allow you to save and share groups of patches with other Spark AR Studio creators. Patch Assets can’t contain producer patches, consumer patches or any assets.
Blocks can only be used in projects with meters as the unit of measurement.
The following features are not supported: