Skip to content
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

Handle multiple feature ID sets in ModelExperimental #10018

Merged
merged 42 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ec8430
Default to empty array
ptrgags Jan 13, 2022
fe5e5a0
Make model feature tables always defined
ptrgags Jan 13, 2022
e9e1ba7
Start handling IDs without property tables
ptrgags Jan 14, 2022
2b83629
Reorganize feature IDs in ModelComponents
ptrgags Jan 18, 2022
58e6d7c
Add featureIdIndex and instanceFeatureIdIndex
ptrgags Jan 18, 2022
7cc3265
Update pipeline stages
ptrgags Jan 18, 2022
e22c111
Split out FeatureIdPipelineStage
ptrgags Jan 18, 2022
e24eb37
Reorganize shaders
ptrgags Jan 18, 2022
15586dd
Add [fv]sInput.featureIds to CustomShader parser
ptrgags Jan 18, 2022
05915ac
Add feature IDs to the custom shader
ptrgags Jan 19, 2022
b042d79
Update custom shader specs
ptrgags Jan 19, 2022
30ffa8a
Fix ModelExperimentalPrimitive specs
ptrgags Jan 19, 2022
993922a
Update SelectedFeatureIdPipelineStage
ptrgags Jan 19, 2022
e56ef99
Fix picking
ptrgags Jan 19, 2022
85bbb21
Fix shader compilation error in VS
ptrgags Jan 19, 2022
9c01d4f
Update photogrammetry classification sandcastle
ptrgags Jan 19, 2022
28cc68e
Start fixing unit tests
ptrgags Jan 20, 2022
0fea72c
Merge branch 'main' into multi-feature-ids
ptrgags Jan 21, 2022
dd69bc7
Make new unit tests for FeatureIdPipelineStage
ptrgags Jan 21, 2022
754843e
Update SelectedFeatureIdPipelineStage specs
ptrgags Jan 21, 2022
6fef5c6
Mark tests as WebGL
ptrgags Jan 21, 2022
33c86b6
Add note in changelog about feature IDs in CustomShader
ptrgags Jan 21, 2022
9c45411
Update I3dmLoader
ptrgags Jan 21, 2022
71d8513
Select different feature ID sets at runtime
ptrgags Jan 21, 2022
2c3c315
Fix race condition
ptrgags Jan 21, 2022
b59697e
Update style when feature ID index is changed
ptrgags Jan 24, 2022
d114a53
Update feature ID in other sandcastle
ptrgags Jan 24, 2022
e0839b4
Update Custom Shader guide
ptrgags Jan 24, 2022
b551bac
Update documentation
ptrgags Jan 24, 2022
a187a94
Merge branch 'main' into multi-feature-ids
ptrgags Jan 24, 2022
7f336aa
Fix unit tests
ptrgags Jan 24, 2022
2563438
Fix typo
ptrgags Jan 24, 2022
f95f680
Update CHANGES.md
ptrgags Jan 24, 2022
004af76
Fix prettier
ptrgags Jan 24, 2022
42263c2
Fix JSDoc formatting
ptrgags Jan 24, 2022
b10e308
Demonstrate using multiple feature ID sets
ptrgags Jan 25, 2022
33b4bab
Update documentation
ptrgags Jan 26, 2022
7323aa9
Handle filtering by pass type
ptrgags Jan 26, 2022
f6df243
applyStyle doesn't need an if guard
ptrgags Jan 26, 2022
b937b9c
Merge tag 'pre-let-const' into lets-merge2
ptrgags Jan 26, 2022
6ff5186
Merge tag 'post-let-const' into lets-merge2
ptrgags Jan 26, 2022
2a61e4f
Simplify multi-feature ID sandcastle
ptrgags Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
const scene = viewer.scene;

const tileset = new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(666297),
url: Cesium.IonResource.fromAssetId(775877),
});

