@archvisioninc/canvas 2.6.3 → 2.6.5

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