Material

MeshNodeMaterial

A custom node-based material.

This material used to describe custom material setups exported from Blender, 3ds Max, or Maya. It can be physically based or non-physical depending on the specified node graph.

Examples

Change material color specified in the "RGB.001" node:

const object = app.scene.getObjectByName("MyObj"); const mat = object.material; const index = mat.nodeRGBMap['RGB.001']; // 'RGB.001' is the name of an RGB node mat.nodeRGB[index] = new v3d.Vector4(1, 0, 0, 1); // new color in RGBA format mat.needsUpdate = true;

Change value specified in the "Value.001" node:

const object = app.scene.getObjectByName("Circle"); const mat = object.material; const index = mat.nodeValueMap['Value.001']; mat.nodeValue[index] = 0.5; // new value mat.needsUpdate = true;

Constructor

MeshNodeMaterial(parameters : Object)

parameters — (optional) an object with one or more properties defining the material's appearance. Any property of the material (including any property inherited from Material) can be passed in here.

The exception is the property color which is 0xffffff (white) by default. In case if no nodeGraph parameter passed to the constructor, this value will be used to generate a fallback node graph which in turn will render that color.

// no nodeGraph passed, this material will render solid red color const mat = new MeshNodeMaterial({color: 'red'});

Designing node-based materials with JavaScript can be a cumbersome task. It is more efficient to use the modelling suite for that, which conveniently provides real-time preview in viewport.

Properties

See the base Material class for common properties.

.additionalNodeGraphs : Object

Additional graphs representing node groups of the main node graph.

.envMap : Texture

The environment map. To ensure a physically correct rendering, you should only add environment maps which were preprocessed by PMREMGenerator. Assigned automatically from a corresponding CubeReflectionProbe object if Material.envMapAutoAssign is true. Default is null.

.envMapIntensity : Float

Scales the effect of the environment map by multiplying its color. Default is 1.

.envMapParallaxMatrix : Matrix4

A Matrix4 used for applying the parallax effect to the material's .envMap. This matrix carries the transformation from the world space to the space of a particular reflection probe, which environment map this material uses for rendering. Calculated automatically if Material.envMapAutoAssign is true. Default is the identity matrix.

.envMapParallaxMatrixInv : Matrix4

A Matrix4 inverse to .envMapParallaxMatrix. Used for applying the parallax effect to the material's .envMap. Calculated automatically if Material.envMapAutoAssign is true. Default is the identity matrix.

.envMapParallaxType : Constant

Defines the type of the parallax volume. The same as CubeReflectionProbe.parallaxType. Assigned automatically from the corresponding CubeReflectionProbe if Material.envMapAutoAssign is true. Default is ReflectionProbeTypeInfinite.

.flatShading : Boolean

Define whether the material is rendered with flat shading. Default is false.

.fog : Boolean

Whether the material is affected by fog. Default is true.

.isMeshNodeMaterial : Boolean

Used to check whether this class represent node material. You should not change this, as it is used internally for optimization.

.materialIndex : Integer

Material index. Used to define the corresponding output in the Blender's object info node.

.nodeGraph : DiGraph

Directed graph which contains material nodes.

.nodeRGB : Array

Array of Vector4 values which contains color values of a material's "RGB" nodes. Please note that these colors are represented by 4-dimentional vector, not the Color class.

.nodeRGBMap : Array

Maps "RGB" node name to index in .nodeRGB array. Used to define which color value is to be updated, see the example listing above.

.nodeTextures : Object

Object with material textures. It maps texture names to textures. You can use it to dynamically assign new textures to a material.

.nodeValue : Array

Array of float values which contain values of the material's "Value" nodes.

.nodeValueMap : Array

Maps "Value" node name to index in .nodeValue array. Used to define which value is to be updated, see the example listing above.

.profile : String

Node material profile, one of "blender", "max", or "maya".

Methods

See the base Material class for common methods.

.canUseGTAO() → Boolean

Check if the node material uses nodes that render GTAO effect.

.connectTexture(tex : Texture, nodeName : String, inputName : String)

Connect texture to the node input. Both the node and its input specified by their names.

.isUnlit() → Boolean

Check if this material is unlit (based on emissive nodes).

.findNodeByName(name : String) → Node

Find and return a node which has the given name.

.getInputColor(node : Node, index : Integer) → Color

Resolve color value passed to given node input.

.getInputTexture(node : Node, index : Integer) → Texture

Find texture connected to given node input.

.getInputValue(node : Node, index : Integer) → Float

Resolve float value passed to given node input.

.getMainShaderNode() → Node

Analyze material and return main shader node.

.getStandardProp(prop : String) → Node

Analyze material node structure and return a value of the "standard" property. If the property could not be resolved, return default value for that property.

Allowed properties:

color
Material base color. Default is 0xffffff (white).
map
Material base texture. Default is null (no texture).
opacity
Material opacity value. Default is 1.0 (opaque).
metalness
Material metalness value. Default is 0.5 (semi-metallic).
metalnessMap
Material metalness texture. Default is null (no texture)
roughness
Material roughness value. Default is 0.5.
roughnessMap
Material roughness texture. Default is null (no texture)
aoMap
Material ambient occlusion texture. Default is null (no texture)
aoMapIntensity
Ambient occlusion map influence. Default it 1.0.
normalMap
Material normal map texture. Default is null (no texture)
normalScale
Intensity of normal mapping along U and V coordinates. Default is (1.0, 1.0).
emissive
Material emissive color. Default is 0x000000 (black).
emissiveMap
Material emissive texture. Default is null (no texture)
emissiveIntensity
Material emissive intensity. Default is 0.0.

.hasNode(nodeType : String) → Boolean

Check if the node material has a node of the specified type (nodeType).

.needsLightPathDir() → Boolean

Check if the node material includes Light Path, Ray Switch, or OSL nodes.

.traverseNodes(cb : Function)

Traverse the node material and execute the given callback function per each node in the graph.

.updateNodeGraph()

Generate shaders and update other material parameters based on the specified .nodeGraph.

.useAddTransparency() → Boolean

Check if the node material uses additive transparency.

.worldMaterialColor() → Color

Check if the world material can be simplified to a solid color and return that color.

Static Methods

.nodeTexUniName(type : String, texIndex : Integer) → String

Generate texture uniform name from the given type and arbitrary index (e.g texture index inside glTF asset).

.nodeGraphFromExtGraph(gltfExtNodeGraph : Object) → DiGraph

Convert glTF node graph to the format used by the material's .nodeGraph property.

.nodeGraphTraverse(nodeGraph : DiGraph, cb : Function)

Traverse the graph and execute the given callback function per each node in the graph.

Puzzles

There are numerous material puzzles to manage your materials with no coding.

Source

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