Skip to content

Commit

Permalink
Merge pull request #6875 from AnalyticalGraphicsInc/clipping-planes-c…
Browse files Browse the repository at this point in the history
…hanged

Add ClippingPlaneCollection add/remove events
  • Loading branch information
mramato authored Aug 3, 2018
2 parents a4775a0 + 62e214e commit 49db47f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

### 1.49 - 2018-09-03

##### Additions :tada:
* Added `ClippingPlaneCollection.collectionChanged` event. This event is raised when a `ClippingPlane` is added or removed from the collection [#6875](https://github.com/AnalyticalGraphicsInc/cesium/pull/6875)

### 1.48 - 2018-08-01

##### Additions :tada:
Expand Down
40 changes: 31 additions & 9 deletions Source/Scene/ClippingPlaneCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define([
'../Core/deprecationWarning',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Event',
'../Core/Intersect',
'../Core/Matrix4',
'../Core/PixelFormat',
Expand All @@ -36,6 +37,7 @@ define([
deprecationWarning,
destroyObject,
DeveloperError,
Event,
Intersect,
Matrix4,
PixelFormat,
Expand Down Expand Up @@ -75,15 +77,6 @@ define([
this._dirtyIndex = -1;
this._multipleDirtyPlanes = false;

// Add each ClippingPlane object.
var planes = options.planes;
if (defined(planes)) {
var planesLength = planes.length;
for (var i = 0; i < planesLength; ++i) {
this.add(planes[i]);
}
}

this._enabled = defaultValue(options.enabled, true);

/**
Expand Down Expand Up @@ -111,6 +104,22 @@ define([
*/
this.edgeWidth = defaultValue(options.edgeWidth, 0.0);

/**
* An event triggered when a new clipping plane is added to the collection. Event handlers
* are passed the new plane and the index at which it was added.
* @type {Event}
* @default Event()
*/
this.planeAdded = new Event();

/**
* An event triggered when a new clipping plane is removed from the collection. Event handlers
* are passed the new plane and the index from which it was removed.
* @type {Event}
* @default Event()
*/
this.planeRemoved = new Event();

// If this ClippingPlaneCollection has an owner, only its owner should update or destroy it.
// This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection.
this._owner = undefined;
Expand All @@ -123,6 +132,15 @@ define([
this._float32View = undefined;

this._clippingPlanesTexture = undefined;

// Add each ClippingPlane object.
var planes = options.planes;
if (defined(planes)) {
var planesLength = planes.length;
for (var i = 0; i < planesLength; ++i) {
this.add(planes[i]);
}
}
}

function unionIntersectFunction(value) {
Expand Down Expand Up @@ -263,6 +281,7 @@ define([

setIndexDirty(this, newPlaneIndex);
this._planes.push(plane);
this.planeAdded.raiseEvent(plane, newPlaneIndex);
};

/**
Expand Down Expand Up @@ -346,6 +365,8 @@ define([
this._multipleDirtyPlanes = true;
planes.length = length;

this.planeRemoved.raiseEvent(clippingPlane, index);

return true;
};

Expand All @@ -365,6 +386,7 @@ define([
plane.onChangeCallback = undefined;
plane.index = -1;
}
this.planeRemoved.raiseEvent(plane, i);
}
this._multipleDirtyPlanes = true;
this._planes = [];
Expand Down
45 changes: 45 additions & 0 deletions Specs/Scene/ClippingPlaneCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ defineSuite([
expect(clippingPlanes._planes[0]).toBe(planes[0]);
});

it('fires the planeAdded event when a plane is added', function() {
clippingPlanes = new ClippingPlaneCollection();
var spy = jasmine.createSpy();
clippingPlanes.planeAdded.addEventListener(spy);
clippingPlanes.add(planes[0]);
expect(spy).toHaveBeenCalled();
});

it('gets the plane at an index', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
Expand Down Expand Up @@ -138,6 +146,43 @@ defineSuite([
expect(result).toBe(false);
});

it('remove fires planeRemoved event', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

var spy = jasmine.createSpy();
clippingPlanes.planeRemoved.addEventListener(spy);

clippingPlanes.remove(planes[0]);
expect(spy).toHaveBeenCalled();
});

it('removeAll removes all of the planes in the collection', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

expect(clippingPlanes.length).toEqual(planes.length);

clippingPlanes.removeAll();

expect(clippingPlanes.length).toBe(0);
});

it('removeAll fires planeRemoved event', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

var spy = jasmine.createSpy();
clippingPlanes.planeRemoved.addEventListener(spy);

clippingPlanes.removeAll();

expect(spy).toHaveBeenCalled();
});

describe('uint8 texture mode', function() {
beforeEach(function() {
spyOn(ClippingPlaneCollection, 'useFloatTexture').and.returnValue(false);
Expand Down

0 comments on commit 49db47f

Please sign in to comment.