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

Fix artifacts in BIM demo #7181

Merged
merged 5 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
125 changes: 123 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles BIM.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,142 @@
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
// Power Plant design model provided by Bentley Systems
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;

var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(5743) });
var tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(8564)
})
);

tileset.readyPromise.then(function(tileset) {
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.5, -0.2, tileset.boundingSphere.radius * 4.0));
}).otherwise(function(error) {
console.log(error);
});

tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.REPLACE;

var picking = false;
Sandcastle.addToggleButton('Per-feature selection', false, function(checked) {
picking = checked;
if (!picking) {
unselectFeature(selectedFeature);
}
});

var selectedFeature;

function selectFeature(feature) {
var element = feature.getProperty('element');
setElementColor(element, Cesium.Color.YELLOW);
selectedFeature = feature;
}

function unselectFeature(feature) {
if (!Cesium.defined(feature)) {
return;
}
var element = feature.getProperty('element');
setElementColor(element, Cesium.Color.WHITE);
if (feature === selectedFeature) {
selectedFeature = undefined;
}
}

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
if (!picking) {
return;
}

var feature = scene.pick(movement.endPosition);

unselectFeature(selectedFeature);

if (feature instanceof Cesium.Cesium3DTileFeature) {
selectFeature(feature);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

// In this tileset every feature has an "element" property which is a global ID.
// This property is used to associate features across different tiles and LODs.
// Workaround until 3D Tiles has the concept of global batch ids: https://github.com/AnalyticalGraphicsInc/3d-tiles/issues/265
var elementMap = {}; // Build a map of elements to features.
var hiddenElements = [112001, 113180, 131136, 113167, 71309, 109652, 111178, 113156, 113170, 124846, 114076, 131122, 113179, 114325, 131134, 113164, 113153, 113179, 109656, 114095, 114093, 39225, 39267, 113149, 113071, 112003, 39229, 113160, 39227, 39234, 113985, 39230, 112004, 39223];

function getElement(feature) {
return parseInt(feature.getProperty('element'), 10);
}

function setElementColor(element, color) {
var featuresToColor = elementMap[element];
var length = featuresToColor.length;
for (var i = 0; i < length; ++i) {
var feature = featuresToColor[i];
feature.color = Cesium.Color.clone(color, feature.color);
}
}

function unloadFeature(feature) {
unselectFeature(feature);
var element = getElement(feature);
var features = elementMap[element];
var index = features.indexOf(feature);
if (index > -1) {
features.splice(index, 1);
}
}

function loadFeature(feature) {
var element = getElement(feature);
var features = elementMap[element];
if (!Cesium.defined(features)) {
features = [];
elementMap[element] = features;
}
features.push(feature);

if (hiddenElements.indexOf(element) > -1) {
feature.show = false;
}
}

function processContentFeatures(content, callback) {
var featuresLength = content.featuresLength;
for (var i = 0; i < featuresLength; ++i) {
var feature = content.getFeature(i);
callback(feature);
}
}

function processTileFeatures(tile, callback) {
var content = tile.content;
var innerContents = content.innerContents;
if (Cesium.defined(innerContents)) {
var length = innerContents.length;
for (var i = 0; i < length; ++i) {
processContentFeatures(innerContents[i], callback);
}
} else {
processContentFeatures(content, callback);
}
}

tileset.tileLoad.addEventListener(function(tile) {
processTileFeatures(tile, loadFeature);
});

tileset.tileUnload.addEventListener(function(tile) {
processTileFeatures(tile, unloadFeature);
});
//Sandcastle_End
Sandcastle.finishedLoading();
}
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
}

// Power Plant design model provided by Bentley Systems
var bimUrl = Cesium.IonResource.fromAssetId(5743);
var bimUrl = Cesium.IonResource.fromAssetId(8564);
var pointCloudUrl = Cesium.IonResource.fromAssetId(5714);
var instancedUrl = '../../SampleData/Cesium3DTiles/Instanced/InstancedOrientation/tileset.json';
var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb';
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Ambient Occlusion.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}

// Power Plant design model provided by Bentley Systems
var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(5743) });
var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(8564) });
tileset.readyPromise.then(function(tileset) {
viewer.scene.primitives.add(tileset);
}).otherwise(function(error) {
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Change Log
* Added `imageBasedLightingFactor` property to `Cesium3DTileset`, `Model`, and `ModelGraphics` to scale the diffuse and specular image-based lighting contributions to the final color. [#7025](https://github.com/AnalyticalGraphicsInc/cesium/pull/7025)
* Added `lightColor` property to `Cesium3DTileset`, `Model`, and `ModelGraphics` to change the intensity of the light used when shading model. [#7025](https://github.com/AnalyticalGraphicsInc/cesium/pull/7025)
* Added `atmosphereHueShift`, `atmosphereSaturationShift`, and `atmosphereBrightnessShift` properties to `Globe` which shift the color of the ground atmosphere to match the hue, saturation, and brightness shifts of the sky atmosphere. [#4195](https://github.com/AnalyticalGraphicsInc/cesium/issues/4195)
* Added per-feature selection to the 3D Tiles BIM Sandcastle example. [#7181](https://github.com/AnalyticalGraphicsInc/cesium/pull/7181)

##### Fixes :wrench:
* Fixed issue removing geometry entities with different materials [#7163](https://github.com/AnalyticalGraphicsInc/cesium/pull/7163)
Expand Down