@xeokit/xeokit-sdk 2.5.2-beta-8 → 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.
@@ -6895,6 +6895,7 @@ const stats = {
6895
6895
  /**
6896
6896
  * @private
6897
6897
  */
6898
+
6898
6899
  function xmlToJson(node, attributeRenamer) {
6899
6900
  if (node.nodeType === node.TEXT_NODE) {
6900
6901
  var v = node.nodeValue;
@@ -7100,13 +7101,13 @@ function loadArraybuffer$1(url, ok, err) {
7100
7101
  for (var i = 0; i < data.length; i++) {
7101
7102
  view[i] = data.charCodeAt(i);
7102
7103
  }
7103
- window.setTimeout(function () {
7104
+ core.scheduleTask(() => {
7104
7105
  ok(buffer);
7105
- }, 0);
7106
+ });
7106
7107
  } catch (error) {
7107
- window.setTimeout(function () {
7108
+ core.scheduleTask(() => {
7108
7109
  err(error);
7109
- }, 0);
7110
+ });
7110
7111
  }
7111
7112
  } else {
7112
7113
  const request = new XMLHttpRequest();
@@ -7354,6 +7355,7 @@ let lastTime = 0;
7354
7355
  let elapsedTime;
7355
7356
  let totalFPS = 0;
7356
7357
 
7358
+
7357
7359
  /**
7358
7360
  * @private
7359
7361
  */
@@ -7439,7 +7441,7 @@ function Core() {
7439
7441
  * @param {Function} callback Callback that runs the task.
7440
7442
  * @param {Object} [scope] Scope for the callback.
7441
7443
  */
7442
- this.scheduleTask = function (callback, scope) {
7444
+ this.scheduleTask = function (callback, scope = null) {
7443
7445
  taskQueue.push(callback);
7444
7446
  taskQueue.push(scope);
7445
7447
  };
@@ -7474,8 +7476,43 @@ function Core() {
7474
7476
  */
7475
7477
  const core = new Core();
7476
7478
 
7477
-
7478
7479
  const frame = function () {
7480
+ let time = Date.now();
7481
+ elapsedTime = time - lastTime;
7482
+ if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats
7483
+ var newFPS = 1000 / elapsedTime; // Moving average of FPS
7484
+ totalFPS += newFPS;
7485
+ fpsSamples.push(newFPS);
7486
+ if (fpsSamples.length >= numFPSSamples) {
7487
+ totalFPS -= fpsSamples.shift();
7488
+ }
7489
+ stats.frame.fps = Math.round(totalFPS / fpsSamples.length);
7490
+ }
7491
+ for (let id in core.scenes) {
7492
+ core.scenes[id].compile();
7493
+ }
7494
+ runTasks(time);
7495
+ lastTime = time;
7496
+ };
7497
+
7498
+ class WorkerInterval {
7499
+ worker = null;
7500
+
7501
+ constructor(callback, interval) {
7502
+ const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
7503
+ const workerScript = URL.createObjectURL(blob);
7504
+ this.worker = new Worker(workerScript);
7505
+ this.worker.onmessage = callback;
7506
+ }
7507
+
7508
+ stop() {
7509
+ this.worker.terminate();
7510
+ }
7511
+ }
7512
+
7513
+ new WorkerInterval(frame, 100);
7514
+
7515
+ const renderFrame = function () {
7479
7516
  let time = Date.now();
7480
7517
  elapsedTime = time - lastTime;
7481
7518
  if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats
@@ -7490,10 +7527,11 @@ const frame = function () {
7490
7527
  runTasks(time);
7491
7528
  fireTickEvents(time);
7492
7529
  renderScenes();
7493
- lastTime = time;
7494
- (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(frame);
7530
+ (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(renderFrame);
7495
7531
  };
7496
7532
 
7533
+ renderFrame();
7534
+
7497
7535
  function runTasks(time) { // Process as many enqueued tasks as we can within the per-frame task budget
7498
7536
  const tasksRun = core.runTasks(time + taskBudget);
7499
7537
  const tasksScheduled = core.getNumTasks();
@@ -7567,17 +7605,6 @@ function renderScenes() {
7567
7605
  }
7568
7606
  }
7569
7607
 
7570
- (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(frame);
7571
-
7572
- function compileScenes() {
7573
-
7574
- for (let id in core.scenes) {
7575
- core.scenes[id].compile();
7576
- }
7577
- }
7578
-
7579
- window.setInterval(compileScenes, 1000 / 60);
7580
-
7581
7608
  /**
7582
7609
  * @desc Base class for all xeokit components.
7583
7610
  *
@@ -8390,6 +8417,14 @@ class Component {
8390
8417
  }
8391
8418
  }
8392
8419
 
8420
+ /**
8421
+ * Schedule a task to perform on the next browser interval
8422
+ * @param task
8423
+ */
8424
+ scheduleTask(task) {
8425
+ core.scheduleTask(task, null);
8426
+ }
8427
+
8393
8428
  /**
8394
8429
  * Protected virtual template method, optionally implemented
8395
8430
  * by sub-classes to perform a scheduled task.
@@ -9145,6 +9180,14 @@ class Plugin {
9145
9180
  viewer.addPlugin(this);
9146
9181
  }
9147
9182
 
9183
+ /**
9184
+ * Schedule a task to perform on the next browser interval
9185
+ * @param task
9186
+ */
9187
+ scheduleTask(task) {
9188
+ core.scheduleTask(task, null);
9189
+ }
9190
+
9148
9191
  /**
9149
9192
  * Fires an event on this Plugin.
9150
9193
  *
@@ -12922,7 +12965,7 @@ class Annotation extends Marker {
12922
12965
  if (utils.isArray(markerHTML)) {
12923
12966
  markerHTML = markerHTML.join("");
12924
12967
  }
12925
- markerHTML = this._renderTemplate(markerHTML);
12968
+ markerHTML = this._renderTemplate(markerHTML.trim());
12926
12969
  const markerFragment = document.createRange().createContextualFragment(markerHTML);
12927
12970
  this._marker = markerFragment.firstChild;
12928
12971
  this._container.appendChild(this._marker);
@@ -12949,7 +12992,7 @@ class Annotation extends Marker {
12949
12992
  if (utils.isArray(labelHTML)) {
12950
12993
  labelHTML = labelHTML.join("");
12951
12994
  }
12952
- labelHTML = this._renderTemplate(labelHTML);
12995
+ labelHTML = this._renderTemplate(labelHTML.trim());
12953
12996
  const labelFragment = document.createRange().createContextualFragment(labelHTML);
12954
12997
  this._label = labelFragment.firstChild;
12955
12998
  this._container.appendChild(this._label);
@@ -77525,7 +77568,7 @@ class FileLoader extends Loader {
77525
77568
  const cached = Cache$1.get(url);
77526
77569
  if (cached !== undefined) {
77527
77570
  this.manager.itemStart(url);
77528
- setTimeout(() => {
77571
+ core.scheduleTask(() => {
77529
77572
  if (onLoad) {
77530
77573
  onLoad(cached);
77531
77574
  }
@@ -86758,13 +86801,13 @@ function loadArraybuffer(glTFSrc, binarySrc, ok, err) {
86758
86801
  for (var i = 0; i < data.length; i++) {
86759
86802
  view[i] = data.charCodeAt(i);
86760
86803
  }
86761
- window.setTimeout(function () {
86804
+ core.scheduleTask(function () {
86762
86805
  ok(buffer);
86763
- }, 0);
86806
+ });
86764
86807
  } catch (error) {
86765
- window.setTimeout(function () {
86808
+ core.scheduleTask(function () {
86766
86809
  err(error);
86767
- }, 0);
86810
+ });
86768
86811
  }
86769
86812
  } else {
86770
86813
  const basePath = getBasePath$1(glTFSrc);
@@ -127719,14 +127762,13 @@ class XKTLoaderPlugin extends Plugin {
127719
127762
  sceneModel.once("destroyed", () => {
127720
127763
  this.viewer.metaScene.destroyMetaModel(metaModel.id);
127721
127764
  });
127722
- window.setTimeout(() => {
127723
-
127765
+ this.scheduleTask(() => {
127724
127766
  if (sceneModel.destroyed) {
127725
127767
  return;
127726
127768
  }
127727
127769
  sceneModel.scene.fire("modelLoaded", sceneModel.id); // FIXME: Assumes listeners know order of these two events
127728
127770
  sceneModel.fire("loaded", true, false); // Don't forget the event, for late subscribers
127729
- }, 100);
127771
+ });
127730
127772
  };
127731
127773
 
127732
127774
  const error = (errMsg) => {
@@ -127804,7 +127846,7 @@ class XKTLoaderPlugin extends Plugin {
127804
127846
  globalizeObjectIds: options.globalizeObjectIds
127805
127847
  });
127806
127848
  i++;
127807
- window.setTimeout( loadNext, 100);
127849
+ this.scheduleTask( loadNext, 100);
127808
127850
  }, error);
127809
127851
  }
127810
127852
  };
@@ -127819,7 +127861,7 @@ class XKTLoaderPlugin extends Plugin {
127819
127861
  this._dataSource.getXKT(`${baseDir}${xktFiles[i]}`, (arrayBuffer) => {
127820
127862
  this._parseModel(arrayBuffer, params, options, sceneModel, metaModel, manifestCtx);
127821
127863
  i++;
127822
- window.setTimeout(loadNext, 100);
127864
+ this.scheduleTask(loadNext, 100);
127823
127865
  }, error);
127824
127866
  }
127825
127867
  };
@@ -6891,6 +6891,7 @@ const stats = {
6891
6891
  /**
6892
6892
  * @private
6893
6893
  */
6894
+
6894
6895
  function xmlToJson(node, attributeRenamer) {
6895
6896
  if (node.nodeType === node.TEXT_NODE) {
6896
6897
  var v = node.nodeValue;
@@ -7096,13 +7097,13 @@ function loadArraybuffer$1(url, ok, err) {
7096
7097
  for (var i = 0; i < data.length; i++) {
7097
7098
  view[i] = data.charCodeAt(i);
7098
7099
  }
7099
- window.setTimeout(function () {
7100
+ core.scheduleTask(() => {
7100
7101
  ok(buffer);
7101
- }, 0);
7102
+ });
7102
7103
  } catch (error) {
7103
- window.setTimeout(function () {
7104
+ core.scheduleTask(() => {
7104
7105
  err(error);
7105
- }, 0);
7106
+ });
7106
7107
  }
7107
7108
  } else {
7108
7109
  const request = new XMLHttpRequest();
@@ -7350,6 +7351,7 @@ let lastTime = 0;
7350
7351
  let elapsedTime;
7351
7352
  let totalFPS = 0;
7352
7353
 
7354
+
7353
7355
  /**
7354
7356
  * @private
7355
7357
  */
@@ -7435,7 +7437,7 @@ function Core() {
7435
7437
  * @param {Function} callback Callback that runs the task.
7436
7438
  * @param {Object} [scope] Scope for the callback.
7437
7439
  */
7438
- this.scheduleTask = function (callback, scope) {
7440
+ this.scheduleTask = function (callback, scope = null) {
7439
7441
  taskQueue.push(callback);
7440
7442
  taskQueue.push(scope);
7441
7443
  };
@@ -7470,8 +7472,43 @@ function Core() {
7470
7472
  */
7471
7473
  const core = new Core();
7472
7474
 
7473
-
7474
7475
  const frame = function () {
7476
+ let time = Date.now();
7477
+ elapsedTime = time - lastTime;
7478
+ if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats
7479
+ var newFPS = 1000 / elapsedTime; // Moving average of FPS
7480
+ totalFPS += newFPS;
7481
+ fpsSamples.push(newFPS);
7482
+ if (fpsSamples.length >= numFPSSamples) {
7483
+ totalFPS -= fpsSamples.shift();
7484
+ }
7485
+ stats.frame.fps = Math.round(totalFPS / fpsSamples.length);
7486
+ }
7487
+ for (let id in core.scenes) {
7488
+ core.scenes[id].compile();
7489
+ }
7490
+ runTasks(time);
7491
+ lastTime = time;
7492
+ };
7493
+
7494
+ class WorkerInterval {
7495
+ worker = null;
7496
+
7497
+ constructor(callback, interval) {
7498
+ const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
7499
+ const workerScript = URL.createObjectURL(blob);
7500
+ this.worker = new Worker(workerScript);
7501
+ this.worker.onmessage = callback;
7502
+ }
7503
+
7504
+ stop() {
7505
+ this.worker.terminate();
7506
+ }
7507
+ }
7508
+
7509
+ new WorkerInterval(frame, 100);
7510
+
7511
+ const renderFrame = function () {
7475
7512
  let time = Date.now();
7476
7513
  elapsedTime = time - lastTime;
7477
7514
  if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats
@@ -7486,10 +7523,11 @@ const frame = function () {
7486
7523
  runTasks(time);
7487
7524
  fireTickEvents(time);
7488
7525
  renderScenes();
7489
- lastTime = time;
7490
- (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(frame);
7526
+ (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(renderFrame);
7491
7527
  };
7492
7528
 
7529
+ renderFrame();
7530
+
7493
7531
  function runTasks(time) { // Process as many enqueued tasks as we can within the per-frame task budget
7494
7532
  const tasksRun = core.runTasks(time + taskBudget);
7495
7533
  const tasksScheduled = core.getNumTasks();
@@ -7563,17 +7601,6 @@ function renderScenes() {
7563
7601
  }
7564
7602
  }
7565
7603
 
7566
- (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(frame);
7567
-
7568
- function compileScenes() {
7569
-
7570
- for (let id in core.scenes) {
7571
- core.scenes[id].compile();
7572
- }
7573
- }
7574
-
7575
- window.setInterval(compileScenes, 1000 / 60);
7576
-
7577
7604
  /**
7578
7605
  * @desc Base class for all xeokit components.
7579
7606
  *
@@ -8386,6 +8413,14 @@ class Component {
8386
8413
  }
8387
8414
  }
8388
8415
 
8416
+ /**
8417
+ * Schedule a task to perform on the next browser interval
8418
+ * @param task
8419
+ */
8420
+ scheduleTask(task) {
8421
+ core.scheduleTask(task, null);
8422
+ }
8423
+
8389
8424
  /**
8390
8425
  * Protected virtual template method, optionally implemented
8391
8426
  * by sub-classes to perform a scheduled task.
@@ -9141,6 +9176,14 @@ class Plugin {
9141
9176
  viewer.addPlugin(this);
9142
9177
  }
9143
9178
 
9179
+ /**
9180
+ * Schedule a task to perform on the next browser interval
9181
+ * @param task
9182
+ */
9183
+ scheduleTask(task) {
9184
+ core.scheduleTask(task, null);
9185
+ }
9186
+
9144
9187
  /**
9145
9188
  * Fires an event on this Plugin.
9146
9189
  *
@@ -12918,7 +12961,7 @@ class Annotation extends Marker {
12918
12961
  if (utils.isArray(markerHTML)) {
12919
12962
  markerHTML = markerHTML.join("");
12920
12963
  }
12921
- markerHTML = this._renderTemplate(markerHTML);
12964
+ markerHTML = this._renderTemplate(markerHTML.trim());
12922
12965
  const markerFragment = document.createRange().createContextualFragment(markerHTML);
12923
12966
  this._marker = markerFragment.firstChild;
12924
12967
  this._container.appendChild(this._marker);
@@ -12945,7 +12988,7 @@ class Annotation extends Marker {
12945
12988
  if (utils.isArray(labelHTML)) {
12946
12989
  labelHTML = labelHTML.join("");
12947
12990
  }
12948
- labelHTML = this._renderTemplate(labelHTML);
12991
+ labelHTML = this._renderTemplate(labelHTML.trim());
12949
12992
  const labelFragment = document.createRange().createContextualFragment(labelHTML);
12950
12993
  this._label = labelFragment.firstChild;
12951
12994
  this._container.appendChild(this._label);
@@ -77521,7 +77564,7 @@ class FileLoader extends Loader {
77521
77564
  const cached = Cache$1.get(url);
77522
77565
  if (cached !== undefined) {
77523
77566
  this.manager.itemStart(url);
77524
- setTimeout(() => {
77567
+ core.scheduleTask(() => {
77525
77568
  if (onLoad) {
77526
77569
  onLoad(cached);
77527
77570
  }
@@ -86754,13 +86797,13 @@ function loadArraybuffer(glTFSrc, binarySrc, ok, err) {
86754
86797
  for (var i = 0; i < data.length; i++) {
86755
86798
  view[i] = data.charCodeAt(i);
86756
86799
  }
86757
- window.setTimeout(function () {
86800
+ core.scheduleTask(function () {
86758
86801
  ok(buffer);
86759
- }, 0);
86802
+ });
86760
86803
  } catch (error) {
86761
- window.setTimeout(function () {
86804
+ core.scheduleTask(function () {
86762
86805
  err(error);
86763
- }, 0);
86806
+ });
86764
86807
  }
86765
86808
  } else {
86766
86809
  const basePath = getBasePath$1(glTFSrc);
@@ -127715,14 +127758,13 @@ class XKTLoaderPlugin extends Plugin {
127715
127758
  sceneModel.once("destroyed", () => {
127716
127759
  this.viewer.metaScene.destroyMetaModel(metaModel.id);
127717
127760
  });
127718
- window.setTimeout(() => {
127719
-
127761
+ this.scheduleTask(() => {
127720
127762
  if (sceneModel.destroyed) {
127721
127763
  return;
127722
127764
  }
127723
127765
  sceneModel.scene.fire("modelLoaded", sceneModel.id); // FIXME: Assumes listeners know order of these two events
127724
127766
  sceneModel.fire("loaded", true, false); // Don't forget the event, for late subscribers
127725
- }, 100);
127767
+ });
127726
127768
  };
127727
127769
 
127728
127770
  const error = (errMsg) => {
@@ -127800,7 +127842,7 @@ class XKTLoaderPlugin extends Plugin {
127800
127842
  globalizeObjectIds: options.globalizeObjectIds
127801
127843
  });
127802
127844
  i++;
127803
- window.setTimeout( loadNext, 100);
127845
+ this.scheduleTask( loadNext, 100);
127804
127846
  }, error);
127805
127847
  }
127806
127848
  };
@@ -127815,7 +127857,7 @@ class XKTLoaderPlugin extends Plugin {
127815
127857
  this._dataSource.getXKT(`${baseDir}${xktFiles[i]}`, (arrayBuffer) => {
127816
127858
  this._parseModel(arrayBuffer, params, options, sceneModel, metaModel, manifestCtx);
127817
127859
  i++;
127818
- window.setTimeout(loadNext, 100);
127860
+ this.scheduleTask(loadNext, 100);
127819
127861
  }, error);
127820
127862
  }
127821
127863
  };