@crystaldesign/real-time-viewer 26.4.0-beta.7 → 26.4.0-beta.8

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.
@@ -50,9 +50,9 @@ import { EngineFactory } from '@babylonjs/core/Engines/engineFactory';
50
50
  import { Scene } from '@babylonjs/core/scene';
51
51
  import { DracoCompression } from '@babylonjs/core/Meshes/Compression/dracoCompression';
52
52
  import { loadAssetContainerAsync } from '@babylonjs/core/Loading/index';
53
- import { PBRMetallicRoughnessMaterial as PBRMetallicRoughnessMaterial$1, Texture as Texture$1, WebGPUEngine } from '@babylonjs/core';
54
53
  import '@babylonjs/loaders/glTF/2.0/';
55
54
  import { UniversalCamera } from '@babylonjs/core/Cameras/universalCamera';
55
+ import { WebGPUEngine } from '@babylonjs/core';
56
56
  import { jsxs, jsx } from 'react/jsx-runtime';
57
57
 
58
58
  (function() {
@@ -3277,7 +3277,7 @@ function _findAssets() {
3277
3277
  case 0:
3278
3278
  _importGeo = function _importGeo3() {
3279
3279
  _importGeo = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(geo, path) {
3280
- var geoCached, cachedGeos, unusedGeos, geoCountToDelete, nextToDelete, size, result, mesh, _sceneStore$onMissing;
3280
+ var geoCached, size, result, mesh, _sceneStore$onMissing;
3281
3281
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
3282
3282
  while (1) switch (_context2.prev = _context2.next) {
3283
3283
  case 0:
@@ -3294,31 +3294,11 @@ function _findAssets() {
3294
3294
  };
3295
3295
  return _context2.abrupt("return", geoCached);
3296
3296
  case 4:
3297
- // cache max size otherwise some devices crash (ram to high)
3298
- cachedGeos = cacheGroup.getChildren(undefined, true);
3299
- if (cachedGeos.length > 10) {
3300
- // find unused geos
3301
- unusedGeos = cachedGeos.filter(function (g) {
3302
- return !cache.find(function (c) {
3303
- var _c$geo;
3304
- return ((_c$geo = c.geo) === null || _c$geo === void 0 ? void 0 : _c$geo.geometry.uniqueId) == g.uniqueId;
3305
- });
3306
- });
3307
- geoCountToDelete = cachedGeos.length - 10;
3308
- while (geoCountToDelete > 0 && unusedGeos.length > 0) {
3309
- nextToDelete = unusedGeos.reduce(function (oIdx, cur, curIdx, ar) {
3310
- return cur.metadata.lastUsed < ar[oIdx].metadata.lastUsed ? curIdx : oIdx;
3311
- }, 0);
3312
- unusedGeos[nextToDelete].dispose();
3313
- unusedGeos.splice(nextToDelete, 1);
3314
- geoCountToDelete--;
3315
- }
3316
- }
3317
3297
  size = 0;
3318
- _context2.prev = 7;
3319
- _context2.next = 10;
3298
+ _context2.prev = 5;
3299
+ _context2.next = 8;
3320
3300
  return loadAssetContainerAsync(path + geo.name + '.glb', sceneStore.scene);
3321
- case 10:
3301
+ case 8:
3322
3302
  result = _context2.sent;
3323
3303
  utilStore.setAnalyzeDataRow({
3324
3304
  name: geo.name,
@@ -3340,9 +3320,9 @@ function _findAssets() {
3340
3320
  lastUsed: Date.now()
3341
3321
  };
3342
3322
  return _context2.abrupt("return", mesh);
3343
- case 24:
3344
- _context2.prev = 24;
3345
- _context2.t0 = _context2["catch"](7);
3323
+ case 22:
3324
+ _context2.prev = 22;
3325
+ _context2.t0 = _context2["catch"](5);
3346
3326
  (_sceneStore$onMissing = sceneStore.onMissingGeo) === null || _sceneStore$onMissing === void 0 || _sceneStore$onMissing.call(sceneStore);
3347
3327
  utilStore.setAnalyzeDataRow({
3348
3328
  name: geo.name,
@@ -3353,11 +3333,11 @@ function _findAssets() {
3353
3333
  found: false
3354
3334
  });
3355
3335
  return _context2.abrupt("return", undefined);
3356
- case 29:
3336
+ case 27:
3357
3337
  case "end":
3358
3338
  return _context2.stop();
3359
3339
  }
3360
- }, _callee2, null, [[7, 24]]);
3340
+ }, _callee2, null, [[5, 22]]);
3361
3341
  }));
3362
3342
  return _importGeo.apply(this, arguments);
3363
3343
  };
