@liveroom-tech/react-immersive 1.4.0 → 2.1.0
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.
- package/README.md +103 -59
- package/dist/index.d.mts +65 -6
- package/dist/index.d.ts +65 -6
- package/dist/index.js +458 -352
- package/dist/index.mjs +452 -350
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,9 +52,13 @@ __export(index_exports, {
|
|
|
52
52
|
MATERIAL_SIDES: () => MATERIAL_SIDES,
|
|
53
53
|
ModelViewer: () => ModelViewer,
|
|
54
54
|
SimpleModelViewer: () => SimpleModelViewer,
|
|
55
|
+
material: () => material,
|
|
56
|
+
patchBindings: () => patchBindings,
|
|
57
|
+
patchSceneConfig: () => patchSceneConfig,
|
|
55
58
|
useObjectBinding: () => useObjectBinding,
|
|
56
59
|
useObjectBindingIds: () => useObjectBindingIds,
|
|
57
|
-
|
|
60
|
+
useObjectBindings: () => useObjectBindings,
|
|
61
|
+
useSceneConfig: () => useSceneConfig,
|
|
58
62
|
useShareableViewerState: () => useShareableViewerState,
|
|
59
63
|
useViewerActions: () => useViewerActions,
|
|
60
64
|
useViewerAnimations: () => useViewerAnimations,
|
|
@@ -433,9 +437,9 @@ function addTriangleEdges(edges, triangle, indexed) {
|
|
|
433
437
|
addEdge(edges, triangle[1], triangle[2], indexed);
|
|
434
438
|
addEdge(edges, triangle[2], triangle[0], indexed);
|
|
435
439
|
}
|
|
436
|
-
function materialForIndex(
|
|
437
|
-
if (!Array.isArray(
|
|
438
|
-
return
|
|
440
|
+
function materialForIndex(material2, materialIndex) {
|
|
441
|
+
if (!Array.isArray(material2)) return material2;
|
|
442
|
+
return material2[materialIndex] ?? null;
|
|
439
443
|
}
|
|
440
444
|
function collectUvLayouts(scene) {
|
|
441
445
|
const layouts = /* @__PURE__ */ new Map();
|
|
@@ -454,16 +458,16 @@ function collectUvLayouts(scene) {
|
|
|
454
458
|
const groups = geometry.groups.length > 0 ? geometry.groups : [{ start: 0, count: elementCount, materialIndex: 0 }];
|
|
455
459
|
for (const group of groups) {
|
|
456
460
|
const materialIndex = group.materialIndex ?? 0;
|
|
457
|
-
const
|
|
458
|
-
if (!
|
|
459
|
-
let layout = layouts.get(
|
|
461
|
+
const material2 = materialForIndex(mesh.material, materialIndex);
|
|
462
|
+
if (!material2) continue;
|
|
463
|
+
let layout = layouts.get(material2.uuid);
|
|
460
464
|
if (!layout) {
|
|
461
465
|
unnamedMaterialIndex += 1;
|
|
462
466
|
layout = {
|
|
463
|
-
name:
|
|
467
|
+
name: material2.name || `Material ${unnamedMaterialIndex}`,
|
|
464
468
|
layers: /* @__PURE__ */ new Map()
|
|
465
469
|
};
|
|
466
|
-
layouts.set(
|
|
470
|
+
layouts.set(material2.uuid, layout);
|
|
467
471
|
}
|
|
468
472
|
let layer = layout.layers.get(mesh.uuid);
|
|
469
473
|
if (!layer) {
|
|
@@ -2362,14 +2366,14 @@ function resolveAnimationClips(clips) {
|
|
|
2362
2366
|
|
|
2363
2367
|
// src/components/model/materialUtils.ts
|
|
2364
2368
|
var import_three11 = require("three");
|
|
2365
|
-
function isMeshStandardMaterial(
|
|
2369
|
+
function isMeshStandardMaterial(material2) {
|
|
2366
2370
|
return Boolean(
|
|
2367
|
-
|
|
2371
|
+
material2 && typeof material2 === "object" && "clone" in material2 && "color" in material2 && "metalness" in material2 && "roughness" in material2
|
|
2368
2372
|
);
|
|
2369
2373
|
}
|
|
2370
|
-
function isMeshPhysicalMaterial(
|
|
2374
|
+
function isMeshPhysicalMaterial(material2) {
|
|
2371
2375
|
return Boolean(
|
|
2372
|
-
|
|
2376
|
+
material2 && typeof material2 === "object" && "isMeshPhysicalMaterial" in material2 && material2.isMeshPhysicalMaterial
|
|
2373
2377
|
);
|
|
2374
2378
|
}
|
|
2375
2379
|
function isMeshNode(object) {
|
|
@@ -2405,8 +2409,8 @@ var SRGB_TEXTURE_KEYS = /* @__PURE__ */ new Set([
|
|
|
2405
2409
|
function colorSpaceForTextureKey(key) {
|
|
2406
2410
|
return SRGB_TEXTURE_KEYS.has(key) ? import_three11.SRGBColorSpace : import_three11.NoColorSpace;
|
|
2407
2411
|
}
|
|
2408
|
-
function getMaterialTexturePath(
|
|
2409
|
-
return
|
|
2412
|
+
function getMaterialTexturePath(material2, key) {
|
|
2413
|
+
return material2?.[key]?.path;
|
|
2410
2414
|
}
|
|
2411
2415
|
function sideFromConfig(side) {
|
|
2412
2416
|
if (side === "back") return import_three11.BackSide;
|
|
@@ -2440,10 +2444,10 @@ function getClipLoopMode(clipConfig) {
|
|
|
2440
2444
|
|
|
2441
2445
|
// src/components/model/materialFactory.ts
|
|
2442
2446
|
var import_three12 = require("three");
|
|
2443
|
-
function toStandardMaterial(
|
|
2444
|
-
if (isMeshStandardMaterial(
|
|
2445
|
-
if (!
|
|
2446
|
-
const src =
|
|
2447
|
+
function toStandardMaterial(material2) {
|
|
2448
|
+
if (isMeshStandardMaterial(material2)) return material2;
|
|
2449
|
+
if (!material2 || typeof material2 !== "object") return null;
|
|
2450
|
+
const src = material2;
|
|
2447
2451
|
const std = new import_three12.MeshStandardMaterial();
|
|
2448
2452
|
if (typeof src.name === "string") std.name = src.name;
|
|
2449
2453
|
std.metalness = 0;
|
|
@@ -2624,69 +2628,69 @@ function snapshotBaseMaterial(cloned) {
|
|
|
2624
2628
|
|
|
2625
2629
|
// src/components/model/applyMaterialConfig.ts
|
|
2626
2630
|
var import_three13 = require("three");
|
|
2627
|
-
function applyMaterialConfig(
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
toSafeVector2(
|
|
2631
|
+
function applyMaterialConfig(material2, configuredMaterial, resolvedBaseColor) {
|
|
2632
|
+
material2.map = material2.userData.baseMap ?? null;
|
|
2633
|
+
material2.color.copy(material2.userData.baseColor);
|
|
2634
|
+
material2.metalness = material2.userData.baseMetalness ?? material2.metalness;
|
|
2635
|
+
material2.metalnessMap = material2.userData.baseMetalnessMap ?? null;
|
|
2636
|
+
material2.roughness = material2.userData.baseRoughness ?? material2.roughness;
|
|
2637
|
+
material2.roughnessMap = material2.userData.baseRoughnessMap ?? null;
|
|
2638
|
+
material2.emissive.copy(material2.userData.baseEmissive ?? new import_three13.Color(0, 0, 0));
|
|
2639
|
+
material2.emissiveIntensity = material2.userData.baseEmissiveIntensity ?? material2.emissiveIntensity;
|
|
2640
|
+
material2.emissiveMap = material2.userData.baseEmissiveMap ?? null;
|
|
2641
|
+
material2.opacity = material2.userData.baseOpacity ?? 1;
|
|
2642
|
+
material2.transparent = material2.userData.baseTransparent ?? false;
|
|
2643
|
+
material2.alphaMap = material2.userData.baseAlphaMap ?? null;
|
|
2644
|
+
material2.alphaTest = material2.userData.baseAlphaTest ?? 0;
|
|
2645
|
+
material2.alphaHash = material2.userData.baseAlphaHash ?? false;
|
|
2646
|
+
material2.dithering = material2.userData.baseDithering ?? false;
|
|
2647
|
+
material2.blending = material2.userData.baseBlending ?? import_three13.NormalBlending;
|
|
2648
|
+
material2.depthWrite = material2.userData.baseDepthWrite ?? true;
|
|
2649
|
+
material2.side = material2.userData.baseSide ?? import_three13.FrontSide;
|
|
2650
|
+
material2.normalMap = material2.userData.baseNormalMap ?? null;
|
|
2651
|
+
material2.normalScale.copy(toSafeVector2(material2.userData.baseNormalScale));
|
|
2652
|
+
material2.bumpMap = material2.userData.baseBumpMap ?? null;
|
|
2653
|
+
material2.bumpScale = material2.userData.baseBumpScale ?? material2.bumpScale;
|
|
2654
|
+
material2.aoMap = material2.userData.baseAoMap ?? null;
|
|
2655
|
+
material2.aoMapIntensity = material2.userData.baseAoMapIntensity ?? material2.aoMapIntensity;
|
|
2656
|
+
material2.displacementMap = material2.userData.baseDisplacementMap ?? null;
|
|
2657
|
+
material2.displacementScale = material2.userData.baseDisplacementScale ?? material2.displacementScale;
|
|
2658
|
+
material2.displacementBias = material2.userData.baseDisplacementBias ?? material2.displacementBias;
|
|
2659
|
+
material2.clearcoat = material2.userData.baseClearcoat ?? material2.clearcoat;
|
|
2660
|
+
material2.clearcoatMap = material2.userData.baseClearcoatMap ?? null;
|
|
2661
|
+
material2.clearcoatRoughness = material2.userData.baseClearcoatRoughness ?? material2.clearcoatRoughness;
|
|
2662
|
+
material2.clearcoatRoughnessMap = material2.userData.baseClearcoatRoughnessMap ?? null;
|
|
2663
|
+
material2.clearcoatNormalMap = material2.userData.baseClearcoatNormalMap ?? null;
|
|
2664
|
+
material2.clearcoatNormalScale.copy(
|
|
2665
|
+
toSafeVector2(material2.userData.baseClearcoatNormalScale)
|
|
2662
2666
|
);
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2667
|
+
material2.sheen = material2.userData.baseSheen ?? material2.sheen;
|
|
2668
|
+
material2.sheenColor.copy(
|
|
2669
|
+
material2.userData.baseSheenColor ?? new import_three13.Color(0, 0, 0)
|
|
2666
2670
|
);
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2671
|
+
material2.sheenColorMap = material2.userData.baseSheenColorMap ?? null;
|
|
2672
|
+
material2.sheenRoughness = material2.userData.baseSheenRoughness ?? material2.sheenRoughness;
|
|
2673
|
+
material2.sheenRoughnessMap = material2.userData.baseSheenRoughnessMap ?? null;
|
|
2674
|
+
material2.anisotropy = material2.userData.baseAnisotropy ?? material2.anisotropy;
|
|
2675
|
+
material2.anisotropyRotation = material2.userData.baseAnisotropyRotation ?? material2.anisotropyRotation;
|
|
2676
|
+
material2.anisotropyMap = material2.userData.baseAnisotropyMap ?? null;
|
|
2677
|
+
material2.transmission = material2.userData.baseTransmission ?? material2.transmission;
|
|
2678
|
+
material2.transmissionMap = material2.userData.baseTransmissionMap ?? null;
|
|
2679
|
+
material2.thickness = material2.userData.baseThickness ?? material2.thickness;
|
|
2680
|
+
material2.thicknessMap = material2.userData.baseThicknessMap ?? null;
|
|
2681
|
+
material2.attenuationColor.copy(
|
|
2682
|
+
material2.userData.baseAttenuationColor ?? new import_three13.Color("#ffffff")
|
|
2679
2683
|
);
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2684
|
+
material2.attenuationDistance = material2.userData.baseAttenuationDistance ?? material2.attenuationDistance;
|
|
2685
|
+
material2.reflectivity = material2.userData.baseReflectivity ?? material2.reflectivity;
|
|
2686
|
+
material2.specularIntensity = material2.userData.baseSpecularIntensity ?? material2.specularIntensity;
|
|
2687
|
+
material2.specularIntensityMap = material2.userData.baseSpecularIntensityMap ?? null;
|
|
2688
|
+
material2.specularColor.copy(
|
|
2689
|
+
material2.userData.baseSpecularColor ?? new import_three13.Color("#ffffff")
|
|
2686
2690
|
);
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2691
|
+
material2.specularColorMap = material2.userData.baseSpecularColorMap ?? null;
|
|
2692
|
+
material2.flatShading = material2.userData.baseFlatShading ?? material2.flatShading;
|
|
2693
|
+
material2.envMapIntensity = material2.userData.baseEnvMapIntensity ?? material2.envMapIntensity;
|
|
2690
2694
|
const texturePath = getMaterialTexturePath(configuredMaterial, "texture");
|
|
2691
2695
|
const metalnessMapPath = getMaterialTexturePath(
|
|
2692
2696
|
configuredMaterial,
|
|
@@ -2749,180 +2753,180 @@ function applyMaterialConfig(material, configuredMaterial, resolvedBaseColor) {
|
|
|
2749
2753
|
"specularColorMap"
|
|
2750
2754
|
);
|
|
2751
2755
|
if (texturePath) {
|
|
2752
|
-
|
|
2753
|
-
|
|
2756
|
+
material2.map = getOrCreateTexture(texturePath, import_three13.SRGBColorSpace);
|
|
2757
|
+
material2.color.set(resolvedBaseColor ?? "#ffffff");
|
|
2754
2758
|
} else if (resolvedBaseColor) {
|
|
2755
|
-
|
|
2756
|
-
|
|
2759
|
+
material2.map = null;
|
|
2760
|
+
material2.color.set(resolvedBaseColor);
|
|
2757
2761
|
}
|
|
2758
2762
|
if (metalnessMapPath) {
|
|
2759
|
-
|
|
2763
|
+
material2.metalnessMap = getOrCreateTexture(metalnessMapPath);
|
|
2760
2764
|
}
|
|
2761
2765
|
if (configuredMaterial?.metalness !== void 0) {
|
|
2762
|
-
|
|
2766
|
+
material2.metalness = configuredMaterial.metalness;
|
|
2763
2767
|
}
|
|
2764
2768
|
if (roughnessMapPath) {
|
|
2765
|
-
|
|
2769
|
+
material2.roughnessMap = getOrCreateTexture(roughnessMapPath);
|
|
2766
2770
|
}
|
|
2767
2771
|
if (configuredMaterial?.roughness !== void 0) {
|
|
2768
|
-
|
|
2772
|
+
material2.roughness = configuredMaterial.roughness;
|
|
2769
2773
|
}
|
|
2770
2774
|
if (configuredMaterial?.emissive) {
|
|
2771
|
-
|
|
2775
|
+
material2.emissive.set(configuredMaterial.emissive);
|
|
2772
2776
|
} else if (emissiveMapPath) {
|
|
2773
|
-
|
|
2777
|
+
material2.emissive.set("#ffffff");
|
|
2774
2778
|
}
|
|
2775
2779
|
if (configuredMaterial?.emissiveIntensity !== void 0) {
|
|
2776
|
-
|
|
2780
|
+
material2.emissiveIntensity = configuredMaterial.emissiveIntensity;
|
|
2777
2781
|
}
|
|
2778
2782
|
if (emissiveMapPath) {
|
|
2779
|
-
|
|
2783
|
+
material2.emissiveMap = getOrCreateTexture(emissiveMapPath, import_three13.SRGBColorSpace);
|
|
2780
2784
|
}
|
|
2781
2785
|
if (configuredMaterial?.opacity !== void 0) {
|
|
2782
|
-
|
|
2786
|
+
material2.opacity = configuredMaterial.opacity;
|
|
2783
2787
|
}
|
|
2784
2788
|
if (alphaMapPath) {
|
|
2785
|
-
|
|
2789
|
+
material2.alphaMap = getOrCreateTexture(alphaMapPath);
|
|
2786
2790
|
}
|
|
2787
2791
|
if (configuredMaterial?.alphaTest !== void 0) {
|
|
2788
|
-
|
|
2792
|
+
material2.alphaTest = configuredMaterial.alphaTest;
|
|
2789
2793
|
}
|
|
2790
2794
|
if (configuredMaterial?.alphaHash !== void 0) {
|
|
2791
|
-
|
|
2795
|
+
material2.alphaHash = configuredMaterial.alphaHash;
|
|
2792
2796
|
}
|
|
2793
2797
|
if (configuredMaterial?.dithering !== void 0) {
|
|
2794
|
-
|
|
2798
|
+
material2.dithering = configuredMaterial.dithering;
|
|
2795
2799
|
}
|
|
2796
2800
|
if (configuredMaterial?.blendingMode) {
|
|
2797
|
-
|
|
2798
|
-
|
|
2801
|
+
material2.blending = blendingFromConfig(configuredMaterial.blendingMode);
|
|
2802
|
+
material2.depthWrite = configuredMaterial.blendingMode !== "additive";
|
|
2799
2803
|
}
|
|
2800
2804
|
if (configuredMaterial?.side) {
|
|
2801
|
-
|
|
2805
|
+
material2.side = sideFromConfig(configuredMaterial.side);
|
|
2802
2806
|
}
|
|
2803
2807
|
if (normalMapPath) {
|
|
2804
|
-
|
|
2808
|
+
material2.normalMap = getOrCreateTexture(normalMapPath);
|
|
2805
2809
|
}
|
|
2806
2810
|
if (normalMapPath || configuredMaterial?.normalScale !== void 0) {
|
|
2807
|
-
const normalScale = configuredMaterial?.normalScale ?? Math.abs(toSafeVector2(
|
|
2808
|
-
|
|
2811
|
+
const normalScale = configuredMaterial?.normalScale ?? Math.abs(toSafeVector2(material2.userData.baseNormalScale).x);
|
|
2812
|
+
material2.normalScale.set(
|
|
2809
2813
|
normalScale,
|
|
2810
2814
|
configuredMaterial?.flipNormalY ? -normalScale : normalScale
|
|
2811
2815
|
);
|
|
2812
2816
|
}
|
|
2813
2817
|
if (bumpMapPath) {
|
|
2814
|
-
|
|
2818
|
+
material2.bumpMap = getOrCreateTexture(bumpMapPath);
|
|
2815
2819
|
}
|
|
2816
2820
|
if (configuredMaterial?.bumpScale !== void 0) {
|
|
2817
|
-
|
|
2821
|
+
material2.bumpScale = configuredMaterial.bumpScale;
|
|
2818
2822
|
}
|
|
2819
2823
|
if (aoMapPath) {
|
|
2820
|
-
|
|
2824
|
+
material2.aoMap = getOrCreateTexture(aoMapPath);
|
|
2821
2825
|
}
|
|
2822
2826
|
if (configuredMaterial?.aoMapIntensity !== void 0) {
|
|
2823
|
-
|
|
2827
|
+
material2.aoMapIntensity = configuredMaterial.aoMapIntensity;
|
|
2824
2828
|
}
|
|
2825
2829
|
if (displacementMapPath) {
|
|
2826
|
-
|
|
2830
|
+
material2.displacementMap = getOrCreateTexture(displacementMapPath);
|
|
2827
2831
|
}
|
|
2828
2832
|
if (configuredMaterial?.displacementScale !== void 0) {
|
|
2829
|
-
|
|
2833
|
+
material2.displacementScale = configuredMaterial.displacementScale;
|
|
2830
2834
|
}
|
|
2831
2835
|
if (configuredMaterial?.displacementBias !== void 0) {
|
|
2832
|
-
|
|
2836
|
+
material2.displacementBias = configuredMaterial.displacementBias;
|
|
2833
2837
|
}
|
|
2834
2838
|
if (clearcoatMapPath) {
|
|
2835
|
-
|
|
2839
|
+
material2.clearcoatMap = getOrCreateTexture(clearcoatMapPath);
|
|
2836
2840
|
}
|
|
2837
2841
|
if (configuredMaterial?.clearcoat !== void 0) {
|
|
2838
|
-
|
|
2842
|
+
material2.clearcoat = configuredMaterial.clearcoat;
|
|
2839
2843
|
}
|
|
2840
2844
|
if (clearcoatRoughnessMapPath) {
|
|
2841
|
-
|
|
2845
|
+
material2.clearcoatRoughnessMap = getOrCreateTexture(
|
|
2842
2846
|
clearcoatRoughnessMapPath
|
|
2843
2847
|
);
|
|
2844
2848
|
}
|
|
2845
2849
|
if (configuredMaterial?.clearcoatRoughness !== void 0) {
|
|
2846
|
-
|
|
2850
|
+
material2.clearcoatRoughness = configuredMaterial.clearcoatRoughness;
|
|
2847
2851
|
}
|
|
2848
2852
|
if (clearcoatNormalMapPath) {
|
|
2849
|
-
|
|
2853
|
+
material2.clearcoatNormalMap = getOrCreateTexture(clearcoatNormalMapPath);
|
|
2850
2854
|
}
|
|
2851
2855
|
if (clearcoatNormalMapPath || configuredMaterial?.clearcoatNormalScale !== void 0) {
|
|
2852
|
-
const clearcoatNormalScale = configuredMaterial?.clearcoatNormalScale ?? Math.abs(toSafeVector2(
|
|
2853
|
-
|
|
2856
|
+
const clearcoatNormalScale = configuredMaterial?.clearcoatNormalScale ?? Math.abs(toSafeVector2(material2.userData.baseClearcoatNormalScale).x);
|
|
2857
|
+
material2.clearcoatNormalScale.set(
|
|
2854
2858
|
clearcoatNormalScale,
|
|
2855
2859
|
configuredMaterial?.flipClearcoatNormalY ? -clearcoatNormalScale : clearcoatNormalScale
|
|
2856
2860
|
);
|
|
2857
2861
|
}
|
|
2858
2862
|
if (configuredMaterial?.sheen !== void 0) {
|
|
2859
|
-
|
|
2863
|
+
material2.sheen = configuredMaterial.sheen;
|
|
2860
2864
|
}
|
|
2861
2865
|
if (configuredMaterial?.sheenColor) {
|
|
2862
|
-
|
|
2866
|
+
material2.sheenColor.set(configuredMaterial.sheenColor);
|
|
2863
2867
|
}
|
|
2864
2868
|
if (sheenColorMapPath) {
|
|
2865
|
-
|
|
2869
|
+
material2.sheenColorMap = getOrCreateTexture(
|
|
2866
2870
|
sheenColorMapPath,
|
|
2867
2871
|
import_three13.SRGBColorSpace
|
|
2868
2872
|
);
|
|
2869
2873
|
}
|
|
2870
2874
|
if (configuredMaterial?.sheenRoughness !== void 0) {
|
|
2871
|
-
|
|
2875
|
+
material2.sheenRoughness = configuredMaterial.sheenRoughness;
|
|
2872
2876
|
}
|
|
2873
2877
|
if (sheenRoughnessMapPath) {
|
|
2874
|
-
|
|
2878
|
+
material2.sheenRoughnessMap = getOrCreateTexture(sheenRoughnessMapPath);
|
|
2875
2879
|
}
|
|
2876
2880
|
if (configuredMaterial?.anisotropy !== void 0) {
|
|
2877
|
-
|
|
2881
|
+
material2.anisotropy = configuredMaterial.anisotropy;
|
|
2878
2882
|
}
|
|
2879
2883
|
if (configuredMaterial?.anisotropyRotation !== void 0) {
|
|
2880
|
-
|
|
2884
|
+
material2.anisotropyRotation = configuredMaterial.anisotropyRotation;
|
|
2881
2885
|
}
|
|
2882
2886
|
if (anisotropyMapPath) {
|
|
2883
|
-
|
|
2887
|
+
material2.anisotropyMap = getOrCreateTexture(anisotropyMapPath);
|
|
2884
2888
|
}
|
|
2885
2889
|
if (configuredMaterial?.transmission !== void 0) {
|
|
2886
|
-
|
|
2890
|
+
material2.transmission = configuredMaterial.transmission;
|
|
2887
2891
|
}
|
|
2888
2892
|
if (transmissionMapPath) {
|
|
2889
|
-
|
|
2893
|
+
material2.transmissionMap = getOrCreateTexture(transmissionMapPath);
|
|
2890
2894
|
}
|
|
2891
2895
|
if (configuredMaterial?.thickness !== void 0) {
|
|
2892
|
-
|
|
2896
|
+
material2.thickness = configuredMaterial.thickness;
|
|
2893
2897
|
}
|
|
2894
2898
|
if (thicknessMapPath) {
|
|
2895
|
-
|
|
2899
|
+
material2.thicknessMap = getOrCreateTexture(thicknessMapPath);
|
|
2896
2900
|
}
|
|
2897
2901
|
if (configuredMaterial?.attenuationColor) {
|
|
2898
|
-
|
|
2902
|
+
material2.attenuationColor.set(configuredMaterial.attenuationColor);
|
|
2899
2903
|
}
|
|
2900
2904
|
if (configuredMaterial?.attenuationDistance !== void 0) {
|
|
2901
|
-
|
|
2905
|
+
material2.attenuationDistance = configuredMaterial.attenuationDistance;
|
|
2902
2906
|
}
|
|
2903
2907
|
if (configuredMaterial?.reflectivity !== void 0) {
|
|
2904
|
-
|
|
2908
|
+
material2.reflectivity = configuredMaterial.reflectivity;
|
|
2905
2909
|
}
|
|
2906
2910
|
if (configuredMaterial?.specularIntensity !== void 0) {
|
|
2907
|
-
|
|
2911
|
+
material2.specularIntensity = configuredMaterial.specularIntensity;
|
|
2908
2912
|
}
|
|
2909
2913
|
if (specularIntensityMapPath) {
|
|
2910
|
-
|
|
2914
|
+
material2.specularIntensityMap = getOrCreateTexture(
|
|
2911
2915
|
specularIntensityMapPath
|
|
2912
2916
|
);
|
|
2913
2917
|
}
|
|
2914
2918
|
if (configuredMaterial?.specularColor) {
|
|
2915
|
-
|
|
2919
|
+
material2.specularColor.set(configuredMaterial.specularColor);
|
|
2916
2920
|
}
|
|
2917
2921
|
if (specularColorMapPath) {
|
|
2918
|
-
|
|
2922
|
+
material2.specularColorMap = getOrCreateTexture(
|
|
2919
2923
|
specularColorMapPath,
|
|
2920
2924
|
import_three13.SRGBColorSpace
|
|
2921
2925
|
);
|
|
2922
2926
|
}
|
|
2923
|
-
|
|
2924
|
-
if (!
|
|
2925
|
-
|
|
2927
|
+
material2.transparent = material2.opacity < 1 || material2.transmission > 0 || material2.blending !== import_three13.NormalBlending || Boolean((alphaMapPath || material2.alphaMap) && material2.alphaTest <= 0);
|
|
2928
|
+
if (!material2.transparent) {
|
|
2929
|
+
material2.depthWrite = true;
|
|
2926
2930
|
}
|
|
2927
2931
|
}
|
|
2928
2932
|
|
|
@@ -3065,8 +3069,8 @@ function Model({
|
|
|
3065
3069
|
}, [perNodeMaterials, materialRefsOut]);
|
|
3066
3070
|
(0, import_react11.useEffect)(() => {
|
|
3067
3071
|
return () => {
|
|
3068
|
-
for (const
|
|
3069
|
-
|
|
3072
|
+
for (const material2 of Object.values(perNodeMaterials)) {
|
|
3073
|
+
material2.dispose();
|
|
3070
3074
|
}
|
|
3071
3075
|
};
|
|
3072
3076
|
}, [perNodeMaterials]);
|
|
@@ -3078,15 +3082,15 @@ function Model({
|
|
|
3078
3082
|
const perNodeBasicMaterials = (0, import_react11.useMemo)(() => {
|
|
3079
3083
|
const map = {};
|
|
3080
3084
|
if (shadingMode !== "unlit") return map;
|
|
3081
|
-
for (const [nodeName,
|
|
3085
|
+
for (const [nodeName, material2] of Object.entries(perNodeMaterials)) {
|
|
3082
3086
|
const basic = new import_three14.MeshBasicMaterial();
|
|
3083
|
-
basic.color.copy(
|
|
3084
|
-
basic.map =
|
|
3085
|
-
basic.alphaMap =
|
|
3086
|
-
basic.alphaTest =
|
|
3087
|
-
basic.transparent =
|
|
3088
|
-
basic.opacity =
|
|
3089
|
-
basic.side =
|
|
3087
|
+
basic.color.copy(material2.color);
|
|
3088
|
+
basic.map = material2.map;
|
|
3089
|
+
basic.alphaMap = material2.alphaMap;
|
|
3090
|
+
basic.alphaTest = material2.alphaTest;
|
|
3091
|
+
basic.transparent = material2.transparent;
|
|
3092
|
+
basic.opacity = material2.opacity;
|
|
3093
|
+
basic.side = material2.side;
|
|
3090
3094
|
map[nodeName] = basic;
|
|
3091
3095
|
}
|
|
3092
3096
|
return map;
|
|
@@ -3103,25 +3107,25 @@ function Model({
|
|
|
3103
3107
|
const map = {};
|
|
3104
3108
|
if (shadingMode !== "lit" || rendererMode !== "matcap") return map;
|
|
3105
3109
|
const matcapTexture = getMatcapTexture();
|
|
3106
|
-
for (const [nodeName,
|
|
3110
|
+
for (const [nodeName, material2] of Object.entries(perNodeMaterials)) {
|
|
3107
3111
|
const matcap = new import_three14.MeshMatcapMaterial();
|
|
3108
3112
|
matcap.matcap = matcapTexture;
|
|
3109
|
-
matcap.color.copy(
|
|
3110
|
-
matcap.alphaMap =
|
|
3111
|
-
matcap.alphaTest =
|
|
3112
|
-
matcap.side =
|
|
3113
|
+
matcap.color.copy(material2.color);
|
|
3114
|
+
matcap.alphaMap = material2.alphaMap;
|
|
3115
|
+
matcap.alphaTest = material2.alphaTest;
|
|
3116
|
+
matcap.side = material2.side;
|
|
3113
3117
|
map[nodeName] = matcap;
|
|
3114
3118
|
}
|
|
3115
3119
|
return map;
|
|
3116
3120
|
}, [perNodeMaterials, shadingMode, rendererMode]);
|
|
3117
3121
|
(0, import_react11.useEffect)(() => {
|
|
3118
3122
|
return () => {
|
|
3119
|
-
for (const
|
|
3120
|
-
|
|
3121
|
-
for (const
|
|
3122
|
-
|
|
3123
|
-
for (const
|
|
3124
|
-
|
|
3123
|
+
for (const material2 of Object.values(perNodeBasicMaterials))
|
|
3124
|
+
material2.dispose();
|
|
3125
|
+
for (const material2 of Object.values(perNodeNormalMaterials))
|
|
3126
|
+
material2.dispose();
|
|
3127
|
+
for (const material2 of Object.values(perNodeMatcapMaterials))
|
|
3128
|
+
material2.dispose();
|
|
3125
3129
|
};
|
|
3126
3130
|
}, [perNodeBasicMaterials, perNodeNormalMaterials, perNodeMatcapMaterials]);
|
|
3127
3131
|
const materialForNode = (nodeName) => {
|
|
@@ -3167,8 +3171,8 @@ function Model({
|
|
|
3167
3171
|
const node = nodeMap[glbNodeName];
|
|
3168
3172
|
if (!isMeshNode(node)) continue;
|
|
3169
3173
|
node.visible = binding.visible !== false;
|
|
3170
|
-
const
|
|
3171
|
-
if (!
|
|
3174
|
+
const material2 = perNodeMaterials[nodeName];
|
|
3175
|
+
if (!material2) continue;
|
|
3172
3176
|
if (rendererMode !== "uv-checker") {
|
|
3173
3177
|
const activeMaterial = materialForNode(nodeName);
|
|
3174
3178
|
if (activeMaterial) {
|
|
@@ -3205,19 +3209,19 @@ function Model({
|
|
|
3205
3209
|
delete appliedTextureUrls.current[nodeName];
|
|
3206
3210
|
}
|
|
3207
3211
|
const resolvedBaseColor = itemMat?.hex ?? configuredMaterial?.baseColor;
|
|
3208
|
-
applyMaterialConfig(
|
|
3212
|
+
applyMaterialConfig(material2, configuredMaterial, resolvedBaseColor);
|
|
3209
3213
|
if (isHighlightedByHover) {
|
|
3210
|
-
|
|
3214
|
+
material2.emissive?.add(HIGHLIGHT_EMISSIVE_TINT);
|
|
3211
3215
|
}
|
|
3212
|
-
|
|
3216
|
+
material2.needsUpdate = true;
|
|
3213
3217
|
if (basicMaterial) {
|
|
3214
|
-
basicMaterial.color.copy(
|
|
3215
|
-
basicMaterial.map =
|
|
3216
|
-
basicMaterial.alphaMap =
|
|
3217
|
-
basicMaterial.alphaTest =
|
|
3218
|
-
basicMaterial.transparent =
|
|
3219
|
-
basicMaterial.opacity =
|
|
3220
|
-
basicMaterial.side =
|
|
3218
|
+
basicMaterial.color.copy(material2.color);
|
|
3219
|
+
basicMaterial.map = material2.map;
|
|
3220
|
+
basicMaterial.alphaMap = material2.alphaMap;
|
|
3221
|
+
basicMaterial.alphaTest = material2.alphaTest;
|
|
3222
|
+
basicMaterial.transparent = material2.transparent;
|
|
3223
|
+
basicMaterial.opacity = material2.opacity;
|
|
3224
|
+
basicMaterial.side = material2.side;
|
|
3221
3225
|
basicMaterial.needsUpdate = true;
|
|
3222
3226
|
}
|
|
3223
3227
|
if (normalMaterial) normalMaterial.needsUpdate = true;
|
|
@@ -3225,14 +3229,14 @@ function Model({
|
|
|
3225
3229
|
if (isHighlightedByHover || isSelected) {
|
|
3226
3230
|
matcapMaterial.color.set(HIGHLIGHT.color);
|
|
3227
3231
|
} else {
|
|
3228
|
-
matcapMaterial.color.copy(
|
|
3232
|
+
matcapMaterial.color.copy(material2.color);
|
|
3229
3233
|
}
|
|
3230
|
-
matcapMaterial.map =
|
|
3231
|
-
matcapMaterial.alphaMap =
|
|
3232
|
-
matcapMaterial.alphaTest =
|
|
3233
|
-
matcapMaterial.transparent =
|
|
3234
|
-
matcapMaterial.opacity =
|
|
3235
|
-
matcapMaterial.side =
|
|
3234
|
+
matcapMaterial.map = material2.map;
|
|
3235
|
+
matcapMaterial.alphaMap = material2.alphaMap;
|
|
3236
|
+
matcapMaterial.alphaTest = material2.alphaTest;
|
|
3237
|
+
matcapMaterial.transparent = material2.transparent;
|
|
3238
|
+
matcapMaterial.opacity = material2.opacity;
|
|
3239
|
+
matcapMaterial.side = material2.side;
|
|
3236
3240
|
matcapMaterial.needsUpdate = true;
|
|
3237
3241
|
}
|
|
3238
3242
|
}
|
|
@@ -3278,14 +3282,14 @@ function Model({
|
|
|
3278
3282
|
const sourceMaterials = Array.isArray(original) ? original : [original];
|
|
3279
3283
|
const hasUv0 = Boolean(object.geometry.getAttribute("uv"));
|
|
3280
3284
|
const diagnosticMaterials = sourceMaterials.map((source, index) => {
|
|
3281
|
-
const
|
|
3285
|
+
const material2 = new import_three14.MeshBasicMaterial({
|
|
3282
3286
|
color: hasUv0 ? "#ffffff" : "#ff00ff",
|
|
3283
3287
|
map: hasUv0 ? checkerTexture : null,
|
|
3284
3288
|
side: source.side
|
|
3285
3289
|
});
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
return
|
|
3290
|
+
material2.name = `${object.name || "mesh"}-uv-checker-${index}`;
|
|
3291
|
+
material2.toneMapped = false;
|
|
3292
|
+
return material2;
|
|
3289
3293
|
});
|
|
3290
3294
|
const diagnostic = Array.isArray(original) ? diagnosticMaterials : diagnosticMaterials[0];
|
|
3291
3295
|
object.material = diagnostic;
|
|
@@ -3296,7 +3300,7 @@ function Model({
|
|
|
3296
3300
|
for (const { node, original, diagnostic } of swaps) {
|
|
3297
3301
|
node.material = original;
|
|
3298
3302
|
const materials = Array.isArray(diagnostic) ? diagnostic : [diagnostic];
|
|
3299
|
-
for (const
|
|
3303
|
+
for (const material2 of materials) material2.dispose();
|
|
3300
3304
|
}
|
|
3301
3305
|
invalidate();
|
|
3302
3306
|
};
|
|
@@ -13205,8 +13209,8 @@ function MaterialSection({
|
|
|
13205
13209
|
{
|
|
13206
13210
|
label: pbrWorkflow === "specular" ? "Albedo color" : "Base color",
|
|
13207
13211
|
value: selectedMaterial?.baseColor ?? "#ffffff",
|
|
13208
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13209
|
-
...
|
|
13212
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13213
|
+
...material2,
|
|
13210
13214
|
baseColor: value
|
|
13211
13215
|
}))
|
|
13212
13216
|
}
|
|
@@ -13220,8 +13224,8 @@ function MaterialSection({
|
|
|
13220
13224
|
min: 0,
|
|
13221
13225
|
max: 1,
|
|
13222
13226
|
step: 0.01,
|
|
13223
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13224
|
-
...
|
|
13227
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13228
|
+
...material2,
|
|
13225
13229
|
metalness: value
|
|
13226
13230
|
}))
|
|
13227
13231
|
}
|
|
@@ -13244,8 +13248,8 @@ function MaterialSection({
|
|
|
13244
13248
|
min: 0,
|
|
13245
13249
|
max: 1,
|
|
13246
13250
|
step: 0.01,
|
|
13247
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13248
|
-
...
|
|
13251
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13252
|
+
...material2,
|
|
13249
13253
|
specularIntensity: value
|
|
13250
13254
|
}))
|
|
13251
13255
|
}
|
|
@@ -13255,8 +13259,8 @@ function MaterialSection({
|
|
|
13255
13259
|
{
|
|
13256
13260
|
label: "Specular color",
|
|
13257
13261
|
value: selectedMaterial?.specularColor ?? "#ffffff",
|
|
13258
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13259
|
-
...
|
|
13262
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13263
|
+
...material2,
|
|
13260
13264
|
specularColor: value
|
|
13261
13265
|
}))
|
|
13262
13266
|
}
|
|
@@ -13296,8 +13300,8 @@ function MaterialSection({
|
|
|
13296
13300
|
min: 0,
|
|
13297
13301
|
max: 1,
|
|
13298
13302
|
step: 0.01,
|
|
13299
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13300
|
-
...
|
|
13303
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13304
|
+
...material2,
|
|
13301
13305
|
reflectivity: value
|
|
13302
13306
|
}))
|
|
13303
13307
|
}
|
|
@@ -13308,8 +13312,8 @@ function MaterialSection({
|
|
|
13308
13312
|
{
|
|
13309
13313
|
label: "Base color",
|
|
13310
13314
|
value: selectedMaterial?.baseColor ?? "#ffffff",
|
|
13311
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13312
|
-
...
|
|
13315
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13316
|
+
...material2,
|
|
13313
13317
|
baseColor: value
|
|
13314
13318
|
}))
|
|
13315
13319
|
}
|
|
@@ -13322,8 +13326,8 @@ function MaterialSection({
|
|
|
13322
13326
|
min: 0,
|
|
13323
13327
|
max: 1,
|
|
13324
13328
|
step: 0.01,
|
|
13325
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13326
|
-
...
|
|
13329
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13330
|
+
...material2,
|
|
13327
13331
|
metalness: value
|
|
13328
13332
|
}))
|
|
13329
13333
|
}
|
|
@@ -13366,8 +13370,8 @@ function MaterialSection({
|
|
|
13366
13370
|
min: 0,
|
|
13367
13371
|
max: 1,
|
|
13368
13372
|
step: 0.01,
|
|
13369
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13370
|
-
...
|
|
13373
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13374
|
+
...material2,
|
|
13371
13375
|
roughness: value
|
|
13372
13376
|
}))
|
|
13373
13377
|
}
|
|
@@ -13379,8 +13383,8 @@ function MaterialSection({
|
|
|
13379
13383
|
min: 0,
|
|
13380
13384
|
max: 1,
|
|
13381
13385
|
step: 0.01,
|
|
13382
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13383
|
-
...
|
|
13386
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13387
|
+
...material2,
|
|
13384
13388
|
roughness: value === void 0 ? void 0 : 1 - value
|
|
13385
13389
|
}))
|
|
13386
13390
|
}
|
|
@@ -13412,8 +13416,8 @@ function MaterialSection({
|
|
|
13412
13416
|
label: "Emissive color",
|
|
13413
13417
|
value: selectedMaterial?.emissive ?? "#000000",
|
|
13414
13418
|
fallback: "#000000",
|
|
13415
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13416
|
-
...
|
|
13419
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13420
|
+
...material2,
|
|
13417
13421
|
emissive: value
|
|
13418
13422
|
}))
|
|
13419
13423
|
}
|
|
@@ -13426,8 +13430,8 @@ function MaterialSection({
|
|
|
13426
13430
|
min: 0,
|
|
13427
13431
|
max: 10,
|
|
13428
13432
|
step: 0.1,
|
|
13429
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13430
|
-
...
|
|
13433
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13434
|
+
...material2,
|
|
13431
13435
|
emissiveIntensity: value
|
|
13432
13436
|
}))
|
|
13433
13437
|
}
|
|
@@ -13461,8 +13465,8 @@ function MaterialSection({
|
|
|
13461
13465
|
min: 0,
|
|
13462
13466
|
max: 1,
|
|
13463
13467
|
step: 0.01,
|
|
13464
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13465
|
-
...
|
|
13468
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13469
|
+
...material2,
|
|
13466
13470
|
opacity: value
|
|
13467
13471
|
}))
|
|
13468
13472
|
}
|
|
@@ -13475,8 +13479,8 @@ function MaterialSection({
|
|
|
13475
13479
|
min: 0,
|
|
13476
13480
|
max: 1,
|
|
13477
13481
|
step: 0.01,
|
|
13478
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13479
|
-
...
|
|
13482
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13483
|
+
...material2,
|
|
13480
13484
|
alphaTest: value
|
|
13481
13485
|
}))
|
|
13482
13486
|
}
|
|
@@ -13496,8 +13500,8 @@ function MaterialSection({
|
|
|
13496
13500
|
label: "Blending mode",
|
|
13497
13501
|
value: selectedMaterial?.blendingMode ?? "normal",
|
|
13498
13502
|
options: MATERIAL_BLENDING_MODES,
|
|
13499
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13500
|
-
...
|
|
13503
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13504
|
+
...material2,
|
|
13501
13505
|
blendingMode: value
|
|
13502
13506
|
}))
|
|
13503
13507
|
}
|
|
@@ -13509,8 +13513,8 @@ function MaterialSection({
|
|
|
13509
13513
|
{
|
|
13510
13514
|
label: "Use alpha hash",
|
|
13511
13515
|
checked: selectedMaterial?.alphaHash ?? false,
|
|
13512
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13513
|
-
...
|
|
13516
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13517
|
+
...material2,
|
|
13514
13518
|
alphaHash: checked
|
|
13515
13519
|
}))
|
|
13516
13520
|
}
|
|
@@ -13523,8 +13527,8 @@ function MaterialSection({
|
|
|
13523
13527
|
{
|
|
13524
13528
|
label: "Use dithering",
|
|
13525
13529
|
checked: selectedMaterial?.dithering ?? false,
|
|
13526
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13527
|
-
...
|
|
13530
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13531
|
+
...material2,
|
|
13528
13532
|
dithering: checked
|
|
13529
13533
|
}))
|
|
13530
13534
|
}
|
|
@@ -13561,8 +13565,8 @@ function MaterialSection({
|
|
|
13561
13565
|
min: 0,
|
|
13562
13566
|
max: 5,
|
|
13563
13567
|
step: 0.01,
|
|
13564
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13565
|
-
...
|
|
13568
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13569
|
+
...material2,
|
|
13566
13570
|
normalScale: value
|
|
13567
13571
|
}))
|
|
13568
13572
|
}
|
|
@@ -13584,8 +13588,8 @@ function MaterialSection({
|
|
|
13584
13588
|
min: 0,
|
|
13585
13589
|
max: 5,
|
|
13586
13590
|
step: 0.01,
|
|
13587
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13588
|
-
...
|
|
13591
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13592
|
+
...material2,
|
|
13589
13593
|
bumpScale: value
|
|
13590
13594
|
}))
|
|
13591
13595
|
}
|
|
@@ -13596,8 +13600,8 @@ function MaterialSection({
|
|
|
13596
13600
|
{
|
|
13597
13601
|
label: "Flip normal Y",
|
|
13598
13602
|
checked: selectedMaterial?.flipNormalY ?? false,
|
|
13599
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13600
|
-
...
|
|
13603
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13604
|
+
...material2,
|
|
13601
13605
|
flipNormalY: checked
|
|
13602
13606
|
}))
|
|
13603
13607
|
}
|
|
@@ -13631,8 +13635,8 @@ function MaterialSection({
|
|
|
13631
13635
|
min: -5,
|
|
13632
13636
|
max: 5,
|
|
13633
13637
|
step: 0.01,
|
|
13634
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13635
|
-
...
|
|
13638
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13639
|
+
...material2,
|
|
13636
13640
|
displacementScale: value
|
|
13637
13641
|
}))
|
|
13638
13642
|
}
|
|
@@ -13645,8 +13649,8 @@ function MaterialSection({
|
|
|
13645
13649
|
min: -5,
|
|
13646
13650
|
max: 5,
|
|
13647
13651
|
step: 0.01,
|
|
13648
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13649
|
-
...
|
|
13652
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13653
|
+
...material2,
|
|
13650
13654
|
displacementBias: value
|
|
13651
13655
|
}))
|
|
13652
13656
|
}
|
|
@@ -13680,8 +13684,8 @@ function MaterialSection({
|
|
|
13680
13684
|
min: 0,
|
|
13681
13685
|
max: 5,
|
|
13682
13686
|
step: 0.01,
|
|
13683
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13684
|
-
...
|
|
13687
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13688
|
+
...material2,
|
|
13685
13689
|
aoMapIntensity: value
|
|
13686
13690
|
}))
|
|
13687
13691
|
}
|
|
@@ -13716,8 +13720,8 @@ function MaterialSection({
|
|
|
13716
13720
|
min: 0,
|
|
13717
13721
|
max: 1,
|
|
13718
13722
|
step: 0.01,
|
|
13719
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13720
|
-
...
|
|
13723
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13724
|
+
...material2,
|
|
13721
13725
|
clearcoat: value
|
|
13722
13726
|
}))
|
|
13723
13727
|
}
|
|
@@ -13743,8 +13747,8 @@ function MaterialSection({
|
|
|
13743
13747
|
min: 0,
|
|
13744
13748
|
max: 1,
|
|
13745
13749
|
step: 0.01,
|
|
13746
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13747
|
-
...
|
|
13750
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13751
|
+
...material2,
|
|
13748
13752
|
clearcoatRoughness: value
|
|
13749
13753
|
}))
|
|
13750
13754
|
}
|
|
@@ -13766,8 +13770,8 @@ function MaterialSection({
|
|
|
13766
13770
|
min: 0,
|
|
13767
13771
|
max: 5,
|
|
13768
13772
|
step: 0.01,
|
|
13769
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13770
|
-
...
|
|
13773
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13774
|
+
...material2,
|
|
13771
13775
|
clearcoatNormalScale: value
|
|
13772
13776
|
}))
|
|
13773
13777
|
}
|
|
@@ -13778,8 +13782,8 @@ function MaterialSection({
|
|
|
13778
13782
|
{
|
|
13779
13783
|
label: "Flip clearcoat normal Y",
|
|
13780
13784
|
checked: selectedMaterial?.flipClearcoatNormalY ?? false,
|
|
13781
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13782
|
-
...
|
|
13785
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13786
|
+
...material2,
|
|
13783
13787
|
flipClearcoatNormalY: checked
|
|
13784
13788
|
}))
|
|
13785
13789
|
}
|
|
@@ -13804,8 +13808,8 @@ function MaterialSection({
|
|
|
13804
13808
|
min: 0,
|
|
13805
13809
|
max: 1,
|
|
13806
13810
|
step: 0.01,
|
|
13807
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13808
|
-
...
|
|
13811
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13812
|
+
...material2,
|
|
13809
13813
|
sheen: value
|
|
13810
13814
|
}))
|
|
13811
13815
|
}
|
|
@@ -13815,8 +13819,8 @@ function MaterialSection({
|
|
|
13815
13819
|
{
|
|
13816
13820
|
label: "Sheen color",
|
|
13817
13821
|
value: selectedMaterial?.sheenColor ?? "#ffffff",
|
|
13818
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13819
|
-
...
|
|
13822
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13823
|
+
...material2,
|
|
13820
13824
|
sheenColor: value
|
|
13821
13825
|
}))
|
|
13822
13826
|
}
|
|
@@ -13838,8 +13842,8 @@ function MaterialSection({
|
|
|
13838
13842
|
min: 0,
|
|
13839
13843
|
max: 1,
|
|
13840
13844
|
step: 0.01,
|
|
13841
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13842
|
-
...
|
|
13845
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13846
|
+
...material2,
|
|
13843
13847
|
sheenRoughness: value
|
|
13844
13848
|
}))
|
|
13845
13849
|
}
|
|
@@ -13873,8 +13877,8 @@ function MaterialSection({
|
|
|
13873
13877
|
min: 0,
|
|
13874
13878
|
max: 1,
|
|
13875
13879
|
step: 0.01,
|
|
13876
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13877
|
-
...
|
|
13880
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13881
|
+
...material2,
|
|
13878
13882
|
anisotropy: value
|
|
13879
13883
|
}))
|
|
13880
13884
|
}
|
|
@@ -13896,8 +13900,8 @@ function MaterialSection({
|
|
|
13896
13900
|
min: 0,
|
|
13897
13901
|
max: 6.28,
|
|
13898
13902
|
step: 0.01,
|
|
13899
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13900
|
-
...
|
|
13903
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13904
|
+
...material2,
|
|
13901
13905
|
anisotropyRotation: value
|
|
13902
13906
|
}))
|
|
13903
13907
|
}
|
|
@@ -13931,8 +13935,8 @@ function MaterialSection({
|
|
|
13931
13935
|
min: 0,
|
|
13932
13936
|
max: 1,
|
|
13933
13937
|
step: 0.01,
|
|
13934
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13935
|
-
...
|
|
13938
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13939
|
+
...material2,
|
|
13936
13940
|
transmission: value
|
|
13937
13941
|
}))
|
|
13938
13942
|
}
|
|
@@ -13954,8 +13958,8 @@ function MaterialSection({
|
|
|
13954
13958
|
min: 0,
|
|
13955
13959
|
max: 5,
|
|
13956
13960
|
step: 0.01,
|
|
13957
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13958
|
-
...
|
|
13961
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13962
|
+
...material2,
|
|
13959
13963
|
thickness: value
|
|
13960
13964
|
}))
|
|
13961
13965
|
}
|
|
@@ -13974,8 +13978,8 @@ function MaterialSection({
|
|
|
13974
13978
|
{
|
|
13975
13979
|
label: "Volume tint",
|
|
13976
13980
|
value: selectedMaterial?.attenuationColor ?? "#ffffff",
|
|
13977
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13978
|
-
...
|
|
13981
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13982
|
+
...material2,
|
|
13979
13983
|
attenuationColor: value
|
|
13980
13984
|
}))
|
|
13981
13985
|
}
|
|
@@ -13988,8 +13992,8 @@ function MaterialSection({
|
|
|
13988
13992
|
min: 0,
|
|
13989
13993
|
step: 0.01,
|
|
13990
13994
|
placeholder: "Infinity when unset",
|
|
13991
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13992
|
-
...
|
|
13995
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13996
|
+
...material2,
|
|
13993
13997
|
attenuationDistance: value
|
|
13994
13998
|
}))
|
|
13995
13999
|
}
|
|
@@ -14011,8 +14015,8 @@ function MaterialSection({
|
|
|
14011
14015
|
label: "Side",
|
|
14012
14016
|
value: selectedMaterial?.side ?? "front",
|
|
14013
14017
|
options: MATERIAL_SIDES,
|
|
14014
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14015
|
-
...
|
|
14018
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14019
|
+
...material2,
|
|
14016
14020
|
side: value
|
|
14017
14021
|
}))
|
|
14018
14022
|
}
|
|
@@ -15011,9 +15015,9 @@ function formatVector3(position) {
|
|
|
15011
15015
|
|
|
15012
15016
|
// src/components/BindingBuilder/utils/exportAssets.ts
|
|
15013
15017
|
function collectTexturePaths(binding) {
|
|
15014
|
-
const
|
|
15015
|
-
if (!
|
|
15016
|
-
return Object.values(
|
|
15018
|
+
const material2 = binding.style?.material;
|
|
15019
|
+
if (!material2) return [];
|
|
15020
|
+
return Object.values(material2).filter(
|
|
15017
15021
|
(value) => !!value && typeof value === "object" && typeof value.path === "string" && value.path.trim().length > 0
|
|
15018
15022
|
).map((value) => value.path);
|
|
15019
15023
|
}
|
|
@@ -15131,30 +15135,30 @@ function materialFieldHasValue(value) {
|
|
|
15131
15135
|
}
|
|
15132
15136
|
return false;
|
|
15133
15137
|
}
|
|
15134
|
-
function normalizeMaterialForStorage(
|
|
15135
|
-
if (!
|
|
15136
|
-
return Object.values(
|
|
15138
|
+
function normalizeMaterialForStorage(material2) {
|
|
15139
|
+
if (!material2) return void 0;
|
|
15140
|
+
return Object.values(material2).some(materialFieldHasValue) ? material2 : void 0;
|
|
15137
15141
|
}
|
|
15138
|
-
function isMaterialPanelEnabled(
|
|
15139
|
-
if (!
|
|
15142
|
+
function isMaterialPanelEnabled(material2, panel) {
|
|
15143
|
+
if (!material2) return false;
|
|
15140
15144
|
return MATERIAL_PANEL_FIELDS[panel].some(
|
|
15141
|
-
(field) => materialFieldHasValue(
|
|
15145
|
+
(field) => materialFieldHasValue(material2[field])
|
|
15142
15146
|
);
|
|
15143
15147
|
}
|
|
15144
|
-
function createMaterialPanelEnabledState(
|
|
15148
|
+
function createMaterialPanelEnabledState(material2) {
|
|
15145
15149
|
return {
|
|
15146
|
-
pbr: isMaterialPanelEnabled(
|
|
15147
|
-
roughness: isMaterialPanelEnabled(
|
|
15148
|
-
emission: isMaterialPanelEnabled(
|
|
15149
|
-
opacity: isMaterialPanelEnabled(
|
|
15150
|
-
normalBump: isMaterialPanelEnabled(
|
|
15151
|
-
displacement: isMaterialPanelEnabled(
|
|
15152
|
-
ao: isMaterialPanelEnabled(
|
|
15153
|
-
clearcoat: isMaterialPanelEnabled(
|
|
15154
|
-
sheen: isMaterialPanelEnabled(
|
|
15155
|
-
anisotropy: isMaterialPanelEnabled(
|
|
15156
|
-
transmission: isMaterialPanelEnabled(
|
|
15157
|
-
faces: isMaterialPanelEnabled(
|
|
15150
|
+
pbr: isMaterialPanelEnabled(material2, "pbr"),
|
|
15151
|
+
roughness: isMaterialPanelEnabled(material2, "roughness"),
|
|
15152
|
+
emission: isMaterialPanelEnabled(material2, "emission"),
|
|
15153
|
+
opacity: isMaterialPanelEnabled(material2, "opacity"),
|
|
15154
|
+
normalBump: isMaterialPanelEnabled(material2, "normalBump"),
|
|
15155
|
+
displacement: isMaterialPanelEnabled(material2, "displacement"),
|
|
15156
|
+
ao: isMaterialPanelEnabled(material2, "ao"),
|
|
15157
|
+
clearcoat: isMaterialPanelEnabled(material2, "clearcoat"),
|
|
15158
|
+
sheen: isMaterialPanelEnabled(material2, "sheen"),
|
|
15159
|
+
anisotropy: isMaterialPanelEnabled(material2, "anisotropy"),
|
|
15160
|
+
transmission: isMaterialPanelEnabled(material2, "transmission"),
|
|
15161
|
+
faces: isMaterialPanelEnabled(material2, "faces")
|
|
15158
15162
|
};
|
|
15159
15163
|
}
|
|
15160
15164
|
function withMaterial(binding, nextMaterial) {
|
|
@@ -15171,9 +15175,9 @@ function withMaterial(binding, nextMaterial) {
|
|
|
15171
15175
|
style: Object.keys(rest).length > 0 ? rest : void 0
|
|
15172
15176
|
};
|
|
15173
15177
|
}
|
|
15174
|
-
function removeMaterialPanelFields(
|
|
15175
|
-
if (!
|
|
15176
|
-
const nextMaterial = { ...
|
|
15178
|
+
function removeMaterialPanelFields(material2, panel) {
|
|
15179
|
+
if (!material2) return void 0;
|
|
15180
|
+
const nextMaterial = { ...material2 };
|
|
15177
15181
|
for (const field of MATERIAL_PANEL_FIELDS[panel]) {
|
|
15178
15182
|
delete nextMaterial[field];
|
|
15179
15183
|
}
|
|
@@ -15431,8 +15435,8 @@ function BindingBuilder({ licenseKey }) {
|
|
|
15431
15435
|
});
|
|
15432
15436
|
};
|
|
15433
15437
|
const setSelectedTexturePath = (nodeKey, key, value) => {
|
|
15434
|
-
updateSelectedMaterial(nodeKey, (
|
|
15435
|
-
...
|
|
15438
|
+
updateSelectedMaterial(nodeKey, (material2) => ({
|
|
15439
|
+
...material2,
|
|
15436
15440
|
[key]: value ? { path: value } : void 0
|
|
15437
15441
|
}));
|
|
15438
15442
|
};
|
|
@@ -16062,8 +16066,8 @@ function BindingBuilder({ licenseKey }) {
|
|
|
16062
16066
|
MaterialPresetGallery,
|
|
16063
16067
|
{
|
|
16064
16068
|
disabled: !selectedItem,
|
|
16065
|
-
onApply: (preset) => selectedItem && updateSelectedMaterial(selectedItem, (
|
|
16066
|
-
...
|
|
16069
|
+
onApply: (preset) => selectedItem && updateSelectedMaterial(selectedItem, (material2) => ({
|
|
16070
|
+
...material2,
|
|
16067
16071
|
...preset
|
|
16068
16072
|
}))
|
|
16069
16073
|
}
|
|
@@ -17591,71 +17595,128 @@ function useObjectBindingIds(objectBindings) {
|
|
|
17591
17595
|
);
|
|
17592
17596
|
}
|
|
17593
17597
|
|
|
17594
|
-
// src/hooks/
|
|
17598
|
+
// src/hooks/useObjectBindings.ts
|
|
17595
17599
|
var import_react44 = require("react");
|
|
17600
|
+
|
|
17601
|
+
// src/utils/deepMerge.ts
|
|
17602
|
+
function isPlainObject2(value) {
|
|
17603
|
+
if (typeof value !== "object" || value === null) return false;
|
|
17604
|
+
const prototype = Object.getPrototypeOf(value);
|
|
17605
|
+
return prototype === Object.prototype || prototype === null;
|
|
17606
|
+
}
|
|
17607
|
+
function deepMerge(base, patch) {
|
|
17608
|
+
if (!isPlainObject2(patch)) return patch;
|
|
17609
|
+
const target = isPlainObject2(base) ? { ...base } : {};
|
|
17610
|
+
for (const key of Object.keys(patch)) {
|
|
17611
|
+
const value = patch[key];
|
|
17612
|
+
target[key] = isPlainObject2(value) ? deepMerge(target[key], value) : value;
|
|
17613
|
+
}
|
|
17614
|
+
return target;
|
|
17615
|
+
}
|
|
17616
|
+
|
|
17617
|
+
// src/utils/patchBindings.ts
|
|
17618
|
+
function isBindingEditArray(value) {
|
|
17619
|
+
return Array.isArray(value) && value.length > 0 && typeof value[0] !== "string";
|
|
17620
|
+
}
|
|
17621
|
+
function patchBindings(bindings, objectIdOrEdits, patch) {
|
|
17622
|
+
const edits = isBindingEditArray(objectIdOrEdits) ? objectIdOrEdits : [{ ids: objectIdOrEdits, patch: patch ?? {} }];
|
|
17623
|
+
let next = bindings;
|
|
17624
|
+
for (const edit of edits) {
|
|
17625
|
+
const ids = Array.isArray(edit.ids) ? edit.ids : [edit.ids];
|
|
17626
|
+
for (const id of ids) {
|
|
17627
|
+
const bindingKey = resolveBindingKey(next, id);
|
|
17628
|
+
if (!bindingKey) continue;
|
|
17629
|
+
const binding = next[bindingKey];
|
|
17630
|
+
if (!binding) continue;
|
|
17631
|
+
const patchedBinding = deepMerge(binding, edit.patch);
|
|
17632
|
+
if (next === bindings) next = { ...bindings };
|
|
17633
|
+
next[bindingKey] = patchedBinding;
|
|
17634
|
+
}
|
|
17635
|
+
}
|
|
17636
|
+
return next;
|
|
17637
|
+
}
|
|
17638
|
+
function material(value) {
|
|
17639
|
+
return { style: { material: value } };
|
|
17640
|
+
}
|
|
17641
|
+
|
|
17642
|
+
// src/hooks/useObjectBindings.ts
|
|
17596
17643
|
function getHiddenObjects(objectBindings) {
|
|
17597
17644
|
return Object.fromEntries(
|
|
17598
17645
|
Object.entries(objectBindings).filter(([, binding]) => binding.visible === false).map(([bindingKey]) => [bindingKey, true])
|
|
17599
17646
|
);
|
|
17600
17647
|
}
|
|
17601
|
-
function
|
|
17602
|
-
const
|
|
17603
|
-
|
|
17648
|
+
function useObjectBindings(initialBindings) {
|
|
17649
|
+
const [objectBindings, setObjectBindings] = (0, import_react44.useState)(initialBindings);
|
|
17650
|
+
const updateObjectBindings = (0, import_react44.useCallback)(
|
|
17651
|
+
(objectIdOrEdits, patchValue) => {
|
|
17652
|
+
setObjectBindings(
|
|
17653
|
+
(current) => patchValue === void 0 ? patchBindings(current, objectIdOrEdits) : patchBindings(
|
|
17654
|
+
current,
|
|
17655
|
+
objectIdOrEdits,
|
|
17656
|
+
patchValue
|
|
17657
|
+
)
|
|
17658
|
+
);
|
|
17659
|
+
},
|
|
17660
|
+
[]
|
|
17661
|
+
);
|
|
17662
|
+
const setMaterial = (0, import_react44.useCallback)(
|
|
17663
|
+
(objectId, value) => updateObjectBindings(objectId, material(value)),
|
|
17664
|
+
[updateObjectBindings]
|
|
17665
|
+
);
|
|
17666
|
+
const setBaseColor = (0, import_react44.useCallback)(
|
|
17667
|
+
(objectId, color) => setMaterial(objectId, { baseColor: color }),
|
|
17668
|
+
[setMaterial]
|
|
17669
|
+
);
|
|
17670
|
+
const resetMaterial = (0, import_react44.useCallback)(
|
|
17671
|
+
(objectId) => updateObjectBindings(objectId, { style: { material: void 0 } }),
|
|
17672
|
+
[updateObjectBindings]
|
|
17673
|
+
);
|
|
17674
|
+
const getMaterial = (0, import_react44.useCallback)(
|
|
17675
|
+
(objectId) => {
|
|
17604
17676
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17605
|
-
|
|
17606
|
-
const targetBinding = objectBindings[bindingKey];
|
|
17607
|
-
if (!targetBinding) return;
|
|
17608
|
-
onObjectBindingsChange({
|
|
17609
|
-
...objectBindings,
|
|
17610
|
-
[bindingKey]: {
|
|
17611
|
-
...targetBinding,
|
|
17612
|
-
visible
|
|
17613
|
-
}
|
|
17614
|
-
});
|
|
17677
|
+
return bindingKey ? objectBindings[bindingKey]?.style?.material ?? null : null;
|
|
17615
17678
|
},
|
|
17616
|
-
[objectBindings
|
|
17679
|
+
[objectBindings]
|
|
17617
17680
|
);
|
|
17618
17681
|
const hideObject = (0, import_react44.useCallback)(
|
|
17619
|
-
(objectId) =>
|
|
17620
|
-
[
|
|
17682
|
+
(objectId) => updateObjectBindings(objectId, { visible: false }),
|
|
17683
|
+
[updateObjectBindings]
|
|
17621
17684
|
);
|
|
17622
17685
|
const showObject = (0, import_react44.useCallback)(
|
|
17623
|
-
(objectId) =>
|
|
17624
|
-
[
|
|
17686
|
+
(objectId) => updateObjectBindings(objectId, { visible: true }),
|
|
17687
|
+
[updateObjectBindings]
|
|
17625
17688
|
);
|
|
17626
17689
|
const toggleObjectVisibility = (0, import_react44.useCallback)(
|
|
17627
17690
|
(objectId) => {
|
|
17628
|
-
|
|
17629
|
-
|
|
17630
|
-
|
|
17631
|
-
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17691
|
+
setObjectBindings((current) => {
|
|
17692
|
+
const objectIds = Array.isArray(objectId) ? objectId : [objectId];
|
|
17693
|
+
const edits = objectIds.reduce((acc, id) => {
|
|
17694
|
+
const bindingKey = resolveBindingKey(current, id);
|
|
17695
|
+
const binding = bindingKey ? current[bindingKey] : null;
|
|
17696
|
+
if (!bindingKey || !binding) return acc;
|
|
17697
|
+
acc.push({
|
|
17698
|
+
ids: bindingKey,
|
|
17699
|
+
patch: { visible: binding.visible === false }
|
|
17700
|
+
});
|
|
17701
|
+
return acc;
|
|
17702
|
+
}, []);
|
|
17703
|
+
return patchBindings(current, edits);
|
|
17638
17704
|
});
|
|
17639
17705
|
},
|
|
17640
|
-
[
|
|
17706
|
+
[setObjectBindings]
|
|
17641
17707
|
);
|
|
17642
17708
|
const clearHiddenObjects = (0, import_react44.useCallback)(() => {
|
|
17643
|
-
|
|
17644
|
-
Object.
|
|
17645
|
-
Object.entries(objectBindings).map(([bindingKey, binding]) => [
|
|
17646
|
-
bindingKey,
|
|
17647
|
-
{ ...binding, visible: true }
|
|
17648
|
-
])
|
|
17649
|
-
)
|
|
17709
|
+
setObjectBindings(
|
|
17710
|
+
(current) => patchBindings(current, Object.keys(current), { visible: true })
|
|
17650
17711
|
);
|
|
17651
|
-
}, [
|
|
17712
|
+
}, [setObjectBindings]);
|
|
17652
17713
|
const hiddenObjects = (0, import_react44.useMemo)(
|
|
17653
17714
|
() => getHiddenObjects(objectBindings),
|
|
17654
17715
|
[objectBindings]
|
|
17655
17716
|
);
|
|
17656
17717
|
const hiddenObjectIds = (0, import_react44.useMemo)(
|
|
17657
|
-
() => Object.
|
|
17658
|
-
(
|
|
17718
|
+
() => Object.keys(hiddenObjects).map(
|
|
17719
|
+
(bindingKey) => objectBindings[bindingKey]?.id ?? bindingKey
|
|
17659
17720
|
),
|
|
17660
17721
|
[hiddenObjects, objectBindings]
|
|
17661
17722
|
);
|
|
@@ -17667,6 +17728,13 @@ function useObjectVisibility(objectBindings, onObjectBindingsChange) {
|
|
|
17667
17728
|
[objectBindings]
|
|
17668
17729
|
);
|
|
17669
17730
|
return {
|
|
17731
|
+
objectBindings,
|
|
17732
|
+
setObjectBindings,
|
|
17733
|
+
updateObjectBindings,
|
|
17734
|
+
setMaterial,
|
|
17735
|
+
setBaseColor,
|
|
17736
|
+
resetMaterial,
|
|
17737
|
+
getMaterial,
|
|
17670
17738
|
hiddenObjects,
|
|
17671
17739
|
hiddenObjectIds,
|
|
17672
17740
|
hideObject,
|
|
@@ -17677,11 +17745,45 @@ function useObjectVisibility(objectBindings, onObjectBindingsChange) {
|
|
|
17677
17745
|
};
|
|
17678
17746
|
}
|
|
17679
17747
|
|
|
17680
|
-
// src/hooks/
|
|
17748
|
+
// src/hooks/useSceneConfig.ts
|
|
17681
17749
|
var import_react45 = require("react");
|
|
17750
|
+
|
|
17751
|
+
// src/utils/patchSceneConfig.ts
|
|
17752
|
+
function patchSceneConfig(sceneConfig, patch) {
|
|
17753
|
+
return deepMerge(sceneConfig, patch);
|
|
17754
|
+
}
|
|
17755
|
+
|
|
17756
|
+
// src/hooks/useSceneConfig.ts
|
|
17757
|
+
function useSceneConfig(initialSceneConfig) {
|
|
17758
|
+
const initialSceneConfigRef = (0, import_react45.useRef)(null);
|
|
17759
|
+
const [sceneConfig, setSceneConfig] = (0, import_react45.useState)(() => {
|
|
17760
|
+
const initial = typeof initialSceneConfig === "function" ? initialSceneConfig() : initialSceneConfig;
|
|
17761
|
+
initialSceneConfigRef.current = initial;
|
|
17762
|
+
return initial;
|
|
17763
|
+
});
|
|
17764
|
+
const updateSceneConfig = (0, import_react45.useCallback)((update) => {
|
|
17765
|
+
setSceneConfig((current) => {
|
|
17766
|
+
const patch = typeof update === "function" ? update(current) : update;
|
|
17767
|
+
return patchSceneConfig(current, patch);
|
|
17768
|
+
});
|
|
17769
|
+
}, []);
|
|
17770
|
+
const resetSceneConfig = (0, import_react45.useCallback)(() => {
|
|
17771
|
+
const initial = initialSceneConfigRef.current;
|
|
17772
|
+
if (initial) setSceneConfig(initial);
|
|
17773
|
+
}, []);
|
|
17774
|
+
return {
|
|
17775
|
+
sceneConfig,
|
|
17776
|
+
setSceneConfig,
|
|
17777
|
+
updateSceneConfig,
|
|
17778
|
+
resetSceneConfig
|
|
17779
|
+
};
|
|
17780
|
+
}
|
|
17781
|
+
|
|
17782
|
+
// src/hooks/useViewerHover.ts
|
|
17783
|
+
var import_react46 = require("react");
|
|
17682
17784
|
function useViewerHover() {
|
|
17683
|
-
const [hoveredObjectBinding, setHoveredObjectBinding] = (0,
|
|
17684
|
-
const handleHoveredObject = (0,
|
|
17785
|
+
const [hoveredObjectBinding, setHoveredObjectBinding] = (0, import_react46.useState)(null);
|
|
17786
|
+
const handleHoveredObject = (0, import_react46.useCallback)(
|
|
17685
17787
|
(binding) => {
|
|
17686
17788
|
setHoveredObjectBinding(binding);
|
|
17687
17789
|
},
|
|
@@ -17694,18 +17796,18 @@ function useViewerHover() {
|
|
|
17694
17796
|
}
|
|
17695
17797
|
|
|
17696
17798
|
// src/hooks/useViewerModel.ts
|
|
17697
|
-
var
|
|
17799
|
+
var import_react47 = require("react");
|
|
17698
17800
|
var import_three22 = require("three");
|
|
17699
17801
|
function toTuple2(vector) {
|
|
17700
17802
|
return [vector.x, vector.y, vector.z];
|
|
17701
17803
|
}
|
|
17702
17804
|
function useViewerModel() {
|
|
17703
|
-
const [isLoading, setIsLoading] = (0,
|
|
17704
|
-
const [isReady, setIsReady] = (0,
|
|
17705
|
-
const [error, setError] = (0,
|
|
17706
|
-
const [bounds, setBounds] = (0,
|
|
17707
|
-
const [objectCount, setObjectCount] = (0,
|
|
17708
|
-
const handleModelLoaded = (0,
|
|
17805
|
+
const [isLoading, setIsLoading] = (0, import_react47.useState)(true);
|
|
17806
|
+
const [isReady, setIsReady] = (0, import_react47.useState)(false);
|
|
17807
|
+
const [error, setError] = (0, import_react47.useState)(null);
|
|
17808
|
+
const [bounds, setBounds] = (0, import_react47.useState)(null);
|
|
17809
|
+
const [objectCount, setObjectCount] = (0, import_react47.useState)(0);
|
|
17810
|
+
const handleModelLoaded = (0, import_react47.useCallback)((scene) => {
|
|
17709
17811
|
const box = new import_three22.Box3().setFromObject(scene);
|
|
17710
17812
|
const min = box.min.clone();
|
|
17711
17813
|
const max = box.max.clone();
|
|
@@ -17730,14 +17832,14 @@ function useViewerModel() {
|
|
|
17730
17832
|
setIsLoading(false);
|
|
17731
17833
|
setIsReady(true);
|
|
17732
17834
|
}, []);
|
|
17733
|
-
const handleLoadError = (0,
|
|
17835
|
+
const handleLoadError = (0, import_react47.useCallback)((nextError) => {
|
|
17734
17836
|
setError(nextError);
|
|
17735
17837
|
setBounds(null);
|
|
17736
17838
|
setObjectCount(0);
|
|
17737
17839
|
setIsLoading(false);
|
|
17738
17840
|
setIsReady(false);
|
|
17739
17841
|
}, []);
|
|
17740
|
-
const resetModelState = (0,
|
|
17842
|
+
const resetModelState = (0, import_react47.useCallback)(() => {
|
|
17741
17843
|
setIsLoading(true);
|
|
17742
17844
|
setIsReady(false);
|
|
17743
17845
|
setError(null);
|
|
@@ -17757,10 +17859,10 @@ function useViewerModel() {
|
|
|
17757
17859
|
}
|
|
17758
17860
|
|
|
17759
17861
|
// src/hooks/useViewerActions.ts
|
|
17760
|
-
var
|
|
17862
|
+
var import_react48 = require("react");
|
|
17761
17863
|
function useViewerActions(objectBindings, options = {}) {
|
|
17762
17864
|
const { onAction, onObjectBindingsChange } = options;
|
|
17763
|
-
const getActionsForObject = (0,
|
|
17865
|
+
const getActionsForObject = (0, import_react48.useCallback)(
|
|
17764
17866
|
(objectId) => {
|
|
17765
17867
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17766
17868
|
if (!bindingKey) {
|
|
@@ -17770,7 +17872,7 @@ function useViewerActions(objectBindings, options = {}) {
|
|
|
17770
17872
|
},
|
|
17771
17873
|
[objectBindings]
|
|
17772
17874
|
);
|
|
17773
|
-
const runAction = (0,
|
|
17875
|
+
const runAction = (0, import_react48.useCallback)(
|
|
17774
17876
|
(objectId, actionId) => {
|
|
17775
17877
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17776
17878
|
if (!bindingKey) {
|
|
@@ -17812,7 +17914,7 @@ function useViewerActions(objectBindings, options = {}) {
|
|
|
17812
17914
|
}
|
|
17813
17915
|
|
|
17814
17916
|
// src/hooks/useShareableViewerState.ts
|
|
17815
|
-
var
|
|
17917
|
+
var import_react49 = require("react");
|
|
17816
17918
|
function serializeState(cameraState, objectBindings, selectedObjectBinding) {
|
|
17817
17919
|
const hidden = Object.values(objectBindings).filter((binding) => binding.visible === false).map((binding) => binding.id);
|
|
17818
17920
|
return {
|
|
@@ -17832,8 +17934,8 @@ function useShareableViewerState({
|
|
|
17832
17934
|
debounceMs = 400,
|
|
17833
17935
|
autoSync = true
|
|
17834
17936
|
}) {
|
|
17835
|
-
const lastWrittenRawRef = (0,
|
|
17836
|
-
const buildHash = (0,
|
|
17937
|
+
const lastWrittenRawRef = (0, import_react49.useRef)(null);
|
|
17938
|
+
const buildHash = (0, import_react49.useCallback)(() => {
|
|
17837
17939
|
const state = serializeState(
|
|
17838
17940
|
cameraState,
|
|
17839
17941
|
objectBindings,
|
|
@@ -17841,12 +17943,12 @@ function useShareableViewerState({
|
|
|
17841
17943
|
);
|
|
17842
17944
|
return `${paramKey}=${encodeURIComponent(JSON.stringify(state))}`;
|
|
17843
17945
|
}, [cameraState, objectBindings, selectedObjectBinding, paramKey]);
|
|
17844
|
-
const getShareUrl = (0,
|
|
17946
|
+
const getShareUrl = (0, import_react49.useCallback)(() => {
|
|
17845
17947
|
const url = new URL(window.location.href);
|
|
17846
17948
|
url.hash = buildHash();
|
|
17847
17949
|
return url.toString();
|
|
17848
17950
|
}, [buildHash]);
|
|
17849
|
-
const syncUrl = (0,
|
|
17951
|
+
const syncUrl = (0, import_react49.useCallback)(() => {
|
|
17850
17952
|
const url = new URL(window.location.href);
|
|
17851
17953
|
url.hash = buildHash();
|
|
17852
17954
|
window.history.replaceState(null, "", url.toString());
|
|
@@ -17854,7 +17956,7 @@ function useShareableViewerState({
|
|
|
17854
17956
|
paramKey
|
|
17855
17957
|
);
|
|
17856
17958
|
}, [buildHash, paramKey]);
|
|
17857
|
-
const latestStateRef = (0,
|
|
17959
|
+
const latestStateRef = (0, import_react49.useRef)({
|
|
17858
17960
|
cameraState,
|
|
17859
17961
|
objectBindings,
|
|
17860
17962
|
selectedObjectBinding
|
|
@@ -17864,9 +17966,9 @@ function useShareableViewerState({
|
|
|
17864
17966
|
objectBindings,
|
|
17865
17967
|
selectedObjectBinding
|
|
17866
17968
|
};
|
|
17867
|
-
const [restoreAttempted, setRestoreAttempted] = (0,
|
|
17868
|
-
const lastSyncedHashRef = (0,
|
|
17869
|
-
(0,
|
|
17969
|
+
const [restoreAttempted, setRestoreAttempted] = (0, import_react49.useState)(false);
|
|
17970
|
+
const lastSyncedHashRef = (0, import_react49.useRef)(null);
|
|
17971
|
+
(0, import_react49.useEffect)(() => {
|
|
17870
17972
|
if (!autoSync || !restoreAttempted) return;
|
|
17871
17973
|
const tick = () => {
|
|
17872
17974
|
const current = latestStateRef.current;
|
|
@@ -17888,9 +17990,9 @@ function useShareableViewerState({
|
|
|
17888
17990
|
const id = window.setInterval(tick, debounceMs);
|
|
17889
17991
|
return () => window.clearInterval(id);
|
|
17890
17992
|
}, [autoSync, restoreAttempted, debounceMs, paramKey]);
|
|
17891
|
-
const lastRestoredRawRef = (0,
|
|
17892
|
-
const restoringRawRef = (0,
|
|
17893
|
-
const restoreFromUrl = (0,
|
|
17993
|
+
const lastRestoredRawRef = (0, import_react49.useRef)(null);
|
|
17994
|
+
const restoringRawRef = (0, import_react49.useRef)(null);
|
|
17995
|
+
const restoreFromUrl = (0, import_react49.useCallback)(async () => {
|
|
17894
17996
|
setRestoreAttempted(true);
|
|
17895
17997
|
const rawHash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
17896
17998
|
const raw = new URLSearchParams(rawHash).get(paramKey);
|
|
@@ -17943,7 +18045,7 @@ function useShareableViewerState({
|
|
|
17943
18045
|
setCameraState,
|
|
17944
18046
|
setSelectedObjectBinding
|
|
17945
18047
|
]);
|
|
17946
|
-
(0,
|
|
18048
|
+
(0, import_react49.useEffect)(() => {
|
|
17947
18049
|
const handleHashChange = () => {
|
|
17948
18050
|
void restoreFromUrl();
|
|
17949
18051
|
};
|
|
@@ -17961,9 +18063,13 @@ function useShareableViewerState({
|
|
|
17961
18063
|
MATERIAL_SIDES,
|
|
17962
18064
|
ModelViewer,
|
|
17963
18065
|
SimpleModelViewer,
|
|
18066
|
+
material,
|
|
18067
|
+
patchBindings,
|
|
18068
|
+
patchSceneConfig,
|
|
17964
18069
|
useObjectBinding,
|
|
17965
18070
|
useObjectBindingIds,
|
|
17966
|
-
|
|
18071
|
+
useObjectBindings,
|
|
18072
|
+
useSceneConfig,
|
|
17967
18073
|
useShareableViewerState,
|
|
17968
18074
|
useViewerActions,
|
|
17969
18075
|
useViewerAnimations,
|