meshUtils

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

Various utilities and convenience functions for working with Mesh objects.

Method Overview

Name Return Type Summary Object

Converts a mesh to a new vertex space.

meshUtils

Creates an elevation sampler from a mesh.

meshUtils

Creates a mesh geometry by sampling elevation data from an elevation service on a regular grid.

meshUtils

Georeferences vertices specified in a Cartesian coordinate system.

meshUtils

Merges multiple meshes into a single mesh.

meshUtils

Projects georeferenced vertices to a Cartesian coordinate system.

meshUtils

Method Details

convertVertexSpace

Method
convertVertexSpace(mesh, targetVertexSpace, options){Promise<Mesh>}
Since: ArcGIS Maps SDK for JavaScript 4.30 meshUtils since 4.7, convertVertexSpace added at 4.30.

Converts a mesh to a new vertex space. Any transform defined on the mesh will be applied to the vertex attributes as part of the conversion.

Parameters
mesh Mesh

the mesh geometry to convert.

the vertex space to convert to.

options Object
optional

Additional options.

Specification
signal AbortSignal
optional

An AbortSignal to abort the animation. If canceled, the promise will be rejected with an error named AbortError. See also AbortController.

Returns
Type Description
Promise<Mesh> The converted mesh.
Examples
// convert cartesian model data to a mesh with absolute coordinates in WebMercator
const converted = convertVertexSpace(
  new Mesh({
    vertexSpace: new MeshLocalVertexSpace({ origin: location }),
    vertexAttributes,
    spatialReference: SpatialReference.WebMercator
  }),
  new MeshGeoreferencedVertexSpace()
);
// convert a georeferenced WebMercator mesh to a mesh with a local tangent coordinate frame
// at the center of the mesh
const center = mesh.extent.center;
const origin = [center.x, center.y, center.z];
const converted = await convertVertexSpace(mesh, new MeshLocalVertexSpace({ origin }));
// convert an existing mesh to absolute coordinates and place a graphic on the highest vertex
const converted = await convertVertexSpace(mesh, new MeshGeoreferencedVertexSpace());
const position = converted.vertexAttributes.position;

const highestPoint = new Point({ x: 0, y: 0, z: 0, spatialReference: converted.spatialReference });

for (let i = 0; i < position.length; i += 3) {
  if (position[2] > highestPoint.z) {
    highestPoint.x = position[0];
    highestPoint.y = position[1];
    highestPoint.z = position[2];
  }
}

view.graphics.add(new Graphic({ geometry: highestPoint }));

createElevationSampler

Method
createElevationSampler(mesh, options){Promise<ElevationSampler>}
Since: ArcGIS Maps SDK for JavaScript 4.12 meshUtils since 4.7, createElevationSampler added at 4.12.

Creates an elevation sampler from a mesh. The sampler can be used to query elevation values on the surface of the mesh. The elevation sampler uses a snapshot of the Mesh geometry and will not update if the mesh changes after the sampler has been created.

Parameters
mesh Mesh

The mesh geometry used to create the elevation sampler.

options Object
optional

Additional options.

Specification
noDataValue Number
optional
Default Value: 0

The value to use when there is no data available.

Returns
Type Description
Promise<ElevationSampler> An elevation sampler.

createFromElevation

Method
createFromElevation(source, extent, options){Promise<Mesh>}

Creates a mesh geometry by sampling elevation data from an elevation service on a regular grid.

Parameters

The source from which to query the elevation data.

extent Extent

The extent from which to create the mesh.

options Object
optional

Additional options.

params.material MeshMaterial
optional

The material to be used for the mesh.

options.demResolution Number|String
optional
Default Value: auto

Controls the horizontal resolution (cell size) in meters from which elevation data is sampled (defaults to auto). See ElevationLayer.queryElevation for more details on the different settings.

options.signal AbortSignal
optional

Signal object that can be used to abort the asynchronous task.