@@ -3817,8 +3797,6 @@ var buildScene = function buildScene(_ref) {
3817
3797
  }
3818
3798
  }
3819
3799
  }
3820
-
3821
- // fill onElement for caching and other for applying in findmaterials
3822
3800
  function findMats(curMat, parentNode) {
3823
3801
  var cachedElement = cachedAssets.find(function (assets) {
3824
3802
  return assets.id == curMat.id;
@@ -3905,6 +3883,26 @@ var buildScene = function buildScene(_ref) {
3905
3883
  }
3906
3884
  }
3907
3885
  recursiveIteration(startNode, parentNode);
3886
+ // cache max size otherwise some devices crash (ram to high)
3887
+ var cachedGeos = cache.getChildren(undefined, true);
3888
+ if (cachedGeos.length > 10) {
3889
+ // find unused geos
3890
+ var unusedGeos = cachedGeos.filter(function (g) {
3891
+ return !cachedAssets.find(function (c) {
3892
+ var _c$geo;
3893
+ return ((_c$geo = c.geo) === null || _c$geo === void 0 ? void 0 : _c$geo.geometry.uniqueId) == g.uniqueId;
3894
+ });
3895
+ });
3896
+ var geoCountToDelete = cachedGeos.length - 10;
3897
+ while (geoCountToDelete > 0 && unusedGeos.length > 0) {
3898
+ var nextToDelete = unusedGeos.reduce(function (oIdx, cur, curIdx, ar) {
3899
+ return cur.metadata.lastUsed < ar[oIdx].metadata.lastUsed ? curIdx : oIdx;
3900
+ }, 0);
3901
+ unusedGeos[nextToDelete].dispose();
3902
+ unusedGeos.splice(nextToDelete, 1);
3903
+ geoCountToDelete--;
3904
+ }
3905
+ }
3908
3906
  sceneStore.cache = cachedAssets;
3909
3907
  };
3910
3908
 
@@ -3914,34 +3912,55 @@ function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.lengt
3914
3912
  function findMaterials(cache) {
3915
3913
  var sceneStore = useSceneStoreContext();
3916
3914
  var matsOnMeshes = {};
3915
+ var getDepth = function getDepth(child, ancestor) {
3916
+ var depth = 0;
3917
+ var current = child;
3918
+ while (current && current.uniqueId !== ancestor.uniqueId) {
3919
+ depth++;
3920
+ current = current.parent;
3921
+ }
3922
+ return depth;
3923
+ };
3924
+
3917
3925
  //! parent = the parent from which on every child should receive the Material
3918
3926
  //! id = the id which points to the material that should be assigned
3919
- var setMaterials = function setMaterials(onNode, mat) {
3920
- var matStillExists = sceneStore.scene.materials.find(function (_mat) {
3921
- return mat.uniqueId == _mat.uniqueId;
3922
- });
3923
- if (!matStillExists) {
3924
- var sharedName = mat.name + '_recreated';
3925
- var sharedMat = sceneStore.scene.getMaterialByName(sharedName);
3926
- if (!sharedMat) {
3927
- sharedMat = new PBRMetallicRoughnessMaterial$1(sharedName, sceneStore.scene);
3928
- sharedMat.baseTexture = new Texture$1(mat.baseTexture.name, sceneStore.scene);
3929
- sharedMat.metallicRoughnessTexture = new Texture$1(mat.metallicRoughnessTexture.name, sceneStore.scene);
3930
- sharedMat.normalTexture = new Texture$1(mat.normalTexture.name, sceneStore.scene);
3931
- }
3932
- mat = sharedMat;
3933
- }
3927
+ // the level defines how many parents above the material was set the lower the higher the prio
3928
+ var setMaterials = function setMaterials(onNode, mat, parent) {
3934
3929
  if (onNode !== null && onNode !== void 0 && onNode._isMesh) {
3935
- matsOnMeshes[onNode.uniqueId] = {
3936
- mat: mat,
3937
- onNode: onNode
3938
- };
3939
- onNode.material = mat;
3930
+ var matStillExists = sceneStore.scene.materials.find(function (_mat) {
3931
+ return mat.uniqueId == _mat.uniqueId;
3932
+ });
3933
+ if (!matStillExists) {
3934
+ var sharedName = mat.name + '_recreated';
3935
+ var sharedMat = sceneStore.scene.getMaterialByName(sharedName);
3936
+ if (!sharedMat) {
3937
+ sharedMat = new PBRMetallicRoughnessMaterial(sharedName, sceneStore.scene);
3938
+ sharedMat.baseTexture = new Texture(mat.baseTexture.name, sceneStore.scene);
3939
+ sharedMat.metallicRoughnessTexture = new Texture(mat.metallicRoughnessTexture.name, sceneStore.scene);
3940
+ sharedMat.normalTexture = new Texture(mat.normalTexture.name, sceneStore.scene);
3941
+ }
3942
+ mat = sharedMat;
3943
+ }
3944
+ var mesh = onNode;
3945
+ if (mesh) {
3946
+ var _mesh$metadata;
3947
+ var depth = getDepth(mesh, parent);
3948
+ if (mesh.material && ((_mesh$metadata = mesh.metadata) === null || _mesh$metadata === void 0 ? void 0 : _mesh$metadata["matLevel"]) < depth) return;
3949
+ matsOnMeshes[onNode.uniqueId] = {
3950
+ mat: mat,
3951
+ onNode: onNode
3952
+ };
3953
+ mesh.material = mat;
3954
+ if (!mesh.metadata) mesh.metadata = {
3955
+ "matLevel": depth
3956
+ };else mesh.metadata["matLevel"] = depth;
3957
+ }
3940
3958
  }
3941
3959
  var _iterator = _createForOfIteratorHelper$1(onNode.getChildMeshes()),
3942
3960
  _step;
3943
3961
  try {
3944
3962
  var _loop = function _loop() {
3963
+ var _mesh$metadata2;
3945
3964
  var mesh = _step.value;
3946
3965
  var existing = Object.keys(matsOnMeshes).find(function (key) {
3947
3966
  return key == mesh.uniqueId.toString();
@@ -3952,16 +3971,24 @@ function findMaterials(cache) {
3952
3971
  return node.uniqueId.toString() == existing;
3953
3972
  })) return 0; // continue
3954
3973
  }
3974
+ var depth = getDepth(mesh, parent);
3975
+ if (mesh.material && ((_mesh$metadata2 = mesh.metadata) === null || _mesh$metadata2 === void 0 ? void 0 : _mesh$metadata2["matLevel"]) < depth) return {
3976
+ v: void 0
3977
+ };
3955
3978
  matsOnMeshes[mesh.uniqueId] = {
3956
3979
  mat: mat,
3957
3980
  onNode: onNode
3958
3981
  };
3959
3982
  mesh.material = mat;
3983
+ if (!mesh.metadata) mesh.metadata = {
3984
+ "matLevel": depth
3985
+ };else mesh.metadata["matLevel"] = depth;
3960
3986
  },
3961
3987
  _ret;
3962
3988
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
3963
3989
  _ret = _loop();
3964
3990
  if (_ret === 0) continue;
3991
+ if (_ret) return _ret.v;
3965
3992
  }
3966
3993
  } catch (err) {
3967
3994
  _iterator.e(err);
@@ -3974,14 +4001,18 @@ function findMaterials(cache) {
3974
4001
  var findOnNode = function findOnNode(mat, parent, onNode) {
3975
4002
  if (!mat.onNodes) return;
3976
4003
  var children = parent.getChildTransformNodes(false);
4004
+ var childMeshes = parent.getChildMeshes(true);
4005
+ if (onNode == "" || onNode == "ALL") childMeshes.forEach(function (cm) {
4006
+ return setMaterials(cm, mat.mat, parent);
4007
+ });
3977
4008
  var _iterator2 = _createForOfIteratorHelper$1(children),
3978
4009
  _step2;
3979
4010
  try {
3980
4011
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3981
4012
  var child = _step2.value;
3982
- if (onNode == '' || onNode == 'ALL') setMaterials(child, mat.mat);
4013
+ if (onNode == "" || onNode == "ALL") setMaterials(child, mat.mat, parent);
3983
4014
  if (child.name.startsWith(onNode) || child.name.startsWith('geo_') && child.name.includes(onNode)) {
3984
- setMaterials(child, mat.mat);
4015
+ setMaterials(child, mat.mat, parent);
3985
4016
  }
3986
4017
  }
3987
4018
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/buildScene/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAkB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpD,QAAA,MAAM,UAAU,oDAKb;IACD,SAAS,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;IACrB,YAAY,EAAE,KAAK,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B,SAgHA,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/buildScene/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAkB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpD,QAAA,MAAM,UAAU,oDAKb;IACD,SAAS,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;IACrB,YAAY,EAAE,KAAK,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B,SA+HA,CAAC;AAGF,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/findAssets/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAW,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKpC,wBAA8B,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE;;;GAmK1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/findAssets/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAW,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKpC,wBAA8B,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE;;;GAoJ1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/findMaterials/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAY,MAAM,aAAa,CAAC;AAK9C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,wBA2DnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/findMaterials/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAY,MAAM,aAAa,CAAC;AAM9C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,wBAwFnD"}