@archvisioninc/canvas 2.6.7 → 2.6.9
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.
|
@@ -153,7 +153,7 @@ export const updateMaterial = inboundData => {
|
|
|
153
153
|
albedoHasAlpha,
|
|
154
154
|
clearTextureChannels
|
|
155
155
|
} = payload;
|
|
156
|
-
const material = scene
|
|
156
|
+
const material = scene?.getMaterialByName?.(id, true);
|
|
157
157
|
if (material) {
|
|
158
158
|
// Renaming material.
|
|
159
159
|
if (newId) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
1
2
|
import { GLTF2 } from 'babylonjs-loaders';
|
|
2
3
|
import { GIZMOS, GUI, TRANSPARENCY_MODES } from '../constants';
|
|
3
4
|
import { orthoOptions } from '../enums';
|
|
@@ -406,18 +407,47 @@ export const buildMeshPositionsArray = args => {
|
|
|
406
407
|
return defaultMeshPosition;
|
|
407
408
|
});
|
|
408
409
|
};
|
|
409
|
-
export const getImageFileFromBuffer =
|
|
410
|
+
export const getImageFileFromBuffer = args => {
|
|
411
|
+
const {
|
|
412
|
+
buffer,
|
|
413
|
+
asDataUrl
|
|
414
|
+
} = args || {};
|
|
410
415
|
if (_.isEmpty(buffer)) return '';
|
|
416
|
+
if (!_.isObject(buffer) && !_.isArray(buffer)) return buffer;
|
|
417
|
+
if (asDataUrl) {
|
|
418
|
+
// Convert buffer to data:image/png;base64 string
|
|
419
|
+
const Uint8ToString = u8a => {
|
|
420
|
+
if (_.isEmpty(u8a)) return '';
|
|
421
|
+
const maxChunkSize = 8192;
|
|
422
|
+
const chunks = [];
|
|
423
|
+
for (let i = 0; i < u8a.length; i += maxChunkSize) {
|
|
424
|
+
const newChunk = String.fromCharCode.apply(null, u8a.subarray(i, i + maxChunkSize));
|
|
425
|
+
chunks.push(newChunk);
|
|
426
|
+
}
|
|
427
|
+
return chunks.join('');
|
|
428
|
+
};
|
|
429
|
+
const ascii = new Uint8Array(buffer);
|
|
430
|
+
const dataString = btoa(Uint8ToString(ascii));
|
|
431
|
+
const dataUrl = `data:image/png;base64,${dataString}`;
|
|
432
|
+
return dataUrl;
|
|
433
|
+
}
|
|
411
434
|
const blob = new Blob([buffer], {
|
|
412
435
|
type: 'image/png'
|
|
413
436
|
});
|
|
414
|
-
const
|
|
415
|
-
return
|
|
437
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
438
|
+
return blobUrl;
|
|
416
439
|
};
|
|
417
|
-
export const getTextureUrl =
|
|
440
|
+
export const getTextureUrl = args => {
|
|
441
|
+
const {
|
|
442
|
+
texture,
|
|
443
|
+
asDataUrl
|
|
444
|
+
} = args || {};
|
|
418
445
|
const buffer = texture?._buffer;
|
|
419
446
|
if (_.isEmpty(buffer)) return texture?.url || '';
|
|
420
|
-
return getImageFileFromBuffer(
|
|
447
|
+
return getImageFileFromBuffer({
|
|
448
|
+
buffer,
|
|
449
|
+
asDataUrl
|
|
450
|
+
});
|
|
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(
|
|
473
|
+
url: getTextureUrl({
|
|
474
|
+
texture: material.albedoTexture,
|
|
475
|
+
asDataUrl: 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(
|
|
483
|
+
url: getTextureUrl({
|
|
484
|
+
texture: material.metallicTexture,
|
|
485
|
+
asDataUrl: true
|
|
486
|
+
})
|
|
451
487
|
},
|
|
452
488
|
roughness: material.roughness,
|
|
453
489
|
microSurfaceTexture: {
|
|
454
490
|
name: material.microSurfaceTexture?.name,
|
|
455
|
-
url: getTextureUrl(
|
|
491
|
+
url: getTextureUrl({
|
|
492
|
+
texture: material.microSurfaceTexture,
|
|
493
|
+
asDataUrl: 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(
|
|
500
|
+
url: getTextureUrl({
|
|
501
|
+
texture: material.emissiveTexture,
|
|
502
|
+
asDataUrl: true
|
|
503
|
+
})
|
|
462
504
|
},
|
|
463
505
|
bumpIntensity: material.bumpTexture?.level || 0.5,
|
|
464
506
|
bumpTexture: {
|
|
465
507
|
name: material.bumpTexture?.name,
|
|
466
|
-
url: getTextureUrl(
|
|
508
|
+
url: getTextureUrl({
|
|
509
|
+
texture: material.bumpTexture,
|
|
510
|
+
asDataUrl: 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(
|
|
521
|
+
url: getTextureUrl({
|
|
522
|
+
texture: material.opacityTexture,
|
|
523
|
+
asDataUrl: true
|
|
524
|
+
})
|
|
477
525
|
},
|
|
478
526
|
transparencyMode: material.transparencyMode,
|
|
479
527
|
sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,
|
package/package.json
CHANGED
|
@@ -190,7 +190,7 @@ export const updateMaterial = inboundData => {
|
|
|
190
190
|
clearTextureChannels,
|
|
191
191
|
} = payload;
|
|
192
192
|
|
|
193
|
-
const material = scene
|
|
193
|
+
const material = scene?.getMaterialByName?.(id, true);
|
|
194
194
|
|
|
195
195
|
if (material) {
|
|
196
196
|
// Renaming material.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
1
2
|
import { GLTF2 } from 'babylonjs-loaders';
|
|
2
3
|
import { GIZMOS, GUI, TRANSPARENCY_MODES } from '../constants';
|
|
3
4
|
import { orthoOptions } from '../enums';
|
|
@@ -466,20 +467,47 @@ export const buildMeshPositionsArray = args => {
|
|
|
466
467
|
});
|
|
467
468
|
};
|
|
468
469
|
|
|
469
|
-
export const getImageFileFromBuffer =
|
|
470
|
+
export const getImageFileFromBuffer = args => {
|
|
471
|
+
const { buffer, asDataUrl } = args || {};
|
|
472
|
+
|
|
470
473
|
if (_.isEmpty(buffer)) return '';
|
|
474
|
+
if (!_.isObject(buffer) && !_.isArray(buffer)) return buffer;
|
|
475
|
+
|
|
476
|
+
if (asDataUrl) {
|
|
477
|
+
// Convert buffer to data:image/png;base64 string
|
|
478
|
+
const Uint8ToString = u8a => {
|
|
479
|
+
if (_.isEmpty(u8a)) return '';
|
|
480
|
+
|
|
481
|
+
const maxChunkSize = 8192;
|
|
482
|
+
const chunks = [];
|
|
483
|
+
|
|
484
|
+
for (let i = 0; i < u8a.length; i += maxChunkSize) {
|
|
485
|
+
const newChunk = String.fromCharCode.apply(null, u8a.subarray(i, i + maxChunkSize));
|
|
486
|
+
chunks.push(newChunk);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return chunks.join('');
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const ascii = new Uint8Array(buffer);
|
|
493
|
+
const dataString = btoa(Uint8ToString(ascii));
|
|
494
|
+
const dataUrl = `data:image/png;base64,${dataString}`;
|
|
495
|
+
|
|
496
|
+
return dataUrl;
|
|
497
|
+
}
|
|
471
498
|
|
|
472
499
|
const blob = new Blob([ buffer ], { type: 'image/png' });
|
|
473
|
-
const
|
|
500
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
474
501
|
|
|
475
|
-
return
|
|
502
|
+
return blobUrl;
|
|
476
503
|
};
|
|
477
504
|
|
|
478
|
-
export const getTextureUrl =
|
|
505
|
+
export const getTextureUrl = args => {
|
|
506
|
+
const { texture, asDataUrl } = args || {};
|
|
479
507
|
const buffer = texture?._buffer;
|
|
480
508
|
|
|
481
509
|
if (_.isEmpty(buffer)) return texture?.url || '';
|
|
482
|
-
return getImageFileFromBuffer(buffer);
|
|
510
|
+
return getImageFileFromBuffer({ buffer, asDataUrl });
|
|
483
511
|
};
|
|
484
512
|
|
|
485
513
|
export const materialData = material => {
|
|
@@ -508,30 +536,30 @@ export const materialData = material => {
|
|
|
508
536
|
albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
509
537
|
albedoTexture: {
|
|
510
538
|
name: material.albedoTexture?.name,
|
|
511
|
-
url: getTextureUrl(material.albedoTexture),
|
|
539
|
+
url: getTextureUrl({ texture: material.albedoTexture, asDataUrl: true }),
|
|
512
540
|
},
|
|
513
541
|
albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
|
|
514
542
|
environmentIntensity: material.environmentIntensity,
|
|
515
543
|
metallic: material.metallic,
|
|
516
544
|
metallicTexture: {
|
|
517
545
|
name: material.metallicTexture?.name,
|
|
518
|
-
url: getTextureUrl(material.metallicTexture),
|
|
546
|
+
url: getTextureUrl({ texture: material.metallicTexture, asDataUrl: true }),
|
|
519
547
|
},
|
|
520
548
|
roughness: material.roughness,
|
|
521
549
|
microSurfaceTexture: {
|
|
522
550
|
name: material.microSurfaceTexture?.name,
|
|
523
|
-
url: getTextureUrl(material.microSurfaceTexture),
|
|
551
|
+
url: getTextureUrl({ texture: material.microSurfaceTexture, asDataUrl: true }),
|
|
524
552
|
},
|
|
525
553
|
emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
526
554
|
emissiveIntensity: material.emissiveIntensity,
|
|
527
555
|
emissiveTexture: {
|
|
528
556
|
name: material.emissiveTexture?.name,
|
|
529
|
-
url: getTextureUrl(material.emissiveTexture),
|
|
557
|
+
url: getTextureUrl({ texture: material.emissiveTexture, asDataUrl: true }),
|
|
530
558
|
},
|
|
531
559
|
bumpIntensity: material.bumpTexture?.level || 0.5,
|
|
532
560
|
bumpTexture: {
|
|
533
561
|
name: material.bumpTexture?.name,
|
|
534
|
-
url: getTextureUrl(material.bumpTexture),
|
|
562
|
+
url: getTextureUrl({ texture: material.bumpTexture, asDataUrl: true }),
|
|
535
563
|
},
|
|
536
564
|
|
|
537
565
|
// Advanced
|
|
@@ -542,7 +570,7 @@ export const materialData = material => {
|
|
|
542
570
|
alpha: material.alpha,
|
|
543
571
|
opacityTexture: {
|
|
544
572
|
name: material.opacityTexture?.name,
|
|
545
|
-
url: getTextureUrl(material.opacityTexture),
|
|
573
|
+
url: getTextureUrl({ texture: material.opacityTexture, asDataUrl: true }),
|
|
546
574
|
},
|
|
547
575
|
transparencyMode: material.transparencyMode,
|
|
548
576
|
sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,
|