MaterialUtils - Verge3D User Manual - Soft8Soft
Description: Learn how to use MaterialUtils in your interactive 3D apps made with Verge3D

# MaterialUtils

A module containing useful utility methods to work with Verge3D materials.

## Methods

### # .replaceTexture(mat : Material, oldTex : Texture, newTex : Texture)

- mat — material instance.
- oldTex — texture to be replaced.
- newTex — a new texture.

Replace one texture by another in the given material. Currently this method supports only MeshNodeMaterial and MeshStandardMaterial materials.

### # .disposeTextures(mat : Material)

- mat — material instance.

Dispose all textures found in the given material. Currently this method supports only MeshNodeMaterial and MeshStandardMaterial materials.

### # .createDiffuseMaterial(name : String, color : Color, opacity : Float, profile : String) → MeshNodeMaterial

- name — material name.
- color — material diffuse color.
- opacity — material opacity.
- profile — (optional) material profile, specifies which nodes will be used to compose the node graph. One of `"blender"`, `"max"`, `"maya"`. Default is `"blender"`.

Generate node-based diffuse (lambert) material with the given `color` and `opacity` params.

### # .createEnvironmentMaterial(name : String, envTex : Texture, bkgTexOrColor : Texture | Color) → MeshNodeMaterial

- name — material name.
- envTex — texture used for environment lighting.
- bkgTexOrColor — texture or color used for background.

Create node-based material which can be used for environment lighting and scene background.

### # .createStandardPBRMaterial(profile : String, params : Object) → MeshNodeMaterial

- profile — (optional) material profile, specifies which nodes will be used to compose the node graph. One of `"blender"`, `"max"`, `"maya"`. Default is `"blender"`.
- params — (optional) additional material properties.

Generate node-based standard PBR material with the given set of parameters:

color
  Material base color. Default is `'white'`.
opacity
  Material opacity value. Default is `1.0` (opaque).
metalness
  Material metalness value. Default is `0` (non-metallic).
roughness
  Material roughness value. Default is `1` (maximum roughness).
emissive
  Material emissive color. Default is `'black'`.
emissiveIntensity
  Material emissive color intensity. Default is `1`.

## Source

For more info on how to obtain the source code of this module see this page.