Skip to content

Commit dfd4f43

Browse files
committed
earth centered 2D instances - correct location but not orientation
1 parent d697bde commit dfd4f43

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ class ModelInstance {
296296
scratchTransform,
297297
);
298298

299-
instanceTransform = Matrix4.multiplyTransformation(
300-
instanceTransform,
301-
sceneGraph._axisCorrectionMatrix,
302-
scratchTransform,
303-
);
299+
// ToDo: check if needed
300+
// instanceTransform = Matrix4.multiplyTransformation(
301+
// instanceTransform,
302+
// sceneGraph._axisCorrectionMatrix,
303+
// scratchTransform,
304+
// );
304305
} else {
305306
instanceTransform = Matrix4.multiplyTransformation(
306307
this.transform,
@@ -321,6 +322,16 @@ class ModelInstance {
321322
result,
322323
);
323324
}
325+
326+
getCenter2D(mapProjection, result) {
327+
result = result ?? new Cartesian3();
328+
const instanceTransform = Transforms.basisTo2D(
329+
mapProjection,
330+
this.transform,
331+
scratchTransform,
332+
);
333+
return Matrix4.getTranslation(instanceTransform, result);
334+
}
324335
}
325336

326337
export default ModelInstance;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,6 @@ function updateComputedModelMatrix2D(sceneGraph, frameState) {
518518

519519
function computeModelMatrix2D(sceneGraph, frameState) {
520520
const modelMatrix = sceneGraph._model.modelMatrix;
521-
// sceneGraph._modelMatrix2D = Transforms.basisTo2D(
522-
// frameState.mapProjection,
523-
// modelMatrix,
524-
// sceneGraph._modelMatrix2D,
525-
// );
526521
const translation = Matrix4.getTranslation(
527522
modelMatrix,
528523
scratchComputedTranslation,

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import BufferUsage from "../../Renderer/BufferUsage.js";
99
import ShaderDestination from "../../Renderer/ShaderDestination.js";
1010
import InstancingStageCommon from "../../Shaders/Model/InstancingStageCommon.js";
1111
import RuntimeModelInstancingPipelineStageVS from "../../Shaders/Model/RuntimeModelInstancingPipelineStageVS.js";
12+
import SceneMode from "../SceneMode.js";
1213

1314
const nodeTransformScratch = new Matrix4();
1415
const relativeScaledTransformScratch = new Matrix4();
16+
const scratchCartesian3 = new Cartesian3();
1517

1618
/**
1719
* The runtime model instancing pipeline stage is responsible for handling GPU mesh instancing
@@ -84,6 +86,20 @@ RuntimeModelInstancingPipelineStage._getTransformsTypedArray = function (
8486
const count = modelInstances.length;
8587
const transformsTypedArray = new Float32Array(count * elements);
8688

89+
const useBoundingSphere2D =
90+
!frameState.scene3DOnly && model.sceneGraph._projectTo2D;
91+
const useModelMatrix2D =
92+
frameState.mode !== SceneMode.SCENE3D && !useBoundingSphere2D;
93+
94+
const modelTranslation = Matrix4.getTranslation(
95+
model.modelMatrix,
96+
scratchCartesian3,
97+
);
98+
let earthCenteredInstances = false;
99+
if (Cartesian3.equals(modelTranslation, Cartesian3.ZERO)) {
100+
earthCenteredInstances = true;
101+
}
102+
87103
for (let i = 0; i < count; i++) {
88104
const modelInstance = modelInstances[i];
89105
if (!defined(modelInstance)) {
@@ -110,7 +126,10 @@ RuntimeModelInstancingPipelineStage._getTransformsTypedArray = function (
110126
transformsTypedArray[offset + 10] = transform[10];
111127
transformsTypedArray[offset + 11] = transform[14];
112128

113-
const translation = modelInstance.center ?? Cartesian3.ZERO;
129+
let translation = modelInstance.center ?? Cartesian3.ZERO;
130+
if (useModelMatrix2D && earthCenteredInstances) {
131+
translation = modelInstance.getCenter2D(frameState.mapProjection);
132+
}
114133

115134
EncodedCartesian3.writeElements(
116135
translation,

0 commit comments

Comments
 (0)