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

Z-ordering for ground geometry entities #6362

Merged
merged 17 commits into from
May 22, 2018
Merged

Z-ordering for ground geometry entities #6362

merged 17 commits into from
May 22, 2018

Conversation

hpinkos
Copy link
Contributor

@hpinkos hpinkos commented Mar 22, 2018

For #4108

  • GeometryVisualizer creates different batches based on the value of the zIndex property
  • Works for Corridor, Ellipse, Polygon and Rectangle
  • Only works for static entities
  • Only works when both height and extrudedHeight are undefined

image

TODO

  • CHANGES.md
  • Specs

@cesium-concierge
Copy link

Signed CLA is on file.

@hpinkos, thanks for the pull request! Maintainers, we have a signed CLA from @hpinkos, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@@ -0,0 +1,93 @@
<!DOCTYPE html>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename this to Z-Indexing Geometry, to both be consistent with our internal terminology and because Z-Indexing is the standard term.

@mramato
Copy link
Contributor

mramato commented Mar 22, 2018

Thanks @hpinkos!, at initial glance, this approach all looks good to me. Just bump when you think it's ready for a full review.

We should hook this up to KML, I'm pretty sure it will be trivial. If it looks more complicated we can do it in a separate PR after this.

@mramato
Copy link
Contributor

mramato commented Mar 22, 2018

We'll also want to make sure we update czml-writer once this is ready and add CZML support (in a separate PR).

