The SimpleMeshLayer renders a number of arbitrary geometries. For example, a fleet of 3d cars each with a position and an orientation over the map.
import DeckGL from '@deck.gl/react';
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
import {CubeGeometry} from '@luma.gl/core'
function App({data, viewState}) {
/**
* Data format:
* [
* {
* position: [-122.45, 37.7],
* angle: 0,
* color: [255, 0, 0]
* },
* {
* position: [-122.46, 37.73],
* angle: 90,
* color: [0, 255, 0]
* },
* ...
* ]
*/
const layer = new SimpleMeshLayer({
id: 'mesh-layer',
data,
texture: 'texture.png',
mesh: new CubeGeometry(),
getPosition: d => d.position,
getColor: d => d.color,
getOrientation: d => [0, d.angle, 0]
});
return <DeckGL viewState={viewState} layers={[layer]} />;
}loaders.gl offers a category of loaders for loading meshes from standard formats. For example, the following code adds support for OBJ files:
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
import {OBJLoader} from '@loaders.gl/obj';
new SimpleMeshLayer({
...
mesh: 'path/to/model.obj',
loaders: [OBJLoader]
});To install the dependencies from NPM:
npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/mesh-layersimport {SimpleMeshLayer} from '@deck.gl/mesh-layers';
new SimpleMeshLayer({});To use pre-bundled scripts:
<script src="https://unpkg.com/deck.gl@^8.0.0/dist.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^8.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/mesh-layers@^8.0.0/dist.min.js"></script>new deck.SimpleMeshLayer({});Inherits from all Base Layer properties.
mesh (String|Geometry|Object)The geometry to render for each data object. One of:
registerLoaders function for this usage.positions (Float32Array) - 3d vertex offset from the object center, in metersnormals (Float32Array) - 3d normalstexCoords (Float32Array) - 2d texture coordinatestexture (String|Texture2D|Image|ImageData|HTMLCanvasElement|HTMLVideoElement|ImageBitmap|Promise|Object, optional)null.The texture of the geometries.
Texture2D constructor, e.g. {width: <number>, height: <number>, data: <Uint8Array>}. Note that whenever this object shallowly changes, a new texture will be created.The image data will be converted to a Texture2D object. See textureParameters prop for advanced customization.
If texture is supplied, texture is used to render the geometries. Otherwise, object color obtained via the getColor accessor is used.
textureParameters (Object)Customize the texture parameters.
If not specified, the layer uses the following defaults to create a linearly smoothed texture from texture:
{
[GL.TEXTURE_MIN_FILTER]: GL.LINEAR_MIPMAP_LINEAR,
[GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
[GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
[GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
}sizeScale (Number, optional) 1.Multiplier to scale each geometry by.
wireframe (Boolean, optional)falseWhether to render the mesh in wireframe mode.
material (Object, optional)trueThis is an object that contains material props for lighting effect applied on extruded polygons. Check the lighting guide for configurable settings.
_useMeshColors (Boolean, optional)falseWhether to color pixels using vertex colors supplied in the mesh (the COLOR_0 or colors attribute). If set to true, vertex colors will be used. If set to false (default) vertex colors will be ignored.
Remarks:
getPosition (Function, optional) object => object.positionMethod called to retrieve the center position for each object in the data stream.
getColor (Function|Array, optional) [0, 0, 0, 255]If mesh does not contain vertex colors, use this color to render each object. If mesh contains vertex colors, then the two colors are mixed together. Use [255, 255, 255] to use the original mesh colors. If texture is assigned, then both colors will be ignored.
The color is in the format of [r, g, b, [a]]. Each channel is a number between 0-255 and a is 255 if not supplied.
getOrientation (Function|Array, optional)[0, 0, 0]Object orientation defined as a vec3 of Euler angles, [pitch, yaw, roll] in degrees. This will be composed with layer's modelMatrix.
getScale (Function|Array, optional)[1, 1, 1]Scaling factor on the mesh along each axis.
getTranslation (Function|Array, optional)[0, 0, 0]Translation of the mesh along each axis. Offset from the center position given by getPosition. [x, y, z] in meters. This will be composed with layer's modelMatrix.
getTransformMatrix (Function|Array, optional)nullExplicitly define a 4x4 column-major model matrix for the mesh. If provided, will override
getOrientation, getScale, getTranslation.