From dea94454fbf4ec26e67098d48157d32de1839015 Mon Sep 17 00:00:00 2001 From: anders-hopland Date: Fri, 6 Sep 2024 11:10:57 +0200 Subject: [PATCH 1/2] Fixes bug where ground plane scale is stored as xz instead of xy --- .../components/SceneContainer/sceneTypes.ts | 1 + react-components/src/hooks/scenes/types.ts | 4 ++- .../src/hooks/scenes/useSceneConfig.ts | 3 ++- .../src/hooks/useGroundPlaneFromScene.tsx | 25 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/react-components/src/components/SceneContainer/sceneTypes.ts b/react-components/src/components/SceneContainer/sceneTypes.ts index 743eb206ba6..1064c0b05d3 100644 --- a/react-components/src/components/SceneContainer/sceneTypes.ts +++ b/react-components/src/components/SceneContainer/sceneTypes.ts @@ -23,6 +23,7 @@ export type SceneConfiguration = { cameraTargetX?: number; cameraTargetY?: number; cameraTargetZ?: number; + updatedAt?: string; }; export type CadOrPointCloudModel = Transformation3d & { diff --git a/react-components/src/hooks/scenes/types.ts b/react-components/src/hooks/scenes/types.ts index 0395b06acdb..cdb306fddba 100644 --- a/react-components/src/hooks/scenes/types.ts +++ b/react-components/src/hooks/scenes/types.ts @@ -32,6 +32,7 @@ export type SceneConfigurationProperties = { cameraTargetX?: number; cameraTargetY?: number; cameraTargetZ?: number; + updatedAt?: string; }; export type SkyboxProperties = { @@ -137,7 +138,8 @@ export const sceneSourceWithProperties = [ 'cameraEulerRotationZ', 'cameraTargetX', 'cameraTargetY', - 'cameraTargetZ' + 'cameraTargetZ', + 'updatedAt' ] } ] as const satisfies SourceSelectorV3; diff --git a/react-components/src/hooks/scenes/useSceneConfig.ts b/react-components/src/hooks/scenes/useSceneConfig.ts index c0a8df03670..b32554f77ee 100644 --- a/react-components/src/hooks/scenes/useSceneConfig.ts +++ b/react-components/src/hooks/scenes/useSceneConfig.ts @@ -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), diff --git a/react-components/src/hooks/useGroundPlaneFromScene.tsx b/react-components/src/hooks/useGroundPlaneFromScene.tsx index a5a4b3cb78a..28bd760b9e1 100644 --- a/react-components/src/hooks/useGroundPlaneFromScene.tsx +++ b/react-components/src/hooks/useGroundPlaneFromScene.tsx @@ -77,13 +77,24 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s } 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 groundPlaneUsesNewScaleFormat = groundPlaneUseNewScaleFormat( + 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 = groundPlaneUsesNewScaleFormat ? groundPlane.scaleZ : groundPlane.scaleY; + + const geometry = new PlaneGeometry(10000 * scaleX, 10000 * scaleY); geometry.name = `CogniteGroundPlane`; @@ -121,4 +132,16 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s clear(groundMeshes); }; }, [groundPlaneTextures]); + + function groundPlaneUseNewScaleFormat(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; + } }; From 60db811605eb91e774af44c191d6ef66cd0ecedd Mon Sep 17 00:00:00 2001 From: anders-hopland Date: Fri, 6 Sep 2024 11:28:30 +0200 Subject: [PATCH 2/2] Make amends --- .../src/hooks/useGroundPlaneFromScene.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/react-components/src/hooks/useGroundPlaneFromScene.tsx b/react-components/src/hooks/useGroundPlaneFromScene.tsx index 28bd760b9e1..8ca690cee09 100644 --- a/react-components/src/hooks/useGroundPlaneFromScene.tsx +++ b/react-components/src/hooks/useGroundPlaneFromScene.tsx @@ -75,14 +75,13 @@ 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 groundPlaneUsesNewScaleFormat = groundPlaneUseNewScaleFormat( - scene.sceneConfiguration.updatedAt - ); + const useNewScaleFormat = groundPlaneUsesNewScaleFormat(scene.sceneConfiguration.updatedAt); scene.groundPlanes.forEach((groundPlane, index) => { if (groundPlaneTextures?.[index] === undefined) { @@ -92,9 +91,12 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s const material = new MeshBasicMaterial({ map: texture, side: DoubleSide }); const scaleX = groundPlane.scaleX; - const scaleY = groundPlaneUsesNewScaleFormat ? groundPlane.scaleZ : groundPlane.scaleY; + const scaleY = useNewScaleFormat ? groundPlane.scaleZ : groundPlane.scaleY; - const geometry = new PlaneGeometry(10000 * scaleX, 10000 * scaleY); + const geometry = new PlaneGeometry( + groundPlaneScaleFactor * scaleX, + groundPlaneScaleFactor * scaleY + ); geometry.name = `CogniteGroundPlane`; @@ -133,7 +135,7 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s }; }, [groundPlaneTextures]); - function groundPlaneUseNewScaleFormat(lastUpdatedAt: string | undefined): boolean { + function groundPlaneUsesNewScaleFormat(lastUpdatedAt: string | undefined): boolean { if (lastUpdatedAt === undefined) { return false; }