-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
Thanks for the pull request @OmarShehata!
Reviewers, don't forget to make sure that:
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
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.
Thanks @OmarShehata.
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
@@ -356,6 +358,16 @@ defineSuite([ | |||
}); | |||
}); | |||
|
|||
fit('loads tileset with extras', function() { |
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.
Change fit
to it
@@ -0,0 +1,124 @@ | |||
{ |
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.
I don't think it's necessary to create a new tileset TilesetWithExtras
just for this change. Just add extras
properties to Tileset
. We did a similar thing when adding the tilesetVersion
property.
After that, make sure to keep SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json
and Specs/Data/Cesium3DTiles/Tilesets/Tileset/tileset.json
in sync.
key
/value
is maybe too generic? Maybe name
or id
instead? Use different values/types for the tileset-level extras and the child extras. This will help make the test more robust.
Open a PR with any modifications to 3D Tiles sample data to https://github.com/AnalyticalGraphicsInc/3d-tiles-tools/tree/master/samples-generator. Then regenerate tileset.json
and update here. There are formatting inconsistencies in this hand-edited file.
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
fit('loads tileset with extras', function() { | ||
return Cesium3DTilesTester.loadTileset(scene, tilesetWithExtras).then(function(tileset) { | ||
expect(tileset.extras).toBeDefined(); | ||
expect(tileset.extras).toEqual({'key': 'value'}); |
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.
Remove expect(tileset.extras).toBeDefined();
- it is redundant.
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
expect(tileset.extras).toEqual({'key': 'value'}); | ||
|
||
expect(tileset.root.extras).toBeDefined(); | ||
expect(tileset.root.extras).toEqual({'key': 'value'}); |
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.
Same comment.
Source/Scene/Cesium3DTileset.js
Outdated
* | ||
* @memberof Cesium3DTileset.prototype | ||
* | ||
* @type {Object} |
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.
Change to @type {*}
, extras
is not necessarily an object, it could be a string, number, etc.
Source/Scene/Cesium3DTileset.js
Outdated
}, | ||
|
||
/** | ||
* Application specific metadata. |
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.
Expand on the description some more. Something like:
Returns the
extras
property at the top-level of the tileset JSON, which contains application specific metadata. Returnsundefined
ifextras
does not exist.
Source/Scene/Cesium3DTile.js
Outdated
* | ||
* @type {Object} | ||
* @readonly | ||
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.} |
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.
Same comments here.
Source/Scene/Cesium3DTile.js
Outdated
*/ | ||
extras : { | ||
get : function() { | ||
return this._extras; |
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.
Instead of storing _extras
as a member variable, this could just be return this._header.extras
@@ -88,7 +88,7 @@ define([ | |||
var contentHeader = header.content; | |||
|
|||
/** | |||
* The local transform of this tile | |||
* The local transform of this tile. |
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.
Thanks for fixing these!
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
expect(tileset.extras).toEqual({'key': 'value'}); | ||
|
||
expect(tileset.root.extras).toBeDefined(); | ||
expect(tileset.root.extras).toEqual({'key': 'value'}); |
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.
Since you mentioned it in the PR description, it might be worthwhile to add a test that checks that extras is undefined for some other tile in the tree that doesn't have extras.
Yeah fine with me, I don't think we have a good use case yet for needing to expose tileset extensions to the API. |
Also... add this change to |
Just did! (0a0af0f) Regenerating the tileset.json seems to change the b3dm files as well, which I've included. (I opened the PR here #6974) But now there's also this warning?
I'm not sure if I regenerated them incorrectly. In the new test/spec, I loop over all the children to count the ones with an |
Sorry, I forgot that CesiumGS/3d-tiles-validator#139 was still open. If you branch CesiumGS/3d-tiles-validator#152 off of that branch and regenerate the tileset most of those problems will go away. |
Source/Scene/Cesium3DTileset.js
Outdated
}, | ||
|
||
/** | ||
* Returns the `extras` property at the top-level of the tileset JSON, which contains application specific metadata. |
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.
Instead of tick marks use <code>extras</code>
in documentation for code highlighting.
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
expect(tileset.root.extras).not.toBeDefined(); | ||
|
||
var taggedChildren = 0; | ||
for(var i = 0;i < tileset.root.children.length; i++) { |
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.
Style things:
- change
for(var
tofor (var
- add space afterfor
- change
i = 0;i
toi = 0; i
- add space after semicolon - change
i++
to++i
- just a convention in the Cesium code base - save
length
as its own variable before the loop - this convention was originally added for performance reasons since length doesn't have to be re-evaluated every iteration. While it doesn't really matter for tests it's just good to get into that habit.
var length = tileset.root.children.length
for (var i = 0; i < length; ++i) {
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
var taggedChildren = 0; | ||
for(var i = 0;i < tileset.root.children.length; i++) { | ||
if (defined(tileset.root.children[i].extras)) { | ||
taggedChildren ++; |
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.
Similarly add the ++
before the variable here too to match the convention:
++taggedChildren;
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
@@ -356,6 +358,22 @@ defineSuite([ | |||
}); | |||
}); | |||
|
|||
it('loads tileset with extras', function() { | |||
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { | |||
expect(tileset.extras).toBeDefined(); |
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.
Checking that the extras is what we expect is still worthwhile:
expect(tileset.extras).toEqual({'name': 'Sample Tileset'});
And remove the toBeDefined
line.
Ah yeah, that's due to the traversal code sorting the children based on distance from camera. The way you're testing it is fine. |
Source/Scene/Cesium3DTileset.js
Outdated
extras : { | ||
get : function() { | ||
return this._extras; | ||
} |
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.
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');
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.
Only needed for the Cesium3DTileset
one, not Cesium3DTile
.
Thanks for the detailed feedback @lilleyse ! Should be all good now. Actually, one issue, I noticed is when using the Should we remove |
In general, properties shouldn't throw exceptions, but if there's a good reason to that's fine; just leave it as it is for now. #832 was written a long time ago to eventually make sure they work (feel free to tackle that if you want 😄 ) |
Specs/Scene/Cesium3DTilesetSpec.js
Outdated
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(); |
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.
Alternatively, toBeUndefined
.
Thanks @OmarShehata! |
This resolves #6490. It reads the
extras
dictionary fromtileset.json
and from all tiles, and makes it accessible via a read only.extras
property.I tested it by modifying the
SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json
to addextras
fields and checking them:I also added a test. It's basically just checking a getter, so it can easily be combined in another test instead of being its own.
I'm not sure if there's much we can do with
extensions
right now aside from just making it accessible in the API. Perhaps it's best to do that until more use cases arise? @lilleyse please review when you get a chance.