const translation = new Cesium.Cartesian3(
Expand Down Expand Up @@ -107,8 +107,7 @@
"const float TOTAL_FEATURES = 12.0;",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (featureId == WINDOW || featureId == SKYLIGHT) {",
" material.alpha = 0.4;",
Expand Down Expand Up @@ -136,8 +135,7 @@
"const float TRAFFIC_LIGHT = 11.0;",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (featureId == CLOCK) {",
" // Shiny brass",
Expand Down Expand Up @@ -183,8 +181,7 @@
fragmentShaderText: [
"const float NOTHING_SELECTED = 12.0;",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" // NOTE: This is exposing internal details of the shader. It would be better if this was added to fsInput somewhere...",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
"",
" if (u_selectedFeature < NOTHING_SELECTED && featureId == u_selectedFeature) {",
" material.specular = vec3(1.00, 0.85, 0.57);",
Expand All @@ -194,13 +191,48 @@
].join("\n"),
});

const multipleFeatureIdsShader = new Cesium.CustomShader({
uniforms: {
u_selectedFeature: {
type: Cesium.UniformType.FLOAT,
value: NOTHING_SELECTED,
},
},
lightingModel: Cesium.LightingModel.UNLIT,
fragmentShaderText: [
"const float IDS0_WINDOW = 0.0;",
"const float IDS1_FACADE = 2.0;",
"const float IDS1_ROOF = 3.0;",
"const vec3 PURPLE = vec3(0.5, 0.0, 1.0);",
"const vec3 YELLOW = vec3(1.0, 1.0, 0.0);",
"const vec3 NO_TINT = vec3(1.0);",
"",
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {",
" float featureId0 = fsInput.featureIds.featureId_0; // fine features",
" float featureId1 = fsInput.featureIds.featureId_1; // coarse features",
"",
" // use both feature ID sets to determine where the features are",
" float isWindow = float(featureId0 == IDS0_WINDOW);",
" float isFacade = float(featureId1 == IDS1_FACADE);",
" float isRoof = float(featureId1 == IDS1_ROOF);",
"",
" // Tint the roof windows yellow and facade windows purple",
" vec3 tint = NO_TINT;",
" tint = mix(tint, YELLOW, isWindow * isRoof);",
" tint = mix(tint, PURPLE, isWindow * isFacade);",
" material.diffuse *= tint;",
"}",
].join("\n"),
});

// Demo Functions =====================================================================

function defaults() {
tileset.style = undefined;
tileset.customShader = unlitShader;
tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.HIGHLIGHT;
tileset.colorBlendAmount = 0.5;
tileset.featureIdIndex = 0;
}

const showPhotogrammetry = defaults;
Expand All @@ -211,6 +243,12 @@
tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.MIX;
}

function showAlternativeClassification() {
showClassification();
// This dataset has a second feature ID texture.
tileset.featureIdIndex = 1;
}

function translucentWindows() {
defaults();
tileset.customShader = translucentWindowsShader;
Expand All @@ -226,6 +264,11 @@
tileset.customShader = selectFeatureShader;
}

function multipleFeatureIds() {
defaults();
tileset.customShader = multipleFeatureIdsShader;
}

// Pick Handlers ======================================================================

// HTML overlay for showing feature name on mouseover
Expand Down Expand Up @@ -304,6 +347,10 @@
text: "Show Classification",
onselect: showClassification,
},
{
text: "Show Alternative Classification",
onselect: showAlternativeClassification,
},
{
text: "Translucent Windows",
onselect: translucentWindows,
Expand All @@ -316,6 +363,10 @@
text: "Golden Touch",
onselect: goldenTouch,
},
{
text: "Multiple Feature ID Sets",
onselect: multipleFeatureIds,
},
];
Sandcastle.addToolbarMenu(demos);

Expand Down
3 changes: 1 addition & 2 deletions Apps/Sandcastle/gallery/3D Tiles Next S2 Globe.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
fragmentShaderText: [
"void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)",
"{",
" // NOTE: this is exposing internal details of the shader.",
" float featureId = floor(texture2D(FEATURE_ID_TEXTURE, FEATURE_ID_TEXCOORD).FEATURE_ID_CHANNEL * 255.0 + 0.5);",
" float featureId = fsInput.featureIds.featureId_0;",
" // Use cartesian coordinates but scale to be roughly [-1, 1]",
" vec3 positionWC = fsInput.attributes.positionWC / 6.3e6;",
" if (featureId == 60.0)",
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

##### Additions :tada:

- Feature IDs for styling and picking in `ModelExperimental` can now be selected via `(tileset|model).featureIdIndex` and `(tileset|model).instanceFeatureIdIndex`. [#10018](https://github.com/CesiumGS/cesium/pull/10018)
- Added support for all types of feature IDs in `CustomShader`. [#10018](https://github.com/CesiumGS/cesium/pull/10018)
- Added getters `Cesium3DTileFeature.featureId` and `ModelFeature.featureId` so the feature ID or batch ID can be accessed from a picked feature. [#10022](https://github.com/CesiumGS/cesium/pull/10022)
- Added `I3dmLoader` to transcode .i3dm to `ModelExperimental`. [#9968](https://github.com/CesiumGS/cesium/pull/9968)
- Added `PntsLoader` to transcode .pnts to `ModelExperimental`. [#9978](https://github.com/CesiumGS/cesium/pull/9978)
Expand Down
23 changes: 23 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
* @param {Boolean} [options.showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.
* @param {Boolean} [options.vectorClassificationOnly=false] Indicates that only the tileset's vector tiles should be used for classification.
* @param {Boolean} [options.vectorKeepDecodedPositions=false] Whether vector tiles should keep decoded positions in memory. This is used with {@link Cesium3DTileFeature.getPolylinePositions}.
* @param {Number} [options.featureIdIndex=0] The index into the list of primitive feature IDs used for picking and styling. For EXT_feature_metadata, feature ID attributes are listed before feature ID textures. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
* @param {Number} [options.instanceFeatureIdIndex=0] The index into the list of instance feature IDs used for picking and styling. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
* @param {String} [options.debugHeatmapTilePropertyName] The tile variable to colorize as a heatmap. All rendered tiles will be colorized relative to each other's specified variable value.
* @param {Boolean} [options.debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering.
* @param {Boolean} [options.debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.
Expand Down Expand Up @@ -963,6 +965,27 @@ function Cesium3DTileset(options) {
ExperimentalFeatures.enableModelExperimental
);

/**
* The index into the list of primitive feature IDs used for picking and
* styling. For EXT_feature_metadata, feature ID attributes are listed before
* feature ID textures. If both per-primitive and per-instance feature IDs are
* present, the instance feature IDs take priority.
*
* @type {Number}
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.featureIdIndex = defaultValue(options.featureIdIndex, 0);

/**
* The index into the list of instance feature IDs used for picking and
* styling. If both per-primitive and per-instance feature IDs are present,
* the instance feature IDs take priority.
*
* @type {Number}
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.instanceFeatureIdIndex = defaultValue(options.instanceFeatureIdIndex, 0);

ptrgags marked this conversation as resolved.
Show resolved Hide resolved
this._schemaLoader = undefined;

const that = this;
Expand Down
Loading