diff --git a/packages/frontend-2/components/viewer/Controls.vue b/packages/frontend-2/components/viewer/Controls.vue
index 4e483ae3ee..924509d71d 100644
--- a/packages/frontend-2/components/viewer/Controls.vue
+++ b/packages/frontend-2/components/viewer/Controls.vue
@@ -183,10 +183,8 @@
diff --git a/packages/viewer/src/modules/extensions/measurements/Measurement.ts b/packages/viewer/src/modules/extensions/measurements/Measurement.ts
index a4591561ea..25090de7d7 100644
--- a/packages/viewer/src/modules/extensions/measurements/Measurement.ts
+++ b/packages/viewer/src/modules/extensions/measurements/Measurement.ts
@@ -61,7 +61,7 @@ export abstract class Measurement extends Object3D {
this.renderingSize.copy(size)
}
- public abstract update(): void
+ public abstract update(): Promise
public abstract raycast(_raycaster: Raycaster, _intersects: Array): void
public abstract highlight(_value: boolean): void
public abstract updateClippingPlanes(_planes: Plane[]): void
diff --git a/packages/viewer/src/modules/extensions/measurements/MeasurementPointGizmo.ts b/packages/viewer/src/modules/extensions/measurements/MeasurementPointGizmo.ts
index 3b7667b8f7..a77d3902a1 100644
--- a/packages/viewer/src/modules/extensions/measurements/MeasurementPointGizmo.ts
+++ b/packages/viewer/src/modules/extensions/measurements/MeasurementPointGizmo.ts
@@ -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
@@ -325,8 +326,8 @@ export class MeasurementPointGizmo extends Group {
position?: Vector3,
quaternion?: Quaternion,
scale?: Vector3
- ) {
- void this.text
+ ): Promise {
+ return this.text
.update({
textValue: value,
height: 1,
@@ -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() {
diff --git a/packages/viewer/src/modules/extensions/measurements/MeasurementsExtension.ts b/packages/viewer/src/modules/extensions/measurements/MeasurementsExtension.ts
index 36480f7ec9..efa527b09e 100644
--- a/packages/viewer/src/modules/extensions/measurements/MeasurementsExtension.ts
+++ b/packages/viewer/src/modules/extensions/measurements/MeasurementsExtension.ts
@@ -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()
@@ -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)
@@ -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 {
@@ -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
}
@@ -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 {
@@ -421,6 +432,7 @@ export class MeasurementsExtension extends Extension {
protected applyOptions() {
const all = [this._activeMeasurement, ...this.measurements]
+ const updatePromises: Promise[] = []
all.forEach((value) => {
if (value) {
value.units =
@@ -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
@@ -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)
}
}
diff --git a/packages/viewer/src/modules/extensions/measurements/PerpendicularMeasurement.ts b/packages/viewer/src/modules/extensions/measurements/PerpendicularMeasurement.ts
index a5ba0ccfe5..e0894bef22 100644
--- a/packages/viewer/src/modules/extensions/measurements/PerpendicularMeasurement.ts
+++ b/packages/viewer/src/modules/extensions/measurements/PerpendicularMeasurement.ts
@@ -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 {
+ 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)
@@ -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) {
diff --git a/packages/viewer/src/modules/extensions/measurements/PointToPointMeasurement.ts b/packages/viewer/src/modules/extensions/measurements/PointToPointMeasurement.ts
index 25ead25838..f61066768f 100644
--- a/packages/viewer/src/modules/extensions/measurements/PointToPointMeasurement.ts
+++ b/packages/viewer/src/modules/extensions/measurements/PointToPointMeasurement.ts
@@ -30,7 +30,8 @@ export class PointToPointMeasurement extends Measurement {
this.endGizmo?.frameUpdate(camera, bounds)
}
- public update() {
+ public update(): Promise {
+ let ret: Promise = Promise.resolve()
this.startGizmo?.updateDisc(this.startPoint, this.startNormal)
this.startGizmo?.updatePoint(this.startPoint)
this.endGizmo?.updateDisc(this.endPoint, this.endNormal)
@@ -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) {