Returns
Type Description
Promise<Mesh> A promise that resolves to a mesh geometry representing the elevation data at the specified extent.
Example
// Create a mesh by sampling the ground
meshUtils.createFromElevation(map.ground, extent)
    .then(function(mesh) {
      // Do something with the mesh
    });

// Create a mesh by sampling the ground surface currently in view
meshUtils.createFromElevation(view.groundView.elevationSampler, view.extent)
    .then(function(mesh) {
      // Do something with the mesh
    });

georeference

Method
georeference(vertexAttributes, location, options){VertexAttributes}
Deprecated since version 4.30. Use convertVertexSpace instead.

Georeferences vertices specified in a Cartesian coordinate system. This is useful when converting general 3D model meshes not typically georeferenced. This method operates on mesh vertex attributes and will convert positions and normals (if specified) from a local (0, 0, 0) Cartesian system to the properly georeferenced coordinates at the specified location. The unit of the source data defaults to the unit of the location's spatial reference. If the coordinate system is WGS84, metric units are used as the default. The unit of the source data may be specified in the additional options in which case a linear unit scale will automatically be applied to bring the source data in the unit of the spatial reference.

Parameters
Specification
vertexAttributes VertexAttributes

The position and normal buffers to georeference.

location Point

The location at which to georeference the position and normal buffers.

options Object
optional

Additional options.

Specification
geographic Boolean
optional

Indicates whether to georeference relative to the globe or the projected coordinate system.

unit LengthUnit
optional

Indicates the unit of the source data. A linear scale will be applied to the position attributes to convert the source data to the unit of the spatial reference at which the mesh is being georeferenced. By default the unit of the source data is assumed to be the same as the target spatial reference.

Returns
Type Description
VertexAttributes The georeferenced position and normal buffers.
Example
const geoVertexAttributes = meshUtils.georeference(vertexAttributes, location);
const mesh = new Mesh({
  vertexAttributes: geoVertexAttributes,
  spatialReference: location.spatialReference
});

merge

Method
merge(geometries){Mesh}

Merges multiple meshes into a single mesh. All mesh geometries must be in the same spatial reference.

Parameter
geometries Mesh[]

One or more meshes.

Returns
Type Description
Mesh The merged mesh geometry.
Example
const mergedMesh = meshUtils.merge([mesh1, mesh2]);

ungeoreference

Method
ungeoreference(vertexAttributes, location, options){VertexAttributes}
Deprecated since version 4.30. Use convertVertexSpace instead.

Projects georeferenced vertices to a Cartesian coordinate system. This is useful for converting existing scene geometry so that it can be used as source material for generating new 3D meshes. This method operates on mesh vertex attributes and will convert positions and normals (if specified) from georeferenced coordinates at the specified location to a local (0, 0, 0) Cartesian system. The unit of the resulting data defaults to the unit of the location's spatial reference. If the coordinate system is WGS84, metric units are used as the default. The unit of the resulting data may be specified in the additional options in which case a linear unit scale will automatically be applied.

Parameters
Specification
vertexAttributes VertexAttributes

The georeferenced position and normal buffers.

location Point

The location to which the position and normal buffers are georeferenced.

options Object
optional

Additional options.

Specification
geographic Boolean
optional

Indicates whether the coordinates are georeferenced relative to the globe or the projected coordinate system.

unit LengthUnit
optional

Indicates the unit of the resulting data. A linear scale will be applied to the position attributes to convert the source data to the specified unit. By default the unit of the resulting data will be the same as the source spatial reference.

Returns
Type Description
VertexAttributes The position and normal buffers in a local Cartesian coordinate system.
Example
const vertexAttributes = meshUtils.ungeoreference(geoVertexAttributes, location);

Type Definitions

VertexAttributes

Type Definition
VertexAttributes Object

Represents the position and normal vertex attribute buffers of a mesh.

Properties
position Float64Array

The position buffer.

normal Float32Array
optional

The normal buffer.

tangent Float32Array
optional

The tangent buffer.

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