@xeokit/xeokit-sdk 2.5.2-beta-9 → 2.5.2-beta-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.5.2-beta-9",
3
+ "version": "2.5.2-beta-10",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -1,4 +1,5 @@
1
1
  import {utils} from "../../viewer/scene/utils.js";
2
+ import {core} from "../../viewer/scene/core";
2
3
 
3
4
  /**
4
5
  * Default data access strategy for {@link GLTFLoaderPlugin}.
@@ -104,13 +105,13 @@ function loadArraybuffer(glTFSrc, binarySrc, ok, err) {
104
105
  for (var i = 0; i < data.length; i++) {
105
106
  view[i] = data.charCodeAt(i);
106
107
  }
107
- window.setTimeout(function () {
108
+ core.scheduleTask(function () {
108
109
  ok(buffer);
109
- }, 0);
110
+ });
110
111
  } catch (error) {
111
- window.setTimeout(function () {
112
+ core.scheduleTask(function () {
112
113
  err(error);
113
- }, 0);
114
+ });
114
115
  }
115
116
  } else {
116
117
  const basePath = getBasePath(glTFSrc);
@@ -957,14 +957,13 @@ class XKTLoaderPlugin extends Plugin {
957
957
  sceneModel.once("destroyed", () => {
958
958
  this.viewer.metaScene.destroyMetaModel(metaModel.id);
959
959
  });
960
- window.setTimeout(() => {
961
-
960
+ this.scheduleTask(() => {
962
961
  if (sceneModel.destroyed) {
963
962
  return;
964
963
  }
965
964
  sceneModel.scene.fire("modelLoaded", sceneModel.id); // FIXME: Assumes listeners know order of these two events
966
965
  sceneModel.fire("loaded", true, false); // Don't forget the event, for late subscribers
967
- }, 100);
966
+ });
968
967
  }
969
968
 
970
969
  const error = (errMsg) => {
@@ -1042,7 +1041,7 @@ class XKTLoaderPlugin extends Plugin {
1042
1041
  globalizeObjectIds: options.globalizeObjectIds
1043
1042
  });
1044
1043
  i++;
1045
- window.setTimeout( loadNext, 100);
1044
+ this.scheduleTask( loadNext, 100);
1046
1045
  }, error);
1047
1046
  }
1048
1047
  }
@@ -1057,7 +1056,7 @@ class XKTLoaderPlugin extends Plugin {
1057
1056
  this._dataSource.getXKT(`${baseDir}${xktFiles[i]}`, (arrayBuffer) => {
1058
1057
  this._parseModel(arrayBuffer, params, options, sceneModel, metaModel, manifestCtx);
1059
1058
  i++;
1060
- window.setTimeout(loadNext, 100);
1059
+ this.scheduleTask(loadNext, 100);
1061
1060
  }, error);
1062
1061
  }
1063
1062
  }
@@ -1,4 +1,5 @@
1
1
  import {Map} from "./scene/utils/Map.js";
2
+ import {core} from "./scene/core";
2
3
 
3
4
  /**
4
5
  @desc Base class for {@link Viewer} plugin classes.
@@ -38,6 +39,14 @@ class Plugin {
38
39
  viewer.addPlugin(this);
39
40
  }
40
41
 
42
+ /**
43
+ * Schedule a task to perform on the next browser interval
44
+ * @param task
45
+ */
46
+ scheduleTask(task) {
47
+ core.scheduleTask(task, null);
48
+ }
49
+
41
50
  /**
42
51
  * Fires an event on this Plugin.
43
52
  *
@@ -814,6 +814,14 @@ class Component {
814
814
  }
815
815
  }
816
816
 
817
+ /**
818
+ * Schedule a task to perform on the next browser interval
819
+ * @param task
820
+ */
821
+ scheduleTask(task) {
822
+ core.scheduleTask(task, null);
823
+ }
824
+
817
825
  /**
818
826
  * Protected virtual template method, optionally implemented
819
827
  * by sub-classes to perform a scheduled task.
@@ -15,6 +15,7 @@ let lastTime = 0;
15
15
  let elapsedTime;
16
16
  let totalFPS = 0;
17
17
 
18
+
18
19
  /**
19
20
  * @private
20
21
  */
@@ -100,7 +101,7 @@ function Core() {
100
101
  * @param {Function} callback Callback that runs the task.
101
102
  * @param {Object} [scope] Scope for the callback.
102
103
  */
103
- this.scheduleTask = function (callback, scope) {
104
+ this.scheduleTask = function (callback, scope = null) {
104
105
  taskQueue.push(callback);
105
106
  taskQueue.push(scope);
106
107
  };
@@ -154,7 +155,22 @@ const frame = function () {
154
155
  lastTime = time;
155
156
  };
156
157
 
157
- window.setInterval(frame, 1000 / 30);
158
+ class WorkerInterval {
159
+ worker = null;
160
+
161
+ constructor(callback, interval) {
162
+ const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
163
+ const workerScript = URL.createObjectURL(blob);
164
+ this.worker = new Worker(workerScript);
165
+ this.worker.onmessage = callback;
166
+ }
167
+
168
+ stop() {
169
+ this.worker.terminate();
170
+ }
171
+ }
172
+
173
+ const interval = new WorkerInterval(frame, 100);
158
174
 
159
175
  const renderFrame = function () {
160
176
  let time = Date.now();
@@ -1,5 +1,6 @@
1
1
  import {Cache} from './Cache.js';
2
2
  import {Loader} from './Loader.js';
3
+ import {core} from "../core";
3
4
 
4
5
  const loading = {};
5
6
 
@@ -20,7 +21,7 @@ class FileLoader extends Loader {
20
21
  const cached = Cache.get(url);
21
22
  if (cached !== undefined) {
22
23
  this.manager.itemStart(url);
23
- setTimeout(() => {
24
+ core.scheduleTask(() => {
24
25
  if (onLoad) {
25
26
  onLoad(cached);
26
27
  }
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @private
3
3
  */
4
+ import {core} from "./core";
5
+
4
6
  function xmlToJson(node, attributeRenamer) {
5
7
  if (node.nodeType === node.TEXT_NODE) {
6
8
  var v = node.nodeValue;
@@ -206,13 +208,13 @@ function loadArraybuffer(url, ok, err) {
206
208
  for (var i = 0; i < data.length; i++) {
207
209
  view[i] = data.charCodeAt(i);
208
210
  }
209
- window.setTimeout(function () {
211
+ core.scheduleTask(() => {
210
212
  ok(buffer);
211
- }, 0);
213
+ });
212
214
  } catch (error) {
213
- window.setTimeout(function () {
215
+ core.scheduleTask(() => {
214
216
  err(error);
215
- }, 0);
217
+ });
216
218
  }
217
219
  } else {
218
220
  const request = new XMLHttpRequest();