Skip to content

Commit

Permalink
Merge pull request #2529 from AnalyticalGraphicsInc/per-vertex-colors
Browse files Browse the repository at this point in the history
Fix perVertex colors for PolylineGeometry and SimplePolylineGeometry
  • Loading branch information
pjcozzi committed Mar 2, 2015
2 parents 1e86633 + 251ea51 commit cf9b614
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Change Log
* Fixed a bug that would cause incorrect geometry for long Corridors and Polyline Volumes. [#2513](https://github.com/AnalyticalGraphicsInc/cesium/issues/2513)
* Fixed a bug in imagery loading that could cause some or all of the globe to be missing when using an imagery layer that does not cover the entire globe.
* Fixed a bug that caused `ElipseOutlineGeometry` and `CircleOutlineGeometry` to be extruded to the ground when they should have instead been drawn at height. [#2499](https://github.com/AnalyticalGraphicsInc/cesium/issues/2499).
* Fixed a bug that prevented per-vertex colors from working with `PolylineGeometry` and `SimplePolylineGeometry` when used asynchronously. [#2516](https://github.com/AnalyticalGraphicsInc/cesium/issues/2516)
* Fixed some styling issues with `InfoBox` and `BaseLayerPicker` caused by using Bootstrap with Cesium. [#2487](https://github.com/AnalyticalGraphicsInc/cesium/issues/2479)
* Added support for rendering a water effect on Quantized-Mesh terrain tiles.
* Added `pack` and `unpack` functions to `Matrix2` and `Matrix3`.
Expand Down
22 changes: 11 additions & 11 deletions Source/Core/PolylineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define([
var positions = options.positions;
var colors = options.colors;
var width = defaultValue(options.width, 1.0);
var perVertex = defaultValue(options.colorsPerVertex, false);
var colorsPerVertex = defaultValue(options.colorsPerVertex, false);

//>>includeStart('debug', pragmas.debug);
if ((!defined(positions)) || (positions.length < 2)) {
Expand All @@ -124,15 +124,15 @@ define([
if (width < 1.0) {
throw new DeveloperError('width must be greater than or equal to one.');
}
if (defined(colors) && ((perVertex && colors.length < positions.length) || (!perVertex && colors.length < positions.length - 1))) {
if (defined(colors) && ((colorsPerVertex && colors.length < positions.length) || (!colorsPerVertex && colors.length < positions.length - 1))) {
throw new DeveloperError('colors has an invalid length.');
}
//>>includeEnd('debug');

this._positions = positions;
this._colors = colors;
this._width = width;
this._perVertex = perVertex;
this._colorsPerVertex = colorsPerVertex;
this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT));
this._followSurface = defaultValue(options.followSurface, true);
this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
Expand Down Expand Up @@ -194,7 +194,7 @@ define([
startingIndex += VertexFormat.packedLength;

array[startingIndex++] = value._width;
array[startingIndex++] = value._perVertex ? 1.0 : 0.0;
array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;
array[startingIndex++] = value._followSurface ? 1.0 : 0.0;
array[startingIndex] = value._granularity;
};
Expand All @@ -207,7 +207,7 @@ define([
ellipsoid : scratchEllipsoid,
vertexFormat : scratchVertexFormat,
width : undefined,
perVertex : undefined,
colorsPerVertex : undefined,
followSurface : undefined,
granularity : undefined
};
Expand Down Expand Up @@ -251,15 +251,15 @@ define([
startingIndex += VertexFormat.packedLength;

var width = array[startingIndex++];
var perVertex = array[startingIndex++] === 1.0;
var colorsPerVertex = array[startingIndex++] === 1.0;
var followSurface = array[startingIndex++] === 1.0;
var granularity = array[startingIndex];

if (!defined(result)) {
scratchOptions.positions = positions;
scratchOptions.colors = colors;
scratchOptions.width = width;
scratchOptions.perVertex = perVertex;
scratchOptions.colorsPerVertex = colorsPerVertex;
scratchOptions.followSurface = followSurface;
scratchOptions.granularity = granularity;
return new PolylineGeometry(scratchOptions);
Expand All @@ -270,7 +270,7 @@ define([
result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);
result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);
result._width = width;
result._perVertex = perVertex;
result._colorsPerVertex = colorsPerVertex;
result._followSurface = followSurface;
result._granularity = granularity;

Expand All @@ -292,7 +292,7 @@ define([
var width = polylineGeometry._width;
var vertexFormat = polylineGeometry._vertexFormat;
var colors = polylineGeometry._colors;
var perVertex = polylineGeometry._perVertex;
var colorsPerVertex = polylineGeometry._colorsPerVertex;
var followSurface = polylineGeometry._followSurface;
var granularity = polylineGeometry._granularity;
var ellipsoid = polylineGeometry._ellipsoid;
Expand Down Expand Up @@ -331,7 +331,7 @@ define([
var c0 = colors[i];

var numColors = PolylinePipeline.numberOfPoints(p0, p1, minDistance);
if (perVertex && i < colorLength) {
if (colorsPerVertex && i < colorLength) {
var c1 = colors[i+1];
var interpolatedColors = interpolateColors(p0, p1, c0, c1, numColors);
var interpolatedColorsLength = interpolatedColors.length;
Expand Down Expand Up @@ -403,7 +403,7 @@ define([

var color0, color1;
if (defined(finalColors)) {
if (j !== 0 && !perVertex) {
if (j !== 0 && !colorsPerVertex) {
color0 = colors[j - 1];
} else {
color0 = colors[j];
Expand Down
18 changes: 9 additions & 9 deletions Source/Core/SimplePolylineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ define([
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
var positions = options.positions;
var colors = options.colors;
var perVertex = defaultValue(options.colorsPerVertex, false);
var colorsPerVertex = defaultValue(options.colorsPerVertex, false);

//>>includeStart('debug', pragmas.debug);
if ((!defined(positions)) || (positions.length < 2)) {
throw new DeveloperError('At least two positions are required.');
}
if (defined(colors) && ((perVertex && colors.length < positions.length) || (!perVertex && colors.length < positions.length - 1))) {
if (defined(colors) && ((colorsPerVertex && colors.length < positions.length) || (!colorsPerVertex && colors.length < positions.length - 1))) {
throw new DeveloperError('colors has an invalid length.');
}
//>>includeEnd('debug');

this._positions = positions;
this._colors = colors;
this._perVertex = perVertex;
this._colorsPerVertex = colorsPerVertex;
this._followSurface = defaultValue(options.followSurface, true);
this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
Expand Down Expand Up @@ -180,7 +180,7 @@ define([
Ellipsoid.pack(value._ellipsoid, array, startingIndex);
startingIndex += Ellipsoid.packedLength;

array[startingIndex++] = value._perVertex ? 1.0 : 0.0;
array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;
array[startingIndex++] = value._followSurface ? 1.0 : 0.0;
array[startingIndex] = value._granularity;
};
Expand Down Expand Up @@ -220,7 +220,7 @@ define([
var ellipsoid = Ellipsoid.unpack(array, startingIndex);
startingIndex += Ellipsoid.packedLength;

var perVertex = array[startingIndex++] === 1.0;
var colorsPerVertex = array[startingIndex++] === 1.0;
var followSurface = array[startingIndex++] === 1.0;
var granularity = array[startingIndex];

Expand All @@ -229,7 +229,7 @@ define([
positions : positions,
colors : colors,
ellipsoid : ellipsoid,
perVertex : perVertex,
colorsPerVertex : colorsPerVertex,
followSurface : followSurface,
granularity : granularity
});
Expand All @@ -238,7 +238,7 @@ define([
result._positions = positions;
result._colors = colors;
result._ellipsoid = ellipsoid;
result._perVertex = perVertex;
result._colorsPerVertex = colorsPerVertex;
result._followSurface = followSurface;
result._granularity = granularity;

Expand All @@ -263,13 +263,13 @@ define([
SimplePolylineGeometry.createGeometry = function(simplePolylineGeometry) {
var positions = simplePolylineGeometry._positions;
var colors = simplePolylineGeometry._colors;
var perVertex = simplePolylineGeometry._perVertex;
var colorsPerVertex = simplePolylineGeometry._colorsPerVertex;
var followSurface = simplePolylineGeometry._followSurface;
var granularity = simplePolylineGeometry._granularity;
var ellipsoid = simplePolylineGeometry._ellipsoid;

var minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
var perSegmentColors = defined(colors) && !perVertex;
var perSegmentColors = defined(colors) && !colorsPerVertex;

var i;
var length = positions.length;
Expand Down
23 changes: 19 additions & 4 deletions Specs/Core/PolylineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,29 @@ defineSuite([
expect(geometry).not.toBeDefined();
});

var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)];
var positions = [new Cartesian3(1, 2, 3), new Cartesian3(4, 5, 6), new Cartesian3(7, 8, 9)];
var line = new PolylineGeometry({
positions : positions,
width : 10.0,
colors : [Color.RED, Color.LIME, Color.BLUE],
colorsPerVertex : true,
followSurface : false,
granularity : 11,
vertexFormat : VertexFormat.POSITION_ONLY,
granularity : Math.PI,
ellipsoid: Ellipsoid.UNIT_SPHERE
ellipsoid : new Ellipsoid(12, 13, 14)
});
var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 1.0, Math.PI];
var packedInstance = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 12, 13, 14, 1, 0, 0, 0, 0, 0, 10, 1, 0, 11];
createPackableSpecs(PolylineGeometry, line, packedInstance, "per vertex colors");

line = new PolylineGeometry({
positions : positions,
width : 10.0,
colorsPerVertex : false,
followSurface : false,
granularity : 11,
vertexFormat : VertexFormat.POSITION_ONLY,
ellipsoid : new Ellipsoid(12, 13, 14)
});
packedInstance = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 12, 13, 14, 1, 0, 0, 0, 0, 0, 10, 0, 0, 11];
createPackableSpecs(PolylineGeometry, line, packedInstance);
});
22 changes: 17 additions & 5 deletions Specs/Core/SimplePolylineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,25 @@ defineSuite([
expect(line.attributes.color.values.length).toEqual(numVertices * 4);
});

var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)];
var positions = [new Cartesian3(1, 2, 3), new Cartesian3(4, 5, 6), new Cartesian3(7, 8, 9)];
var line = new SimplePolylineGeometry({
positions : positions,
ellipsoid : Ellipsoid.UNIT_SPHERE,
granularity : 0.1,
followSurface: false
colors : [Color.RED, Color.LIME, Color.BLUE],
colorsPerVertex : true,
followSurface : false,
granularity : 11,
ellipsoid : new Ellipsoid(12, 13, 14)
});
var packedInstance = [3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.1];
var packedInstance = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 12, 13, 14, 1, 0, 11];
createPackableSpecs(SimplePolylineGeometry, line, packedInstance, "per vertex colors");

line = new SimplePolylineGeometry({
positions : positions,
colorsPerVertex : false,
followSurface : false,
granularity : 11,
ellipsoid : new Ellipsoid(12, 13, 14)
});
packedInstance = [3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 12, 13, 14, 0, 0, 11];
createPackableSpecs(SimplePolylineGeometry, line, packedInstance);
});

0 comments on commit cf9b614

Please sign in to comment.