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

Measurements Units Fixes #3741

Merged
merged 4 commits into from
Dec 20, 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
6 changes: 2 additions & 4 deletions packages/frontend-2/components/viewer/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@
</div>
<div
ref="scrollableControlsContainer"
:class="`simple-scrollbar absolute z-10 pl-12 pr-2 md:pr-0 md:pl-14 mb-4 max-h-[calc(100dvh-4.5rem)] overflow-y-auto px-[2px] py-[2px] transition ${
activePanel !== 'none'
? 'translate-x-0 opacity-100'
: '-translate-x-[100%] opacity-0'
:class="`simple-scrollbar absolute z-10 pl-12 pr-2 md:pr-0 md:pl-14 mb-4 max-h-[calc(100dvh-4.5rem)] overflow-y-auto px-[2px] py-[2px] ${
activePanel !== 'none' ? 'opacity-100' : 'opacity-0'
} ${isEmbedEnabled ? 'mt-1.5' : 'mt-[3.7rem]'}`"
:style="`width: ${isMobile ? '100%' : `${width + 4}px`};`"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class Measurement extends Object3D {
this.renderingSize.copy(size)
}

public abstract update(): void
public abstract update(): Promise<void>
public abstract raycast(_raycaster: Raycaster, _intersects: Array<Intersection>): void
public abstract highlight(_value: boolean): void
public abstract updateClippingPlanes(_planes: Plane[]): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { SpeckleText } from '../../objects/SpeckleText.js'
import SpeckleTextMaterial from '../../materials/SpeckleTextMaterial.js'
import SpeckleBasicMaterial from '../../materials/SpeckleBasicMaterial.js'
import { ObjectLayers } from '../../../IViewer.js'
import Logger from '../../utils/Logger.js'

export interface MeasurementPointGizmoStyle {
fixedSize?: number | boolean
Expand Down Expand Up @@ -325,8 +326,8 @@ export class MeasurementPointGizmo extends Group {
position?: Vector3,
quaternion?: Quaternion,
scale?: Vector3
) {
void this.text
): Promise<void> {
return this.text
.update({
textValue: value,
height: 1,
Expand All @@ -343,6 +344,9 @@ export class MeasurementPointGizmo extends Group {
if (this.text.backgroundMesh) this.text.backgroundMesh.renderOrder = 3
this.text.textMesh.renderOrder = 4
})
.catch((reason) => {
Logger.log(`Could not update text: ${reason}`)
})
}

public updateStyle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MeasurementsExtension extends Extension {
this._enabled = value
if (this._activeMeasurement) {
this._activeMeasurement.isVisible = value
this._activeMeasurement.update()
void this._activeMeasurement.update()
if (!value) this.cancelMeasurement()
}
this.viewer.requestRender()
Expand Down Expand Up @@ -180,9 +180,10 @@ export class MeasurementsExtension extends Extension {
this._activeMeasurement.endPoint.copy(this.pointBuff)
this._activeMeasurement.endNormal.copy(this.normalBuff)
}
this._activeMeasurement.update()
void this._activeMeasurement.update().then(() => {
this.viewer.requestRender()
})

this.viewer.requestRender()
this._frameLock = true
this._sceneHit = true
// console.log('Time -> ', performance.now() - start)
Expand Down Expand Up @@ -282,8 +283,9 @@ export class MeasurementsExtension extends Extension {
this._activeMeasurement.endPoint.copy(perpResult[0].point)
this._activeMeasurement.endNormal.copy(perpResult[0].face.normal)
this._activeMeasurement.state = MeasurementState.DANGLING_END
this._activeMeasurement.update()
this.finishMeasurement()
void this._activeMeasurement.update().then(() => {
this.finishMeasurement()
})
}

protected startMeasurement(): Measurement {
Expand All @@ -295,12 +297,21 @@ export class MeasurementsExtension extends Extension {
else throw new Error('Unsupported measurement type!')

measurement.state = MeasurementState.DANGLING_START
measurement.units =
this._options.units !== undefined
? this._options.units
: DefaultMeasurementsOptions.units
measurement.precision =
this._options.precision !== undefined
? this._options.precision
: DefaultMeasurementsOptions.precision
measurement.frameUpdate(
this.renderer.renderingCamera,
this.screenBuff0,
this.renderer.sceneBox
)
this.renderer.scene.add(measurement)

return measurement
}

Expand All @@ -314,7 +325,7 @@ export class MeasurementsExtension extends Extension {
if (!this._activeMeasurement) return

this._activeMeasurement.state = MeasurementState.COMPLETE
this._activeMeasurement.update()
void this._activeMeasurement.update()
if (this._activeMeasurement.value > 0) {
this.measurements.push(this._activeMeasurement)
} else {
Expand Down Expand Up @@ -421,6 +432,7 @@ export class MeasurementsExtension extends Extension {

protected applyOptions() {
const all = [this._activeMeasurement, ...this.measurements]
const updatePromises: Promise<void>[] = []
all.forEach((value) => {
if (value) {
value.units =
Expand All @@ -431,7 +443,7 @@ export class MeasurementsExtension extends Extension {
this._options.precision !== undefined
? this._options.precision
: DefaultMeasurementsOptions.precision
value.update()
updatePromises.push(value.update())
}
})
this.viewer
Expand All @@ -440,18 +452,19 @@ export class MeasurementsExtension extends Extension {

if (this._options.visible) this.raycaster.layers.enable(ObjectLayers.MEASUREMENTS)
else this.raycaster.layers.disable(ObjectLayers.MEASUREMENTS)

this.viewer.requestRender()
void Promise.all(updatePromises).then(() => {
this.viewer.requestRender()
})
}

public fromMeasurementData(startPoint: Vector3, endPoint: Vector3) {
public async fromMeasurementData(startPoint: Vector3, endPoint: Vector3) {
const measurement = new PointToPointMeasurement()
measurement.startPoint.copy(startPoint)
measurement.endPoint.copy(endPoint)
measurement.state = MeasurementState.DANGLING_END
measurement.update()
await measurement.update()
measurement.state = MeasurementState.COMPLETE
measurement.update()
await measurement.update()
this.measurements.push(measurement)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export class PerpendicularMeasurement extends Measurement {
* won't look correct while zooming
*/
if (this._state === MeasurementState.DANGLING_START) {
this.update()
void this.update()
}
}

public update() {
if (isNaN(this.startPoint.length())) return
if (!this.renderingCamera) return
public update(): Promise<void> {
let ret = Promise.resolve()

if (isNaN(this.startPoint.length())) return ret
if (!this.renderingCamera) return ret

this.startGizmo?.updateDisc(this.startPoint, this.startNormal)
this.startGizmo?.updatePoint(this.startPoint)
Expand Down Expand Up @@ -180,23 +182,27 @@ export class PerpendicularMeasurement extends Measurement {
)

this.value = this.midPoint.distanceTo(this.startPoint)
this.startGizmo?.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`,
textPos
)
if (this.startGizmo)
ret = this.startGizmo.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`,
textPos
)
this.endGizmo?.enable(true, true, true, true)
}
if (this._state === MeasurementState.COMPLETE) {
this.startGizmo?.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`
)
if (this.startGizmo)
ret = this.startGizmo.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`
)
this.startGizmo?.enable(false, true, true, true)
this.endGizmo?.enable(false, false, true, false)
}

return ret
}

public raycast(raycaster: Raycaster, intersects: Array<Intersection>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class PointToPointMeasurement extends Measurement {
this.endGizmo?.frameUpdate(camera, bounds)
}

public update() {
public update(): Promise<void> {
let ret: Promise<void> = Promise.resolve()
this.startGizmo?.updateDisc(this.startPoint, this.startNormal)
this.startGizmo?.updatePoint(this.startPoint)
this.endGizmo?.updateDisc(this.endPoint, this.endNormal)
Expand Down Expand Up @@ -71,23 +72,26 @@ export class PointToPointMeasurement extends Measurement {

this.startGizmo?.updateLine([this.startPoint, lineEndPoint])
this.endGizmo?.updatePoint(lineEndPoint)
this.startGizmo?.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`,
textPos
)
if (this.startGizmo)
ret = this.startGizmo.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`,
textPos
)
this.endGizmo?.enable(true, true, true, true)
}
if (this._state === MeasurementState.COMPLETE) {
this.startGizmo?.enable(false, true, true, true)
this.endGizmo?.enable(false, false, true, false)
this.startGizmo?.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`
)
if (this.startGizmo)
ret = this.startGizmo.updateText(
`${(this.value * getConversionFactor('m', this.units)).toFixed(
this.precision
)} ${this.units}`
)
}
return ret
}

public raycast(raycaster: Raycaster, intersects: Array<Intersection>) {
Expand Down
Loading