diff --git a/CHANGES.md b/CHANGES.md index f82c1efc5303..8ab34fa04552 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,9 +7,10 @@ Beta Releases ### 1.0 - 2014-07-01 * Breaking changes ([why so many?](https://groups.google.com/forum/#!topic/cesium-dev/Y_mG11IZD9k)) - * Renamed `Simon1994PlanetaryPositions` functions `ComputeSunPositionInEarthInertialFrame` and `ComputeMoonPositionInEarthInertialFrame` to `computeSunPositionInEarthInertialFrame` and `computeMoonPositionInEarthInertialFrame`, respectively. - * Replaced `Scene.scene2D.projection` property with read-only `Scene.mapProjection`. Set this with the `mapProjection` option for the `Viewer`, `CesiumWidget`, or `Scene` constructors. - * `Scene` constructor function now takes an `options` parameter instead of individual parameters. + * Renamed `Simon1994PlanetaryPositions` functions `ComputeSunPositionInEarthInertialFrame` and `ComputeMoonPositionInEarthInertialFrame` to `computeSunPositionInEarthInertialFrame` and `computeMoonPositionInEarthInertialFrame`, respectively. + * Replaced `Scene.scene2D.projection` property with read-only `Scene.mapProjection`. Set this with the `mapProjection` option for the `Viewer`, `CesiumWidget`, or `Scene` constructors. + * `Scene` constructor function now takes an `options` parameter instead of individual parameters. + * Replaced `color`, `outlineColor`, and `outlineWidth` in `DynamicPath` with a `material` property. * CZML property references now use a `#` symbol to separate identifier from property path. `objectId.position` should now be `objectId#position`. * `DynamicObject.id` can now include period characters. * `ReferenceProperty` can now handle sub-properties, for example, `myObject#billboard.scale`. diff --git a/Source/DynamicScene/CzmlDataSource.js b/Source/DynamicScene/CzmlDataSource.js index 15458f7faf32..73c83391c6fb 100644 --- a/Source/DynamicScene/CzmlDataSource.js +++ b/Source/DynamicScene/CzmlDataSource.js @@ -1192,14 +1192,42 @@ define([ dynamicObject.path = path = new DynamicPath(); } - processPacketData(Color, path, 'color', pathData.color, interval, sourceUri, dynamicObjectCollection); - processPacketData(Number, path, 'width', pathData.width, interval, sourceUri, dynamicObjectCollection); - processPacketData(Color, path, 'outlineColor', pathData.outlineColor, interval, sourceUri, dynamicObjectCollection); - processPacketData(Number, path, 'outlineWidth', pathData.outlineWidth, interval, sourceUri, dynamicObjectCollection); + //Since CZML does not support PolylineOutlineMaterial, we map its properties into one. + var materialToProcess = path.material; + if (defined(interval)) { + var materialInterval; + var composite = materialToProcess; + if (!(composite instanceof CompositeMaterialProperty)) { + composite = new CompositeMaterialProperty(); + path.material = composite; + if (defined(materialToProcess)) { + materialInterval = Iso8601.MAXIMUM_INTERVAL.clone(); + materialInterval.data = materialToProcess; + composite.intervals.addInterval(materialInterval); + } + } + materialInterval = composite.intervals.findInterval(interval.start, interval.stop, interval.isStartIncluded, interval.isStopIncluded); + if (defined(materialInterval)) { + materialToProcess = materialInterval.data; + } else { + materialToProcess = new PolylineOutlineMaterialProperty(); + materialInterval = interval.clone(); + materialInterval.data = materialToProcess; + composite.intervals.addInterval(materialInterval); + } + } else if (!(materialToProcess instanceof PolylineOutlineMaterialProperty)) { + materialToProcess = new PolylineOutlineMaterialProperty(); + path.material = materialToProcess; + } + processPacketData(Boolean, path, 'show', pathData.show, interval, sourceUri, dynamicObjectCollection); + processPacketData(Number, path, 'width', pathData.width, interval, sourceUri, dynamicObjectCollection); processPacketData(Number, path, 'resolution', pathData.resolution, interval, sourceUri, dynamicObjectCollection); processPacketData(Number, path, 'leadTime', pathData.leadTime, interval, sourceUri, dynamicObjectCollection); processPacketData(Number, path, 'trailTime', pathData.trailTime, interval, sourceUri, dynamicObjectCollection); + processPacketData(Color, materialToProcess, 'color', pathData.color, interval, sourceUri, dynamicObjectCollection); + processPacketData(Color, materialToProcess, 'outlineColor', pathData.outlineColor, interval, sourceUri, dynamicObjectCollection); + processPacketData(Number, materialToProcess, 'outlineWidth', pathData.outlineWidth, interval, sourceUri, dynamicObjectCollection); } function processPoint(dynamicObject, packet, dynamicObjectCollection, sourceUri) { @@ -1326,7 +1354,7 @@ define([ dynamicObject.polyline = polyline = new DynamicPolyline(); } - //Since CZML does not support PolylineOutlineMaterial, we map it's properties into one. + //Since CZML does not support PolylineOutlineMaterial, we map its properties into one. var materialToProcess = polyline.material; if (defined(interval)) { var materialInterval; diff --git a/Source/DynamicScene/DynamicPath.js b/Source/DynamicScene/DynamicPath.js index 0911b7566b5f..c5cd06da2631 100644 --- a/Source/DynamicScene/DynamicPath.js +++ b/Source/DynamicScene/DynamicPath.js @@ -21,12 +21,8 @@ define([ * @constructor */ var DynamicPath = function() { - this._color = undefined; - this._colorSubscription = undefined; - this._outlineColor = undefined; - this._outlineColorSubscription = undefined; - this._outlineWidth = undefined; - this._outlineWidthSubscription = undefined; + this._material = undefined; + this._materialSubscription = undefined; this._show = undefined; this._showSubscription = undefined; this._width = undefined; @@ -56,25 +52,11 @@ define([ }, /** - * Gets or sets the {@link Color} {@link Property} specifying the the path's color. + * Gets or sets the {@link MaterialProperty} specifying the appearance of the path. * @memberof DynamicPath.prototype - * @type {Property} - */ - color : createDynamicPropertyDescriptor('color'), - - /** - * Gets or sets the {@link Color} {@link Property} specifying the the path's outline color. - * @memberof DynamicPath.prototype - * @type {Property} - */ - outlineColor : createDynamicPropertyDescriptor('outlineColor'), - - /** - * Gets or sets the numeric {@link Property} specifying the the path's outline width. - * @memberof DynamicPath.prototype - * @type {Property} + * @type {MaterialProperty} */ - outlineWidth : createDynamicPropertyDescriptor('outlineWidth'), + material : createDynamicPropertyDescriptor('material'), /** * Gets or sets the boolean {@link Property} specifying the path's visibility. @@ -122,11 +104,9 @@ define([ if (!defined(result)) { result = new DynamicPath(); } - result.color = this.color; + result.material = this.material; result.width = this.width; result.resolution = this.resolution; - result.outlineColor = this.outlineColor; - result.outlineWidth = this.outlineWidth; result.show = this.show; result.leadTime = this.leadTime; result.trailTime = this.trailTime; @@ -146,11 +126,9 @@ define([ } //>>includeEnd('debug'); - this.color = defaultValue(this.color, source.color); + this.material = defaultValue(this.material, source.material); this.width = defaultValue(this.width, source.width); this.resolution = defaultValue(this.resolution, source.resolution); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); this.show = defaultValue(this.show, source.show); this.leadTime = defaultValue(this.leadTime, source.leadTime); this.trailTime = defaultValue(this.trailTime, source.trailTime); diff --git a/Source/DynamicScene/DynamicPathVisualizer.js b/Source/DynamicScene/DynamicPathVisualizer.js index 6c2825a0c9ea..00790974d3e6 100644 --- a/Source/DynamicScene/DynamicPathVisualizer.js +++ b/Source/DynamicScene/DynamicPathVisualizer.js @@ -15,6 +15,7 @@ define([ '../Scene/SceneMode', './CompositePositionProperty', './ConstantPositionProperty', + './MaterialProperty', './SampledPositionProperty', './TimeIntervalCollectionPositionProperty' ], function( @@ -33,6 +34,7 @@ define([ SceneMode, CompositePositionProperty, ConstantPositionProperty, + MaterialProperty, SampledPositionProperty, TimeIntervalCollectionPositionProperty) { "use strict"; @@ -340,7 +342,6 @@ define([ return; } - var uniforms; if (!defined(pathVisualizerIndex)) { var unusedIndexes = this._unusedIndexes; var length = unusedIndexes.length; @@ -360,13 +361,12 @@ define([ material = Material.fromType(Material.PolylineOutlineType); polyline.material = material; } - uniforms = material.uniforms; + var uniforms = material.uniforms; Color.clone(Color.WHITE, uniforms.color); Color.clone(Color.BLACK, uniforms.outlineColor); uniforms.outlineWidth = 0; } else { polyline = this._polylineCollection.get(pathVisualizerIndex); - uniforms = polyline.material.uniforms; } polyline.show = true; @@ -381,21 +381,7 @@ define([ } polyline.positions = subSample(positionProperty, sampleStart, sampleStop, time, this._referenceFrame, maxStepSize, polyline.positions); - - property = dynamicPath._color; - if (defined(property)) { - uniforms.color = property.getValue(time, uniforms.color); - } - - property = dynamicPath._outlineColor; - if (defined(property)) { - uniforms.outlineColor = property.getValue(time, uniforms.outlineColor); - } - - property = dynamicPath._outlineWidth; - if (defined(property)) { - uniforms.outlineWidth = property.getValue(time); - } + polyline.material = MaterialProperty.getValue(time, dynamicPath._material, polyline.material); property = dynamicPath._width; if (defined(property)) { diff --git a/Specs/DynamicScene/CzmlDataSourceSpec.js b/Specs/DynamicScene/CzmlDataSourceSpec.js index b1fbc9c401d7..b2ac86a80c74 100644 --- a/Specs/DynamicScene/CzmlDataSourceSpec.js +++ b/Specs/DynamicScene/CzmlDataSourceSpec.js @@ -1307,11 +1307,11 @@ defineSuite([ var dynamicObject = dataSource.dynamicObjects.getObjects()[0]; expect(dynamicObject.path).toBeDefined(); - expect(dynamicObject.path.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.path.material.color.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); expect(dynamicObject.path.width.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.width); expect(dynamicObject.path.resolution.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.resolution); - expect(dynamicObject.path.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.path.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.outlineWidth); + expect(dynamicObject.path.material.outlineColor.getValue(Iso8601.MINIMUM_VALUE)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.path.material.outlineWidth.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.outlineWidth); expect(dynamicObject.path.leadTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.leadTime); expect(dynamicObject.path.trailTime.getValue(Iso8601.MINIMUM_VALUE)).toEqual(pathPacket.path.trailTime); expect(dynamicObject.path.show.getValue(Iso8601.MINIMUM_VALUE)).toEqual(true); @@ -1344,19 +1344,17 @@ defineSuite([ var dynamicObject = dataSource.dynamicObjects.getObjects()[0]; expect(dynamicObject.path).toBeDefined(); - expect(dynamicObject.path.color.getValue(validTime)).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); expect(dynamicObject.path.width.getValue(validTime)).toEqual(pathPacket.path.width); expect(dynamicObject.path.resolution.getValue(validTime)).toEqual(pathPacket.path.resolution); - expect(dynamicObject.path.outlineColor.getValue(validTime)).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); - expect(dynamicObject.path.outlineWidth.getValue(validTime)).toEqual(pathPacket.path.outlineWidth); expect(dynamicObject.path.leadTime.getValue(validTime)).toEqual(pathPacket.path.leadTime); expect(dynamicObject.path.trailTime.getValue(validTime)).toEqual(pathPacket.path.trailTime); expect(dynamicObject.path.show.getValue(validTime)).toEqual(true); + expect(dynamicObject.path.material.getValue(validTime).color).toEqual(new Color(0.1, 0.1, 0.1, 0.1)); + expect(dynamicObject.path.material.getValue(validTime).outlineColor).toEqual(new Color(0.2, 0.2, 0.2, 0.2)); + expect(dynamicObject.path.material.getValue(validTime).outlineWidth).toEqual(pathPacket.path.outlineWidth); - expect(dynamicObject.path.color.getValue(invalidTime)).toBeUndefined(); + expect(dynamicObject.path.material.getValue(invalidTime)).toBeUndefined(); expect(dynamicObject.path.width.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.outlineColor.getValue(invalidTime)).toBeUndefined(); - expect(dynamicObject.path.outlineWidth.getValue(invalidTime)).toBeUndefined(); expect(dynamicObject.path.leadTime.getValue(invalidTime)).toBeUndefined(); expect(dynamicObject.path.trailTime.getValue(invalidTime)).toBeUndefined(); expect(dynamicObject.path.show.getValue(invalidTime)).toBeUndefined(); diff --git a/Specs/DynamicScene/DynamicPathSpec.js b/Specs/DynamicScene/DynamicPathSpec.js index 9f8df8a4d1d7..b17f71c3edd6 100644 --- a/Specs/DynamicScene/DynamicPathSpec.js +++ b/Specs/DynamicScene/DynamicPathSpec.js @@ -1,21 +1,19 @@ /*global defineSuite*/ defineSuite([ 'DynamicScene/DynamicPath', - 'Core/Color', + 'DynamicScene/ColorMaterialProperty', 'DynamicScene/ConstantProperty' ], function( DynamicPath, - Color, + ColorMaterialProperty, ConstantProperty) { "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ it('merge assigns unassigned properties', function() { var source = new DynamicPath(); - source.color = new ConstantProperty(Color.WHITE); + source.material = new ColorMaterialProperty(); source.width = new ConstantProperty(1); - source.outlineColor = new ConstantProperty(Color.WHITE); - source.outlineWidth = new ConstantProperty(1); source.show = new ConstantProperty(true); source.leadTime = new ConstantProperty(1); source.trailTime = new ConstantProperty(1); @@ -23,10 +21,8 @@ defineSuite([ var target = new DynamicPath(); target.merge(source); - expect(target.color).toBe(source.color); + expect(target.material).toBe(source.material); expect(target.width).toBe(source.width); - expect(target.outlineColor).toBe(source.outlineColor); - expect(target.outlineWidth).toBe(source.outlineWidth); expect(target.show).toBe(source.show); expect(target.leadTime).toBe(source.leadTime); expect(target.trailTime).toBe(source.trailTime); @@ -35,39 +31,31 @@ defineSuite([ it('merge does not assign assigned properties', function() { var source = new DynamicPath(); - source.color = new ConstantProperty(Color.WHITE); + source.material = new ColorMaterialProperty(); source.width = new ConstantProperty(1); - source.outlineColor = new ConstantProperty(Color.WHITE); - source.outlineWidth = new ConstantProperty(1); source.show = new ConstantProperty(true); source.leadTime = new ConstantProperty(1); source.trailTime = new ConstantProperty(1); source.resolution = new ConstantProperty(1); - var color = new ConstantProperty(Color.WHITE); + var color = new ColorMaterialProperty(); var width = new ConstantProperty(1); - var outlineColor = new ConstantProperty(Color.WHITE); - var outlineWidth = new ConstantProperty(1); var show = new ConstantProperty(true); var leadTime = new ConstantProperty(1); var trailTime = new ConstantProperty(1); var resolution = new ConstantProperty(1); var target = new DynamicPath(); - target.color = color; + target.material = color; target.width = width; - target.outlineColor = outlineColor; - target.outlineWidth = outlineWidth; target.show = show; target.leadTime = leadTime; target.trailTime = trailTime; target.resolution = resolution; target.merge(source); - expect(target.color).toBe(color); + expect(target.material).toBe(color); expect(target.width).toBe(width); - expect(target.outlineColor).toBe(outlineColor); - expect(target.outlineWidth).toBe(outlineWidth); expect(target.show).toBe(show); expect(target.leadTime).toBe(leadTime); expect(target.trailTime).toBe(trailTime); @@ -76,20 +64,16 @@ defineSuite([ it('clone works', function() { var source = new DynamicPath(); - source.color = new ConstantProperty(Color.WHITE); + source.material = new ColorMaterialProperty(); source.width = new ConstantProperty(1); - source.outlineColor = new ConstantProperty(Color.WHITE); - source.outlineWidth = new ConstantProperty(1); source.show = new ConstantProperty(true); source.leadTime = new ConstantProperty(1); source.trailTime = new ConstantProperty(1); source.resolution = new ConstantProperty(1); var result = source.clone(); - expect(result.color).toBe(source.color); + expect(result.material).toBe(source.material); expect(result.width).toBe(source.width); - expect(result.outlineColor).toBe(source.outlineColor); - expect(result.outlineWidth).toBe(source.outlineWidth); expect(result.show).toBe(source.show); expect(result.leadTime).toBe(source.leadTime); expect(result.trailTime).toBe(source.trailTime); diff --git a/Specs/DynamicScene/DynamicPathVisualizerSpec.js b/Specs/DynamicScene/DynamicPathVisualizerSpec.js index bb1484f4182c..1f509fc032b7 100644 --- a/Specs/DynamicScene/DynamicPathVisualizerSpec.js +++ b/Specs/DynamicScene/DynamicPathVisualizerSpec.js @@ -11,6 +11,8 @@ defineSuite([ 'DynamicScene/ConstantProperty', 'DynamicScene/DynamicObjectCollection', 'DynamicScene/DynamicPath', + 'DynamicScene/PolylineGlowMaterialProperty', + 'DynamicScene/PolylineOutlineMaterialProperty', 'DynamicScene/SampledPositionProperty', 'DynamicScene/TimeIntervalCollectionPositionProperty', 'Specs/createScene', @@ -27,6 +29,8 @@ defineSuite([ ConstantProperty, DynamicObjectCollection, DynamicPath, + PolylineGlowMaterialProperty, + PolylineOutlineMaterialProperty, SampledPositionProperty, TimeIntervalCollectionPositionProperty, createScene, @@ -111,10 +115,11 @@ defineSuite([ var path = testObject.path = new DynamicPath(); path.show = new ConstantProperty(true); - path.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.material = new PolylineOutlineMaterialProperty(); + path.material.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.material.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); + path.material.outlineWidth = new ConstantProperty(2.5); path.width = new ConstantProperty(12.5); - path.outlineColor = new ConstantProperty(new Color(0.1, 0.2, 0.3, 0.4)); - path.outlineWidth = new ConstantProperty(2.5); path.leadTime = new ConstantProperty(25); path.trailTime = new ConstantProperty(10); @@ -131,15 +136,51 @@ defineSuite([ expect(primitive.width).toEqual(testObject.path.width.getValue(updateTime)); var material = primitive.material; - expect(material.uniforms.color).toEqual(testObject.path.color.getValue(updateTime)); - expect(material.uniforms.outlineColor).toEqual(testObject.path.outlineColor.getValue(updateTime)); - expect(material.uniforms.outlineWidth).toEqual(testObject.path.outlineWidth.getValue(updateTime)); + expect(material.uniforms.color).toEqual(testObject.path.material.color.getValue(updateTime)); + expect(material.uniforms.outlineColor).toEqual(testObject.path.material.outlineColor.getValue(updateTime)); + expect(material.uniforms.outlineWidth).toEqual(testObject.path.material.outlineWidth.getValue(updateTime)); path.show = new ConstantProperty(false); visualizer.update(updateTime); expect(primitive.show).toEqual(testObject.path.show.getValue(updateTime)); }); + it('A custom material can be used.', function() { + var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; + var updateTime = new JulianDate(0.5, 0); + var positions = [new Cartesian3(1234, 5678, 9101112), new Cartesian3(5678, 1234, 1101112)]; + + var dynamicObjectCollection = new DynamicObjectCollection(); + visualizer = new DynamicPathVisualizer(scene, dynamicObjectCollection); + + expect(scene.primitives.length).toEqual(0); + + var testObject = dynamicObjectCollection.getOrCreateObject('test'); + var position = new SampledPositionProperty(); + testObject.position = position; + position.addSamples(times, positions); + + var path = testObject.path = new DynamicPath(); + path.show = new ConstantProperty(true); + path.material = new PolylineGlowMaterialProperty(); + path.material.color = new ConstantProperty(new Color(0.8, 0.7, 0.6, 0.5)); + path.material.glowPower = new ConstantProperty(0.2); + path.width = new ConstantProperty(12.5); + path.leadTime = new ConstantProperty(25); + path.trailTime = new ConstantProperty(10); + + visualizer.update(updateTime); + + expect(scene.primitives.length).toEqual(1); + + var polylineCollection = scene.primitives.get(0); + var primitive = polylineCollection.get(0); + + var material = primitive.material; + expect(material.uniforms.color).toEqual(testObject.path.material.color.getValue(updateTime)); + expect(material.uniforms.glowPower).toEqual(testObject.path.material.glowPower.getValue(updateTime)); + }); + it('clear hides primitives.', function() { var times = [new JulianDate(0, 0), new JulianDate(1, 0)]; var updateTime = new JulianDate(0.5, 0);