Skip to content

Commit 90b3e09

Browse files
committed
scaling fix for non earth centered models
1 parent ce8c00c commit 90b3e09

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const scratchTranslationRotationScale = new TranslationRotationScale();
1111
const scratchRotation = new Matrix3();
1212
const scratchTransform = new Matrix4();
1313
const scratchBoundingSphere = new BoundingSphere();
14+
const scratchCartesian3 = new Cartesian3();
1415
/**
1516
* A copy of a {@link Model} mesh, known as an instance, used for rendering multiple copies with GPU instancing. Instancing is useful for efficiently rendering a large number of the same model, such as trees in a forest or vehicles in a parking lot.
1617
* @see {@link ModelInstanceCollection} for a collection of instances.
@@ -193,8 +194,11 @@ class ModelInstance {
193194
* viewer.camera.flyToBoundingSphere(boundingSphere);
194195
*/
195196
getBoundingSphere(model, useBoundingSphere2D, mapProjection, result) {
196-
const modelMatrix = model.modelMatrix;
197+
let modelMatrix = model.modelMatrix;
197198
const sceneGraph = model.sceneGraph;
199+
if (useBoundingSphere2D) {
200+
modelMatrix = sceneGraph._modelMatrix2D;
201+
}
198202
const instanceBoundingSpheres = [];
199203

200204
for (const runtimeNode of sceneGraph._runtimeNodes) {
@@ -314,19 +318,19 @@ class ModelInstance {
314318
);
315319

316320
let instanceTransform;
317-
if (useInstanceTransform2D) {
321+
const modelTranslation = Matrix4.getTranslation(
322+
modelMatrix,
323+
scratchCartesian3,
324+
);
325+
if (
326+
useInstanceTransform2D &
327+
Cartesian3.equals(modelTranslation, Cartesian3.ZERO)
328+
) {
318329
instanceTransform = Transforms.basisTo2D(
319330
mapProjection,
320331
this.transform,
321332
scratchTransform,
322333
);
323-
324-
// ToDo: check if needed
325-
// instanceTransform = Matrix4.multiplyTransformation(
326-
// instanceTransform,
327-
// sceneGraph._axisCorrectionMatrix,
328-
// scratchTransform,
329-
// );
330334
} else {
331335
instanceTransform = Matrix4.multiplyTransformation(
332336
this.transform,

0 commit comments

Comments
 (0)