@colijnit/configuratorcore 262.1.5 → 262.1.7

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.
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three';
2
- import { Group, BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial, Vector3, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, EquirectangularReflectionMapping, Vector2, Material as Material$1, Texture, Source, Camera, Box3, LinearSRGBColorSpace, SRGBColorSpace, Color, MaterialLoader, MeshPhongMaterial, NearestFilter, DoubleSide, MeshPhysicalMaterial, MeshStandardMaterial, Euler, Quaternion } from 'three';
2
+ import { Group, BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial, Vector3, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, EquirectangularReflectionMapping, Vector2, Material as Material$1, Texture, Source, LinearSRGBColorSpace, SRGBColorSpace, Color, MaterialLoader, MeshPhongMaterial, NearestFilter, DoubleSide, MeshPhysicalMaterial, MeshStandardMaterial, Box3, Euler, Quaternion } from 'three';
3
3
  import { Subject, BehaviorSubject } from 'rxjs';
4
4
  import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
5
5
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
@@ -451,7 +451,7 @@ class ThreedUtils {
451
451
  loader.dracoLoader.setDecoderConfig({ type: 'js' });
452
452
  loader.load(file, async (object) => {
453
453
  this.clips = object.animations || [];
454
- const obj = this.cleanedUpObjectsWeb(object.scene, false);
454
+ const obj = this._cleanedUpObjects(object.scene, cleanUp);
455
455
  this._objectCache.set(file, obj);
456
456
  resolve(obj);
457
457
  }, xhr => this._handleUpdateProgressBar(xhr.loaded / xhr.total * 100), error => {
@@ -473,7 +473,7 @@ class ThreedUtils {
473
473
  }
474
474
  }
475
475
  async loadGlbSource(file, setVisibleFalse = true, dracoPath) {
476
- const obj = await this.loadGlbModel(file, true, dracoPath);
476
+ const obj = await this.loadGlbModel(file, false, dracoPath);
477
477
  if (obj) {
478
478
  obj.children = obj.children.filter(c => !(c instanceof THREE.Camera || (c.constructor.name && c.constructor.name.toLowerCase().indexOf('camera') > -1)));
479
479
  obj.children.sort((a, b) => a['name'] < b['name'] ? 1 : -1);
@@ -511,46 +511,6 @@ class ThreedUtils {
511
511
  }, null, reject);
512
512
  });
513
513
  }
514
- cleanedUpObjectsWeb(object, cleanUp = true) {
515
- let obj = new Object3D();
516
- // console.log(this.clips);
517
- object.children.forEach((c) => {
518
- if (!(c instanceof Camera)) {
519
- if (cleanUp && c instanceof Group || (c.children.length === 1 && c.children[0] instanceof Group)) {
520
- this._addGroupChildrenToObject(c, obj);
521
- }
522
- else if ((cleanUp && !(c instanceof Mesh)) || (!(c instanceof Mesh) && !c.name && c.children.length > 0)) {
523
- c.children.forEach((child) => {
524
- child.translateY(c.position.y);
525
- });
526
- c.translateY(-c.position.y);
527
- if (obj.children.length > 0) {
528
- obj.add(c.clone());
529
- }
530
- else {
531
- obj = c.clone();
532
- }
533
- }
534
- else {
535
- // if (c.position.y > 0 || c.position.y < 0) {
536
- // c.children.forEach((child) => {
537
- // child.translateY(c.position.y);
538
- // });
539
- // c.translateY(-c.position.y);
540
- // }
541
- obj.add(c.clone());
542
- }
543
- }
544
- });
545
- const boundingBox = new Box3().setFromObject(obj);
546
- const bbCenterPivot = new Vector3();
547
- boundingBox.getCenter(bbCenterPivot);
548
- const delta = new Vector3().add(bbCenterPivot).negate();
549
- obj.children.forEach((cc) => {
550
- cc.position.add(delta);
551
- });
552
- return obj;
553
- }
554
514
  _cleanedUpObjects(object, cleanUp = true) {
555
515
  let obj = new THREE.Object3D();
556
516
  object.children.forEach((c) => {
@@ -571,12 +531,6 @@ class ThreedUtils {
571
531
  }
572
532
  }
573
533
  else {
574
- if (c.position.y > 0 || c.position.y < 0) {
575
- c.children.forEach((child) => {
576
- child.translateY(c.position.y);
577
- });
578
- c.translateY(-c.position.y);
579
- }
580
534
  obj.add(c.clone());
581
535
  }
582
536
  }
@@ -1782,7 +1736,7 @@ class VariationHelper extends VariationCacheHelper {
1782
1736
  const lastKnownVariations = [];
1783
1737
  const variationPromise = [];
1784
1738
  for (let j = 0; j < variations.length; j++) {
1785
- variationPromise.push(this.loadCachedVariation(variations[j].materialUrl ? variations[j].materialCode : (variations[j].gameObjectName || parts[i].decoId)).then(async (variationSettings) => {
1739
+ variationPromise.push(this.loadCachedVariation(variations[j].materialUrl ? this.getFileNameFromUrl(variations[j].materialUrl) : (variations[j].gameObjectName || parts[i].decoId)).then(async (variationSettings) => {
1786
1740
  const newVariation = this._createVariationFromNode(variations[j]);
1787
1741
  newVariation.material = await AssetUtils.CreateMaterialFromAsset(variationSettings);
1788
1742
  this.loadedAsset = variations[j].materialUrl ? variations[j].materialUrl : VariationUtils.GetUrl(assetPath, parts[i].schema, variations[j].gameObjectName || parts[i].decoId);
@@ -1803,6 +1757,12 @@ class VariationHelper extends VariationCacheHelper {
1803
1757
  }
1804
1758
  });
1805
1759
  }
1760
+ getFileNameFromUrl(url) {
1761
+ // Make sure that when we are referencing a material, we always use the URL values and not the code.
1762
+ // materialCode can be different than the materialUrl file part and will cause issues.
1763
+ const fileNameFromUrl = url ? url.substr(url.lastIndexOf('/') + 1, url.length) : null;
1764
+ return fileNameFromUrl ? fileNameFromUrl.substr(0, fileNameFromUrl.lastIndexOf('.')) : null;
1765
+ }
1806
1766
  async loadVariationFromLocalFile(id, file, obj) {
1807
1767
  try {
1808
1768
  const variationSettings = await VariationUtils.GetVariationSettingsFromFile(id, file);