Skip to content
Draft
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
4 changes: 2 additions & 2 deletions packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
Viewer,
ViewModes,
SelectionExtension,
HybridCameraController
HybridCameraController,
BoxSelection
} from '@speckle/viewer'

import './style.css'
Expand All @@ -20,7 +21,6 @@ import {
import { SectionTool } from '@speckle/viewer'
import { SectionOutlines } from '@speckle/viewer'
import { ViewModesKeys } from './Extensions/ViewModesKeys'
import { BoxSelection } from './Extensions/BoxSelection'
import { PassReader } from './Extensions/PassReader'

const createViewer = async (containerName: string, _stream: string) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ import {
EdgesPass,
EdgesPassOptions
} from './modules/pipeline/Passes/EdgesPass.js'
import { BoxSelection } from './modules/extensions/BoxSelection.js'

export {
Viewer,
Expand Down Expand Up @@ -188,6 +189,7 @@ export {
CameraEvent,
ExplodeExtension,
DiffExtension,
BoxSelection,
Loader,
SpeckleConverter,
GeometryConverter,
Expand Down
3 changes: 3 additions & 0 deletions packages/viewer/src/modules/LegacyViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SpeckleLoader } from './loaders/Speckle/SpeckleLoader.js'
import Logger from './utils/Logger.js'
import { ViewModes } from './extensions/ViewModes.js'
import { HybridCameraController } from './extensions/HybridCameraController.js'
import { BoxSelection } from './extensions/BoxSelection.js'

class LegacySelectionExtension extends SelectionExtension {
/** FE2 'manually' selects objects pon it's own, so we're disabling the extension's event handler
Expand Down Expand Up @@ -132,6 +133,8 @@ export class LegacyViewer extends Viewer {
this.diffExtension = this.createExtension(DiffExtension)
this.highlightExtension = this.createExtension(HighlightExtension)
this.createExtension(ViewModes)
const boxSelect = this.createExtension(BoxSelection)
boxSelect.realtimeSelection = false
}

public async init(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { CONTAINED, InputEvent } from '@speckle/viewer'
import { ObjectLayers } from '@speckle/viewer'
import { SelectionExtension } from '@speckle/viewer'
Expand Down Expand Up @@ -26,6 +25,7 @@ export class BoxSelection extends Extension {

private dragging = false
private frameLock = false
private shiftDown = false
private _realTimeSelection = true

private idsToSelect: Set<string> | null = new Set()
Expand All @@ -44,7 +44,6 @@ export class BoxSelection extends Extension {
public constructor(viewer: IViewer, private cameraController: CameraController) {
super(viewer)
/** Get the SelectionExtension. We'll need it to remotely enable/disable it */
//@ts-ignore
this.selectionExtension = this.viewer.getExtension(SelectionExtension)

/** Create the drag box */
Expand All @@ -59,12 +58,13 @@ export class BoxSelection extends Extension {
public onEarlyUpdate() {
if (this.idsToSelect?.size) {
/** Send the ids to the selection extension to be selected */
this.selectionExtension.clearSelection()
if (!this.shiftDown) this.selectionExtension.clearSelection()
this.selectionExtension.selectObjects(Array.from(this.idsToSelect), true)
this.idsToSelect = null
this.viewer.requestRender()
}
this.frameLock = false
this.shiftDown = false
}
private onPointerDown(e: Vector2 & { event: PointerEvent }) {
if (e.event.altKey) {
Expand All @@ -88,6 +88,7 @@ export class BoxSelection extends Extension {
if (!this._realTimeSelection && e.event.altKey) {
/** Get the ids of objects that fall withing the selection box */
this.idsToSelect = this.getSelectionIds(this.ndcBox)
this.shiftDown = e.event.shiftKey
}

this.ndcBox.makeEmpty()
Expand All @@ -104,7 +105,7 @@ export class BoxSelection extends Extension {
const ndcTransform = this.getNDCTransform(this.ndcFrom, this.ndcTo)

/** Update the selection box visual */
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access

this.dragBoxMaterial.uniforms.transform.value.copy(ndcTransform)
this.dragBoxMaterial.needsUpdate = true

Expand Down