|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import Frozen from "../Core/Frozen.js"; |
| 4 | +import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; |
| 5 | + |
| 6 | +/** @import Color from "../Core/Color.js"; */ |
| 7 | +/** @import BufferPoint from "./BufferPoint.js"; */ |
| 8 | + |
| 9 | +/** |
| 10 | + * @typedef {object} BufferPointMaterialOptions |
| 11 | + * @property {Color} [color=Color.WHITE] Color of fill. |
| 12 | + * @property {Color} [outlineColor=Color.WHITE] Color of outline. |
| 13 | + * @property {number} [outlineWidth=0.0] Width of outline, 0-255px. |
| 14 | + * @property {number} [size=1.0] Size of point, 0-255px. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * Material description for a {@link BufferPoint}. |
| 19 | + * |
| 20 | + * <p>BufferPointMaterial objects are {@link Packable|packable}, stored |
| 21 | + * when calling {@link BufferPoint#setMaterial}. Subsequent changes to the |
| 22 | + * material will not affect the point until setMaterial() is called again.</p> |
| 23 | + * |
| 24 | + * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. |
| 25 | + * @extends BufferPrimitiveMaterial |
| 26 | + */ |
| 27 | +class BufferPointMaterial extends BufferPrimitiveMaterial { |
| 28 | + /** @ignore */ |
| 29 | + static Layout = { |
| 30 | + ...BufferPrimitiveMaterial.Layout, |
| 31 | + SIZE_U8: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH, |
| 32 | + __BYTE_LENGTH: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH + 4, |
| 33 | + }; |
| 34 | + |
| 35 | + /** |
| 36 | + * @type {BufferPointMaterial} |
| 37 | + * @ignore |
| 38 | + */ |
| 39 | + static DEFAULT_MATERIAL = Object.freeze(new BufferPointMaterial()); |
| 40 | + |
| 41 | + /** |
| 42 | + * @param {BufferPointMaterialOptions} [options] |
| 43 | + */ |
| 44 | + constructor(options = Frozen.EMPTY_OBJECT) { |
| 45 | + super(options); |
| 46 | + |
| 47 | + /** |
| 48 | + * Size of point, 0-255px. |
| 49 | + * @type {number} |
| 50 | + */ |
| 51 | + this.size = options.size ?? 1; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @override |
| 56 | + * @param {BufferPointMaterial} material |
| 57 | + * @param {DataView} view |
| 58 | + * @param {number} byteOffset |
| 59 | + * @override |
| 60 | + */ |
| 61 | + static pack(material, view, byteOffset) { |
| 62 | + super.pack(material, view, byteOffset); |
| 63 | + view.setUint8(this.Layout.SIZE_U8 + byteOffset, material.size); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @override |
| 68 | + * @param {DataView} view |
| 69 | + * @param {number} byteOffset |
| 70 | + * @param {BufferPointMaterial} result |
| 71 | + * @returns {BufferPointMaterial} |
| 72 | + * @override |
| 73 | + */ |
| 74 | + static unpack(view, byteOffset, result) { |
| 75 | + super.unpack(view, byteOffset, result); |
| 76 | + result.size = view.getUint8(this.Layout.SIZE_U8 + byteOffset); |
| 77 | + return result; |
| 78 | + } |
| 79 | + |
| 80 | + ///////////////////////////////////////////////////////////////////////////// |
| 81 | + // DEBUG |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns a JSON-serializable object representing the material. This encoding |
| 85 | + * is not memory-efficient, and should generally be used for debugging and |
| 86 | + * testing. |
| 87 | + * |
| 88 | + * @returns {Object} JSON-serializable object. |
| 89 | + */ |
| 90 | + toJSON() { |
| 91 | + return { ...super.toJSON(), size: this.size }; |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +export default BufferPointMaterial; |
0 commit comments