Skip to content

Commit b66679c

Browse files
committed
Merge pull request #1115 from AnalyticalGraphicsInc/polylineGeometry
Polyline geometry
2 parents d74ba6a + 3498a5b commit b66679c

25 files changed

+1632
-223
lines changed

Apps/Sandcastle/gallery/Geometry and Appearances.html

+74-20
Original file line numberDiff line numberDiff line change
@@ -719,39 +719,93 @@
719719
closed : true
720720
})
721721
}));
722-
723-
// Combine several polylines, each with a unique color.
724-
// Override the appearance render state to change the
725-
// line on system's that support it (Linx/Mac).
726-
727-
instances = [];
728-
729-
for (i = 0; i < 40; i += 2) {
730-
instances.push(new Cesium.GeometryInstance({
731-
geometry : new Cesium.SimplePolylineGeometry({
732-
positions : ellipsoid.cartographicArrayToCartesianArray([
733-
Cesium.Cartographic.fromDegrees(-100.0 + i, 48.0),
734-
Cesium.Cartographic.fromDegrees(-102.0 + i, 48.0)
735-
])
736-
}),
737-
attributes : {
738-
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom({alpha : 1.0}))
739-
}
740-
}));
722+
723+
positions = [];
724+
var colors = [];
725+
for (i = 0; i < 40; ++i) {
726+
positions.push(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0 + i, 48.0)));
727+
colors.push(Cesium.Color.fromRandom({alpha : 1.0}));
741728
}
742729

743730
primitives.add(new Cesium.Primitive({
744-
geometryInstances : instances,
731+
geometryInstances : new Cesium.GeometryInstance({
732+
geometry : new Cesium.SimplePolylineGeometry({
733+
positions : positions,
734+
colors : colors
735+
})
736+
}),
745737
appearance : new Cesium.PerInstanceColorAppearance({
746738
flat : true,
747739
renderState : {
748740
depthTest : {
749741
enabled : true
750742
},
743+
// Override the appearance render state to change the
744+
// line width on system's that support it (Linx/Mac).
751745
lineWidth : Math.min(4.0, scene.getContext().getMaximumAliasedLineWidth())
752746
}
753747
})
754748
}));
749+
750+
// create a polyline with a material
751+
positions = [];
752+
for (i = 0; i < 40; ++i) {
753+
positions.push(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0 + i, 15.0)));
754+
}
755+
756+
primitives.add(new Cesium.Primitive({
757+
geometryInstances : new Cesium.GeometryInstance({
758+
geometry : new Cesium.PolylineGeometry({
759+
positions : positions,
760+
width : 10.0,
761+
vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
762+
})
763+
}),
764+
appearance : new Cesium.PolylineMaterialAppearance({
765+
material : Cesium.Material.fromType(scene.getContext(), Cesium.Material.PolylineGlowType)
766+
})
767+
}));
768+
769+
// create a polyline with per segment colors
770+
positions = [];
771+
colors = [];
772+
for (i = 0; i < 40; ++i) {
773+
positions.push(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0 + i, 12.0)));
774+
colors.push(Cesium.Color.fromRandom({alpha : 1.0}));
775+
}
776+
777+
primitives.add(new Cesium.Primitive({
778+
geometryInstances : new Cesium.GeometryInstance({
779+
geometry : new Cesium.PolylineGeometry({
780+
positions : positions,
781+
width : 10.0,
782+
vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
783+
colors : colors
784+
})
785+
}),
786+
appearance : new Cesium.PolylineColorAppearance()
787+
}));
788+
789+
// create a polyline with per vertex colors
790+
positions = [];
791+
colors = [];
792+
for (i = 0; i < 40; ++i) {
793+
positions.push(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0 + i, 9.0)));
794+
colors.push(Cesium.Color.fromRandom({alpha : 1.0}));
795+
}
796+
797+
primitives.add(new Cesium.Primitive({
798+
geometryInstances : new Cesium.GeometryInstance({
799+
geometry : new Cesium.PolylineGeometry({
800+
positions : positions,
801+
width : 10.0,
802+
vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
803+
colors : colors,
804+
colorsPerVertex : true
805+
})
806+
}),
807+
appearance : new Cesium.PolylineColorAppearance()
808+
}));
755809