var zIndex = updater.zIndex;
var batchArray = this._groundColorBatches[zIndex];
if (!defined(batchArray)) {
batchArray = createGroundColorBatch(this._orderedGroundPrimitives.add(new PrimitiveCollection()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now I create a three new StaticGroundGeometryColorBatch (one for each classification type) and one new PrimitiveCollection() for each zIndex.
And I never remove them (the PrimitiveCollections get removed and destroyed on GeometryVisualizer.destroy)

Do you think this is a problem? I didn't think it would be because the zIndex has to be ConstantProperty so we shouldn't end up with empty primitive collections unless someone changes the zIndex value.

Instead of creating a StaticGroundGeometryColorBatch for each classification type, do you think I should create them only if that classification type gets used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just because it's a constant property doesn't mean it can't change, it just means it won't change with respect to simulation time. I think we should try and delay creating anything until we actually need it, perhaps the key to _groundColorBatches can be the zIndex and type together?

Is there a reason we also can't remove it if/when it's empty?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing about this feature that I don't think was made clear is that zIndex only works for completely non-time-varying ground primitives. It has nothing to do with zIndex being constant or not. The way you have the code written here, if color/positions/etc.. is time-dynamic, z-indexing doesn't work. (Unless I'm missing something?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should try and delay creating anything until we actually need it, perhaps the key to _groundColorBatches can be the zIndex and type together?

Good idea, I think that approach will work

Is there a reason we also can't remove it if/when it's empty?

I'm not sure exactly how to figure out whether a batch is empty. StaticGroundGeometryColorBatch doesn't have a length property or anything.

Another thing about this feature that I don't think was made clear is that zIndex only works for completely non-time-varying ground primitives.

Yes that's true. I have no idea how to maintain zIndex across the StaticGroundGeometryColorBatch and the DynamicGeometryBatch without making bigger changes. There would have to be some class that aggregates both and manages the primitives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea how to maintain zIndex across the StaticGroundGeometryColorBatch and the DynamicGeometryBatch without making bigger changes.

Actually, this is probably something we'll need anyway for when the ground primitive material changes come in. I'll have to think about this. I have an idea for what I want to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, it might be worth holding off this PR until after ground primitive materials are ready then. I think this initial attempt was definitely worth it; but to avoid churn it might be better to do everything at once.

@hpinkos
Copy link
Contributor Author

hpinkos commented Mar 22, 2018

@mramato this is ready for a full review

@mramato
Copy link
Contributor

mramato commented May 9, 2018

@mramato this is ready for a full review

I thought we were waiting for ground primitives with materials before merging this because we were worrying about it's impact on this code. Is that not the case?

@mramato
Copy link
Contributor

mramato commented May 9, 2018

Nevermind, I just noticed your comment was from March, GitHub notified me that this thread was updated but it was just your merge of master, sorry for the noise.

@hpinkos
Copy link
Contributor Author

hpinkos commented May 9, 2018

No problem =) Yeah, I'm working on merging in Gary's ground material stuff now, and this should be ready for a review when I'm finished with that

@hpinkos
Copy link
Contributor Author

hpinkos commented May 9, 2018

The new changes I made will make this trivial to integrate into Gary's branch. I think this should be merged first since Gary's having some texture woes, this change is pretty much ready to go. I just have to write tests.

@@ -47,5 +47,7 @@ define([

oneTimeWarning.geometryOutlines = 'Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.';

oneTimeWarning.geometryZIndex = 'Entity geometry with zIndex are unsupported when the entity is dynamic, or height or extrudedHeight are defined. zIndex will be ignored';
Copy link
Contributor

Choose a reason for hiding this comment

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

Are dynamic entities still not supported? This message appears to only be used in one place and doesn't check anything about dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah no, I fixed that. I'll update the message

* Gets or sets the zIndex Property specifying the ordering of the corridor. Only has an effect if the coridor is static and neither height or exturdedHeight are specified.
* @memberof CorridorGraphics.prototype
* @type {ConstantProperty}
* @default 0
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the defaults say 0, but there's not actually a default is there? It's just undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined === 0 for zIndex. I defaultValue(zIndex, 0) in the geometry updaters


var ellipsoid = dataSource._ellipsoid;
var coordinates = readCoordinates(coordinatesNode, ellipsoid);
var polyline = styleEntity.polyline;
if (canExtrude && extrude) {
if (defined(zIndex)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check isn't needed, Google Earth silently ignores zIndex for extruded geometry and since we match GE/KML, there's no reason for us to warn here either.

} else {
if (defined(zIndex)) {
oneTimeWarning('kml-gx:drawOrder', 'KML - gx:drawOrder is not supported in LineStrings');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe extend this message to say "when clampToGround is false".

@@ -42,6 +42,9 @@ define([
this._primitives = [];
this._guid = createGuid();

// Used by the OrderedGroundPrimitiveCollection
this._zIndex = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than glob a specific zIndex property onto here, and since PrimitiveCollection is a primitive, and primitives normally have ids, why no add an id property as the zIndex. This way there's no reason to have a special case here and the PrimitiveCollection is owned by the OrderedGroundPrimitiveCollection anyway, so it's not weird to use id as the z-index. (we do similar things elsewhere.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, we spoke offline and decided to leave it as is

* @private
*/
function OrderedGroundPrimitiveCollection() {
this._length = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can shorten/simplify this class by using AssociativeArray, you've basically rolled your own here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, AssociativeArray has no concept of order and that's critical for this to work

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, you're absolutely correct. Sorry.

@mramato
Copy link
Contributor

mramato commented May 9, 2018

Looks good, bump again when tests are ready and I'll do a final smoke screen and merge. Thanks!

@hpinkos
Copy link
Contributor Author

hpinkos commented May 9, 2018

@mramato ready for a full review!

@mramato
Copy link
Contributor

mramato commented May 10, 2018

I also didn't think to do any type checking.

You should probably check that it's a Number and throw a developer error if not. This can be done at the same time you call getValue. I believe we normally defer to the primitive layer for these kind of checks, but since this is all Entity API, then we need to do it ourselves. Please also add specs to cover these new checks.

@hpinkos
Copy link
Contributor Author

hpinkos commented May 10, 2018

I was going to add a check to OrderedGroundPrimitiveCollection

@mramato
Copy link
Contributor

mramato commented May 10, 2018

I was going to add a check to OrderedGroundPrimitiveCollection

That's fine, as long as it provides a useful call stack so that the Developer can easily find out which object is the problem. It the callstack isn't useful, then it probably needs to happen sooner.

@hpinkos
Copy link
Contributor Author

hpinkos commented May 10, 2018

@mramato anything else?

@hpinkos
Copy link
Contributor Author

hpinkos commented May 21, 2018

@mramato this is ready for another look.

There's some weirdness that was introduced with materials on ground primitives. Ground primitives with different classification types cannot be ordered because they're rendered in separate passes. Because materials on ground primitives is only supported for ClassificationType.TERRAIN, the classification type for any ground geometry entity with a material defaults to ClassificationType.TERRAIN. However, all ground geometry with a color defaults to ClassificationType.BOTH. And therefore, z index doesn't work when intermingling colored ground geometry and textured ground geometry unless you specify ClassificationType.TERRAIN for all the colored ground geometry.

@mramato
Copy link
Contributor

mramato commented May 22, 2018

There's some weirdness that was introduced with materials on ground primitives. Ground primitives with different classification types cannot be ordered because they're rendered in separate passes. Because materials on ground primitives is only supported for ClassificationType.TERRAIN, the classification type for any ground geometry entity with a material defaults to ClassificationType.TERRAIN. However, all ground geometry with a color defaults to ClassificationType.BOTH. And therefore, z index doesn't work when intermingling colored ground geometry and textured ground geometry unless you specify ClassificationType.TERRAIN for all the colored ground geometry.

In the interest of avoiding user confusion, can we just make everything default to ClassificationType.TERRAIN and then users have to opt-in to BOTH?

Also, do we have a separate github issue written up for this? It's a bug even without z-indexing because you can still order ground primitives, right?

@mramato
Copy link
Contributor

mramato commented May 22, 2018

Probably a bug in my gallery generation code, but any idea why Z-Indexing Geometry is showing up twice in the New in 1.45 label? Doesn't have to hold up this PR.

@mramato
Copy link
Contributor

mramato commented May 22, 2018

Update the screenshot on the new example as well.

CHANGES.md Outdated
@@ -30,6 +31,7 @@ Change Log

##### Breaking Changes :mega:
* Removed `Scene.copyGlobeDepth`. Globe depth will now be copied by default when supported. [#6393](https://github.com/AnalyticalGraphicsInc/cesium/pull/6393)
* The default `classificationType` for `GroundPrimitive`, `CorridorGraphics`, `EllipseGraphics`, `PolygonGraphics` and `RectangleGraphics` is now `ClassificationType.TERRAIN`. If you wish the geometry to color both terrain and 3D tiles, pass in the option `classificationType: Cesium.ClassificationType.BOTH`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably add a mention here about BOTH not being supported for ground geometry without materials?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's mentioned elsewhere

@mramato
Copy link
Contributor

mramato commented May 22, 2018

That's all I have, let me know when this is ready for merge.

@hpinkos
Copy link
Contributor Author

hpinkos commented May 22, 2018

@mramato this is ready now

@mramato
Copy link
Contributor

mramato commented May 22, 2018

Did this during test, it was trippy enough to share.
peek 2018-05-22 12-07

@hpinkos
Copy link
Contributor Author

hpinkos commented May 22, 2018

Probably a bug in my gallery generation code, but any idea why Z-Indexing Geometry is showing up twice in the New in 1.45 label?

Yeah, I think that's a bug in the gallery generation code. I'll write up an issue

@hpinkos
Copy link
Contributor Author

hpinkos commented May 22, 2018

@mramato bump

@mramato
Copy link
Contributor

mramato commented May 22, 2018

Was just waiting for it to go green.

@mramato mramato merged commit 87cc8b0 into master May 22, 2018
@mramato mramato deleted the z-index branch May 22, 2018 17:33
@eatjhuapl
Copy link

Does zIndex work with geojson datasource?

@hpinkos
Copy link
Contributor Author

hpinkos commented Jun 18, 2018

@eatapl we haven't hooked this up to GeoJson because I couldn't find anything in the GeoJSON spec that can be used to specify polygon ordering. Does GeoJSON have a property used for ordering that I missed? Thanks!


edit: @eatapl please reply in #4108

@mramato
Copy link
Contributor

mramato commented Jun 18, 2018

@eatapl Just to add-on to @hpinkos' comment. The GeoJSON spec does not cover Z ordering but you can definitely assign zIndex values to entities created by GeoJSON, just like you can add styling and user any other Entity API features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants