@xeokit/xeokit-sdk 2.6.57 → 2.6.59

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.
@@ -11571,6 +11571,7 @@ const tmpVec4a = math.vec4();
11571
11571
  const tmpVec4b = math.vec4();
11572
11572
  const tmpVec4c = math.vec4();
11573
11573
  const tmpVec4d = math.vec4();
11574
+ const tmpMat4 = math.mat4();
11574
11575
 
11575
11576
  const nop = () => { };
11576
11577
 
@@ -11581,6 +11582,15 @@ function transformToNode(from, to, vec) {
11581
11582
  vec[1] += fromRec.top - toRec.top;
11582
11583
  }
11583
11584
  const toClipSpace = (camera, worldPos, p) => {
11585
+ // The reason the projMatrix is explicitely fetched as below is a complex callback chain
11586
+ // leading from a boundary update to a viewMatrix and projMatrix updates, which change their values
11587
+ // in the mid of the toClipSpace, leading to incorrect values.
11588
+ // The fetch ensures that matrix values are stabilized before used to transform worldPos to p.
11589
+ // Better solution would be to ensure that no mutually-triggered callbacks
11590
+ // (like boundary => view/projMatrix in this situation) ever happen, so user code can rely
11591
+ // on a callback running in a stable context.
11592
+ tmpMat4.set(camera.viewMatrix);
11593
+ tmpMat4.set(camera.projMatrix);
11584
11594
  // to homogeneous coords
11585
11595
  p.set(worldPos);
11586
11596
  p[3] = 1;
@@ -101437,11 +101447,12 @@ class MetaModel {
101437
101447
  this.metaScene.metaObjects[id] = metaObject;
101438
101448
  metaObject.metaModels = [];
101439
101449
  }
101440
- this.metaObjects[id] =metaObject;
101450
+ this.metaObjects[id] = metaObject;
101441
101451
  if (!metaObjectData.parent) {
101442
101452
  this.rootMetaObjects.push(metaObject);
101443
101453
  metaScene.rootMetaObjects[id] = metaObject;
101444
101454
  }
101455
+ metaObject.metaModels.push(this);
101445
101456
  }
101446
101457
  }
101447
101458
  }
@@ -101845,15 +101856,15 @@ class MetaScene {
101845
101856
  // Remove MetaObjects
101846
101857
 
101847
101858
  if (metaModel.metaObjects) {
101848
- for (let i = 0, len = metaModel.metaObjects.length; i < len; i++) {
101849
- const metaObject = metaModel.metaObjects[i];
101850
- metaObject.type;
101851
- const id = metaObject.id;
101852
- if (metaObject.metaModels.length === 1&& metaObject.metaModels[0].id === metaModelId) { // MetaObject owned only by this model, delete
101853
- delete this.metaObjects[id];
101859
+ for (let objectId in metaModel.metaObjects) {
101860
+ const metaObject = metaModel.metaObjects[objectId];
101861
+ if (metaObject.metaModels.length === 1 && metaObject.metaModels[0].id === metaModelId) { // MetaObject owned only by this model, delete
101862
+ delete this.metaObjects[objectId];
101854
101863
  if (!metaObject.parent) {
101855
- delete this.rootMetaObjects[id];
101864
+ delete this.rootMetaObjects[objectId];
101856
101865
  }
101866
+ } else {
101867
+ metaObject.metaModels = metaObject.metaModels.filter(metaModel => metaModel.id !== metaModelId);
101857
101868
  }
101858
101869
  }
101859
101870
  }
@@ -11567,6 +11567,7 @@ const tmpVec4a = math.vec4();
11567
11567
  const tmpVec4b = math.vec4();
11568
11568
  const tmpVec4c = math.vec4();
11569
11569
  const tmpVec4d = math.vec4();
11570
+ const tmpMat4 = math.mat4();
11570
11571
 
11571
11572
  const nop = () => { };
11572
11573
 
@@ -11577,6 +11578,15 @@ function transformToNode(from, to, vec) {
11577
11578
  vec[1] += fromRec.top - toRec.top;
11578
11579
  }
11579
11580
  const toClipSpace = (camera, worldPos, p) => {
11581
+ // The reason the projMatrix is explicitely fetched as below is a complex callback chain
11582
+ // leading from a boundary update to a viewMatrix and projMatrix updates, which change their values
11583
+ // in the mid of the toClipSpace, leading to incorrect values.
11584
+ // The fetch ensures that matrix values are stabilized before used to transform worldPos to p.
11585
+ // Better solution would be to ensure that no mutually-triggered callbacks
11586
+ // (like boundary => view/projMatrix in this situation) ever happen, so user code can rely
11587
+ // on a callback running in a stable context.
11588
+ tmpMat4.set(camera.viewMatrix);
11589
+ tmpMat4.set(camera.projMatrix);
11580
11590
  // to homogeneous coords
11581
11591
  p.set(worldPos);
11582
11592
  p[3] = 1;
@@ -101433,11 +101443,12 @@ class MetaModel {
101433
101443
  this.metaScene.metaObjects[id] = metaObject;
101434
101444
  metaObject.metaModels = [];
101435
101445
  }
101436
- this.metaObjects[id] =metaObject;
101446
+ this.metaObjects[id] = metaObject;
101437
101447
  if (!metaObjectData.parent) {
101438
101448
  this.rootMetaObjects.push(metaObject);
101439
101449
  metaScene.rootMetaObjects[id] = metaObject;
101440
101450
  }
101451
+ metaObject.metaModels.push(this);
101441
101452
  }
101442
101453
  }
101443
101454
  }
@@ -101841,15 +101852,15 @@ class MetaScene {
101841
101852
  // Remove MetaObjects
101842
101853
 
101843
101854
  if (metaModel.metaObjects) {
101844
- for (let i = 0, len = metaModel.metaObjects.length; i < len; i++) {
101845
- const metaObject = metaModel.metaObjects[i];
101846
- metaObject.type;
101847
- const id = metaObject.id;
101848
- if (metaObject.metaModels.length === 1&& metaObject.metaModels[0].id === metaModelId) { // MetaObject owned only by this model, delete
101849
- delete this.metaObjects[id];
101855
+ for (let objectId in metaModel.metaObjects) {
101856
+ const metaObject = metaModel.metaObjects[objectId];
101857
+ if (metaObject.metaModels.length === 1 && metaObject.metaModels[0].id === metaModelId) { // MetaObject owned only by this model, delete
101858
+ delete this.metaObjects[objectId];
101850
101859
  if (!metaObject.parent) {
101851
- delete this.rootMetaObjects[id];
101860
+ delete this.rootMetaObjects[objectId];
101852
101861
  }
101862
+ } else {
101863
+ metaObject.metaModels = metaObject.metaModels.filter(metaModel => metaModel.id !== metaModelId);
101853
101864
  }
101854
101865
  }
101855
101866
  }