UNPKG

@deck.gl/experimental-layers

Version:

Experimental layers for deck.gl

40 lines (35 loc) 1.67 kB
import { Geometry } from 'luma.gl'; export default class Arrow2DGeometry extends Geometry { constructor() { let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; super(Object.assign({}, opts, { attributes: getArrowAttributes(opts) })); } } function getArrowAttributes(_ref) { let _ref$length = _ref.length, length = _ref$length === void 0 ? 1 : _ref$length, _ref$headSize = _ref.headSize, headSize = _ref$headSize === void 0 ? 0.2 : _ref$headSize, _ref$tailWidth = _ref.tailWidth, tailWidth = _ref$tailWidth === void 0 ? 0.05 : _ref$tailWidth, _ref$tailStart = _ref.tailStart, tailStart = _ref$tailStart === void 0 ? 0.05 : _ref$tailStart; const texCoords = [// HEAD 0.5, 1.0, 0, 0.5 - headSize / 2, 1.0 - headSize, 0, 0.5 + headSize / 2, 1.0 - headSize, 0, 0.5 - tailWidth / 2, tailStart, 0, 0.5 + tailWidth / 2, 1.0 - headSize, 0, 0.5 + tailWidth / 2, tailStart, 0, 0.5 - tailWidth / 2, tailStart, 0, 0.5 - tailWidth / 2, 1.0 - headSize, 0, 0.5 + tailWidth / 2, 1.0 - headSize, 0]; const normals = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]; // Center and scale const positions = new Array(texCoords.length); for (let i = 0; i < texCoords.length / 3; i++) { const i3 = i * 3; positions[i3 + 0] = (texCoords[i3 + 0] - 0.5) * length; positions[i3 + 1] = (texCoords[i3 + 1] - 0.5) * length; positions[i3 + 2] = 0; } return { positions: new Float32Array(positions), normals: new Float32Array(normals), texCoords: new Float32Array(texCoords) }; } //# sourceMappingURL=arrow-2d-geometry.js.map