# 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');

// Locate the plane in the Scene
const plane = Scene.root.find('plane0');

// Locate the plane in the Scene
const material = Materials.get('defaultMaterial0');

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

// Set the opacity of the material to 50%
material.opacity = 0.5;
```

## Properties

This module exposes no properties.

## Methods

| Method             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `findFirst`        | <p><code>findFirst(name: string): Promise\<MaterialBase></code></p><p>Returns a promise that is resolved with the material of a requested name or null if none was found.</p><p><strong>See Also</strong>: <code>Materials.findUsingPattern</code>, <code>Materials.getAll</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `findUsingPattern` | <p><code>findUsingPattern(namePattern: string): Promise\<Array\<MaterialBase>> findUsingPattern(namePattern: string, config: {limit: number}): Promise\<Array\<MaterialBase>></code></p><p>Returns a promise that is resolved with the all of the materials matching the name pattern or empty array if none was found.</p><p>Pattern format: <code>*</code> matches any characters sequence. <code>\</code> can be used to include in pattern any of the control characters (including '' itself)</p><p>Examples: <code>findUsingPattern("*")</code> will retrive all of the materials. <code>findUsingPattern("*A")</code> will retrieve all of the materials suffixed with 'A'. <code>findUsingPattern("A*")</code> will retrieve all of the materials prefixed with 'A'. <code>findUsingPattern("*A*", {limit: 10})</code> will retrieve at most 10 of the materials containing 'A',</p><p><code>limit</code> parameter describes if <code>findUsingPattern</code> should finish the search if it finds specified number of results (default is no limit). Non-positive values for limit are treated as unlimited.</p><p><strong>See Also</strong>: <code>Materials.getAll</code>, <code>Materials.findFirst</code>.</p> |
| `get`              | <p><code>get(materialName: string): MaterialBase</code></p><p>Returns a <code>MaterialBase</code> class that represents the material specified by the <code>materialName</code> parameter. The materials are defined in the AR Studio project.</p><p>An exception is thrown when the identifier isn't found in the project.</p><p><strong>See Also</strong>: <code>MaterialBase.name</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `getAll`           | <p><code>getAll(): Promise\<Array\<MaterialBase>></code></p><p>Returns a promise that is resolved with all of the materials.</p><p><strong>See Also</strong>: <code>Materials.findUsingPattern</code>, <code>Materials.findFirst</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

## Classes

| Class                                                                                                                                        | Description                                                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [`BlendedMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.blendedmaterial)                           | The `BlendedMaterial` class encapsulates materials blended from multiple textures.                                   |
| [`BlendShapeToWarpMapMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.blendshapetowarpmapmaterial)   | The `BlendShapeToWarpMapMaterial` class.                                                                             |
| [`ColorPaintMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.colorpaintmaterial)                     | The `ColorPaintMaterial` class encapsulates a face-paint material.                                                   |
| [`ComposedMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.composedmaterial)                         | The `ComposedMaterial` class encapsulates patch asset materials.                                                     |
| [`DefaultMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.defaultmaterial)                           | The `DefaultMaterial` class encapsulates an image-based material.                                                    |
| [`MaterialBase`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.materialbase)                                 | The `MaterialBase` class exposes properties common to all material types.                                            |
| [`MetallicRoughnessPbrMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.metallicroughnesspbrmaterial) | The `MetallicRoughnessPbrMaterial` class encapsulates physically based materials.                                    |
| [`RetouchingMaterial`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.retouchingmaterial)                     | The `RetouchingMaterial` class encapsulates parameters which define the extend of certain beautification techniques. |
| [`TextureTransform`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/materialsmodule.texturetransform)                         | The `TextureTransform` class encapsulates scaling and translation transforms about a textures UV axis.               |

## Enums

| Enum                                                                                                 | Description                                             |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| [`BlendMode`](https://sparkar.facebook.com/docs/ar-studio/reference/enums/materialsmodule.blendmode) | The `BlendMode` enum describes how material is blended. |
| [`CullMode`](https://sparkar.facebook.com/docs/ar-studio/reference/enums/materialsmodule.cullmode)   | The `CullMode` enum describes how material is culled.   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sparkar-community.gitbook.io/docs/materialsmodule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
