MeshMaterial

AMD: require(["esri/geometry/support/MeshMaterial"], (MeshMaterial) => { /* code goes here */ });
ESM: import MeshMaterial from "@arcgis/core/geometry/support/MeshMaterial.js";
Class: esri/geometry/support/MeshMaterial
Inheritance: MeshMaterialAccessor
Since: ArcGIS Maps SDK for JavaScript 4.11

The material determines how a MeshComponent is visualized. One of the major characteristics of a material is its color. The color property can be used to set a uniform color for the whole MeshComponent. Use the colorTexture property to map an image onto the mesh component, using the uv coordinate specified for each vertex in the Mesh.vertexAttributes.

The material properties support a number of convenience autocast types, including hex color strings and well known color strings (autocasts to Color), or strings representing urls to images, HTMLImageElements, HTMLCanvasElements, HTMLVideoElement, or ImageData (autocasts to MeshTexture).


// create a material that uses a color

const meshWithColor = new MeshComponent({
  // autocasts to MeshMaterial
  material: {
    color: "#ff00ff"
  }
});

// create a material that uses a texture by linking to
// an image url

const meshTextureByUrl = new MeshTexture({
  url: "./image.png"
});

const boxMesh = Mesh.createBox(location, {
  material: {
    colorTexture: meshTextureByUrl
  }
});

// create a material that uses a texture from
// a canvas element

function createLinearGradient() {
  const canvas = document.createElement("canvas");
  canvas.width = 32;
  canvas.height = 32;

  const ctx = canvas.getContext("2d");

  // Create the linear gradient with which to fill the canvas
  const gradient = ctx.createLinearGradient(0, 0, 0, 32);
  gradient.addColorStop(0, "#00ff00");
  gradient.addColorStop(1, "#009900");

  // Fill the canvas with the gradient pattern
  ctx.fillStyle = gradient;
  ctx.fillRect(0, 0, 32, 32);

  return canvas;
}

const component = new MeshComponent({
  material: {
    // Autocast canvas element to MeshTexture instance
    colorTexture: createLinearGradient()
  }
});
See also

Constructors

MeshMaterial

Constructor
new MeshMaterial(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
Show inherited properties Hide inherited properties
Name Type Summary Class

Specifies how transparency on the object is handled.

MeshMaterial

Specifies how transparency on the object is handled.

MeshMaterial

Specifies a single, uniform color for the mesh component.

MeshMaterial

Specifies a texture from which to get color information.

MeshMaterial

A transformation of UV mesh coordinates used to sample the color texture.

MeshMaterial

The name of the class.

Accessor

Specifies whether both sides of each triangle are displayed, or only the front sides.

MeshMaterial

Specifies a texture from which to get normal information.

MeshMaterial

A transformation of UV mesh coordinates used to sample the normal texture.

MeshMaterial

Property Details

alphaCutoff

Property
alphaCutoff Number

Specifies how transparency on the object is handled. If alphaMode is set to either mask or auto this property specifies the cutoff value below which masking happens (that is, the corresponding part of the Mesh is rendered fully transparent).

Default Value:0.5

alphaMode

Property
alphaMode String

Specifies how transparency on the object is handled. See also alphaCutoff.

Type Description
opaque Alpha is ignored, and the object is rendered fully opaque.
blend Alpha values are used for gradual transparency, blending between the object and its background.
mask Alpha values are used for binary transparency, either displaying the object, or its background. See also alphaCutoff.
auto The implementation mixes the mask and blend settings, masking below alphaCutoff and blending above it.

Possible Values:"auto" |"blend" |"opaque" |"mask"

Default Value:"auto"

color

Property
color Colorautocast
Autocasts from Object|Number[]|String

Specifies a single, uniform color for the mesh component. This can be autocast with a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or a Color object.

colorTexture

Property
colorTexture MeshTextureautocast

Specifies a texture from which to get color information. The texture is accessed using the uv coordinate specified for each vertex in the Mesh.vertexAttributes.

colorTextureTransform

Property
colorTextureTransform MeshTextureTransform
Since: ArcGIS Maps SDK for JavaScript 4.27 MeshMaterial since 4.11, colorTextureTransform added at 4.27.

A transformation of UV mesh coordinates used to sample the color texture. Texture transformations can be used to optimize re-use of textures, for example by packing many images into a single texture "atlas" and using the texture transform offset and scale to sample a specific region within this larger texture.

Default Value:undefined

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

doubleSided

Property
doubleSided Boolean

Specifies whether both sides of each triangle are displayed, or only the front sides.

Default Value:true

normalTexture

Property
normalTexture MeshTextureautocast

Specifies a texture from which to get normal information. The texture is accessed using the uv coordinate specified for each vertex in the Mesh.vertexAttributes.

normalTextureTransform

Property
normalTextureTransform MeshTextureTransform
Since: ArcGIS Maps SDK for JavaScript 4.27 MeshMaterial since 4.11, normalTextureTransform added at 4.27.

A transformation of UV mesh coordinates used to sample the normal texture. Texture transformations can be used to optimize re-use of textures, for example by packing many images into a single texture "atlas" and using the texture transform offset and scale to sample a specific region within this larger texture.

Default Value:undefined

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.