Skip to content

Commit

Permalink
fix: fixes issue CesiumGS#12356 performance drop
Browse files Browse the repository at this point in the history
  • Loading branch information
jfayot committed Dec 9, 2024
1 parent c72ad38 commit c4a8948
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/engine/Source/DataSources/ModelGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createArticulationStagePropertyBag(value) {
* @property {PropertyBag | Object<string, number>} [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.
*/

/**
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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"),
});

/**
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions packages/engine/Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c4a8948

Please sign in to comment.