Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/examples/ws-8.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
christjt authored Jun 19, 2024
2 parents d793bc1 + 2c9fa9d commit 35cb24f
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 28 deletions.
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.49.1",
"version": "0.50.0",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class ApplyClipCommand extends RenderTargetCommand {
return 'Crop';
}

public override get buttonType(): string {
return 'primary';
}

public override get isEnabled(): boolean {
if (this.getSelectedCropBoxDomainObject() !== undefined) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PrimitiveType } from '../primitives/PrimitiveType';
import { BoxCreator } from '../primitives/box/BoxCreator';
import { LineCreator } from '../primitives/line/LineCreator';
import { type VisualDomainObject } from '../../base/domainObjects/VisualDomainObject';
import { CDF_TO_VIEWER_TRANSFORMATION } from '@cognite/reveal';

export class MeasurementTool extends PrimitiveEditTool {
// ==================================================
Expand Down Expand Up @@ -57,7 +58,28 @@ export class MeasurementTool extends PrimitiveEditTool {

public override onActivate(): void {
super.onActivate();
this.setAllVisible(true);

if (!this.renderTarget.isGlobalClippingActive) {
this.setAllVisible(true);
return;
}
const sceneBoundingBox = this.renderTarget.clippedSceneBoundingBox;
for (const domainObject of this.getSelectable()) {
if (domainObject instanceof MeasureBoxDomainObject) {
const boundingBox = domainObject.getBoundingBox();
boundingBox.applyMatrix4(CDF_TO_VIEWER_TRANSFORMATION);
if (!sceneBoundingBox.intersectsBox(boundingBox)) {
continue;
}
} else if (domainObject instanceof MeasureLineDomainObject) {
const boundingBox = domainObject.getBoundingBox();
boundingBox.applyMatrix4(CDF_TO_VIEWER_TRANSFORMATION);
if (!sceneBoundingBox.intersectsBox(boundingBox)) {
continue;
}
}
domainObject.setVisibleInteractive(true, this.renderTarget);
}
}

public override onDeactivate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { type RenderStyle } from '../../../base/renderStyles/RenderStyle';
import { type ThreeView } from '../../../base/views/ThreeView';
import { LineView } from './LineView';
import { Vector3 } from 'three';
import { Box3, Vector3 } from 'three';
import { PrimitiveType } from '../PrimitiveType';
import { LineRenderStyle } from './LineRenderStyle';
import {
Expand Down Expand Up @@ -197,6 +197,14 @@ export abstract class LineDomainObject extends VisualDomainObject {
return Math.abs(sum) / 2;
}

public getBoundingBox(): Box3 {
const boundingBox = new Box3().makeEmpty();
for (const point of this.points) {
boundingBox.expandByPoint(point);
}
return boundingBox;
}

public setFocusInteractive(focusType: FocusType): boolean {
if (this.focusType === focusType) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const CommandButton = ({
const { key, fallback } = newCommand.tooltip;
// This was the only way it went through compiler: (more button types will be added in the future)
const type = newCommand.buttonType;
if (type !== 'ghost' && type !== 'ghost-destructive') {
if (type !== 'ghost' && type !== 'ghost-destructive' && type !== 'primary') {
return <></>;
}
const text = key === undefined ? fallback : t(key, fallback);
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal",
"version": "4.14.7",
"version": "4.14.8",
"description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.",
"homepage": "https://github.com/cognitedata/reveal/tree/master/viewer",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export class FlexibleCameraManager extends PointerEvents implements IFlexibleCam
this.updateControlsSensitivity(modelBoundingBox);
}

public get options(): FlexibleControlsOptions {
return this._controls.options;
}

//================================================
// OVERRIDES of PointerEvents
//================================================
Expand Down Expand Up @@ -293,10 +297,6 @@ export class FlexibleCameraManager extends PointerEvents implements IFlexibleCam
// INSTANCE METHODS: Setters and getters
//================================================

public get options(): FlexibleControlsOptions {
return this._controls.options;
}

public get controls(): FlexibleControls {
return this._controls;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ export class FlexibleControls {
if (!this.isStationary) {
this.setControlsType(FlexibleControlsType.FirstPerson);
}
const speedFactor = this._keyboard.isShiftPressed() ? this._options.keyboardFastMoveFactor : 1;
const speedXY = timeScale * speedFactor * this._options.keyboardPanSpeed;
const speedZ = timeScale * speedFactor * this._options.keyboardDollySpeed;
const keyboardSpeed = this._options.getKeyboardSpeed(this._keyboard.isShiftPressed());
const speedXY = timeScale * keyboardSpeed * this._options.keyboardPanSpeed;
const speedZ = timeScale * keyboardSpeed * this._options.keyboardDollySpeed;

this.pan(speedXY * deltaX, speedXY * deltaY, speedZ * deltaZ, true);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export class FlexibleControlsOptions {
// INSTANCE FIELDS
//================================================

// Main behaivor
// Main behavior
public controlsType = FlexibleControlsType.Orbit;

// Mouse click, double click and wheel behaivor
// Mouse click, double click and wheel behavior
public mouseWheelAction = FlexibleWheelZoomType.Auto;
public mouseClickType = FlexibleMouseActionType.SetTarget;
public mouseDoubleClickType = FlexibleMouseActionType.SetTargetAndCameraPosition;
Expand All @@ -41,7 +41,7 @@ export class FlexibleControlsOptions {
public minAzimuthAngle = -Infinity;
public maxAzimuthAngle = Infinity;

// Dampning
// Damping
public enableDamping = true;
public dampingFactor = 0.25;

Expand Down Expand Up @@ -72,6 +72,7 @@ export class FlexibleControlsOptions {
public mouseDollySpeed = 100;

// Keyboard speed for dolly and pan
public keyboardSpeed = 1;
public keyboardPanSpeed = 100;
public keyboardDollySpeed = 200;
public keyboardFastMoveFactor = 5;
Expand Down Expand Up @@ -117,6 +118,13 @@ export class FlexibleControlsOptions {
}
}

public getKeyboardSpeed(shift: boolean): number {
if (!shift) {
return this.keyboardSpeed;
}
return this.keyboardFastMoveFactor * this.keyboardSpeed;
}

//================================================
// INSTANCE METHODS: Getters
//================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { CameraManager } from '../CameraManager';
import { FlexibleControlsOptions } from './FlexibleControlsOptions';
import { FlexibleControlsType } from './FlexibleControlsType';
import { Vector3 } from 'three';

Expand All @@ -12,23 +13,29 @@ import { Vector3 } from 'three';
export type FlexibleControlsTypeChangeDelegate = (controlsType: FlexibleControlsType) => void;

/**
* Flexible implementation of {@link CameraManager}. The user can switch between Orbit, FirstPersion or OrbitInCenter
* Flexible implementation of {@link CameraManager}. The user can switch between Orbit, FirstPerson or OrbitInCenter
* Supports automatic update of camera near and far planes and animated change of camera position and target.
* It provides additional functionality for controlling camera behavior and rotation.
* @beta
*/

export interface IFlexibleCameraManager extends CameraManager {
/**
* Get curent FlexibleControlsType type
* Get current FlexibleControlsType type
*/
get controlsType(): FlexibleControlsType;

/**
* Set curent FlexibleControlsType type
* Set current FlexibleControlsType type
*/
set controlsType(value: FlexibleControlsType);

/**
* Set the options for the camera manager
* @beta
*/
get options(): FlexibleControlsOptions;

/**
* Rotates the camera to look in the specified direction.
* Supports automatic update of camera near and far planes and animated change of camera position and target.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

import { CompositeShape } from '@reveal/utilities';

import { applyDefaultModelTransformation } from '../utilities/applyDefaultModelTransformation';
import { PointCloudObject, CdfPointCloudObjectAnnotation } from './types';
import { StylableObject } from './StylableObject';

import { Matrix4 } from 'three';
import { File3dFormat } from '../types';

function cdfAnnotationsToPointCloudObjects(cdfAnnotations: CdfPointCloudObjectAnnotation[]): PointCloudObject[] {
const resultAnnotations = cdfAnnotations.map((cdfAnnotation, index) => {
const shapes = cdfAnnotation.region;
Expand All @@ -21,9 +17,6 @@ function cdfAnnotationsToPointCloudObjects(cdfAnnotations: CdfPointCloudObjectAn
objectId: index + 1
};

const cadFromCdfToThreeMatrix = new Matrix4();
applyDefaultModelTransformation(cadFromCdfToThreeMatrix, File3dFormat.EptPointCloud);

return {
annotationId: cdfAnnotation.annotationId,
assetId: cdfAnnotation.asset?.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void main()
vec3 intersectionPoint = E + dist * D;
float theta = atan(intersectionPoint.y, intersectionPoint.x);
if (theta < v_angle) theta += 2.0 * PI;
if (theta < v_angle) theta += 2.0 * PI;

// Intersection point in camera space
vec3 p = rayTarget + dist * rayDirection;
Expand All @@ -116,7 +117,10 @@ void main()
intersectionPoint = E + dist * D;
theta = atan(intersectionPoint.y, intersectionPoint.x);
p = rayTarget + dist * rayDirection;

if (theta < v_angle) theta += 2.0 * PI;
if (theta < v_angle) theta += 2.0 * PI;

if (intersectionPoint.z <= 0.0 ||
intersectionPoint.z > height ||
theta > v_angle + v_arcAngle ||
Expand Down
5 changes: 5 additions & 0 deletions viewer/reveal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ export class FlexibleControlsOptions {
// (undocumented)
enableKeyboardNavigation: boolean;
// (undocumented)
getKeyboardSpeed(shift: boolean): number;
// (undocumented)
getLegalAzimuthAngle(azimuthAngle: number): number;
// (undocumented)
getLegalFov(fov: number): number;
Expand All @@ -942,6 +944,8 @@ export class FlexibleControlsOptions {
// (undocumented)
keyboardRotationSpeedPolar: number;
// (undocumented)
keyboardSpeed: number;
// (undocumented)
maxAzimuthAngle: number;
// (undocumented)
maximumFov: number;
Expand Down Expand Up @@ -1126,6 +1130,7 @@ export interface IFlexibleCameraManager extends CameraManager {
onPointerDrag(event: PointerEvent, leftButton: boolean): Promise<void>;
onPointerUp(event: PointerEvent, leftButton: boolean): Promise<void>;
onWheel(event: WheelEvent, delta: number): Promise<void>;
get options(): FlexibleControlsOptions;
removeControlsTypeChangeListener(callback: FlexibleControlsTypeChangeDelegate): void;
rotateCameraTo(direction: Vector3, animationDuration: number): void;
}
Expand Down
6 changes: 3 additions & 3 deletions viewer/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35cb24f

Please sign in to comment.