-
Notifications
You must be signed in to change notification settings - Fork 3.8k
BufferPrimitiveCollection: Material API #13313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
donmccurdy
merged 14 commits into
main
from
donmccurdy/feat/bufferprimitivecollection-materials
Mar 24, 2026
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b865dd7
BufferPrimitiveCollection: Material API
donmccurdy 68df5e0
fix: Missing suffix on imports
donmccurdy 9a392ed
fix: Missing suffix on imports
donmccurdy b6ca663
Merge branch 'main' into donmccurdy/feat/bufferprimitivecollection-ma…
danielzhong b80149c
fix: Update docs to reflect BufferPrimitiveMaterial, with tests and c…
donmccurdy a3b6366
Merge branch 'main' into donmccurdy/feat/bufferprimitivecollection-ma…
donmccurdy 1f8fac9
Merge branch 'main' into donmccurdy/feat/bufferprimitivecollection-ma…
donmccurdy 1da342d
refactor: Update VectorGltf3DTileContent#applyDebugSettings
donmccurdy 9fa90b9
Vector Tiles: Add VectorGltf3DTileContent#applyStyle
donmccurdy 46ca204
BufferPointMaterial: Rename 'pixelSize' -> 'size'
donmccurdy 5405a40
Merge branch 'main' into donmccurdy/feat/bufferprimitivecollection-ma…
donmccurdy 59333b4
BufferPrimitiveMaterial: Rename shader source files
donmccurdy 0cf487c
BufferPrimitiveMaterial: Rename shader source files pt2
donmccurdy 5cd8ba3
Fix: Add 'lineWidth' to Cesium3DTileStyle specs
donmccurdy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // @ts-check | ||
|
|
||
| import Frozen from "../Core/Frozen.js"; | ||
| import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; | ||
|
|
||
| /** @import Color from "../Core/Color.js"; */ | ||
| /** @import BufferPoint from "./BufferPoint.js"; */ | ||
|
|
||
| /** | ||
| * @typedef {object} BufferPointMaterialOptions | ||
| * @property {Color} [color=Color.WHITE] Color of fill. | ||
| * @property {Color} [outlineColor=Color.WHITE] Color of outline. | ||
| * @property {number} [outlineWidth=0.0] Width of outline, 0-255px. | ||
| * @property {number} [pixelSize=1.0] Size of point, 0-255px. | ||
| */ | ||
|
|
||
| /** | ||
| * Material description for a {@link BufferPoint}. | ||
| * | ||
| * <p>BufferPointMaterial objects are {@link Packable|packable}, stored | ||
| * when calling {@link BufferPoint#setMaterial}. Subsequent changes to the | ||
| * material will not affect the point until setMaterial() is called again.</p> | ||
| * | ||
| * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. | ||
| * @extends BufferPrimitiveMaterial | ||
| */ | ||
| class BufferPointMaterial extends BufferPrimitiveMaterial { | ||
| /** @ignore */ | ||
| static Layout = { | ||
| ...BufferPrimitiveMaterial.Layout, | ||
| PIXEL_SIZE_U8: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH, | ||
| __BYTE_LENGTH: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH + 4, | ||
| }; | ||
|
|
||
| /** | ||
| * @type {BufferPointMaterial} | ||
| * @ignore | ||
| */ | ||
| static DEFAULT_MATERIAL = Object.freeze(new BufferPointMaterial()); | ||
|
|
||
| /** | ||
| * @param {BufferPointMaterialOptions} [options] | ||
| */ | ||
| constructor(options = Frozen.EMPTY_OBJECT) { | ||
| super(options); | ||
|
|
||
| /** | ||
| * Size of point, 0-255px. | ||
| * @type {number} | ||
| */ | ||
| this.pixelSize = options.pixelSize ?? 1; | ||
| } | ||
|
|
||
| /** | ||
| * @override | ||
| * @param {BufferPointMaterial} material | ||
| * @param {DataView} view | ||
| * @param {number} byteOffset | ||
| * @override | ||
| */ | ||
| static pack(material, view, byteOffset) { | ||
| super.pack(material, view, byteOffset); | ||
| view.setUint8(this.Layout.PIXEL_SIZE_U8 + byteOffset, material.pixelSize); | ||
| } | ||
|
|
||
| /** | ||
| * @override | ||
| * @param {DataView} view | ||
| * @param {number} byteOffset | ||
| * @param {BufferPointMaterial} result | ||
| * @returns {BufferPointMaterial} | ||
| * @override | ||
| */ | ||
| static unpack(view, byteOffset, result) { | ||
| super.unpack(view, byteOffset, result); | ||
| result.pixelSize = view.getUint8(this.Layout.PIXEL_SIZE_U8 + byteOffset); | ||
| return result; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////////////////////////// | ||
| // DEBUG | ||
|
|
||
| /** | ||
| * Returns a JSON-serializable object representing the material. This encoding | ||
| * is not memory-efficient, and should generally be used for debugging and | ||
| * testing. | ||
| * | ||
| * @returns {Object} JSON-serializable object. | ||
| */ | ||
| toJSON() { | ||
| return { ...super.toJSON(), pixelSize: this.pixelSize }; | ||
| } | ||
| } | ||
|
|
||
| export default BufferPointMaterial; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // @ts-check | ||
|
|
||
| import Frozen from "../Core/Frozen.js"; | ||
| import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; | ||
|
|
||
| /** @import Color from "../Core/Color.js"; */ | ||
| /** @import BufferPolygon from "./BufferPolygon.js"; */ | ||
|
|
||
| /** | ||
| * @typedef {object} BufferPolygonMaterialOptions | ||
| * @property {Color} [color=Color.WHITE] Color of fill. | ||
| * @property {Color} [outlineColor=Color.WHITE] Color of outline. | ||
| * @property {number} [outlineWidth=0.0] Width of outline, 0-255px. | ||
| */ | ||
|
|
||
| /** | ||
| * Material description for a {@link BufferPolygon}. | ||
| * | ||
| * <p>BufferPolygonMaterial objects are {@link Packable|packable}, stored | ||
| * when calling {@link BufferPolygon#setMaterial}. Subsequent changes to the | ||
| * material will not affect the polygon until setMaterial() is called again.</p> | ||
| * | ||
| * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. | ||
| * @extends BufferPrimitiveMaterial | ||
| */ | ||
| class BufferPolygonMaterial extends BufferPrimitiveMaterial { | ||
| /** | ||
| * @type {BufferPolygonMaterial} | ||
| * @ignore | ||
| */ | ||
| static DEFAULT_MATERIAL = Object.freeze(new BufferPolygonMaterial()); | ||
|
|
||
| /** | ||
| * @param {BufferPolygonMaterialOptions} [options] | ||
| */ | ||
| constructor(options = Frozen.EMPTY_OBJECT) { | ||
| super(options); | ||
| } | ||
| } | ||
|
|
||
| export default BufferPolygonMaterial; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // @ts-check | ||
|
|
||
| import Frozen from "../Core/Frozen.js"; | ||
| import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; | ||
|
|
||
| /** @import Color from "../Core/Color.js"; */ | ||
| /** @import BufferPolyline from "./BufferPolyline.js"; */ | ||
|
|
||
| /** | ||
| * @typedef {object} BufferPolylineMaterialOptions | ||
| * @property {Color} [color=Color.WHITE] Color of fill. | ||
| * @property {Color} [outlineColor=Color.WHITE] Color of outline. | ||
| * @property {number} [outlineWidth=0.0] Width of outline, 0-255px. | ||
| * @property {number} [width=1.0] Width of line, 0-255px. | ||
| */ | ||
|
|
||
| /** | ||
| * Material description for a {@link BufferPolyline}. | ||
| * | ||
| * <p>BufferPolylineMaterial objects are {@link Packable|packable}, stored | ||
| * when calling {@link BufferPolyline#setMaterial}. Subsequent changes to the | ||
| * material will not affect the polyline until setMaterial() is called again.</p> | ||
| * | ||
| * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. | ||
| * @extends BufferPrimitiveMaterial | ||
| */ | ||
| class BufferPolylineMaterial extends BufferPrimitiveMaterial { | ||
| /** @ignore */ | ||
| static Layout = { | ||
| ...BufferPrimitiveMaterial.Layout, | ||
| WIDTH_U8: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH, | ||
| __BYTE_LENGTH: BufferPrimitiveMaterial.Layout.__BYTE_LENGTH + 4, | ||
| }; | ||
|
|
||
| /** | ||
| * @type {BufferPolylineMaterial} | ||
| * @ignore | ||
| */ | ||
| static DEFAULT_MATERIAL = Object.freeze(new BufferPolylineMaterial()); | ||
|
|
||
| /** | ||
| * @param {BufferPolylineMaterialOptions} [options] | ||
| */ | ||
| constructor(options = Frozen.EMPTY_OBJECT) { | ||
| super(options); | ||
|
|
||
| /** | ||
| * Width of polyline, 0–255px. | ||
| * @type {number} | ||
| */ | ||
| this.width = options.width ?? 1; | ||
| } | ||
|
|
||
| /** | ||
| * @param {BufferPolylineMaterial} material | ||
| * @param {DataView} view | ||
| * @param {number} byteOffset | ||
| * @override | ||
| */ | ||
| static pack(material, view, byteOffset) { | ||
| super.pack(material, view, byteOffset); | ||
| view.setUint8(this.Layout.WIDTH_U8 + byteOffset, material.width); | ||
| } | ||
|
|
||
| /** | ||
| * @param {DataView} view | ||
| * @param {number} byteOffset | ||
| * @param {BufferPolylineMaterial} result | ||
| * @returns {BufferPolylineMaterial} | ||
| * @override | ||
| */ | ||
| static unpack(view, byteOffset, result) { | ||
| super.unpack(view, byteOffset, result); | ||
| result.width = view.getUint8(this.Layout.WIDTH_U8 + byteOffset); | ||
| return result; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////////////////////////// | ||
| // DEBUG | ||
|
|
||
| /** | ||
| * Returns a JSON-serializable object representing the material. This encoding | ||
| * is not memory-efficient, and should generally be used for debugging and | ||
| * testing. | ||
| * | ||
| * @returns {Object} JSON-serializable object. | ||
| */ | ||
| toJSON() { | ||
| return { ...super.toJSON(), width: this.width }; | ||
| } | ||
| } | ||
|
|
||
| export default BufferPolylineMaterial; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.width = options.width ?? 1;has already been removed, please remember update the docs accordingly.Also, the JSDoc/examples for
BufferPointCollection,BufferPolylineCollection, andBufferPolygonCollectionstill reference the old color initialization andsetColor()workflow. Since this PR moves styling to material classes, those examples should we update to usematerial / setMaterial()instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch – I think I've updated all the documentation now.
I'd like for the type checker to either catch errors like the unused width, or to extend the BufferPrimitiveMaterialOptions so we don't have to duplicate so much here, but I think that's currently blocked by #10455.