@archvisioninc/canvas 2.6.7 → 2.6.8
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,53 @@ 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 (asDataUrl) {
|
|
417
|
+
const ascii = new Uint8Array(buffer);
|
|
418
|
+
const Uint8ToString = u8a => {
|
|
419
|
+
if (_.isEmpty(u8a)) return '';
|
|
420
|
+
const maxChunkSize = 8192;
|
|
421
|
+
const chunks = [];
|
|
422
|
+
for (let i = 0; i < u8a.length; i += maxChunkSize) {
|
|
423
|
+
const newChunk = String.fromCharCode.apply(null, u8a.subarray(i, i + maxChunkSize));
|
|
424
|
+
chunks.push(newChunk);
|
|
425
|
+
}
|
|
426
|
+
return chunks.join('');
|
|
427
|
+
};
|
|
428
|
+
const dataString = btoa(Uint8ToString(ascii));
|
|
429
|
+
const blob = new Blob([dataString], {
|
|
430
|
+
type: 'image/png'
|
|
431
|
+
});
|
|
432
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
433
|
+
console.log({
|
|
434
|
+
dataString,
|
|
435
|
+
blob,
|
|
436
|
+
blobUrl
|
|
437
|
+
});
|
|
438
|
+
return blobUrl;
|
|
439
|
+
}
|
|
411
440
|
const blob = new Blob([buffer], {
|
|
412
441
|
type: 'image/png'
|
|
413
442
|
});
|
|
414
443
|
const url = URL.createObjectURL(blob);
|
|
415
444
|
return url;
|
|
416
445
|
};
|
|
417
|
-
export const getTextureUrl =
|
|
446
|
+
export const getTextureUrl = args => {
|
|
447
|
+
const {
|
|
448
|
+
texture,
|
|
449
|
+
asDataUrl
|
|
450
|
+
} = args || {};
|
|
418
451
|
const buffer = texture?._buffer;
|
|
419
452
|
if (_.isEmpty(buffer)) return texture?.url || '';
|
|
420
|
-
return getImageFileFromBuffer(
|
|
453
|
+
return getImageFileFromBuffer({
|
|
454
|
+
buffer,
|
|
455
|
+
asDataUrl
|
|
456
|
+
});
|
|
421
457
|
};
|
|
422
458
|
export const materialData = material => {
|
|
423
459
|
const meshesWithMaterial = getUserMeshes().map(mesh => {
|
|
@@ -440,30 +476,45 @@ export const materialData = material => {
|
|
|
440
476
|
albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
441
477
|
albedoTexture: {
|
|
442
478
|
name: material.albedoTexture?.name,
|
|
443
|
-
url: getTextureUrl(
|
|
479
|
+
url: getTextureUrl({
|
|
480
|
+
texture: material.albedoTexture,
|
|
481
|
+
asDataUrl: true
|
|
482
|
+
})
|
|
444
483
|
},
|
|
445
484
|
albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
|
|
446
485
|
environmentIntensity: material.environmentIntensity,
|
|
447
486
|
metallic: material.metallic,
|
|
448
487
|
metallicTexture: {
|
|
449
488
|
name: material.metallicTexture?.name,
|
|
450
|
-
url: getTextureUrl(
|
|
489
|
+
url: getTextureUrl({
|
|
490
|
+
texture: material.metallicTexture,
|
|
491
|
+
asDataUrl: true
|
|
492
|
+
})
|
|
451
493
|
},
|
|
452
494
|
roughness: material.roughness,
|
|
453
495
|
microSurfaceTexture: {
|
|
454
496
|
name: material.microSurfaceTexture?.name,
|
|
455
|
-
url: getTextureUrl(
|
|
497
|
+
url: getTextureUrl({
|
|
498
|
+
texture: material.microSurfaceTexture,
|
|
499
|
+
asDataUrl: true
|
|
500
|
+
})
|
|
456
501
|
},
|
|
457
502
|
emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
458
503
|
emissiveIntensity: material.emissiveIntensity,
|
|
459
504
|
emissiveTexture: {
|
|
460
505
|
name: material.emissiveTexture?.name,
|
|
461
|
-
url: getTextureUrl(
|
|
506
|
+
url: getTextureUrl({
|
|
507
|
+
texture: material.emissiveTexture,
|
|
508
|
+
asDataUrl: true
|
|
509
|
+
})
|
|
462
510
|
},
|
|
463
511
|
bumpIntensity: material.bumpTexture?.level || 0.5,
|
|
464
512
|
bumpTexture: {
|
|
465
513
|
name: material.bumpTexture?.name,
|
|
466
|
-
url: getTextureUrl(
|
|
514
|
+
url: getTextureUrl({
|
|
515
|
+
texture: material.bumpTexture,
|
|
516
|
+
asDataUrl: true
|
|
517
|
+
})
|
|
467
518
|
},
|
|
468
519
|
// Advanced
|
|
469
520
|
clearCoatEnabled: material.clearCoat?.isEnabled || false,
|
|
@@ -473,7 +524,10 @@ export const materialData = material => {
|
|
|
473
524
|
alpha: material.alpha,
|
|
474
525
|
opacityTexture: {
|
|
475
526
|
name: material.opacityTexture?.name,
|
|
476
|
-
url: getTextureUrl(
|
|
527
|
+
url: getTextureUrl({
|
|
528
|
+
texture: material.opacityTexture,
|
|
529
|
+
asDataUrl: true
|
|
530
|
+
})
|
|
477
531
|
},
|
|
478
532
|
transparencyMode: material.transparencyMode,
|
|
479
533
|
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,48 @@ 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 '';
|
|
471
474
|
|
|
475
|
+
if (asDataUrl) {
|
|
476
|
+
const ascii = new Uint8Array(buffer);
|
|
477
|
+
|
|
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 dataString = btoa(Uint8ToString(ascii));
|
|
493
|
+
const blob = new Blob([ dataString ], { type: 'image/png' });
|
|
494
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
495
|
+
|
|
496
|
+
console.log({ dataString, blob, blobUrl });
|
|
497
|
+
return blobUrl;
|
|
498
|
+
}
|
|
499
|
+
|
|
472
500
|
const blob = new Blob([ buffer ], { type: 'image/png' });
|
|
473
501
|
const url = URL.createObjectURL(blob);
|
|
474
502
|
|
|
475
503
|
return url;
|
|
476
504
|
};
|
|
477
505
|
|
|
478
|
-
export const getTextureUrl =
|
|
506
|
+
export const getTextureUrl = args => {
|
|
507
|
+
const { texture, asDataUrl } = args || {};
|
|
479
508
|
const buffer = texture?._buffer;
|
|
480
509
|
|
|
481
510
|
if (_.isEmpty(buffer)) return texture?.url || '';
|
|
482
|
-
return getImageFileFromBuffer(buffer);
|
|
511
|
+
return getImageFileFromBuffer({ buffer, asDataUrl });
|
|
483
512
|
};
|
|
484
513
|
|
|
485
514
|
export const materialData = material => {
|
|
@@ -508,30 +537,30 @@ export const materialData = material => {
|
|
|
508
537
|
albedoColor: material.albedoColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
509
538
|
albedoTexture: {
|
|
510
539
|
name: material.albedoTexture?.name,
|
|
511
|
-
url: getTextureUrl(material.albedoTexture),
|
|
540
|
+
url: getTextureUrl({ texture: material.albedoTexture, asDataUrl: true }),
|
|
512
541
|
},
|
|
513
542
|
albedoHasAlpha: material.albedoTexture?.hasAlpha || false,
|
|
514
543
|
environmentIntensity: material.environmentIntensity,
|
|
515
544
|
metallic: material.metallic,
|
|
516
545
|
metallicTexture: {
|
|
517
546
|
name: material.metallicTexture?.name,
|
|
518
|
-
url: getTextureUrl(material.metallicTexture),
|
|
547
|
+
url: getTextureUrl({ texture: material.metallicTexture, asDataUrl: true }),
|
|
519
548
|
},
|
|
520
549
|
roughness: material.roughness,
|
|
521
550
|
microSurfaceTexture: {
|
|
522
551
|
name: material.microSurfaceTexture?.name,
|
|
523
|
-
url: getTextureUrl(material.microSurfaceTexture),
|
|
552
|
+
url: getTextureUrl({ texture: material.microSurfaceTexture, asDataUrl: true }),
|
|
524
553
|
},
|
|
525
554
|
emissiveColor: material.emissiveColor?.toHexString() || props?.theme?.colors?.[props.$selectedTheme]?.black,
|
|
526
555
|
emissiveIntensity: material.emissiveIntensity,
|
|
527
556
|
emissiveTexture: {
|
|
528
557
|
name: material.emissiveTexture?.name,
|
|
529
|
-
url: getTextureUrl(material.emissiveTexture),
|
|
558
|
+
url: getTextureUrl({ texture: material.emissiveTexture, asDataUrl: true }),
|
|
530
559
|
},
|
|
531
560
|
bumpIntensity: material.bumpTexture?.level || 0.5,
|
|
532
561
|
bumpTexture: {
|
|
533
562
|
name: material.bumpTexture?.name,
|
|
534
|
-
url: getTextureUrl(material.bumpTexture),
|
|
563
|
+
url: getTextureUrl({ texture: material.bumpTexture, asDataUrl: true }),
|
|
535
564
|
},
|
|
536
565
|
|
|
537
566
|
// Advanced
|
|
@@ -542,7 +571,7 @@ export const materialData = material => {
|
|
|
542
571
|
alpha: material.alpha,
|
|
543
572
|
opacityTexture: {
|
|
544
573
|
name: material.opacityTexture?.name,
|
|
545
|
-
url: getTextureUrl(material.opacityTexture),
|
|
574
|
+
url: getTextureUrl({ texture: material.opacityTexture, asDataUrl: true }),
|
|
546
575
|
},
|
|
547
576
|
transparencyMode: material.transparencyMode,
|
|
548
577
|
sssRefractionEnabled: material.subSurface?.isRefractionEnabled || false,
|