diff --git a/packages/engine/Source/DataSources/Entity.js b/packages/engine/Source/DataSources/Entity.js index f07f1d5b3d0..94bb567bad0 100644 --- a/packages/engine/Source/DataSources/Entity.js +++ b/packages/engine/Source/DataSources/Entity.js @@ -98,6 +98,7 @@ function createPropertyTypeDescriptor(name, Type) { * @property {PolylineVolumeGraphics | PolylineVolumeGraphics.ConstructorOptions} [polylineVolume] A polylineVolume to associate with this entity. * @property {RectangleGraphics | RectangleGraphics.ConstructorOptions} [rectangle] A rectangle to associate with this entity. * @property {WallGraphics | WallGraphics.ConstructorOptions} [wall] A wall to associate with this entity. + * @property {boolean} [asynchronous=true] Determines if the underlying primitives will be created asynchronously or block until ready. */ /** @@ -121,6 +122,7 @@ function Entity(options) { this._availability = undefined; this._id = id; + this._asynchronous = options.asynchronous ?? true; this._definitionChanged = new Event(); this._name = options.name; this._show = options.show ?? true; @@ -249,6 +251,16 @@ Object.defineProperties(Entity.prototype, { return this._id; }, }, + /** + * Gets whether the underlying primitives should be created asynchronously or block until ready. + * @memberof Entity.prototype + * @type {boolean} + */ + asynchronous: { + get: function () { + return this._asynchronous; + }, + }, /** * Gets the event that is raised whenever a property or sub-property is changed or modified. * @memberof Entity.prototype diff --git a/packages/engine/Source/DataSources/GeometryUpdater.js b/packages/engine/Source/DataSources/GeometryUpdater.js index 9062fc9ed09..ea710b2d247 100644 --- a/packages/engine/Source/DataSources/GeometryUpdater.js +++ b/packages/engine/Source/DataSources/GeometryUpdater.js @@ -50,6 +50,7 @@ function GeometryUpdater(options) { const geometryPropertyName = options.geometryPropertyName; this._entity = entity; + this._asynchronous = entity.asynchronous; this._scene = options.scene; this._fillEnabled = false; this._isClosed = false; @@ -242,6 +243,19 @@ Object.defineProperties(GeometryUpdater.prototype, { return this._dynamic; }, }, + /** + * Gets a value indicating if the geometry should be created asynchronously + * + * @memberof GeometryUpdater.prototype + * + * @type {boolean} + * @readonly + */ + asynchronous: { + get: function () { + return this._asynchronous; + }, + }, /** * Gets a value indicating if the geometry is closed. * This property is only valid for static geometry. diff --git a/packages/engine/Source/DataSources/StaticGeometryColorBatch.js b/packages/engine/Source/DataSources/StaticGeometryColorBatch.js index 4d65ea05dd8..c849eb466c6 100644 --- a/packages/engine/Source/DataSources/StaticGeometryColorBatch.js +++ b/packages/engine/Source/DataSources/StaticGeometryColorBatch.js @@ -27,6 +27,7 @@ function Batch( depthFailMaterialProperty, closed, shadows, + asynchronous, ) { this.translucent = translucent; this.appearanceType = appearanceType; @@ -48,6 +49,7 @@ function Batch( this.showsUpdated = new AssociativeArray(); this.itemsToRemove = []; this.invalidated = false; + this.asynchronous = asynchronous ?? true; let removeMaterialSubscription; if (defined(depthFailMaterialProperty)) { @@ -156,7 +158,7 @@ Batch.prototype.update = function (time) { primitive = new Primitive({ show: false, - asynchronous: true, + asynchronous: this.asynchronous, geometryInstances: geometries.slice(), appearance: new this.appearanceType({ translucent: this.translucent, @@ -430,7 +432,10 @@ StaticGeometryColorBatch.prototype.add = function (time, updater) { const length = items.length; for (let i = 0; i < length; i++) { const item = items[i]; - if (item.isMaterial(updater)) { + if ( + item.isMaterial(updater) && + item.asynchronous === updater.asynchronous + ) { item.add(updater, instance); return; } @@ -443,6 +448,7 @@ StaticGeometryColorBatch.prototype.add = function (time, updater) { updater.depthFailMaterialProperty, this._closed, this._shadows, + updater.asynchronous, ); batch.add(updater, instance); items.push(batch);