@archvisioninc/canvas 2.6.4 → 2.6.6

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.
@@ -406,18 +406,48 @@ export const buildMeshPositionsArray = args => {
406
406
  return defaultMeshPosition;
407
407
  });
408
408
  };
409
- export const getImageFileFromBuffer = buffer => {
409
+ export const getImageFileFromBuffer = args => {
410
+ const {
411
+ buffer,
412
+ asBase64Data
413
+ } = args || {};
410
414
  if (_.isEmpty(buffer)) return '';
411
- const blob = new Blob([buffer], {
412
- type: 'image/png'
413
- });
414
- const url = URL.createObjectURL(blob);
415
- return url;
415
+ try {
416
+ const blob = new Blob([buffer], {
417
+ type: 'image/png'
418
+ });
419
+ const url = URL.createObjectURL(blob);
420
+ if (asBase64Data) {
421
+ return new Promise((resolve, reject) => {
422
+ const reader = new FileReader();
423
+ reader.onloadend = () => {
424
+ resolve(reader.result);
425
+ };
426
+ reader.onerror = error => {
427
+ console.error('Error reading buffer: ', error);
428
+ reject(error);
429
+ };
430
+ reader.readAsDataURL(blob);
431
+ });
432
+ }
433
+ return Promise.resolve(url);
434
+ } catch (error) {
435
+ console.error('Unable to get image from buffer: ', error);
436
+ return Promise.reject(error);
437
+ }
416
438
  };
417
- export const getTextureUrl = texture => {
439
+ export const getTextureUrl = async args => {
440
+ const {
441
+ texture,
442
+ asBase64Data
443
+ } = args || {};
418
444
  const buffer = texture?._buffer;
419
445
  if (_.isEmpty(buffer)) return texture?.url || '';
420
- return getImageFileFromBuffer(buffer);
446
+ const url = await getImageFileFromBuffer({
447
+ buffer,
448
+ asBase64Data
449
+ });
450
+ return url;
421
451
  };
422
452
  export const materialData = material => {
423
453
  const meshesWithMaterial = getUserMeshes().map(mesh => {
@@ -440,30 +470,45 @@ export const materialData = material => {
440
470
  albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
441
471
  albedoTexture: {
442
472
  name: material.albedoTexture?.name,
443
- url: getTextureUrl(material.albedoTexture)
473
+ url: getTextureUrl({
474
+ texture: material.albedoTexture,
475
+ asBase64Data: true
476
+ })
444
477
  },
445
478
  albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
446
479
  environmentIntensity: material.environmentIntensity,
447
480
  metallic: material.metallic,
448
481
  metallicTexture: {
449
482
  name: material.metallicTexture?.name,
450
- url: getTextureUrl(material.metallicTexture)
483
+ url: getTextureUrl({
484
+ texture: material.metallicTexture,
485
+ asBase64Data: true
486
+ })
451
487
  },
452
488
  roughness: material.roughness,
453
489
  microSurfaceTexture: {
454
490
  name: material.microSurfaceTexture?.name,
455
- url: getTextureUrl(material.microSurfaceTexture)
491
+ url: getTextureUrl({
492
+ texture: material.microSurfaceTexture,
493
+ asBase64Data: true
494
+ })
456
495
  },
457
496
  emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
458
497
  emissiveIntensity: material.emissiveIntensity,
459
498
  emissiveTexture: {
460
499
  name: material.emissiveTexture?.name,
461
- url: getTextureUrl(material.emissiveTexture)
500
+ url: getTextureUrl({
501
+ texture: material.emissiveTexture,
502
+ asBase64Data: true
503
+ })
462
504
  },
463
505
  bumpIntensity: material.bumpTexture?.level || 0.5,
464
506
  bumpTexture: {
465
507
  name: material.bumpTexture?.name,
466
- url: getTextureUrl(material.bumpTexture)
508
+ url: getTextureUrl({
509
+ texture: material.bumpTexture,
510
+ asBase64Data: true
511
+ })
467
512
  },
468
513
  // Advanced
469
514
  clearCoatEnabled: material.clearCoat?.isEnabled || false,
@@ -473,7 +518,10 @@ export const materialData = material => {
473
518
  alpha: material.alpha,
474
519
  opacityTexture: {
475
520
  name: material.opacityTexture?.name,
476
- url: getTextureUrl(material.opacityTexture)
521
+ url: getTextureUrl({
522
+ texture: material.opacityTexture,
523
+ asBase64Data: true
524
+ })
477
525
  },
478
526
  transparencyMode: material.transparencyMode,
479
527
  sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "2.6.4",
3
+ "version": "2.6.6",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -466,20 +466,46 @@ export const buildMeshPositionsArray = args => {
466
466
  });
467
467
  };
468
468
 
469
- export const getImageFileFromBuffer = buffer => {
469
+ export const getImageFileFromBuffer = args => {
470
+ const { buffer, asBase64Data } = args || {};
471
+
470
472
  if (_.isEmpty(buffer)) return '';
471
473
 
472
- const blob = new Blob([ buffer ], { type: 'image/png' });
473
- const url = URL.createObjectURL(blob);
474
+ try {
475
+ const blob = new Blob([ buffer ], { type: 'image/png' });
476
+ const url = URL.createObjectURL(blob);
474
477
 
475
- return url;
478
+ if (asBase64Data) {
479
+ return new Promise((resolve, reject) => {
480
+ const reader = new FileReader();
481
+
482
+ reader.onloadend = () => {
483
+ resolve(reader.result);
484
+ };
485
+
486
+ reader.onerror = error => {
487
+ console.error('Error reading buffer: ', error);
488
+ reject(error);
489
+ };
490
+
491
+ reader.readAsDataURL(blob);
492
+ });
493
+ }
494
+
495
+ return Promise.resolve(url);
496
+ } catch (error) {
497
+ console.error('Unable to get image from buffer: ', error);
498
+ return Promise.reject(error);
499
+ }
476
500
  };
477
501
 
478
- export const getTextureUrl = texture => {
502
+ export const getTextureUrl = async args => {
503
+ const { texture, asBase64Data } = args || {};
479
504
  const buffer = texture?._buffer;
480
505
 
481
506
  if (_.isEmpty(buffer)) return texture?.url || '';
482
- return getImageFileFromBuffer(buffer);
507
+ const url = await getImageFileFromBuffer({ buffer, asBase64Data });
508
+ return url;
483
509
  };
484
510
 
485
511
  export const materialData = material => {
@@ -508,30 +534,30 @@ export const materialData = material => {
508
534
  albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
509
535
  albedoTexture: {
510
536
  name: material.albedoTexture?.name,
511
- url: getTextureUrl(material.albedoTexture),
537
+ url: getTextureUrl({ texture: material.albedoTexture, asBase64Data: true }),
512
538
  },
513
539
  albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
514
540
  environmentIntensity: material.environmentIntensity,
515
541
  metallic: material.metallic,
516
542
  metallicTexture: {
517
543
  name: material.metallicTexture?.name,
518
- url: getTextureUrl(material.metallicTexture),
544
+ url: getTextureUrl({ texture: material.metallicTexture, asBase64Data: true }),
519
545
  },
520
546
  roughness: material.roughness,
521
547
  microSurfaceTexture: {
522
548
  name: material.microSurfaceTexture?.name,
523
- url: getTextureUrl(material.microSurfaceTexture),
549
+ url: getTextureUrl({ texture: material.microSurfaceTexture, asBase64Data: true }),
524
550
  },
525
551
  emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
526
552
  emissiveIntensity: material.emissiveIntensity,
527
553
  emissiveTexture: {
528
554
  name: material.emissiveTexture?.name,
529
- url: getTextureUrl(material.emissiveTexture),
555
+ url: getTextureUrl({ texture: material.emissiveTexture, asBase64Data: true }),
530
556
  },
531
557
  bumpIntensity: material.bumpTexture?.level || 0.5,
532
558
  bumpTexture: {
533
559
  name: material.bumpTexture?.name,
534
- url: getTextureUrl(material.bumpTexture),
560
+ url: getTextureUrl({ texture: material.bumpTexture, asBase64Data: true }),
535
561
  },
536
562
 
537
563
  // Advanced
@@ -542,7 +568,7 @@ export const materialData = material => {
542
568
  alpha: material.alpha,
543
569
  opacityTexture: {
544
570
  name: material.opacityTexture?.name,
545
- url: getTextureUrl(material.opacityTexture),
571
+ url: getTextureUrl({ texture: material.opacityTexture, asBase64Data: true }),
546
572
  },
547
573
  transparencyMode: material.transparencyMode,
548
574
  sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,