From dac90cbb89e6162f7d410e59913f3d49c560c2bd Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 25 Aug 2016 14:28:39 -0400 Subject: [PATCH] Use original billboard/label/point instead of trying to clone them. Billboard images are impossible to clone without reading from the texture atlas. --- Source/DataSources/EntityCluster.js | 73 ++---------------------- Source/Scene/Billboard.js | 14 +++++ Source/Scene/BillboardCollection.js | 2 +- Source/Scene/Label.js | 23 ++++++++ Source/Scene/PointPrimitive.js | 14 +++++ Source/Scene/PointPrimitiveCollection.js | 2 +- 6 files changed, 57 insertions(+), 71 deletions(-) diff --git a/Source/DataSources/EntityCluster.js b/Source/DataSources/EntityCluster.js index 9ea4441b3381..24020cb73294 100644 --- a/Source/DataSources/EntityCluster.js +++ b/Source/DataSources/EntityCluster.js @@ -152,80 +152,13 @@ define([ return bbox; } - function cloneLabel(label) { - return { - text : label.text, - show : label.show, - font : label.font, - fillColor : label.fillColor, - outlineColor : label.outlineColor, - outlineWidth : label.outlineWidth, - style : label.outlineStyle, - verticalOrigin : label.verticalOrigin, - horizontalOrigin : label.horizontalOrigin, - pixelOffset : label.pixelOffset, - eyeOffset : label.eyeOffset, - position : label.position, - scale : label.scale, - id : label.id, - translucencyByDistance : label.translucencyByDistance, - pixelOffsetScaleByDistance : label.pixelOffsetScaleByDistance, - heightReference : label.heightReference - }; - } - - function cloneBillboard(billboard) { - return { - show : billboard.show, - position : billboard.position, - heightReference : billboard.heightReference, - pixelOffset : billboard.pixelOffset, - scaleByDistance : billboard.scaleByDistance, - translucencyByDistance : billboard.translucencyByDistance, - pixelOffsetScaleByDistance : billboard.pixelOffsetScaleByDistance, - eyeOffset : billboard.eyeOffset, - horizontalOrigin : billboard.horizontalOrigin, - verticalOrigin : billboard.verticalOrigin, - scale : billboard.scale, - color : billboard.color, - rotation : billboard.rotation, - alignedAxis : billboard.alignedAxis, - width : billboard.width, - height : billboard.height, - sizeInMeters : billboard.sizeInMeters, - id : billboard.id, - pickPrimitive : billboard.pickPrimitive, - image : billboard.image - }; - } - - function clonePoint(point) { - return { - show : point.show, - position : point.position, - scaleByDistance : point.scaleByDistance, - translucencyByDistance : point.translucencyByDistance, - pixelSize : point.pixelSize, - color : point.color, - outlineColor : point.outlineColor, - outlineWidth : point.outlineWidth, - id : point.id - }; - } - function addNonClusteredItem(item, entityCluster) { - if (defined(item._labelCollection)) { - entityCluster._clusterLabelCollection.add(cloneLabel(item)); - } else if (defined(item._billboardCollection)) { - entityCluster._clusterBillboardCollection.add(cloneBillboard(item)); - } else if (defined(item._pointPrimitiveCollection)) { - entityCluster._clusterPointCollection.add(clonePoint(item)); - } + item._clusterRender = true; if (!defined(item._labelCollection) && defined(item.id._label)) { var labelIndex = item.id._labelIndex; var label = entityCluster._labelCollection.get(labelIndex); - entityCluster._clusterLabelCollection.add(cloneLabel(label)); + label._clusterRender = true; } } @@ -245,6 +178,8 @@ define([ var length = collection.length; for (var i = 0; i < length; ++i) { var item = collection.get(i); + item._clusterRender = false; + if (!item.show || !occluder.isPointVisible(item.position)) { continue; } diff --git a/Source/Scene/Billboard.js b/Source/Scene/Billboard.js index 84f4e39e34b4..535f572785bb 100644 --- a/Source/Scene/Billboard.js +++ b/Source/Scene/Billboard.js @@ -151,6 +151,8 @@ define([ this._removeCallbackFunc = undefined; this._mode = SceneMode.SCENE3D; + this._clusterShow = true; + this._updateClamping(); } @@ -821,6 +823,18 @@ define([ this._actualClampedPosition = Cartesian3.clone(value, this._actualClampedPosition); makeDirty(this, POSITION_INDEX); } + }, + + _clusterRender : { + get : function() { + return this._clusterShow; + }, + set : function(value) { + if (this._clusterShow !== value) { + this._clusterShow = value; + makeDirty(this, SHOW_INDEX); + } + } } }); diff --git a/Source/Scene/BillboardCollection.js b/Source/Scene/BillboardCollection.js index 3e101a01a023..396802a7d54f 100644 --- a/Source/Scene/BillboardCollection.js +++ b/Source/Scene/BillboardCollection.js @@ -791,7 +791,7 @@ define([ var horizontalOrigin = billboard.horizontalOrigin; var heightReference = billboard._heightReference; var verticalOrigin = (heightReference === HeightReference.NONE) ? billboard._verticalOrigin : VerticalOrigin.BOTTOM; - var show = billboard.show; + var show = billboard.show && billboard._clusterRender; // If the color alpha is zero, do not show this billboard. This lets us avoid providing // color during the pick pass and also eliminates a discard in the fragment shader. diff --git a/Source/Scene/Label.js b/Source/Scene/Label.js index 7bf979ef1936..a43259b6a73d 100644 --- a/Source/Scene/Label.js +++ b/Source/Scene/Label.js @@ -100,6 +100,8 @@ define([ this._removeCallbackFunc = undefined; this._mode = undefined; + this._clusterShow = true; + this._updateClamping(); } @@ -701,6 +703,27 @@ define([ } } } + }, + + _clusterRender : { + get : function() { + return this._clusterShow; + }, + set : function(value) { + if (this._clusterShow !== value) { + this._clusterShow = value; + + var glyphs = this._glyphs; + for (var i = 0, len = glyphs.length; i < len; i++) { + var glyph = glyphs[i]; + if (defined(glyph.billboard)) { + // Set all the private values here, because we already clamped to ground + // so we don't want to do it again for every glyph + glyph.billboard._clusterRender = value; + } + } + } + } } }); diff --git a/Source/Scene/PointPrimitive.js b/Source/Scene/PointPrimitive.js index bead41db9798..d3ed11811e61 100644 --- a/Source/Scene/PointPrimitive.js +++ b/Source/Scene/PointPrimitive.js @@ -75,6 +75,8 @@ define([ this._id = options.id; this._collection = defaultValue(options.collection, pointPrimitiveCollection); + this._clusterShow = true; + this._pickId = undefined; this._pointPrimitiveCollection = pointPrimitiveCollection; this._dirty = false; @@ -354,6 +356,18 @@ define([ this._pickId.object.id = value; } } + }, + + _clusterRender : { + get : function() { + return this._clusterShow; + }, + set : function(value) { + if (this._clusterShow !== value) { + this._clusterShow = value; + makeDirty(this, SHOW_INDEX); + } + } } }); diff --git a/Source/Scene/PointPrimitiveCollection.js b/Source/Scene/PointPrimitiveCollection.js index eb9c513e6f89..286d9d3aa70e 100644 --- a/Source/Scene/PointPrimitiveCollection.js +++ b/Source/Scene/PointPrimitiveCollection.js @@ -555,7 +555,7 @@ define([ } } - var show = pointPrimitive.show; + var show = pointPrimitive.show && pointPrimitive._clusterRender; // If the color alphas are zero, do not show this pointPrimitive. This lets us avoid providing // color during the pick pass and also eliminates a discard in the fragment shader.