MaterialsModule Overview
MaterialsModule Overview
MaterialsModule Overview

MaterialsModule

The Materials module provides access to the materials in an effect.

Example

//==============================================================================
// The following example demonstrates how to access a material in the Assets,
// assign it to an object, and change it's opacity.
//
// Project setup:
// - Insert a plane
// - Create a material
//==============================================================================

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

// Enable async/await in JS [part 1]
(async function() {
  const [plane, material] = await Promise.all([
    // Locate the plane in the Scene
    Scene.root.findFirst('plane0'),
    // Locate the plane in the Scene
    Materials.findFirst('defaultMaterial0')
  ]);

  // Assign the material to the plane
  plane.material = material;

  // Set the opacity of the material to 50%
  material.opacity = 0.5;
// Enable async/await in JS [part 2]
})();

Properties

This module exposes no properties.

Methods

MethodDescription
clone
clone(material: string | MaterialBase, initialState?: {[key: string]: any}): Promise<MaterialBase>


Clone a material asynchronously.
When creating the materials, keep the following in mind:
- Cloning a material with an identifier that doesn't exist fails the Promise.
- New materials always get assigned a globally unique name and identifier.
- initialState is optional, but encouraged to be used.
- All properties that are using Signal types get assigned a ConstSignal with last value. Use initialState to override it.
create
create(className: string, initialState?: {[key: string]: any}): Promise<MaterialBase>


Create a material asynchronously.
When creating the materials, keep the following in mind:
- All materials must have an existing class.
- New materials always get assigned a globally unique name and identifier.
- initialState is optional, but encouraged to be used.
destroy
destroy(material: string | MaterialBase): Promise<void>


Destroy a material asynchronously.
When destroying the materials, keep the following in mind:
- All bound properties will be automatically unbound on destruction.
- Destroying a material that doesn't exist fails the Future.
- Destroying a set of Materials that was created in Studio fails the Future.
findFirst
findFirst(name: string): Promise<MaterialBase | null>


Returns a promise that is resolved with the material of a requested name or null if none was found.
See Also: Materials.findUsingPattern, Materials.getAll.
findUsingPattern
findUsingPattern(namePattern: string, config?: {limit: number}): Promise<Array<MaterialBase>>


Returns a promise that is resolved with the all of the materials matching the name pattern or empty array if none was found.
Pattern format:
* matches any characters sequence.
\ can be used to include in pattern any of the control characters (including '\' itself)

Examples:
findUsingPattern("*") will retrive all of the materials.
findUsingPattern("*A") will retrieve all of the materials suffixed with 'A'.
findUsingPattern("A*") will retrieve all of the materials prefixed with 'A'.
findUsingPattern("*A*", {limit: 10}) will retrieve at most 10 of the materials containing 'A',

limit parameter describes if findUsingPattern should finish the search if it finds specified number of results (default is no limit). Non-positive values for limit are treated as unlimited.

See Also: Materials.getAll, Materials.findFirst.
getAll
getAll(): Promise<Array<MaterialBase>>


Returns a promise that is resolved with all of the materials.
See Also: Materials.findUsingPattern, Materials.findFirst.

Classes

ClassDescription
BlendedMaterialThe BlendedMaterial class encapsulates materials blended from multiple textures.
BlendShapeToWarpMapMaterialThe BlendShapeToWarpMapMaterial class is the JS-side representation of the "Face Warp Material" in Spark AR Studio, used to create face warp effects.
ColorPaintMaterialThe ColorPaintMaterial class encapsulates a face-paint material.
ComposedMaterialThe ComposedMaterial class encapsulates patch asset materials.
DefaultMaterialThe DefaultMaterial class encapsulates an image-based material.
MaterialBaseThe MaterialBase class exposes properties common to all material types.
MetallicRoughnessPbrMaterialThe MetallicRoughnessPbrMaterial class encapsulates physically based materials.
RetouchingMaterialThe RetouchingMaterial class encapsulates parameters which define the extend of certain beautification techniques.
TextureTransformThe TextureTransform class encapsulates scaling and translation transforms about a textures UV axis.

Enums

EnumDescription
BlendModeThe BlendMode enum describes how material is blended.
CullModeThe CullMode enum describes how material is culled.

Was this article helpful?