Skip to content

Commit

Permalink
fix(react-components): Fixes bug where ground plane scale is stored a…
Browse files Browse the repository at this point in the history
…s xz instead of xy (#4743)

* Fixes bug where ground plane scale is stored as xz instead of xy
  • Loading branch information
anders-hopland authored Sep 6, 2024
1 parent c054f6b commit f860ce1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type SceneConfiguration = {
cameraTargetX?: number;
cameraTargetY?: number;
cameraTargetZ?: number;
updatedAt?: string;
};

export type CadOrPointCloudModel = Transformation3d & {
Expand Down
4 changes: 3 additions & 1 deletion react-components/src/hooks/scenes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type SceneConfigurationProperties = {
cameraTargetX?: number;
cameraTargetY?: number;
cameraTargetZ?: number;
updatedAt?: string;
};

export type SkyboxProperties = {
Expand Down Expand Up @@ -137,7 +138,8 @@ export const sceneSourceWithProperties = [
'cameraEulerRotationZ',
'cameraTargetX',
'cameraTargetY',
'cameraTargetZ'
'cameraTargetZ',
'updatedAt'
]
}
] as const satisfies SourceSelectorV3;
Expand Down
3 changes: 2 additions & 1 deletion react-components/src/hooks/scenes/useSceneConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export const useSceneConfig = (
cameraEulerRotationZ: sceneConfigurationProperties.cameraEulerRotationZ,
cameraTargetX: sceneConfigurationProperties.cameraTargetX,
cameraTargetY: sceneConfigurationProperties.cameraTargetY,
cameraTargetZ: sceneConfigurationProperties.cameraTargetZ
cameraTargetZ: sceneConfigurationProperties.cameraTargetZ,
updatedAt: sceneConfigurationProperties.updatedAt
},
skybox: getSkybox(sceneResponse),
groundPlanes: getGroundPlanes(sceneResponse),
Expand Down
27 changes: 26 additions & 1 deletion react-components/src/hooks/useGroundPlaneFromScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,28 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s
) {
return;
}
const groundPlaneScaleFactor = 10000;
const groundMeshes: CustomObject[] = [];

// New scale format was introduced as a bug in the Scenebuilder
// on August 1st, 2024. This is a temporary fix to handle both formats.
// This should be removed when we upgrade the Scene Data Model to a new version
const useNewScaleFormat = groundPlaneUsesNewScaleFormat(scene.sceneConfiguration.updatedAt);

scene.groundPlanes.forEach((groundPlane, index) => {
if (groundPlaneTextures?.[index] === undefined) {
return;
}
const texture = groundPlaneTextures[index];
const material = new MeshBasicMaterial({ map: texture, side: DoubleSide });
const geometry = new PlaneGeometry(10000 * groundPlane.scaleX, 10000 * groundPlane.scaleY);

const scaleX = groundPlane.scaleX;
const scaleY = useNewScaleFormat ? groundPlane.scaleZ : groundPlane.scaleY;

const geometry = new PlaneGeometry(
groundPlaneScaleFactor * scaleX,
groundPlaneScaleFactor * scaleY
);

geometry.name = `CogniteGroundPlane`;

Expand Down Expand Up @@ -121,4 +134,16 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s
clear(groundMeshes);
};
}, [groundPlaneTextures]);

function groundPlaneUsesNewScaleFormat(lastUpdatedAt: string | undefined): boolean {
if (lastUpdatedAt === undefined) {
return false;
}

const dateModified = new Date(lastUpdatedAt);

const groundPlaneScaleFormatChangedDate = new Date('2024-08-01T10:44:00.000Z');

return dateModified > groundPlaneScaleFormatChangedDate;
}
};

0 comments on commit f860ce1

Please sign in to comment.