From 973f499810251d7b2646f64b677258a8fa0576b4 Mon Sep 17 00:00:00 2001 From: "jerome.fayot" Date: Wed, 4 Dec 2024 19:43:45 +0100 Subject: [PATCH] fix: fixes issue #12356 performance drop --- .../engine/Source/DataSources/ModelGraphics.js | 16 ++++++++++++++++ .../engine/Source/DataSources/ModelVisualizer.js | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/packages/engine/Source/DataSources/ModelGraphics.js b/packages/engine/Source/DataSources/ModelGraphics.js index 8320768fa319..c5f33788ae41 100644 --- a/packages/engine/Source/DataSources/ModelGraphics.js +++ b/packages/engine/Source/DataSources/ModelGraphics.js @@ -46,6 +46,7 @@ function createArticulationStagePropertyBag(value) { * @property {PropertyBag | Object} [articulations] An object, where keys are composed of an articulation name, a single space, and a stage name, and the values are numeric properties. * @property {Property | ClippingPlaneCollection} [clippingPlanes] A property specifying the {@link ClippingPlaneCollection} used to selectively disable rendering the model. * @property {Property | CustomShader} [customShader] A property specifying the {@link CustomShader} to apply to this model. + * @property {Property | boolean} [enableEnvironmentMap=true] A boolean Property specifying if the model has {@link DynamicEnvironmentMapManager} enabled. */ /** @@ -113,6 +114,8 @@ function ModelGraphics(options) { this._clippingPlanesSubscription = undefined; this._customShader = undefined; this._customShaderSubscription = undefined; + this._enableEnvironmentMap = undefined; + this._enableEnvironmentMapSubscription = undefined; this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); } @@ -333,6 +336,14 @@ Object.defineProperties(ModelGraphics.prototype, { * @type {Property|undefined} */ customShader: createPropertyDescriptor("customShader"), + + /** + * Gets or sets the boolean Property specifying if the model has {@link DynamicEnvironmentMapManager} enabled. + * @memberof ModelGraphics.prototype + * @type {Property|undefined} + * @default true + */ + enableEnvironmentMap: createPropertyDescriptor("enableEnvironmentMap"), }); /** @@ -367,6 +378,7 @@ ModelGraphics.prototype.clone = function (result) { result.articulations = this.articulations; result.clippingPlanes = this.clippingPlanes; result.customShader = this.customShader; + result.enableEnvironmentMap = this.enableEnvironmentMap; return result; }; @@ -441,6 +453,10 @@ ModelGraphics.prototype.merge = function (source) { source.clippingPlanes, ); this.customShader = defaultValue(this.customShader, source.customShader); + this.enableEnvironmentMap = defaultValue( + this.enableEnvironmentMap, + source.enableEnvironmentMap, + ); const sourceNodeTransformations = source.nodeTransformations; if (defined(sourceNodeTransformations)) { diff --git a/packages/engine/Source/DataSources/ModelVisualizer.js b/packages/engine/Source/DataSources/ModelVisualizer.js index 42d1bd177592..9c8fa3d6749f 100644 --- a/packages/engine/Source/DataSources/ModelVisualizer.js +++ b/packages/engine/Source/DataSources/ModelVisualizer.js @@ -35,6 +35,7 @@ const defaultColor = Color.WHITE; const defaultColorBlendMode = ColorBlendMode.HIGHLIGHT; const defaultColorBlendAmount = 0.5; const defaultImageBasedLightingFactor = new Cartesian2(1.0, 1.0); +const defaultEnableEnvironmentMap = true; const modelMatrixScratch = new Matrix4(); const nodeMatrixScratch = new Matrix4(); @@ -289,6 +290,12 @@ ModelVisualizer.prototype.update = function (time) { time, ); + model.environmentMapManager.enabled = Property.getValueOrDefault( + modelGraphics._enableEnvironmentMap, + time, + defaultEnableEnvironmentMap, + ); + // It's possible for getBoundingSphere to run before // model becomes ready and these properties are updated modelHash[entity.id].modelUpdated = true;