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