-
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
Z-ordering for ground geometry entities #6362
Conversation
@hpinkos, thanks for the pull request! Maintainers, we have a signed CLA from @hpinkos, so you can review this at any time.
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
@@ -0,0 +1,93 @@ | |||
<!DOCTYPE html> |
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 would rename this to Z-Indexing Geometry
, to both be consistent with our internal terminology and because Z-Indexing is the standard term.
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. |
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())); |
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.
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?
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.
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?
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.
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?)
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 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.
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 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.
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.
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.
@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? |
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. |
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 |
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. |
Source/Core/oneTimeWarning.js
Outdated
@@ -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'; |
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.
Are dynamic entities still not supported? This message appears to only be used in one place and doesn't check anything about dynamic.
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.
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 |
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.
All of the defaults say 0, but there's not actually a default is there? It's just undefined.
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.
undefined === 0 for zIndex. I defaultValue(zIndex, 0)
in the geometry updaters
Source/DataSources/KmlDataSource.js
Outdated
|
||
var ellipsoid = dataSource._ellipsoid; | ||
var coordinates = readCoordinates(coordinatesNode, ellipsoid); | ||
var polyline = styleEntity.polyline; | ||
if (canExtrude && extrude) { | ||
if (defined(zIndex)) { |
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.
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.
Source/DataSources/KmlDataSource.js
Outdated
} else { | ||
if (defined(zIndex)) { | ||
oneTimeWarning('kml-gx:drawOrder', 'KML - gx:drawOrder is not supported in LineStrings'); |
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.
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; |
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.
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.)
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.
Good idea, thanks!
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.
Nevermind, we spoke offline and decided to leave it as is
* @private | ||
*/ | ||
function OrderedGroundPrimitiveCollection() { | ||
this._length = 0; |
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 think you can shorten/simplify this class by using AssociativeArray
, you've basically rolled your own here.
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.
Nope, AssociativeArray
has no concept of order and that's critical for this to work
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.
Ahh, you're absolutely correct. Sorry.
Looks good, bump again when tests are ready and I'll do a final smoke screen and merge. Thanks! |
@mramato ready for a full review! |
You should probably check that it's a |
I was going to add a check to |
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. |
@mramato anything else? |
@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 |
In the interest of avoiding user confusion, can we just make everything default to 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? |
Probably a bug in my gallery generation code, but any idea why |
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`. |
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.
Probably add a mention here about BOTH
not being supported for ground geometry without materials?
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's mentioned elsewhere
That's all I have, let me know when this is ready for merge. |
@mramato this is ready now |
Yeah, I think that's a bug in the gallery generation code. I'll write up an issue |
@mramato bump |
Was just waiting for it to go green. |
Does zIndex work with geojson datasource? |
@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 |
@eatapl Just to add-on to @hpinkos' comment. The GeoJSON spec does not cover Z ordering but you can definitely assign |
For #4108
GeometryVisualizer
creates different batches based on the value of thezIndex
propertyCorridor
,Ellipse
,Polygon
andRectangle
height
andextrudedHeight
are undefinedTODO