-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extensibility to various classes #11859
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
062a051
add extensibility to various classes
jjspace 2307841
add new specs
jjspace f73c3de
extract GeometryUpdaterSet
jjspace 9b5cb6e
pr comments
jjspace 0db26ac
Merge remote-tracking branch 'origin/main' into package-extensibility
jjspace ab9e341
Add PR links to CHANGES.md
ggetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/engine/Source/DataSources/GeometryUpdaterSet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import destroyObject from "../Core/destroyObject.js"; | ||
import Event from "../Core/Event.js"; | ||
import EventHelper from "../Core/EventHelper.js"; | ||
import BoxGeometryUpdater from "./BoxGeometryUpdater.js"; | ||
import CorridorGeometryUpdater from "./CorridorGeometryUpdater.js"; | ||
import CylinderGeometryUpdater from "./CylinderGeometryUpdater.js"; | ||
import EllipseGeometryUpdater from "./EllipseGeometryUpdater.js"; | ||
import EllipsoidGeometryUpdater from "./EllipsoidGeometryUpdater.js"; | ||
import PlaneGeometryUpdater from "./PlaneGeometryUpdater.js"; | ||
import PolygonGeometryUpdater from "./PolygonGeometryUpdater.js"; | ||
import PolylineVolumeGeometryUpdater from "./PolylineVolumeGeometryUpdater.js"; | ||
import RectangleGeometryUpdater from "./RectangleGeometryUpdater.js"; | ||
import WallGeometryUpdater from "./WallGeometryUpdater.js"; | ||
|
||
/** @type {GeometryUpdater[]} */ | ||
const geometryUpdaters = [ | ||
BoxGeometryUpdater, | ||
CylinderGeometryUpdater, | ||
CorridorGeometryUpdater, | ||
EllipseGeometryUpdater, | ||
EllipsoidGeometryUpdater, | ||
PlaneGeometryUpdater, | ||
PolygonGeometryUpdater, | ||
PolylineVolumeGeometryUpdater, | ||
RectangleGeometryUpdater, | ||
WallGeometryUpdater, | ||
]; | ||
|
||
/** | ||
* Manages a set of "updater" classes for the {@link GeometryVisualizer} for each entity | ||
* | ||
* @private | ||
jjspace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {Entity} entity | ||
* @param {Scene} scene | ||
*/ | ||
function GeometryUpdaterSet(entity, scene) { | ||
this.entity = entity; | ||
this.scene = scene; | ||
const updaters = new Array(geometryUpdaters.length); | ||
const geometryChanged = new Event(); | ||
const eventHelper = new EventHelper(); | ||
for (let i = 0; i < updaters.length; i++) { | ||
const updater = new geometryUpdaters[i](entity, scene); | ||
eventHelper.add(updater.geometryChanged, (geometry) => { | ||
geometryChanged.raiseEvent(geometry); | ||
}); | ||
updaters[i] = updater; | ||
} | ||
this.updaters = updaters; | ||
this.geometryChanged = geometryChanged; | ||
this.eventHelper = eventHelper; | ||
|
||
this._removeEntitySubscription = entity.definitionChanged.addEventListener( | ||
GeometryUpdaterSet.prototype._onEntityPropertyChanged, | ||
this | ||
); | ||
} | ||
|
||
GeometryUpdaterSet.prototype._onEntityPropertyChanged = function ( | ||
entity, | ||
propertyName, | ||
newValue, | ||
oldValue | ||
) { | ||
const updaters = this.updaters; | ||
for (let i = 0; i < updaters.length; i++) { | ||
updaters[i]._onEntityPropertyChanged( | ||
entity, | ||
propertyName, | ||
newValue, | ||
oldValue | ||
); | ||
} | ||
}; | ||
|
||
GeometryUpdaterSet.prototype.forEach = function (callback) { | ||
const updaters = this.updaters; | ||
for (let i = 0; i < updaters.length; i++) { | ||
callback(updaters[i]); | ||
} | ||
}; | ||
|
||
GeometryUpdaterSet.prototype.destroy = function () { | ||
this.eventHelper.removeAll(); | ||
const updaters = this.updaters; | ||
for (let i = 0; i < updaters.length; i++) { | ||
updaters[i].destroy(); | ||
} | ||
this._removeEntitySubscription(); | ||
destroyObject(this); | ||
}; | ||
|
||
/** | ||
* Add the provided updater to the default list of updaters if not already included | ||
* @param {GeometryUpdater} updater | ||
*/ | ||
GeometryUpdaterSet.registerUpdater = function (updater) { | ||
if (!geometryUpdaters.includes(updater)) { | ||
geometryUpdaters.push(updater); | ||
} | ||
}; | ||
|
||
/** | ||
* Remove the provided updater from the default list of updaters if included | ||
* @param {GeometryUpdater} updater | ||
*/ | ||
GeometryUpdaterSet.unregisterUpdater = function (updater) { | ||
if (geometryUpdaters.includes(updater)) { | ||
const index = geometryUpdaters.indexOf(updater); | ||
geometryUpdaters.splice(index, 1); | ||
} | ||
}; | ||
|
||
export default GeometryUpdaterSet; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configurable: true
which then lets medelete Entity.prototype.propertyName
. But I'm not entirely sure we want to make the property fully configurable?privateName
andsubscriptionName
are not always defined so usingObject.keys
to check doesn't seem like a 100% complete solution.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline: Given we'd have to jump through hoops here to make an "unsubscribe" function, we'll omit.
Depending on if we need additional Entity flexibility in the future, we could consider how the types are managed under the hood. But for the scope of this PR, its not needed.