From 3e9a280fc65a37d832f07bd1690dd24a219b3b4d Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 29 Feb 2016 12:16:32 -0500 Subject: [PATCH] remove empty triangles from north and south pole --- CHANGES.md | 1 + Source/Core/EllipsoidGeometry.js | 28 +++++++++++++++++++++++----- Specs/Core/EllipsoidGeometrySpec.js | 4 ++-- Specs/Core/SphereGeometrySpec.js | 4 ++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a93115d1e32a..7d7306bf508b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,6 +32,7 @@ Change Log * Added `Color.add`, `Color.subtract`, `Color.multiply`, `Color.divide`, `Color.mod`, `Color.multiplyByScalar`, and `Color.divideByScalar` functions to perform arithmetic operations on colors. * Fixed bug causing `navigator is not defined` reference error when Cesium is used with Node.js. * Upgraded Knockout from version 3.2.0 to 3.4.0. +* Fixed hole that appeared in the top of in dynamic ellipsoids ### 1.18 - 2016-02-01 * Breaking changes diff --git a/Source/Core/EllipsoidGeometry.js b/Source/Core/EllipsoidGeometry.js index 97c8a9275646..13c7e71d426f 100644 --- a/Source/Core/EllipsoidGeometry.js +++ b/Source/Core/EllipsoidGeometry.js @@ -200,7 +200,7 @@ define([ var vertexCount = stackPartitions * slicePartitions; var positions = new Float64Array(vertexCount * 3); - var numIndices = 6 * (slicePartitions - 1) * (stackPartitions - 1); + var numIndices = 6 * (slicePartitions - 1) * (stackPartitions - 2); var indices = IndexDatatype.createTypedArray(vertexCount, numIndices); var normals = (vertexFormat.normal) ? new Float32Array(vertexCount * 3) : undefined; @@ -244,7 +244,7 @@ define([ for (i = 0; i < slicePartitions; i++) { // duplicate first point for correct - // texture coordinates at the north pole. + // texture coordinates at the south pole. positions[index++] = 0.0; positions[index++] = 0.0; positions[index++] = -radii.z; @@ -356,9 +356,17 @@ define([ } index = 0; - for (i = 0; i < stackPartitions; i++) { - var topOffset = i * slicePartitions; - var bottomOffset = (i + 1) * slicePartitions; + for (j = 0; j < slicePartitions - 1; j++) { + indices[index++] = slicePartitions + j; + indices[index++] = slicePartitions + j + 1; + indices[index++] = j + 1; + } + + var topOffset; + var bottomOffset; + for (i = 1; i < stackPartitions - 2; i++) { + topOffset = i * slicePartitions; + bottomOffset = (i + 1) * slicePartitions; for (j = 0; j < slicePartitions - 1; j++) { indices[index++] = bottomOffset + j; @@ -371,6 +379,16 @@ define([ } } + i = stackPartitions - 2; + topOffset = i * slicePartitions; + bottomOffset = (i + 1) * slicePartitions; + + for (j = 0; j < slicePartitions - 1; j++) { + indices[index++] = bottomOffset + j; + indices[index++] = topOffset + j + 1; + indices[index++] = topOffset + j; + } + return new Geometry({ attributes : attributes, indices : indices, diff --git a/Specs/Core/EllipsoidGeometrySpec.js b/Specs/Core/EllipsoidGeometrySpec.js index d00790a6ab0c..581649c60df8 100644 --- a/Specs/Core/EllipsoidGeometrySpec.js +++ b/Specs/Core/EllipsoidGeometrySpec.js @@ -37,7 +37,7 @@ defineSuite([ })); expect(m.attributes.position.values.length).toEqual(3 * 16); - expect(m.indices.length).toEqual(6 * 9); + expect(m.indices.length).toEqual(3 * 12); expect(m.boundingSphere.radius).toEqual(1); }); @@ -53,7 +53,7 @@ defineSuite([ expect(m.attributes.normal.values.length).toEqual(3 * 16); expect(m.attributes.tangent.values.length).toEqual(3 * 16); expect(m.attributes.binormal.values.length).toEqual(3 * 16); - expect(m.indices.length).toEqual(6 * 9); + expect(m.indices.length).toEqual(3 * 12); }); it('computes attributes for a unit sphere', function() { diff --git a/Specs/Core/SphereGeometrySpec.js b/Specs/Core/SphereGeometrySpec.js index f86dbd6435dd..95173a7117a2 100644 --- a/Specs/Core/SphereGeometrySpec.js +++ b/Specs/Core/SphereGeometrySpec.js @@ -38,7 +38,7 @@ defineSuite([ })); expect(m.attributes.position.values.length).toEqual(3 * 16); - expect(m.indices.length).toEqual(6 * 9); + expect(m.indices.length).toEqual(3 * 12); expect(m.boundingSphere.radius).toEqual(1); }); @@ -55,7 +55,7 @@ defineSuite([ expect(m.attributes.normal.values.length).toEqual(3 * 16); expect(m.attributes.tangent.values.length).toEqual(3 * 16); expect(m.attributes.binormal.values.length).toEqual(3 * 16); - expect(m.indices.length).toEqual(6 * 9); + expect(m.indices.length).toEqual(3 * 12); }); it('computes attributes for a unit sphere', function() {