Skip to content

Commit db4cfe5

Browse files
authored
Merge pull request #12358 from jfayot/fix_12356
fixes issue #12356 performance drop due to EnvironmentMap
2 parents abae345 + 971166f commit db4cfe5

File tree

7 files changed

+96
-8
lines changed

7 files changed

+96
-8
lines changed

.vscode/cspell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
"3DTILES",
3737
"aabb",
3838
"Amato",
39+
"basisu",
3940
"bathymetric",
4041
"bitangent",
4142
"bitangents",
4243
"bivariate",
4344
"Bourke",
4445
"brdf",
4546
"cartesians",
47+
"carto",
4648
"cartographics",
4749
"cesiumjs",
4850
"comms",
@@ -93,6 +95,7 @@
9395
"unregisters",
9496
"unrenderable",
9597
"voxel",
98+
"VVLH",
9699
"WEBG",
97100
"xdescribe"
98101
]

CHANGES.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
### 1.125 - 2025-01-02
44

5+
#### @cesium/engine
6+
57
##### Additions :tada:
68

79
- Expanded the integration with the [iTwin Platform](https://developer.bentley.com/) to load GeoJSON and KML data from the Reality Management API. Use `ITwinData.createDataSourceForRealityDataId(iTwinId, realityDataId)` to load data as the corresponding Data Source. [#12344](https://github.com/CesiumGS/cesium/pull/12344)
10+
- Added `environmentMapOptions` to `ModelGraphics`. For performance reasons, the environment map will not update if the entity position changes by default. If environment map updates based on entity position are desired, ensure to provide an appropriate `environmentMapOptions.maximumPositionEpsilon` value. [#12358](https://github.com/CesiumGS/cesium/pull/12358)
811

912
##### Fixes :wrench:
1013

1114
- Reduced memory usage and peformance bottlenecks when using environment maps with models. [#12356](https://github.com/CesiumGS/cesium/issues/12356)
12-
- Fixed JulianDate to always generate valid ISO strings for fractional milliseconds. [#12345](https://github.com/CesiumGS/cesium/pull/12345)
15+
- Fixed JulianDate to always generate valid ISO strings for fractional milliseconds [#12345](https://github.com/CesiumGS/cesium/pull/12345)
1316
- Fixed intermittent z-fighting issue. [#12337](https://github.com/CesiumGS/cesium/issues/12337)
1417

1518
### 1.124 - 2024-12-02
@@ -102,9 +105,6 @@
102105
- Fix flickering issue caused by bounding sphere retrieval being blocked by the bounding sphere of another entity. [#12230](https://github.com/CesiumGS/cesium/pull/12230)
103106
- Fixed `ImageBasedLighting.imageBasedLightingFactor` not affecting lighting. [#12129](https://github.com/CesiumGS/cesium/pull/12129)
104107
- Fix error with normalization of corner points for lines and corridors with collinear points. [#12255](https://github.com/CesiumGS/cesium/pull/12255)
105-
106-
##### Fixes :wrench:
107-
108108
- Properly handle `offset` and `scale` properties when picking metadata from property textures. [#12237](https://github.com/CesiumGS/cesium/pull/12237)
109109

110110
### 1.122 - 2024-10-01

packages/engine/Source/DataSources/ModelGraphics.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function createArticulationStagePropertyBag(value) {
1818
return new PropertyBag(value);
1919
}
2020

21+
function createEnvironmentMapPropertyBag(value) {
22+
return new PropertyBag(value);
23+
}
24+
2125
/**
2226
* @typedef {object} ModelGraphics.ConstructorOptions
2327
*
@@ -40,6 +44,7 @@ function createArticulationStagePropertyBag(value) {
4044
* @property {Property | ColorBlendMode} [colorBlendMode=ColorBlendMode.HIGHLIGHT] An enum Property specifying how the color blends with the model.
4145
* @property {Property | number} [colorBlendAmount=0.5] A numeric Property specifying the color strength when the <code>colorBlendMode</code> is <code>MIX</code>. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.
4246
* @property {Property | Cartesian2} [imageBasedLightingFactor=new Cartesian2(1.0, 1.0)] A property specifying the contribution from diffuse and specular image-based lighting.
47+
* @property {PropertyBag | Object<string, *>} [environmentMapOptions] The properties for managing dynamic environment maps on this entity.
4348
* @property {Property | Color} [lightColor] A property specifying the light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
4449
* @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this model will be displayed.
4550
* @property {PropertyBag | Object<string, TranslationRotationScale>} [nodeTransformations] An object, where keys are names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node. The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.
@@ -101,6 +106,8 @@ function ModelGraphics(options) {
101106
this._colorBlendAmountSubscription = undefined;
102107
this._imageBasedLightingFactor = undefined;
103108
this._imageBasedLightingFactorSubscription = undefined;
109+
this._environmentMapOptions = undefined;
110+
this._environmentMapOptionsSubscription = undefined;
104111
this._lightColor = undefined;
105112
this._lightColorSubscription = undefined;
106113
this._distanceDisplayCondition = undefined;
@@ -279,6 +286,17 @@ Object.defineProperties(ModelGraphics.prototype, {
279286
"imageBasedLightingFactor",
280287
),
281288

289+
/**
290+
* Gets or sets the {@link DynamicEnvironmentMapManager.ConstructorOptions} to apply to this model. This is represented as an {@link PropertyBag}.
291+
* @memberof ModelGraphics.prototype
292+
* @type {PropertyBag}
293+
*/
294+
environmentMapOptions: createPropertyDescriptor(
295+
"environmentMapOptions",
296+
undefined,
297+
createEnvironmentMapPropertyBag,
298+
),
299+
282300
/**
283301
* A property specifying the {@link Cartesian3} light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
284302
* @memberOf ModelGraphics.prototype
@@ -361,6 +379,7 @@ ModelGraphics.prototype.clone = function (result) {
361379
result.colorBlendMode = this.colorBlendMode;
362380
result.colorBlendAmount = this.colorBlendAmount;
363381
result.imageBasedLightingFactor = this.imageBasedLightingFactor;
382+
result.environmentMapOptions = this.environmentMapOptions;
364383
result.lightColor = this.lightColor;
365384
result.distanceDisplayCondition = this.distanceDisplayCondition;
366385
result.nodeTransformations = this.nodeTransformations;
@@ -430,7 +449,10 @@ ModelGraphics.prototype.merge = function (source) {
430449
this.imageBasedLightingFactor,
431450
source.imageBasedLightingFactor,
432451
);
433-
452+
this.environmentMapOptions = defaultValue(
453+
this.environmentMapOptions,
454+
source.environmentMapOptions,
455+
);
434456
this.lightColor = defaultValue(this.lightColor, source.lightColor);
435457
this.distanceDisplayCondition = defaultValue(
436458
this.distanceDisplayCondition,

packages/engine/Source/DataSources/ModelVisualizer.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const defaultColor = Color.WHITE;
3535
const defaultColorBlendMode = ColorBlendMode.HIGHLIGHT;
3636
const defaultColorBlendAmount = 0.5;
3737
const defaultImageBasedLightingFactor = new Cartesian2(1.0, 1.0);
38+
const defaultEnvironmentMapOptions = {
39+
maximumPositionEpsilon: Number.POSITIVE_INFINITY,
40+
};
3841

3942
const modelMatrixScratch = new Matrix4();
4043
const nodeMatrixScratch = new Matrix4();
@@ -76,6 +79,7 @@ async function createModelPrimitive(
7679
entity,
7780
resource,
7881
incrementallyLoadTextures,
82+
environmentMapOptions,
7983
) {
8084
const primitives = visualizer._primitives;
8185
const modelHash = visualizer._modelHash;
@@ -85,6 +89,7 @@ async function createModelPrimitive(
8589
url: resource,
8690
incrementallyLoadTextures: incrementallyLoadTextures,
8791
scene: visualizer._scene,
92+
environmentMapOptions: environmentMapOptions,
8893
});
8994

9095
if (visualizer.isDestroyed() || !defined(modelHash[entity.id])) {
@@ -176,6 +181,9 @@ ModelVisualizer.prototype.update = function (time) {
176181
articulationsScratch: {},
177182
loadFailed: false,
178183
modelUpdated: false,
184+
environmentMapOptionsScratch: {
185+
...defaultEnvironmentMapOptions,
186+
},
179187
};
180188
modelHash[entity.id] = modelData;
181189

@@ -185,7 +193,20 @@ ModelVisualizer.prototype.update = function (time) {
185193
defaultIncrementallyLoadTextures,
186194
);
187195

188-
createModelPrimitive(this, entity, resource, incrementallyLoadTextures);
196+
const environmentMapOptions = Property.getValueOrDefault(
197+
modelGraphics._environmentMapOptions,
198+
time,
199+
defaultEnvironmentMapOptions,
200+
modelData.environmentMapOptionsScratch,
201+
);
202+
203+
createModelPrimitive(
204+
this,
205+
entity,
206+
resource,
207+
incrementallyLoadTextures,
208+
environmentMapOptions,
209+
);
189210
}
190211

191212
const model = modelData.modelPrimitive;

packages/engine/Source/Scene/Cesium3DTileset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import DynamicEnvironmentMapManager from "./DynamicEnvironmentMapManager.js";
105105
* @property {object} [pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation based on geometric error and lighting.
106106
* @property {Cartesian3} [lightColor] The light color when shading models. When <code>undefined</code> the scene's light color is used instead.
107107
* @property {ImageBasedLighting} [imageBasedLighting] The properties for managing image-based lighting for this tileset.
108-
* @param {DynamicEnvironmentMapManager.ConstructorOptions} [options.environmentMapOptions] The properties for managing dynamic environment maps on this model.
108+
* @property {DynamicEnvironmentMapManager.ConstructorOptions} [environmentMapOptions] The properties for managing dynamic environment maps on this tileset.
109109
* @property {boolean} [backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the glTF material's doubleSided property; when false, back face culling is disabled.
110110
* @property {boolean} [enableShowOutline=true] Whether to enable outlines for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set to false to avoid the additional processing of geometry at load time. When false, the showOutlines and outlineColor options are ignored.
111111
* @property {boolean} [showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.

packages/engine/Source/Scene/Model/Model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ Model.prototype.applyArticulations = function () {
18231823
*
18241824
* The given name may be the name of a glTF extension, like `"EXT_example_extension"`.
18251825
* If the specified extension was present in the root of the underlying glTF asset,
1826-
* and a loder for the specified extension has processed the extension data, then
1826+
* and a loader for the specified extension has processed the extension data, then
18271827
* this will return the model representation of the extension.
18281828
*
18291829
* @param {string} extensionName The name of the extension

packages/engine/Specs/DataSources/ModelVisualizerSpec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ describe(
196196

197197
expect(primitive.lightColor).toEqual(new Cartesian3(1.0, 1.0, 0.0));
198198

199+
expect(primitive.environmentMapManager.enabled).toBeTrue();
200+
expect(primitive.environmentMapManager.maximumPositionEpsilon).toEqual(
201+
Number.POSITIVE_INFINITY,
202+
);
203+
199204
// wait till the model is loaded before we can check node transformations
200205
await pollToPromise(function () {
201206
scene.render();
@@ -276,6 +281,43 @@ describe(
276281
expect(node.matrix).toEqualEpsilon(expected, CesiumMath.EPSILON14);
277282
});
278283

284+
it("can apply model environmentMapOptions", async function () {
285+
const time = JulianDate.now();
286+
287+
const model = new ModelGraphics();
288+
model.uri = new ConstantProperty(boxArticulationsUrl);
289+
290+
model.environmentMapOptions = {
291+
enabled: false,
292+
};
293+
294+
const testObject = entityCollection.getOrCreateEntity("test");
295+
testObject.position = new ConstantPositionProperty(
296+
Cartesian3.fromDegrees(1, 2, 3),
297+
);
298+
testObject.model = model;
299+
300+
visualizer.update(time);
301+
302+
let primitive;
303+
await pollToPromise(function () {
304+
primitive = scene.primitives.get(0);
305+
return defined(primitive);
306+
});
307+
308+
// wait till the model is loaded before we can check articulations
309+
await pollToPromise(function () {
310+
scene.render();
311+
return primitive.ready;
312+
});
313+
visualizer.update(time);
314+
315+
expect(primitive.environmentMapManager.enabled).toBeFalse();
316+
expect(primitive.environmentMapManager.maximumPositionEpsilon).toEqual(
317+
Number.POSITIVE_INFINITY,
318+
);
319+
});
320+
279321
it("creates a primitive from ModelGraphics with a Resource", async function () {
280322
const time = JulianDate.now();
281323

0 commit comments

Comments
 (0)