diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index 37ec3c50fe4b..0fdd97b8a2fe 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -1064,7 +1064,8 @@ define([ attributes : attributes, indices : attr.indices, primitiveType : PrimitiveType.TRIANGLES, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : corridorGeometry._offsetAttribute }); }; diff --git a/Source/Core/CorridorOutlineGeometry.js b/Source/Core/CorridorOutlineGeometry.js index 069da5df4f1b..56bda2844cc5 100644 --- a/Source/Core/CorridorOutlineGeometry.js +++ b/Source/Core/CorridorOutlineGeometry.js @@ -546,7 +546,8 @@ define([ attributes : attributes, indices : attr.indices, primitiveType : PrimitiveType.LINES, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : corridorOutlineGeometry._offsetAttribute }); }; diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 69f46eddb096..9c855da8566d 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -1009,7 +1009,8 @@ define([ attributes : geometry.attributes, indices : geometry.indices, primitiveType : PrimitiveType.TRIANGLES, - boundingSphere : geometry.boundingSphere + boundingSphere : geometry.boundingSphere, + offsetAttribute : ellipseGeometry._offsetAttribute }); }; diff --git a/Source/Core/EllipseOutlineGeometry.js b/Source/Core/EllipseOutlineGeometry.js index 6ed83c0d2e99..390ae2860552 100644 --- a/Source/Core/EllipseOutlineGeometry.js +++ b/Source/Core/EllipseOutlineGeometry.js @@ -389,7 +389,8 @@ define([ attributes : geometry.attributes, indices : geometry.indices, primitiveType : PrimitiveType.LINES, - boundingSphere : geometry.boundingSphere + boundingSphere : geometry.boundingSphere, + offsetAttribute : ellipseGeometry._offsetAttribute }); }; diff --git a/Source/Core/Geometry.js b/Source/Core/Geometry.js index 7190996c80ed..6edb62ad0554 100644 --- a/Source/Core/Geometry.js +++ b/Source/Core/Geometry.js @@ -6,6 +6,7 @@ define([ './defaultValue', './defined', './DeveloperError', + './GeometryOffsetAttribute', './GeometryType', './Matrix2', './Matrix3', @@ -22,6 +23,7 @@ define([ defaultValue, defined, DeveloperError, + GeometryOffsetAttribute, GeometryType, Matrix2, Matrix3, @@ -176,6 +178,12 @@ define([ * @private */ this.boundingSphereCV = options.boundingSphereCV; + + /** + * @private + * Used for computing the bounding sphere for geometry using the applyOffset vertex attribute + */ + this.offsetAttribute = options.offsetAttribute; } /** diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index fab63507bc73..6d6477cbf709 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -963,7 +963,8 @@ define([ attributes : attributes, indices : geometry.indices, primitiveType : geometry.primitiveType, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : polygonGeometry._offsetAttribute }); }; diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index 95a854cd1f65..3ff65722a6c4 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -591,7 +591,8 @@ define([ attributes : geometry.attributes, indices : geometry.indices, primitiveType : geometry.primitiveType, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : polygonGeometry._offsetAttribute }); }; diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index dd8d3d728f50..f2ec375489c8 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -948,7 +948,8 @@ define([ attributes : geometry.attributes, indices : geometry.indices, primitiveType : geometry.primitiveType, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : rectangleGeometry._offsetAttribute }); }; diff --git a/Source/Core/RectangleOutlineGeometry.js b/Source/Core/RectangleOutlineGeometry.js index 780e4b37800d..5853b46bce8a 100644 --- a/Source/Core/RectangleOutlineGeometry.js +++ b/Source/Core/RectangleOutlineGeometry.js @@ -397,7 +397,8 @@ define([ attributes : geometry.attributes, indices : geometry.indices, primitiveType : PrimitiveType.LINES, - boundingSphere : boundingSphere + boundingSphere : boundingSphere, + offsetAttribute : rectangleGeometry._offsetAttribute }); }; diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index 4e471bd0179b..f539f2c51e9b 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -18,6 +18,7 @@ define([ '../Core/Geometry', '../Core/GeometryAttribute', '../Core/GeometryAttributes', + '../Core/GeometryOffsetAttribute', '../Core/Intersect', '../Core/isArray', '../Core/Matrix4', @@ -61,6 +62,7 @@ define([ Geometry, GeometryAttribute, GeometryAttributes, + GeometryOffsetAttribute, Intersect, isArray, Matrix4, @@ -526,7 +528,7 @@ define([ var name; for (name in attributes0) { - if (attributes0.hasOwnProperty(name)) { + if (attributes0.hasOwnProperty(name) && defined(attributes0[name])) { var attribute = attributes0[name]; var inAllInstances = true; @@ -1893,13 +1895,13 @@ define([ var offsetBoundingSphereScratch1 = new BoundingSphere(); var offsetBoundingSphereScratch2 = new BoundingSphere(); - function transformBoundingSphere(boundingSphere, offset, extend) { - if (extend) { + function transformBoundingSphere(boundingSphere, offset, offsetAttribute) { + if (offsetAttribute === GeometryOffsetAttribute.TOP) { var origBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch1); var offsetBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch2); offsetBS.center = Cartesian3.add(offsetBS.center, offset, offsetBS.center); boundingSphere = BoundingSphere.union(origBS, offsetBS, boundingSphere); - } else { + } else if (offsetAttribute === GeometryOffsetAttribute.ALL) { boundingSphere.center = Cartesian3.add(boundingSphere.center, offset, boundingSphere.center); } @@ -1943,6 +1945,7 @@ define([ get : function() { var boundingSphere = primitive._instanceBoundingSpheres[index]; if (defined(boundingSphere)) { + boundingSphere = boundingSphere.clone(); var modelMatrix = primitive.modelMatrix; var offset = properties.offset; if (defined(offset)) { diff --git a/Source/Scene/PrimitivePipeline.js b/Source/Scene/PrimitivePipeline.js index b4549b046d92..b65436c863c2 100644 --- a/Source/Scene/PrimitivePipeline.js +++ b/Source/Scene/PrimitivePipeline.js @@ -301,7 +301,7 @@ define([ boundingSpheres[i] = geometry.boundingSphere; boundingSpheresCV[i] = geometry.boundingSphereCV; if (hasOffset) { - offsetInstanceExtend[i] = defined(instance.geometry.attributes) && defined(instance.geometry.attributes.applyOffset) && instance.geometry.attributes.applyOffset.values.indexOf(0) !== -1; + offsetInstanceExtend[i] = instance.geometry.offsetAttribute; } }