Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-components): Add ground plane rotation 0.52.0 #4638

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal-react-components",
"version": "0.51.0",
"version": "0.52.0",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
15 changes: 7 additions & 8 deletions react-components/src/hooks/useGroundPlaneFromScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useSDK } from '../components/RevealCanvas/SDKProvider';
import { CDF_TO_VIEWER_TRANSFORMATION, CustomObject } from '@cognite/reveal';
import { useReveal } from '../components/RevealCanvas/ViewerContext';
import { clear } from '../architecture/base/utilities/extensions/arrayExtensions';
import { transformation3dToMatrix4 } from '../utilities/transformation3dToMatrix4';

export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: string): void => {
const { data: scene } = useSceneConfig(sceneExternalId, sceneSpaceId);
Expand Down Expand Up @@ -83,19 +84,17 @@ export const useGroundPlaneFromScene = (sceneExternalId: string, sceneSpaceId: s
}
const texture = groundPlaneTextures[index];
const material = new MeshBasicMaterial({ map: texture, side: DoubleSide });
const geometry = new PlaneGeometry(10000 * groundPlane.scaleX, 10000 * groundPlane.scaleY);
const geometry = new PlaneGeometry(10000, 10000);

geometry.name = `CogniteGroundPlane`;

const mesh = new Mesh(geometry, material);
mesh.position.set(
groundPlane.translationX,
groundPlane.translationY,
groundPlane.translationZ
);
mesh.rotation.set(-Math.PI / 2, 0, 0);

mesh.position.applyMatrix4(CDF_TO_VIEWER_TRANSFORMATION);
const matrix4 = transformation3dToMatrix4(groundPlane).premultiply(
CDF_TO_VIEWER_TRANSFORMATION
);
mesh.matrix.copy(matrix4);
mesh.matrixAutoUpdate = false;

const customObject = new CustomObject(mesh);
customObject.isPartOfBoundingBox = false;
Expand Down
33 changes: 33 additions & 0 deletions react-components/src/utilities/transformation3dToMatrix4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* Copyright 2024 Cognite AS
*/

import { Euler, MathUtils, Matrix4, Quaternion, Vector3 } from 'three';
import { type Transformation3d } from '../hooks/types';

export const transformation3dToMatrix4 = ({
translationX,
translationY,
translationZ,
eulerRotationX,
eulerRotationY,
eulerRotationZ,
scaleX,
scaleY,
scaleZ
}: Transformation3d): Matrix4 => {
const quaternion = new Quaternion().setFromEuler(
new Euler(
MathUtils.degToRad(eulerRotationX),
MathUtils.degToRad(eulerRotationY),
MathUtils.degToRad(eulerRotationZ),
'XYZ'
)
);

return new Matrix4().compose(
new Vector3(translationX, translationY, translationZ),
quaternion,
new Vector3(scaleX, scaleY, scaleZ)
);
};
Loading