@@ -50,6 +50,8 @@ export class ModelViewerWidget implements OnInit {
50
50
private group ;
51
51
private kinematics ;
52
52
53
+ private hasDeviceMeasurements : boolean = false ;
54
+
53
55
// constructor()
54
56
constructor ( private fetchClient : FetchClient , private realtimeService : Realtime ) {
55
57
this . modelContainerId = 'model-container-' + Date . now ( ) ;
@@ -90,6 +92,8 @@ export class ModelViewerWidget implements OnInit {
90
92
for ( let i = 0 ; i < this . config . customwidgetdata . variables . length ; i ++ ) {
91
93
if ( this . config . customwidgetdata . variables [ i ] . target === 'none' ) {
92
94
this . mathScope [ this . config . customwidgetdata . variables [ i ] . name ] = this . config . customwidgetdata . variables [ i ] . value ;
95
+ } else {
96
+ this . hasDeviceMeasurements = true ;
93
97
}
94
98
}
95
99
}
@@ -148,6 +152,7 @@ export class ModelViewerWidget implements OnInit {
148
152
modelContainer . appendChild ( this . renderer . domElement ) ;
149
153
let me = this ;
150
154
loader . load ( modelUrl , function ( collada ) {
155
+
151
156
const modelScene = collada . scene ;
152
157
me . group = new THREE . Group ( ) ;
153
158
me . group . add ( modelScene ) ;
@@ -171,18 +176,24 @@ export class ModelViewerWidget implements OnInit {
171
176
this . mixer . clipAction ( animations [ 0 ] ) . play ( ) ;
172
177
}
173
178
me . scene . add ( me . group ) ;
174
-
179
+
175
180
me . kinematics = collada . kinematics ;
181
+
182
+ if ( me . deviceId !== '' ) {
183
+
184
+ // only evaluates before subscriptions if there are no device measurements specific variables are defined
185
+ if ( ! me . hasDeviceMeasurements ) {
186
+ me . evaluateProperties ( ) ;
187
+ }
188
+
189
+ // Subscribe to realtime measurments
190
+ me . realtimeService . subscribe ( '/measurements/' + me . deviceId , ( data ) => {
191
+ me . setMathScope ( data . data . data ) ;
192
+ me . evaluateProperties ( ) ;
193
+ } ) ;
194
+ }
176
195
} ) ;
177
196
this . animate ( ) ;
178
-
179
- if ( this . deviceId !== '' ) {
180
- // Subscribe to realtime measurments
181
- this . realtimeService . subscribe ( '/measurements/' + this . deviceId , ( data ) => {
182
- this . setMathScope ( data . data . data ) ;
183
- this . evaluateProperties ( ) ;
184
- } ) ;
185
- }
186
197
}
187
198
188
199
private animate ( ) : void {
0 commit comments