Skip to content

Commit 1e40c93

Browse files
committed
fixes to model scale
1 parent daa0838 commit 1e40c93

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Cartographic from "../../Core/Cartographic.js";
44
import Check from "../../Core/Check.js";
55
import Credit from "../../Core/Credit.js";
66
import Color from "../../Core/Color.js";
7+
import CesiumMath from "../../Core/Math.js";
78
import defined from "../../Core/defined.js";
89
import Frozen from "../../Core/Frozen.js";
910
import DeveloperError from "../../Core/DeveloperError.js";
@@ -2374,7 +2375,8 @@ function getComputedScale(model, modelMatrix, frameState) {
23742375
return scaleInPixels(position, radius, frameState);
23752376
};
23762377

2377-
let maxScaleInPixels = 0.5; // TODO: We need to ensure this is never 0, because we divide by it
2378+
// maxScaleInPixels is always > 0
2379+
let maxScaleInPixels = CesiumMath.EPSILON12;
23782380
maxScaleInPixels = Math.max(
23792381
maxScaleInPixels,
23802382
getScaleInPixels(modelMatrix),
@@ -2478,7 +2480,7 @@ function updateSceneGraph(model, frameState) {
24782480
const modelMatrix = defined(model._clampedModelMatrix)
24792481
? model._clampedModelMatrix
24802482
: model.modelMatrix;
2481-
sceneGraph.updateModelMatrix(modelMatrix, frameState);
2483+
sceneGraph.updateModelMatrix(modelMatrix, model._computedScale, frameState);
24822484
model._updateModelMatrix = false;
24832485
}
24842486

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ModelSceneGraph.prototype.initialize = function (model, components) {
275275
);
276276

277277
this._projectTo2D = model._projectTo2D;
278+
this._computedModelScale = model._computedScale;
278279
// TODO: 2DBoundingSphere?
279280

280281
// If the model has a height reference that modifies the model matrix,
@@ -283,6 +284,7 @@ ModelSceneGraph.prototype.initialize = function (model, components) {
283284
this._rootTransform = computeRootTransform(this, this._rootTransform);
284285
this._computedModelMatrix = computeModelMatrix(
285286
modelMatrix,
287+
this._computedModelScale,
286288
this._rootTransform,
287289
this._computedModelMatrix,
288290
);
@@ -390,13 +392,17 @@ function computeRootTransform(sceneGraph, result) {
390392
* @param {Matrix4} result
391393
* @returns {Matrix4}
392394
*/
393-
function computeModelMatrix(modelMatrix, rootTransform, result) {
394-
// TODO: include model scaling
395-
// modelMatrix = Matrix4.multiplyByUniformScale(
396-
// modelMatrix,
397-
// computedModelScale,
398-
// result,
399-
// );
395+
function computeModelMatrix(
396+
modelMatrix,
397+
computedModelScale,
398+
rootTransform,
399+
result,
400+
) {
401+
modelMatrix = Matrix4.multiplyByUniformScale(
402+
modelMatrix,
403+
computedModelScale,
404+
result,
405+
);
400406

401407
const transform = Matrix4.multiplyTransformation(
402408
modelMatrix,
@@ -767,11 +773,14 @@ ModelSceneGraph.prototype.update = function (frameState, updateForAnimations) {
767773

768774
ModelSceneGraph.prototype.updateModelMatrix = function (
769775
modelMatrix,
776+
computedScale,
770777
frameState,
771778
) {
772779
this._rootTransform = computeRootTransform(this, this._rootTransform);
780+
this._computedModelScale = computedScale;
773781
this._computedModelMatrix = computeModelMatrix(
774782
modelMatrix,
783+
this._computedModelScale,
775784
this._rootTransform,
776785
this._computedModelMatrix,
777786
);

0 commit comments

Comments
 (0)