@archvisioninc/canvas 2.6.5 → 2.6.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.
@@ -182,7 +182,7 @@ export const updateMaterial = inboundData => {
182
182
 
183
183
  // Reset supported texture channels, useful when manually importing a new material.
184
184
  if (clearTextureChannels) {
185
- const workingMaterial = scene.metadata.materials.find(mat => mat.materialId === id);
185
+ const workingMaterial = scene.metadata.materials.find(mat => mat.materialId === id) || {};
186
186
  Object.keys(workingMaterial)?.forEach(key => {
187
187
  if (key.endsWith('Texture')) {
188
188
  material[key] = null;
@@ -406,37 +406,18 @@ export const buildMeshPositionsArray = args => {
406
406
  return defaultMeshPosition;
407
407
  });
408
408
  };
409
- export const getImageFileFromBuffer = args => {
410
- const {
411
- buffer,
412
- asBase64Data
413
- } = args || {};
409
+ export const getImageFileFromBuffer = buffer => {
414
410
  if (_.isEmpty(buffer)) return '';
415
- try {
416
- const blob = new Blob([buffer], {
417
- type: 'image/png'
418
- });
419
- const url = URL.createObjectURL(blob);
420
- if (asBase64Data) {
421
- const base64DataUrl = `data:image/png;base64,${btoa(String.fromCharCode(...new Uint8Array(buffer)))}`;
422
- return base64DataUrl;
423
- }
424
- return url;
425
- } catch (error) {
426
- console.error('Unable to get image from buffer: ', error);
427
- }
411
+ const blob = new Blob([buffer], {
412
+ type: 'image/png'
413
+ });
414
+ const url = URL.createObjectURL(blob);
415
+ return url;
428
416
  };
429
- export const getTextureUrl = args => {
430
- const {
431
- texture,
432
- asBase64Data
433
- } = args || {};
417
+ export const getTextureUrl = texture => {
434
418
  const buffer = texture?._buffer;
435
419
  if (_.isEmpty(buffer)) return texture?.url || '';
436
- return getImageFileFromBuffer({
437
- buffer,
438
- asBase64Data
439
- });
420
+ return getImageFileFromBuffer(buffer);
440
421
  };
441
422
  export const materialData = material => {
442
423
  const meshesWithMaterial = getUserMeshes().map(mesh => {
@@ -459,45 +440,30 @@ export const materialData = material => {
459
440
  albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
460
441
  albedoTexture: {
461
442
  name: material.albedoTexture?.name,
462
- url: getTextureUrl({
463
- texture: material.albedoTexture,
464
- asBase64Data: true
465
- })
443
+ url: getTextureUrl(material.albedoTexture)
466
444
  },
467
445
  albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
468
446
  environmentIntensity: material.environmentIntensity,
469
447
  metallic: material.metallic,
470
448
  metallicTexture: {
471
449
  name: material.metallicTexture?.name,
472
- url: getTextureUrl({
473
- texture: material.metallicTexture,
474
- asBase64Data: true
475
- })
450
+ url: getTextureUrl(material.metallicTexture)
476
451
  },
477
452
  roughness: material.roughness,
478
453
  microSurfaceTexture: {
479
454
  name: material.microSurfaceTexture?.name,
480
- url: getTextureUrl({
481
- texture: material.microSurfaceTexture,
482
- asBase64Data: true
483
- })
455
+ url: getTextureUrl(material.microSurfaceTexture)
484
456
  },
485
457
  emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
486
458
  emissiveIntensity: material.emissiveIntensity,
487
459
  emissiveTexture: {
488
460
  name: material.emissiveTexture?.name,
489
- url: getTextureUrl({
490
- texture: material.emissiveTexture,
491
- asBase64Data: true
492
- })
461
+ url: getTextureUrl(material.emissiveTexture)
493
462
  },
494
463
  bumpIntensity: material.bumpTexture?.level || 0.5,
495
464
  bumpTexture: {
496
465
  name: material.bumpTexture?.name,
497
- url: getTextureUrl({
498
- texture: material.bumpTexture,
499
- asBase64Data: true
500
- })
466
+ url: getTextureUrl(material.bumpTexture)
501
467
  },
502
468
  // Advanced
503
469
  clearCoatEnabled: material.clearCoat?.isEnabled || false,
@@ -507,10 +473,7 @@ export const materialData = material => {
507
473
  alpha: material.alpha,
508
474
  opacityTexture: {
509
475
  name: material.opacityTexture?.name,
510
- url: getTextureUrl({
511
- texture: material.opacityTexture,
512
- asBase64Data: true
513
- })
476
+ url: getTextureUrl(material.opacityTexture)
514
477
  },
515
478
  transparencyMode: material.transparencyMode,
516
479
  sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -220,7 +220,7 @@ export const updateMaterial = inboundData => {
220
220
 
221
221
  // Reset supported texture channels, useful when manually importing a new material.
222
222
  if (clearTextureChannels) {
223
- const workingMaterial = scene.metadata.materials.find(mat => mat.materialId === id);
223
+ const workingMaterial = scene.metadata.materials.find(mat => mat.materialId === id) || {};
224
224
 
225
225
  Object.keys(workingMaterial)?.forEach(key => {
226
226
  if (key.endsWith('Texture')) {
@@ -466,32 +466,20 @@ export const buildMeshPositionsArray = args => {
466
466
  });
467
467
  };
468
468
 
469
- export const getImageFileFromBuffer = args => {
470
- const { buffer, asBase64Data } = args || {};
471
-
469
+ export const getImageFileFromBuffer = buffer => {
472
470
  if (_.isEmpty(buffer)) return '';
473
471
 
474
- try {
475
- const blob = new Blob([ buffer ], { type: 'image/png' });
476
- const url = URL.createObjectURL(blob);
472
+ const blob = new Blob([ buffer ], { type: 'image/png' });
473
+ const url = URL.createObjectURL(blob);
477
474
 
478
- if (asBase64Data) {
479
- const base64DataUrl = `data:image/png;base64,${btoa(String.fromCharCode(...new Uint8Array(buffer)))}`;
480
- return base64DataUrl;
481
- }
482
-
483
- return url;
484
- } catch (error) {
485
- console.error('Unable to get image from buffer: ', error);
486
- }
475
+ return url;
487
476
  };
488
477
 
489
- export const getTextureUrl = args => {
490
- const { texture, asBase64Data } = args || {};
478
+ export const getTextureUrl = texture => {
491
479
  const buffer = texture?._buffer;
492
480
 
493
481
  if (_.isEmpty(buffer)) return texture?.url || '';
494
- return getImageFileFromBuffer({ buffer, asBase64Data });
482
+ return getImageFileFromBuffer(buffer);
495
483
  };
496
484
 
497
485
  export const materialData = material => {
@@ -520,30 +508,30 @@ export const materialData = material => {
520
508
  albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
521
509
  albedoTexture: {
522
510
  name: material.albedoTexture?.name,
523
- url: getTextureUrl({ texture: material.albedoTexture, asBase64Data: true }),
511
+ url: getTextureUrl(material.albedoTexture),
524
512
  },
525
513
  albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
526
514
  environmentIntensity: material.environmentIntensity,
527
515
  metallic: material.metallic,
528
516
  metallicTexture: {
529
517
  name: material.metallicTexture?.name,
530
- url: getTextureUrl({ texture: material.metallicTexture, asBase64Data: true }),
518
+ url: getTextureUrl(material.metallicTexture),
531
519
  },
532
520
  roughness: material.roughness,
533
521
  microSurfaceTexture: {
534
522
  name: material.microSurfaceTexture?.name,
535
- url: getTextureUrl({ texture: material.microSurfaceTexture, asBase64Data: true }),
523
+ url: getTextureUrl(material.microSurfaceTexture),
536
524
  },
537
525
  emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
538
526
  emissiveIntensity: material.emissiveIntensity,
539
527
  emissiveTexture: {
540
528
  name: material.emissiveTexture?.name,
541
- url: getTextureUrl({ texture: material.emissiveTexture, asBase64Data: true }),
529
+ url: getTextureUrl(material.emissiveTexture),
542
530
  },
543
531
  bumpIntensity: material.bumpTexture?.level || 0.5,
544
532
  bumpTexture: {
545
533
  name: material.bumpTexture?.name,
546
- url: getTextureUrl({ texture: material.bumpTexture, asBase64Data: true }),
534
+ url: getTextureUrl(material.bumpTexture),
547
535
  },
548
536
 
549
537
  // Advanced
@@ -554,7 +542,7 @@ export const materialData = material => {
554
542
  alpha: material.alpha,
555
543
  opacityTexture: {
556
544
  name: material.opacityTexture?.name,
557
- url: getTextureUrl({ texture: material.opacityTexture, asBase64Data: true }),
545
+ url: getTextureUrl(material.opacityTexture),
558
546
  },
559
547
  transparencyMode: material.transparencyMode,
560
548
  sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,