Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 5b89bd2

Browse files
Fixed the model working in case there are no device measurements configured.
1 parent 7d56faf commit 5b89bd2

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dist\\bundle-src\\custom-widget.js": "3d-model-viewer-widget-CustomWidget",
55
"dist/bundle-src/custom-widget.js": "3d-model-viewer-widget-CustomWidget"
66
},
7-
"version": "1.0.0",
7+
"version": "1.0.1",
88
"description": "",
99
"main": "index.js",
1010
"scripts": {

src/model-viewer-widget/model-viewer-widget-config.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import { Component, Input, OnInit } from '@angular/core';
20+
import { jsonpFactory } from '@angular/http/src/http_module';
2021
import { IResult, IFetchOptions } from '@c8y/client/lib/src/core';
2122
import { IManagedObjectBinary } from '@c8y/client/lib/src/inventory';
2223
import { FetchClient, InventoryBinaryService } from '@c8y/ngx-components/api';

src/model-viewer-widget/model-viewer-widget.component.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class ModelViewerWidget implements OnInit {
5050
private group;
5151
private kinematics;
5252

53+
private hasDeviceMeasurements: boolean = false;
54+
5355
// constructor()
5456
constructor(private fetchClient: FetchClient, private realtimeService: Realtime) {
5557
this.modelContainerId = 'model-container-'+Date.now();
@@ -90,6 +92,8 @@ export class ModelViewerWidget implements OnInit {
9092
for(let i=0; i<this.config.customwidgetdata.variables.length; i++) {
9193
if(this.config.customwidgetdata.variables[i].target === 'none') {
9294
this.mathScope[this.config.customwidgetdata.variables[i].name] = this.config.customwidgetdata.variables[i].value;
95+
} else {
96+
this.hasDeviceMeasurements = true;
9397
}
9498
}
9599
}
@@ -148,6 +152,7 @@ export class ModelViewerWidget implements OnInit {
148152
modelContainer.appendChild(this.renderer.domElement);
149153
let me = this;
150154
loader.load(modelUrl, function(collada) {
155+
151156
const modelScene = collada.scene;
152157
me.group = new THREE.Group();
153158
me.group.add(modelScene);
@@ -171,18 +176,24 @@ export class ModelViewerWidget implements OnInit {
171176
this.mixer.clipAction(animations[0]).play();
172177
}
173178
me.scene.add(me.group);
174-
179+
175180
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+
}
176195
});
177196
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-
}
186197
}
187198

188199
private animate(): void {

0 commit comments

Comments
 (0)