import MeshMaterial from "@arcgis/core/geometry/support/MeshMaterial.js";const MeshMaterial = await $arcgis.import("@arcgis/core/geometry/support/MeshMaterial.js");- Inheritance:
- MeshMaterial→
Accessor
- Subclasses:
- MeshMaterialMetallicRoughness
- 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() }});Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
| | ||
MeshTexture | null | undefined | | |
| | ||
declaredClass readonly inherited | ||
| | ||
MeshTexture | null | undefined | | |
| |
alphaMode
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. |
- Default value
- "auto"
colorTexture
- Type
- MeshTexture | null | undefined
Specifies a texture from which to get color information. The texture is accessed using the UV coordinates specified for each vertex in the Mesh.vertexAttributes.
colorTextureTransform
- Type
- MeshTextureTransform | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 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.
doubleSided
- Type
- boolean
Specifies whether both sides of each triangle are displayed, or only the front sides.
- Default value
- true
normalTexture
- Type
- MeshTexture | null | undefined
Specifies a texture from which to get normal information. The texture is accessed using the UV coordinates specified for each vertex in the Mesh.vertexAttributes.
normalTextureTransform
- Type
- MeshTextureTransform | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 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.
Methods
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): this
Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.
- Returns
- this
A deep clone of the class instance that invoked this method.
toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.