require(["esri/geometry/support/MeshTexture"], (MeshTexture) => { /* code goes here */ });
import MeshTexture from "@arcgis/core/geometry/support/MeshTexture.js";
esri/geometry/support/MeshTexture
MeshTexture represents image data to be used for MeshMaterial or MeshMaterialMetallicRoughness. It is mapped to the mesh by its uv vertex attributes. MeshTexture instances can be used with the MeshComponent.material property and they can be set either as a MeshMaterial.colorTexture or as MeshMaterial.normalTexture. Images can be referred to either by url or directly by data ( HTMLImageElement, HTMLCanvasElement, HTMLVideoElement or ImageData).
const meshColorByUrl = new MeshTexture({
url: "./image.png"
});
const mesh = Mesh.createBox(location, {
material: {
colorTexture: meshColorByUrl
}
});
const meshColorByCanvas = new MeshTexture({
data: canvasElement
});
const meshWithCanvasMaterial = Mesh.createBox(location, {
material: {
colorTexture: meshColorByCanvas
}
});
// Support for autocasting within a mesh material constructor
const meshWithAutocastMaterial = Mesh.createSphere(location, {
material: {
colorTexture: {
url: "./image.png"
}
}
});
// Mesh materials also support additional advanced autocasting types
// such as a Canvas element. In this case the canvas element will be
// available in the MeshTexture.data property.
const meshWithCanvasAutocastMaterial = Mesh.createSphere(location, {
material: {
colorTexture: canvasElement
}
});
// When using a video as a texture, you need to create a Video element
// and pass it in the MeshTexture.data property.
const video = document.createElement("video");
video.src = "./my-video.mp4";
video.crossOrigin = "anonymous";
video.autoplay = true;
video.muted = true;
// The video needs to be added to the DOM and be located in
// the viewport in order for it to play
document.body.appendChild(video);
video.style.position = "absolute";
video.style.top = 0;
// Hide the video element
video.style.height = 0;
video.style.visibility = "hidden";
const meshWithVideoMaterial = Mesh.createPlane(location, {
material: {
colorTexture: { data: video }
}
});
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
A direct reference to the image or video data. | MeshTexture | ||
The name of the class. | Accessor | ||
Indicates whether the image data should be interpreted as being semi-transparent. | MeshTexture | ||
The url to the image resource. | MeshTexture | ||
Specifies how uv coordinates outside the [0, 1] range are handled. | MeshTexture |
Property Details
-
data
data HTMLImageElement |HTMLCanvasElement |HTMLVideoElement |ImageData
-
A direct reference to the image or video data. The data can be an image element, canvas element, video element or ImageData. If the data is set to a video element, the element needs to be visible in the DOM. The data property is mutually exclusive with the url property, setting the data will clear the url (if there is one).
-
transparent
transparent Boolean
-
Indicates whether the image data should be interpreted as being semi-transparent. The default value is automatically derived when the data property contains a canvas element or an ImageData object. If instead a url to a .png file was provided, it is assumed that transparency is present. In all other cases it defaults to
false
.- Default Value:undefined
-
url
url String
-
The url to the image resource. This can either be a remote url (absolute or relative) or a data url. Video resources can only be loaded using the data property. The url property is mutually exclusive with the data property, setting the url will clear the data (if there is one).
-
wrap
wrap String |SeparableWrapModes
-
Specifies how uv coordinates outside the [0, 1] range are handled. One of "repeat", "clamp" or "mirror". Can also be specified separately for the two texture axes using an object:
{ vertical: "clamp", horizontal: "repeat" }
Possible Values:"clamp" |"repeat" |"mirror"
- Default Value:"repeat"
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Creates a deep clone. | MeshTexture | ||
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor 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();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey 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.
-
clone
clone(){MeshTexture}
-
Creates a deep clone.
ReturnsType Description MeshTexture A deep clone of the object that invoked this method.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType 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"); }
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
Type Definitions
-
A separable wrap configuration for horizontal and vertical wrapping modes.