756810
// Create a single wall
757811
positions = ellipsoid.cartographicArrayToCartesianArray([

CHANGES.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Beta Releases
99
* Breaking changes:
1010
* Renamed `TextureWrap.CLAMP` to `TextureWrap.CLAMP_TO_EDGE`.
1111
* Added `CorridorOutlineGeometry`.
12+
* Added `PolylineGeometry`, `PolylineColorAppearance`, and `PolylineMaterialAppearance`.
13+
* Added `colors` option to `SimplePolylineGeometry` for per vertex or per segment colors.
1214
* Improved runtime generation of GLSL shaders.
1315
* Added new built-in GLSL functions `czm_getLambertDiffuse` and `czm_getSpecular`.
1416
* Made sun size accurate.
@@ -39,7 +41,8 @@ _This releases fixes 2D and other issues with Chrome 29.0.1547.57 ([#1002](https
3941
* `ConstantPositionProperty` - a `PositionProperty` whose value does not change in respect to the `ReferenceFrame` in which is it defined.
4042
* `SampledPositionProperty` - a `SampledProperty` for positions.
4143
* `TimeIntervalCollectionPositionProperty` - A `TimeIntervalCollectionProperty` for positions.
42-
* Removed `processCzml`, use `CzmlDataSource` instead. * `Source/Widgets/Viewer/lighter.css` was deleted, use `Source/Widgets/lighter.css` instead.
44+
* Removed `processCzml`, use `CzmlDataSource` instead.
45+
* `Source/Widgets/Viewer/lighter.css` was deleted, use `Source/Widgets/lighter.css` instead.
4346
* Replaced `ExtentGeometry` parameters for extruded extent to make them consistent with other geometries.
4447
* `options.extrudedOptions.height` -> `options.extrudedHeight`
4548
* `options.extrudedOptions.closeTop` -> `options.closeBottom`

Source/Core/GeometryAttributes.js

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ define(['./defaultValue'], function(defaultValue) {
7676
* @default undefined
7777
*/
7878
this.tangent = options.tangent;
79+
80+
/**
81+
* The color attribute.
82+
* <p>
83+
* 8-bit unsigned integer. 4 components per attribute.
84+
* </p>
85+
*
86+
* @type GeometryAttribute
87+
*
88+
* @default undefined
89+
*/
90+
this.color = options.color;
7991
};
8092

8193
return GeometryAttributes;

Source/Core/GeometryPipeline.js

+53-26
Original file line numberDiff line numberDiff line change
@@ -582,51 +582,78 @@ define([
582582
* </p>
583583
*
584584
* @param {Geometry} geometry The geometry to modify.
585+
* @param {String} attributeName The name of the attribute.
586+
* @param {String} attributeName3D The name of the attribute in 3D.
587+
* @param {String} attributeName2D The name of the attribute in 2D.
585588
* @param {Object} [projection=new GeographicProjection()] The projection to use.
586589
*
587590
* @returns {Geometry} The modified <code>geometry</code> argument with <code>position3D</code> and <code>position2D</code> attributes.
588591
*
589592
* @exception {DeveloperError} geometry is required.
593+
* @exception {DeveloperError} attributeName is required.
594+
* @exception {DeveloperError} attributeName3D is required.
595+
* @exception {DeveloperError} attributeName2D is required.
596+
* @exception {DeveloperError} geometry must have attribute matching the attributeName argument.
597+
* @exception {DeveloperError} The attribute componentDatatype must be ComponentDatatype.DOUBLE.
590598
*
591599
* @example
592-
* geometry = GeometryPipeline.projectTo2D(geometry);
600+
* geometry = GeometryPipeline.projectTo2D(geometry, 'position', 'position3D', 'position2D');
593601
*/
594-
GeometryPipeline.projectTo2D = function(geometry, projection) {
602+
GeometryPipeline.projectTo2D = function(geometry, attributeName, attributeName3D, attributeName2D, projection) {
595603
if (!defined(geometry)) {
596604
throw new DeveloperError('geometry is required.');
597605
}
598606

599-
if (defined(geometry.attributes.position)) {
600-
projection = (defined(projection)) ? projection : new GeographicProjection();
601-
var ellipsoid = projection.getEllipsoid();
607+
if (!defined(attributeName)) {
608+
throw new DeveloperError('attributeName is required.');
609+
}
602610

603-
// Project original positions to 2D.
604-
var positions3D = geometry.attributes.position.values;
605-
var projectedPositions = new Float64Array(positions3D.length);
606-
var index = 0;
611+
if (!defined(attributeName3D)) {
612+
throw new DeveloperError('attributeName3D is required.');
613+
}
607614

608-
for ( var i = 0; i < positions3D.length; i += 3) {
609-
var position = Cartesian3.fromArray(positions3D, i, scratchProjectTo2DCartesian3);
610-
var lonLat = ellipsoid.cartesianToCartographic(position, scratchProjectTo2DCartographic);
611-
var projectedLonLat = projection.project(lonLat, scratchProjectTo2DCartesian3);
615+
if (!defined(attributeName2D)) {
616+
throw new DeveloperError('attributeName2D is required.');
617+
}
612618

613-
projectedPositions[index++] = projectedLonLat.x;
614-
projectedPositions[index++] = projectedLonLat.y;
615-
projectedPositions[index++] = projectedLonLat.z;
616-
}
619+
var attribute = geometry.attributes[attributeName];
620+
if (!defined(attribute)) {
621+
throw new DeveloperError('geometry must have attribute matching the attributeName argument: ' + attributeName + '.');
622+
}
617623

618-
// Rename original positions to WGS84 Positions.
619-
geometry.attributes.position3D = geometry.attributes.position;
624+
if (attribute.componentDatatype.value !== ComponentDatatype.DOUBLE.value) {
625+
throw new DeveloperError('The attribute componentDatatype must be ComponentDatatype.DOUBLE.');
626+
}
620627

621-
// Replace original positions with 2D projected positions
622-
geometry.attributes.position2D = new GeometryAttribute({
623-
componentDatatype : ComponentDatatype.DOUBLE,
624-
componentsPerAttribute : 3,
625-
values : projectedPositions
626-
});
627-
delete geometry.attributes.position;
628+
projection = (defined(projection)) ? projection : new GeographicProjection();
629+
var ellipsoid = projection.getEllipsoid();
630+
631+
// Project original values to 2D.
632+
var values3D = attribute.values;
633+
var projectedValues = new Float64Array(values3D.length);
634+
var index = 0;
635+
636+
for ( var i = 0; i < values3D.length; i += 3) {
637+
var value = Cartesian3.fromArray(values3D, i, scratchProjectTo2DCartesian3);
638+
var lonLat = ellipsoid.cartesianToCartographic(value, scratchProjectTo2DCartographic);
639+
var projectedLonLat = projection.project(lonLat, scratchProjectTo2DCartesian3);
640+
641+
projectedValues[index++] = projectedLonLat.x;
642+
projectedValues[index++] = projectedLonLat.y;
643+
projectedValues[index++] = projectedLonLat.z;
628644
}
629645

646+
// Rename original cartesians to WGS84 cartesians.
647+
geometry.attributes[attributeName3D] = attribute;
648+
649+
// Replace original cartesians with 2D projected cartesians
650+
geometry.attributes[attributeName2D] = new GeometryAttribute({
651+
componentDatatype : ComponentDatatype.DOUBLE,
652+
componentsPerAttribute : 3,
653+
values : projectedValues
654+
});
655+
delete geometry.attributes[attributeName];
656+
630657
return geometry;
631658
};
632659

0 commit comments

Comments
 (0)