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

Add Extras to 3DTile and 3DTileset #6974

Merged
merged 16 commits into from
Aug 31, 2018
Binary file modified Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/ll.b3dm
Binary file not shown.
Binary file modified Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/lr.b3dm
Binary file not shown.
Binary file modified Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/parent.b3dm
Binary file not shown.
6 changes: 6 additions & 0 deletions Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0",
"tilesetVersion": "1.2.3"
},
"extras": {
"name": "Sample Tileset"
},
"properties": {
"id": {
"minimum": 0,
Expand Down Expand Up @@ -79,6 +82,9 @@
"geometricError": 0,
"content": {
"uri": "lr.b3dm"
},
"extras": {
"id": "Special Tile"
}
},
{
Expand Down
Binary file modified Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/ul.b3dm
Binary file not shown.
Binary file modified Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/ur.b3dm
Binary file not shown.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Change Log
* Added `GeocoderViewModel.destinationFound` for specifying a function that is called upon a successful geocode. The default behavior is to fly to the destination found by the geocoder. [#6915](https://github.com/AnalyticalGraphicsInc/cesium/pull/6915)
* Added optional `width` and `height` to `Scene.drillPick` for specifying a search area.
* Added `Cesium3DTileset.root` for getting the root tile of a tileset. [#6944](https://github.com/AnalyticalGraphicsInc/cesium/pull/6944)
* Added `Cesium3DTileset.extras` and `Cesium3DTile.extras` for getting application specific metadata from 3D Tiles. [#6974](https://github.com/AnalyticalGraphicsInc/cesium/pull/6974)
* Added `heightReference` to `BoxGraphics`, `CylinderGraphics` and `EllipsoidGraphics`, which can be used to clamp these entity types to terrain [#6932](https://github.com/AnalyticalGraphicsInc/cesium/pull/6932)

##### Fixes :wrench:
Expand Down
20 changes: 18 additions & 2 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ define([
var contentHeader = header.content;

/**
* The local transform of this tile
* The local transform of this tile.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing these!

* @type {Matrix4}
*/
this.transform = defined(header.transform) ? Matrix4.unpack(header.transform) : Matrix4.clone(Matrix4.IDENTITY);
Expand All @@ -100,7 +100,7 @@ define([
this._initialTransform = Matrix4.multiply(parentInitialTransform, this.transform, new Matrix4());

/**
* The final computed transform of this tile
* The final computed transform of this tile.
* @type {Matrix4}
* @readonly
*/
Expand Down Expand Up @@ -429,6 +429,22 @@ define([
}
},

/**
* Returns the <code>extras</code> property in the tileset JSON for this tile, which contains application specific metadata.
* Returns <code>undefined</code> if <code>extras</code> does not exist.
*
* @memberof Cesium3DTile.prototype
*
* @type {*}
* @readonly
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments here.

*/
extras : {
get : function() {
return this._header.extras;
}
},

/**
* Gets or sets the tile's highlight color.
*
Expand Down
27 changes: 27 additions & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ define([
this._selectedTilesToStyle = [];
this._loadTimestamp = undefined;
this._timeSinceLoad = 0.0;
this._extras = undefined;

this._cullWithChildrenBounds = defaultValue(options.cullWithChildrenBounds, true);
this._allTilesAdditive = true;
Expand Down Expand Up @@ -710,6 +711,7 @@ define([
that._geometricError = tilesetJson.geometricError;
that._extensionsUsed = tilesetJson.extensionsUsed;
that._gltfUpAxis = gltfUpAxis;
that._extras = tilesetJson.extras;
that._readyPromise.resolve(that);
}).otherwise(function(error) {
that._readyPromise.reject(error);
Expand Down Expand Up @@ -1237,6 +1239,31 @@ define([
get : function() {
return this._ellipsoid;
}
},

/**
* Returns the <code>extras</code> property at the top-level of the tileset JSON, which contains application specific metadata.
* Returns <code>undefined</code> if <code>extras</code> does not exist.
*
* @memberof Cesium3DTileset.prototype
*
* @exception {DeveloperError} The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.
*
* @type {*}
* @readonly
*
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}
*/
extras : {
get : function() {
//>>includeStart('debug', pragmas.debug);
if (!this.ready) {
throw new DeveloperError('The tileset is not loaded. Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.');
}
//>>includeEnd('debug');
OmarShehata marked this conversation as resolved.
Show resolved Hide resolved

return this._extras;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to check if the tileset is ready before accessing extras and throw an error otherwise. See asset:

//>>includeStart('debug', pragmas.debug);
if (!this.ready) {
    throw new DeveloperError('The tileset is not loaded.  Use Cesium3DTileset.readyPromise or wait for Cesium3DTileset.ready to be true.');
}
//>>includeEnd('debug');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only needed for the Cesium3DTileset one, not Cesium3DTile.

}
});

Expand Down
Binary file modified Specs/Data/Cesium3DTiles/Tilesets/Tileset/ll.b3dm
Binary file not shown.
Binary file modified Specs/Data/Cesium3DTiles/Tilesets/Tileset/lr.b3dm
Binary file not shown.
Binary file modified Specs/Data/Cesium3DTiles/Tilesets/Tileset/parent.b3dm
Binary file not shown.
6 changes: 6 additions & 0 deletions Specs/Data/Cesium3DTiles/Tilesets/Tileset/tileset.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0",
"tilesetVersion": "1.2.3"
},
"extras": {
"name": "Sample Tileset"
},
"properties": {
"id": {
"minimum": 0,
Expand Down Expand Up @@ -79,6 +82,9 @@
"geometricError": 0,
"content": {
"uri": "lr.b3dm"
},
"extras": {
"id": "Special Tile"
}
},
{
Expand Down
Binary file modified Specs/Data/Cesium3DTiles/Tilesets/Tileset/ul.b3dm
Binary file not shown.
Binary file modified Specs/Data/Cesium3DTiles/Tilesets/Tileset/ur.b3dm
Binary file not shown.
20 changes: 20 additions & 0 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defineSuite([
'Scene/Cesium3DTileset',
'Core/Cartesian3',
'Core/Color',
'Core/defined',
'Core/CullingVolume',
'Core/getAbsoluteUri',
'Core/getStringFromTypedArray',
Expand Down Expand Up @@ -32,6 +33,7 @@ defineSuite([
Cesium3DTileset,
Cartesian3,
Color,
defined,
CullingVolume,
getAbsoluteUri,
getStringFromTypedArray,
Expand Down Expand Up @@ -356,6 +358,24 @@ defineSuite([
});
});

it('loads tileset with extras', function() {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) {
expect(tileset.extras).toEqual({ 'name': 'Sample Tileset' });
expect(tileset.root.extras).not.toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, toBeUndefined.


var length = tileset.root.children.length;
var taggedChildren = 0;
for (var i = 0; i < length; ++i) {
if (defined(tileset.root.children[i].extras)) {
expect(tileset.root.children[i].extras).toEqual({ 'id': 'Special Tile' });
++taggedChildren;
}
}

expect(taggedChildren).toEqual(1);
});
});

it('gets root tile', function() {
var tileset = scene.primitives.add(new Cesium3DTileset({
url : tilesetUrl
Expand Down