@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.mjs
CHANGED
|
@@ -391,9 +391,9 @@ function addTriangleEdges(edges, triangle, indexed) {
|
|
|
391
391
|
addEdge(edges, triangle[1], triangle[2], indexed);
|
|
392
392
|
addEdge(edges, triangle[2], triangle[0], indexed);
|
|
393
393
|
}
|
|
394
|
-
function materialForIndex(
|
|
395
|
-
if (!Array.isArray(
|
|
396
|
-
return
|
|
394
|
+
function materialForIndex(material2, materialIndex) {
|
|
395
|
+
if (!Array.isArray(material2)) return material2;
|
|
396
|
+
return material2[materialIndex] ?? null;
|
|
397
397
|
}
|
|
398
398
|
function collectUvLayouts(scene) {
|
|
399
399
|
const layouts = /* @__PURE__ */ new Map();
|
|
@@ -412,16 +412,16 @@ function collectUvLayouts(scene) {
|
|
|
412
412
|
const groups = geometry.groups.length > 0 ? geometry.groups : [{ start: 0, count: elementCount, materialIndex: 0 }];
|
|
413
413
|
for (const group of groups) {
|
|
414
414
|
const materialIndex = group.materialIndex ?? 0;
|
|
415
|
-
const
|
|
416
|
-
if (!
|
|
417
|
-
let layout = layouts.get(
|
|
415
|
+
const material2 = materialForIndex(mesh.material, materialIndex);
|
|
416
|
+
if (!material2) continue;
|
|
417
|
+
let layout = layouts.get(material2.uuid);
|
|
418
418
|
if (!layout) {
|
|
419
419
|
unnamedMaterialIndex += 1;
|
|
420
420
|
layout = {
|
|
421
|
-
name:
|
|
421
|
+
name: material2.name || `Material ${unnamedMaterialIndex}`,
|
|
422
422
|
layers: /* @__PURE__ */ new Map()
|
|
423
423
|
};
|
|
424
|
-
layouts.set(
|
|
424
|
+
layouts.set(material2.uuid, layout);
|
|
425
425
|
}
|
|
426
426
|
let layer = layout.layers.get(mesh.uuid);
|
|
427
427
|
if (!layer) {
|
|
@@ -2379,14 +2379,14 @@ import {
|
|
|
2379
2379
|
SRGBColorSpace as SRGBColorSpace3,
|
|
2380
2380
|
Vector2 as Vector24
|
|
2381
2381
|
} from "three";
|
|
2382
|
-
function isMeshStandardMaterial(
|
|
2382
|
+
function isMeshStandardMaterial(material2) {
|
|
2383
2383
|
return Boolean(
|
|
2384
|
-
|
|
2384
|
+
material2 && typeof material2 === "object" && "clone" in material2 && "color" in material2 && "metalness" in material2 && "roughness" in material2
|
|
2385
2385
|
);
|
|
2386
2386
|
}
|
|
2387
|
-
function isMeshPhysicalMaterial(
|
|
2387
|
+
function isMeshPhysicalMaterial(material2) {
|
|
2388
2388
|
return Boolean(
|
|
2389
|
-
|
|
2389
|
+
material2 && typeof material2 === "object" && "isMeshPhysicalMaterial" in material2 && material2.isMeshPhysicalMaterial
|
|
2390
2390
|
);
|
|
2391
2391
|
}
|
|
2392
2392
|
function isMeshNode(object) {
|
|
@@ -2422,8 +2422,8 @@ var SRGB_TEXTURE_KEYS = /* @__PURE__ */ new Set([
|
|
|
2422
2422
|
function colorSpaceForTextureKey(key) {
|
|
2423
2423
|
return SRGB_TEXTURE_KEYS.has(key) ? SRGBColorSpace3 : NoColorSpace2;
|
|
2424
2424
|
}
|
|
2425
|
-
function getMaterialTexturePath(
|
|
2426
|
-
return
|
|
2425
|
+
function getMaterialTexturePath(material2, key) {
|
|
2426
|
+
return material2?.[key]?.path;
|
|
2427
2427
|
}
|
|
2428
2428
|
function sideFromConfig(side) {
|
|
2429
2429
|
if (side === "back") return BackSide;
|
|
@@ -2457,10 +2457,10 @@ function getClipLoopMode(clipConfig) {
|
|
|
2457
2457
|
|
|
2458
2458
|
// src/components/model/materialFactory.ts
|
|
2459
2459
|
import { Color as Color6, MeshPhysicalMaterial as MeshPhysicalMaterial2, MeshStandardMaterial as MeshStandardMaterial2, Texture as Texture2 } from "three";
|
|
2460
|
-
function toStandardMaterial(
|
|
2461
|
-
if (isMeshStandardMaterial(
|
|
2462
|
-
if (!
|
|
2463
|
-
const src =
|
|
2460
|
+
function toStandardMaterial(material2) {
|
|
2461
|
+
if (isMeshStandardMaterial(material2)) return material2;
|
|
2462
|
+
if (!material2 || typeof material2 !== "object") return null;
|
|
2463
|
+
const src = material2;
|
|
2464
2464
|
const std = new MeshStandardMaterial2();
|
|
2465
2465
|
if (typeof src.name === "string") std.name = src.name;
|
|
2466
2466
|
std.metalness = 0;
|
|
@@ -2646,69 +2646,69 @@ import {
|
|
|
2646
2646
|
NormalBlending as NormalBlending2,
|
|
2647
2647
|
SRGBColorSpace as SRGBColorSpace4
|
|
2648
2648
|
} from "three";
|
|
2649
|
-
function applyMaterialConfig(
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
toSafeVector2(
|
|
2649
|
+
function applyMaterialConfig(material2, configuredMaterial, resolvedBaseColor) {
|
|
2650
|
+
material2.map = material2.userData.baseMap ?? null;
|
|
2651
|
+
material2.color.copy(material2.userData.baseColor);
|
|
2652
|
+
material2.metalness = material2.userData.baseMetalness ?? material2.metalness;
|
|
2653
|
+
material2.metalnessMap = material2.userData.baseMetalnessMap ?? null;
|
|
2654
|
+
material2.roughness = material2.userData.baseRoughness ?? material2.roughness;
|
|
2655
|
+
material2.roughnessMap = material2.userData.baseRoughnessMap ?? null;
|
|
2656
|
+
material2.emissive.copy(material2.userData.baseEmissive ?? new Color7(0, 0, 0));
|
|
2657
|
+
material2.emissiveIntensity = material2.userData.baseEmissiveIntensity ?? material2.emissiveIntensity;
|
|
2658
|
+
material2.emissiveMap = material2.userData.baseEmissiveMap ?? null;
|
|
2659
|
+
material2.opacity = material2.userData.baseOpacity ?? 1;
|
|
2660
|
+
material2.transparent = material2.userData.baseTransparent ?? false;
|
|
2661
|
+
material2.alphaMap = material2.userData.baseAlphaMap ?? null;
|
|
2662
|
+
material2.alphaTest = material2.userData.baseAlphaTest ?? 0;
|
|
2663
|
+
material2.alphaHash = material2.userData.baseAlphaHash ?? false;
|
|
2664
|
+
material2.dithering = material2.userData.baseDithering ?? false;
|
|
2665
|
+
material2.blending = material2.userData.baseBlending ?? NormalBlending2;
|
|
2666
|
+
material2.depthWrite = material2.userData.baseDepthWrite ?? true;
|
|
2667
|
+
material2.side = material2.userData.baseSide ?? FrontSide2;
|
|
2668
|
+
material2.normalMap = material2.userData.baseNormalMap ?? null;
|
|
2669
|
+
material2.normalScale.copy(toSafeVector2(material2.userData.baseNormalScale));
|
|
2670
|
+
material2.bumpMap = material2.userData.baseBumpMap ?? null;
|
|
2671
|
+
material2.bumpScale = material2.userData.baseBumpScale ?? material2.bumpScale;
|
|
2672
|
+
material2.aoMap = material2.userData.baseAoMap ?? null;
|
|
2673
|
+
material2.aoMapIntensity = material2.userData.baseAoMapIntensity ?? material2.aoMapIntensity;
|
|
2674
|
+
material2.displacementMap = material2.userData.baseDisplacementMap ?? null;
|
|
2675
|
+
material2.displacementScale = material2.userData.baseDisplacementScale ?? material2.displacementScale;
|
|
2676
|
+
material2.displacementBias = material2.userData.baseDisplacementBias ?? material2.displacementBias;
|
|
2677
|
+
material2.clearcoat = material2.userData.baseClearcoat ?? material2.clearcoat;
|
|
2678
|
+
material2.clearcoatMap = material2.userData.baseClearcoatMap ?? null;
|
|
2679
|
+
material2.clearcoatRoughness = material2.userData.baseClearcoatRoughness ?? material2.clearcoatRoughness;
|
|
2680
|
+
material2.clearcoatRoughnessMap = material2.userData.baseClearcoatRoughnessMap ?? null;
|
|
2681
|
+
material2.clearcoatNormalMap = material2.userData.baseClearcoatNormalMap ?? null;
|
|
2682
|
+
material2.clearcoatNormalScale.copy(
|
|
2683
|
+
toSafeVector2(material2.userData.baseClearcoatNormalScale)
|
|
2684
2684
|
);
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2685
|
+
material2.sheen = material2.userData.baseSheen ?? material2.sheen;
|
|
2686
|
+
material2.sheenColor.copy(
|
|
2687
|
+
material2.userData.baseSheenColor ?? new Color7(0, 0, 0)
|
|
2688
2688
|
);
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2689
|
+
material2.sheenColorMap = material2.userData.baseSheenColorMap ?? null;
|
|
2690
|
+
material2.sheenRoughness = material2.userData.baseSheenRoughness ?? material2.sheenRoughness;
|
|
2691
|
+
material2.sheenRoughnessMap = material2.userData.baseSheenRoughnessMap ?? null;
|
|
2692
|
+
material2.anisotropy = material2.userData.baseAnisotropy ?? material2.anisotropy;
|
|
2693
|
+
material2.anisotropyRotation = material2.userData.baseAnisotropyRotation ?? material2.anisotropyRotation;
|
|
2694
|
+
material2.anisotropyMap = material2.userData.baseAnisotropyMap ?? null;
|
|
2695
|
+
material2.transmission = material2.userData.baseTransmission ?? material2.transmission;
|
|
2696
|
+
material2.transmissionMap = material2.userData.baseTransmissionMap ?? null;
|
|
2697
|
+
material2.thickness = material2.userData.baseThickness ?? material2.thickness;
|
|
2698
|
+
material2.thicknessMap = material2.userData.baseThicknessMap ?? null;
|
|
2699
|
+
material2.attenuationColor.copy(
|
|
2700
|
+
material2.userData.baseAttenuationColor ?? new Color7("#ffffff")
|
|
2701
2701
|
);
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2702
|
+
material2.attenuationDistance = material2.userData.baseAttenuationDistance ?? material2.attenuationDistance;
|
|
2703
|
+
material2.reflectivity = material2.userData.baseReflectivity ?? material2.reflectivity;
|
|
2704
|
+
material2.specularIntensity = material2.userData.baseSpecularIntensity ?? material2.specularIntensity;
|
|
2705
|
+
material2.specularIntensityMap = material2.userData.baseSpecularIntensityMap ?? null;
|
|
2706
|
+
material2.specularColor.copy(
|
|
2707
|
+
material2.userData.baseSpecularColor ?? new Color7("#ffffff")
|
|
2708
2708
|
);
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2709
|
+
material2.specularColorMap = material2.userData.baseSpecularColorMap ?? null;
|
|
2710
|
+
material2.flatShading = material2.userData.baseFlatShading ?? material2.flatShading;
|
|
2711
|
+
material2.envMapIntensity = material2.userData.baseEnvMapIntensity ?? material2.envMapIntensity;
|
|
2712
2712
|
const texturePath = getMaterialTexturePath(configuredMaterial, "texture");
|
|
2713
2713
|
const metalnessMapPath = getMaterialTexturePath(
|
|
2714
2714
|
configuredMaterial,
|
|
@@ -2771,180 +2771,180 @@ function applyMaterialConfig(material, configuredMaterial, resolvedBaseColor) {
|
|
|
2771
2771
|
"specularColorMap"
|
|
2772
2772
|
);
|
|
2773
2773
|
if (texturePath) {
|
|
2774
|
-
|
|
2775
|
-
|
|
2774
|
+
material2.map = getOrCreateTexture(texturePath, SRGBColorSpace4);
|
|
2775
|
+
material2.color.set(resolvedBaseColor ?? "#ffffff");
|
|
2776
2776
|
} else if (resolvedBaseColor) {
|
|
2777
|
-
|
|
2778
|
-
|
|
2777
|
+
material2.map = null;
|
|
2778
|
+
material2.color.set(resolvedBaseColor);
|
|
2779
2779
|
}
|
|
2780
2780
|
if (metalnessMapPath) {
|
|
2781
|
-
|
|
2781
|
+
material2.metalnessMap = getOrCreateTexture(metalnessMapPath);
|
|
2782
2782
|
}
|
|
2783
2783
|
if (configuredMaterial?.metalness !== void 0) {
|
|
2784
|
-
|
|
2784
|
+
material2.metalness = configuredMaterial.metalness;
|
|
2785
2785
|
}
|
|
2786
2786
|
if (roughnessMapPath) {
|
|
2787
|
-
|
|
2787
|
+
material2.roughnessMap = getOrCreateTexture(roughnessMapPath);
|
|
2788
2788
|
}
|
|
2789
2789
|
if (configuredMaterial?.roughness !== void 0) {
|
|
2790
|
-
|
|
2790
|
+
material2.roughness = configuredMaterial.roughness;
|
|
2791
2791
|
}
|
|
2792
2792
|
if (configuredMaterial?.emissive) {
|
|
2793
|
-
|
|
2793
|
+
material2.emissive.set(configuredMaterial.emissive);
|
|
2794
2794
|
} else if (emissiveMapPath) {
|
|
2795
|
-
|
|
2795
|
+
material2.emissive.set("#ffffff");
|
|
2796
2796
|
}
|
|
2797
2797
|
if (configuredMaterial?.emissiveIntensity !== void 0) {
|
|
2798
|
-
|
|
2798
|
+
material2.emissiveIntensity = configuredMaterial.emissiveIntensity;
|
|
2799
2799
|
}
|
|
2800
2800
|
if (emissiveMapPath) {
|
|
2801
|
-
|
|
2801
|
+
material2.emissiveMap = getOrCreateTexture(emissiveMapPath, SRGBColorSpace4);
|
|
2802
2802
|
}
|
|
2803
2803
|
if (configuredMaterial?.opacity !== void 0) {
|
|
2804
|
-
|
|
2804
|
+
material2.opacity = configuredMaterial.opacity;
|
|
2805
2805
|
}
|
|
2806
2806
|
if (alphaMapPath) {
|
|
2807
|
-
|
|
2807
|
+
material2.alphaMap = getOrCreateTexture(alphaMapPath);
|
|
2808
2808
|
}
|
|
2809
2809
|
if (configuredMaterial?.alphaTest !== void 0) {
|
|
2810
|
-
|
|
2810
|
+
material2.alphaTest = configuredMaterial.alphaTest;
|
|
2811
2811
|
}
|
|
2812
2812
|
if (configuredMaterial?.alphaHash !== void 0) {
|
|
2813
|
-
|
|
2813
|
+
material2.alphaHash = configuredMaterial.alphaHash;
|
|
2814
2814
|
}
|
|
2815
2815
|
if (configuredMaterial?.dithering !== void 0) {
|
|
2816
|
-
|
|
2816
|
+
material2.dithering = configuredMaterial.dithering;
|
|
2817
2817
|
}
|
|
2818
2818
|
if (configuredMaterial?.blendingMode) {
|
|
2819
|
-
|
|
2820
|
-
|
|
2819
|
+
material2.blending = blendingFromConfig(configuredMaterial.blendingMode);
|
|
2820
|
+
material2.depthWrite = configuredMaterial.blendingMode !== "additive";
|
|
2821
2821
|
}
|
|
2822
2822
|
if (configuredMaterial?.side) {
|
|
2823
|
-
|
|
2823
|
+
material2.side = sideFromConfig(configuredMaterial.side);
|
|
2824
2824
|
}
|
|
2825
2825
|
if (normalMapPath) {
|
|
2826
|
-
|
|
2826
|
+
material2.normalMap = getOrCreateTexture(normalMapPath);
|
|
2827
2827
|
}
|
|
2828
2828
|
if (normalMapPath || configuredMaterial?.normalScale !== void 0) {
|
|
2829
|
-
const normalScale = configuredMaterial?.normalScale ?? Math.abs(toSafeVector2(
|
|
2830
|
-
|
|
2829
|
+
const normalScale = configuredMaterial?.normalScale ?? Math.abs(toSafeVector2(material2.userData.baseNormalScale).x);
|
|
2830
|
+
material2.normalScale.set(
|
|
2831
2831
|
normalScale,
|
|
2832
2832
|
configuredMaterial?.flipNormalY ? -normalScale : normalScale
|
|
2833
2833
|
);
|
|
2834
2834
|
}
|
|
2835
2835
|
if (bumpMapPath) {
|
|
2836
|
-
|
|
2836
|
+
material2.bumpMap = getOrCreateTexture(bumpMapPath);
|
|
2837
2837
|
}
|
|
2838
2838
|
if (configuredMaterial?.bumpScale !== void 0) {
|
|
2839
|
-
|
|
2839
|
+
material2.bumpScale = configuredMaterial.bumpScale;
|
|
2840
2840
|
}
|
|
2841
2841
|
if (aoMapPath) {
|
|
2842
|
-
|
|
2842
|
+
material2.aoMap = getOrCreateTexture(aoMapPath);
|
|
2843
2843
|
}
|
|
2844
2844
|
if (configuredMaterial?.aoMapIntensity !== void 0) {
|
|
2845
|
-
|
|
2845
|
+
material2.aoMapIntensity = configuredMaterial.aoMapIntensity;
|
|
2846
2846
|
}
|
|
2847
2847
|
if (displacementMapPath) {
|
|
2848
|
-
|
|
2848
|
+
material2.displacementMap = getOrCreateTexture(displacementMapPath);
|
|
2849
2849
|
}
|
|
2850
2850
|
if (configuredMaterial?.displacementScale !== void 0) {
|
|
2851
|
-
|
|
2851
|
+
material2.displacementScale = configuredMaterial.displacementScale;
|
|
2852
2852
|
}
|
|
2853
2853
|
if (configuredMaterial?.displacementBias !== void 0) {
|
|
2854
|
-
|
|
2854
|
+
material2.displacementBias = configuredMaterial.displacementBias;
|
|
2855
2855
|
}
|
|
2856
2856
|
if (clearcoatMapPath) {
|
|
2857
|
-
|
|
2857
|
+
material2.clearcoatMap = getOrCreateTexture(clearcoatMapPath);
|
|
2858
2858
|
}
|
|
2859
2859
|
if (configuredMaterial?.clearcoat !== void 0) {
|
|
2860
|
-
|
|
2860
|
+
material2.clearcoat = configuredMaterial.clearcoat;
|
|
2861
2861
|
}
|
|
2862
2862
|
if (clearcoatRoughnessMapPath) {
|
|
2863
|
-
|
|
2863
|
+
material2.clearcoatRoughnessMap = getOrCreateTexture(
|
|
2864
2864
|
clearcoatRoughnessMapPath
|
|
2865
2865
|
);
|
|
2866
2866
|
}
|
|
2867
2867
|
if (configuredMaterial?.clearcoatRoughness !== void 0) {
|
|
2868
|
-
|
|
2868
|
+
material2.clearcoatRoughness = configuredMaterial.clearcoatRoughness;
|
|
2869
2869
|
}
|
|
2870
2870
|
if (clearcoatNormalMapPath) {
|
|
2871
|
-
|
|
2871
|
+
material2.clearcoatNormalMap = getOrCreateTexture(clearcoatNormalMapPath);
|
|
2872
2872
|
}
|
|
2873
2873
|
if (clearcoatNormalMapPath || configuredMaterial?.clearcoatNormalScale !== void 0) {
|
|
2874
|
-
const clearcoatNormalScale = configuredMaterial?.clearcoatNormalScale ?? Math.abs(toSafeVector2(
|
|
2875
|
-
|
|
2874
|
+
const clearcoatNormalScale = configuredMaterial?.clearcoatNormalScale ?? Math.abs(toSafeVector2(material2.userData.baseClearcoatNormalScale).x);
|
|
2875
|
+
material2.clearcoatNormalScale.set(
|
|
2876
2876
|
clearcoatNormalScale,
|
|
2877
2877
|
configuredMaterial?.flipClearcoatNormalY ? -clearcoatNormalScale : clearcoatNormalScale
|
|
2878
2878
|
);
|
|
2879
2879
|
}
|
|
2880
2880
|
if (configuredMaterial?.sheen !== void 0) {
|
|
2881
|
-
|
|
2881
|
+
material2.sheen = configuredMaterial.sheen;
|
|
2882
2882
|
}
|
|
2883
2883
|
if (configuredMaterial?.sheenColor) {
|
|
2884
|
-
|
|
2884
|
+
material2.sheenColor.set(configuredMaterial.sheenColor);
|
|
2885
2885
|
}
|
|
2886
2886
|
if (sheenColorMapPath) {
|
|
2887
|
-
|
|
2887
|
+
material2.sheenColorMap = getOrCreateTexture(
|
|
2888
2888
|
sheenColorMapPath,
|
|
2889
2889
|
SRGBColorSpace4
|
|
2890
2890
|
);
|
|
2891
2891
|
}
|
|
2892
2892
|
if (configuredMaterial?.sheenRoughness !== void 0) {
|
|
2893
|
-
|
|
2893
|
+
material2.sheenRoughness = configuredMaterial.sheenRoughness;
|
|
2894
2894
|
}
|
|
2895
2895
|
if (sheenRoughnessMapPath) {
|
|
2896
|
-
|
|
2896
|
+
material2.sheenRoughnessMap = getOrCreateTexture(sheenRoughnessMapPath);
|
|
2897
2897
|
}
|
|
2898
2898
|
if (configuredMaterial?.anisotropy !== void 0) {
|
|
2899
|
-
|
|
2899
|
+
material2.anisotropy = configuredMaterial.anisotropy;
|
|
2900
2900
|
}
|
|
2901
2901
|
if (configuredMaterial?.anisotropyRotation !== void 0) {
|
|
2902
|
-
|
|
2902
|
+
material2.anisotropyRotation = configuredMaterial.anisotropyRotation;
|
|
2903
2903
|
}
|
|
2904
2904
|
if (anisotropyMapPath) {
|
|
2905
|
-
|
|
2905
|
+
material2.anisotropyMap = getOrCreateTexture(anisotropyMapPath);
|
|
2906
2906
|
}
|
|
2907
2907
|
if (configuredMaterial?.transmission !== void 0) {
|
|
2908
|
-
|
|
2908
|
+
material2.transmission = configuredMaterial.transmission;
|
|
2909
2909
|
}
|
|
2910
2910
|
if (transmissionMapPath) {
|
|
2911
|
-
|
|
2911
|
+
material2.transmissionMap = getOrCreateTexture(transmissionMapPath);
|
|
2912
2912
|
}
|
|
2913
2913
|
if (configuredMaterial?.thickness !== void 0) {
|
|
2914
|
-
|
|
2914
|
+
material2.thickness = configuredMaterial.thickness;
|
|
2915
2915
|
}
|
|
2916
2916
|
if (thicknessMapPath) {
|
|
2917
|
-
|
|
2917
|
+
material2.thicknessMap = getOrCreateTexture(thicknessMapPath);
|
|
2918
2918
|
}
|
|
2919
2919
|
if (configuredMaterial?.attenuationColor) {
|
|
2920
|
-
|
|
2920
|
+
material2.attenuationColor.set(configuredMaterial.attenuationColor);
|
|
2921
2921
|
}
|
|
2922
2922
|
if (configuredMaterial?.attenuationDistance !== void 0) {
|
|
2923
|
-
|
|
2923
|
+
material2.attenuationDistance = configuredMaterial.attenuationDistance;
|
|
2924
2924
|
}
|
|
2925
2925
|
if (configuredMaterial?.reflectivity !== void 0) {
|
|
2926
|
-
|
|
2926
|
+
material2.reflectivity = configuredMaterial.reflectivity;
|
|
2927
2927
|
}
|
|
2928
2928
|
if (configuredMaterial?.specularIntensity !== void 0) {
|
|
2929
|
-
|
|
2929
|
+
material2.specularIntensity = configuredMaterial.specularIntensity;
|
|
2930
2930
|
}
|
|
2931
2931
|
if (specularIntensityMapPath) {
|
|
2932
|
-
|
|
2932
|
+
material2.specularIntensityMap = getOrCreateTexture(
|
|
2933
2933
|
specularIntensityMapPath
|
|
2934
2934
|
);
|
|
2935
2935
|
}
|
|
2936
2936
|
if (configuredMaterial?.specularColor) {
|
|
2937
|
-
|
|
2937
|
+
material2.specularColor.set(configuredMaterial.specularColor);
|
|
2938
2938
|
}
|
|
2939
2939
|
if (specularColorMapPath) {
|
|
2940
|
-
|
|
2940
|
+
material2.specularColorMap = getOrCreateTexture(
|
|
2941
2941
|
specularColorMapPath,
|
|
2942
2942
|
SRGBColorSpace4
|
|
2943
2943
|
);
|
|
2944
2944
|
}
|
|
2945
|
-
|
|
2946
|
-
if (!
|
|
2947
|
-
|
|
2945
|
+
material2.transparent = material2.opacity < 1 || material2.transmission > 0 || material2.blending !== NormalBlending2 || Boolean((alphaMapPath || material2.alphaMap) && material2.alphaTest <= 0);
|
|
2946
|
+
if (!material2.transparent) {
|
|
2947
|
+
material2.depthWrite = true;
|
|
2948
2948
|
}
|
|
2949
2949
|
}
|
|
2950
2950
|
|
|
@@ -3087,8 +3087,8 @@ function Model({
|
|
|
3087
3087
|
}, [perNodeMaterials, materialRefsOut]);
|
|
3088
3088
|
useEffect7(() => {
|
|
3089
3089
|
return () => {
|
|
3090
|
-
for (const
|
|
3091
|
-
|
|
3090
|
+
for (const material2 of Object.values(perNodeMaterials)) {
|
|
3091
|
+
material2.dispose();
|
|
3092
3092
|
}
|
|
3093
3093
|
};
|
|
3094
3094
|
}, [perNodeMaterials]);
|
|
@@ -3100,15 +3100,15 @@ function Model({
|
|
|
3100
3100
|
const perNodeBasicMaterials = useMemo7(() => {
|
|
3101
3101
|
const map = {};
|
|
3102
3102
|
if (shadingMode !== "unlit") return map;
|
|
3103
|
-
for (const [nodeName,
|
|
3103
|
+
for (const [nodeName, material2] of Object.entries(perNodeMaterials)) {
|
|
3104
3104
|
const basic = new MeshBasicMaterial();
|
|
3105
|
-
basic.color.copy(
|
|
3106
|
-
basic.map =
|
|
3107
|
-
basic.alphaMap =
|
|
3108
|
-
basic.alphaTest =
|
|
3109
|
-
basic.transparent =
|
|
3110
|
-
basic.opacity =
|
|
3111
|
-
basic.side =
|
|
3105
|
+
basic.color.copy(material2.color);
|
|
3106
|
+
basic.map = material2.map;
|
|
3107
|
+
basic.alphaMap = material2.alphaMap;
|
|
3108
|
+
basic.alphaTest = material2.alphaTest;
|
|
3109
|
+
basic.transparent = material2.transparent;
|
|
3110
|
+
basic.opacity = material2.opacity;
|
|
3111
|
+
basic.side = material2.side;
|
|
3112
3112
|
map[nodeName] = basic;
|
|
3113
3113
|
}
|
|
3114
3114
|
return map;
|
|
@@ -3125,25 +3125,25 @@ function Model({
|
|
|
3125
3125
|
const map = {};
|
|
3126
3126
|
if (shadingMode !== "lit" || rendererMode !== "matcap") return map;
|
|
3127
3127
|
const matcapTexture = getMatcapTexture();
|
|
3128
|
-
for (const [nodeName,
|
|
3128
|
+
for (const [nodeName, material2] of Object.entries(perNodeMaterials)) {
|
|
3129
3129
|
const matcap = new MeshMatcapMaterial();
|
|
3130
3130
|
matcap.matcap = matcapTexture;
|
|
3131
|
-
matcap.color.copy(
|
|
3132
|
-
matcap.alphaMap =
|
|
3133
|
-
matcap.alphaTest =
|
|
3134
|
-
matcap.side =
|
|
3131
|
+
matcap.color.copy(material2.color);
|
|
3132
|
+
matcap.alphaMap = material2.alphaMap;
|
|
3133
|
+
matcap.alphaTest = material2.alphaTest;
|
|
3134
|
+
matcap.side = material2.side;
|
|
3135
3135
|
map[nodeName] = matcap;
|
|
3136
3136
|
}
|
|
3137
3137
|
return map;
|
|
3138
3138
|
}, [perNodeMaterials, shadingMode, rendererMode]);
|
|
3139
3139
|
useEffect7(() => {
|
|
3140
3140
|
return () => {
|
|
3141
|
-
for (const
|
|
3142
|
-
|
|
3143
|
-
for (const
|
|
3144
|
-
|
|
3145
|
-
for (const
|
|
3146
|
-
|
|
3141
|
+
for (const material2 of Object.values(perNodeBasicMaterials))
|
|
3142
|
+
material2.dispose();
|
|
3143
|
+
for (const material2 of Object.values(perNodeNormalMaterials))
|
|
3144
|
+
material2.dispose();
|
|
3145
|
+
for (const material2 of Object.values(perNodeMatcapMaterials))
|
|
3146
|
+
material2.dispose();
|
|
3147
3147
|
};
|
|
3148
3148
|
}, [perNodeBasicMaterials, perNodeNormalMaterials, perNodeMatcapMaterials]);
|
|
3149
3149
|
const materialForNode = (nodeName) => {
|
|
@@ -3189,8 +3189,8 @@ function Model({
|
|
|
3189
3189
|
const node = nodeMap[glbNodeName];
|
|
3190
3190
|
if (!isMeshNode(node)) continue;
|
|
3191
3191
|
node.visible = binding.visible !== false;
|
|
3192
|
-
const
|
|
3193
|
-
if (!
|
|
3192
|
+
const material2 = perNodeMaterials[nodeName];
|
|
3193
|
+
if (!material2) continue;
|
|
3194
3194
|
if (rendererMode !== "uv-checker") {
|
|
3195
3195
|
const activeMaterial = materialForNode(nodeName);
|
|
3196
3196
|
if (activeMaterial) {
|
|
@@ -3227,19 +3227,19 @@ function Model({
|
|
|
3227
3227
|
delete appliedTextureUrls.current[nodeName];
|
|
3228
3228
|
}
|
|
3229
3229
|
const resolvedBaseColor = itemMat?.hex ?? configuredMaterial?.baseColor;
|
|
3230
|
-
applyMaterialConfig(
|
|
3230
|
+
applyMaterialConfig(material2, configuredMaterial, resolvedBaseColor);
|
|
3231
3231
|
if (isHighlightedByHover) {
|
|
3232
|
-
|
|
3232
|
+
material2.emissive?.add(HIGHLIGHT_EMISSIVE_TINT);
|
|
3233
3233
|
}
|
|
3234
|
-
|
|
3234
|
+
material2.needsUpdate = true;
|
|
3235
3235
|
if (basicMaterial) {
|
|
3236
|
-
basicMaterial.color.copy(
|
|
3237
|
-
basicMaterial.map =
|
|
3238
|
-
basicMaterial.alphaMap =
|
|
3239
|
-
basicMaterial.alphaTest =
|
|
3240
|
-
basicMaterial.transparent =
|
|
3241
|
-
basicMaterial.opacity =
|
|
3242
|
-
basicMaterial.side =
|
|
3236
|
+
basicMaterial.color.copy(material2.color);
|
|
3237
|
+
basicMaterial.map = material2.map;
|
|
3238
|
+
basicMaterial.alphaMap = material2.alphaMap;
|
|
3239
|
+
basicMaterial.alphaTest = material2.alphaTest;
|
|
3240
|
+
basicMaterial.transparent = material2.transparent;
|
|
3241
|
+
basicMaterial.opacity = material2.opacity;
|
|
3242
|
+
basicMaterial.side = material2.side;
|
|
3243
3243
|
basicMaterial.needsUpdate = true;
|
|
3244
3244
|
}
|
|
3245
3245
|
if (normalMaterial) normalMaterial.needsUpdate = true;
|
|
@@ -3247,14 +3247,14 @@ function Model({
|
|
|
3247
3247
|
if (isHighlightedByHover || isSelected) {
|
|
3248
3248
|
matcapMaterial.color.set(HIGHLIGHT.color);
|
|
3249
3249
|
} else {
|
|
3250
|
-
matcapMaterial.color.copy(
|
|
3250
|
+
matcapMaterial.color.copy(material2.color);
|
|
3251
3251
|
}
|
|
3252
|
-
matcapMaterial.map =
|
|
3253
|
-
matcapMaterial.alphaMap =
|
|
3254
|
-
matcapMaterial.alphaTest =
|
|
3255
|
-
matcapMaterial.transparent =
|
|
3256
|
-
matcapMaterial.opacity =
|
|
3257
|
-
matcapMaterial.side =
|
|
3252
|
+
matcapMaterial.map = material2.map;
|
|
3253
|
+
matcapMaterial.alphaMap = material2.alphaMap;
|
|
3254
|
+
matcapMaterial.alphaTest = material2.alphaTest;
|
|
3255
|
+
matcapMaterial.transparent = material2.transparent;
|
|
3256
|
+
matcapMaterial.opacity = material2.opacity;
|
|
3257
|
+
matcapMaterial.side = material2.side;
|
|
3258
3258
|
matcapMaterial.needsUpdate = true;
|
|
3259
3259
|
}
|
|
3260
3260
|
}
|
|
@@ -3300,14 +3300,14 @@ function Model({
|
|
|
3300
3300
|
const sourceMaterials = Array.isArray(original) ? original : [original];
|
|
3301
3301
|
const hasUv0 = Boolean(object.geometry.getAttribute("uv"));
|
|
3302
3302
|
const diagnosticMaterials = sourceMaterials.map((source, index) => {
|
|
3303
|
-
const
|
|
3303
|
+
const material2 = new MeshBasicMaterial({
|
|
3304
3304
|
color: hasUv0 ? "#ffffff" : "#ff00ff",
|
|
3305
3305
|
map: hasUv0 ? checkerTexture : null,
|
|
3306
3306
|
side: source.side
|
|
3307
3307
|
});
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
return
|
|
3308
|
+
material2.name = `${object.name || "mesh"}-uv-checker-${index}`;
|
|
3309
|
+
material2.toneMapped = false;
|
|
3310
|
+
return material2;
|
|
3311
3311
|
});
|
|
3312
3312
|
const diagnostic = Array.isArray(original) ? diagnosticMaterials : diagnosticMaterials[0];
|
|
3313
3313
|
object.material = diagnostic;
|
|
@@ -3318,7 +3318,7 @@ function Model({
|
|
|
3318
3318
|
for (const { node, original, diagnostic } of swaps) {
|
|
3319
3319
|
node.material = original;
|
|
3320
3320
|
const materials = Array.isArray(diagnostic) ? diagnostic : [diagnostic];
|
|
3321
|
-
for (const
|
|
3321
|
+
for (const material2 of materials) material2.dispose();
|
|
3322
3322
|
}
|
|
3323
3323
|
invalidate();
|
|
3324
3324
|
};
|
|
@@ -13287,8 +13287,8 @@ function MaterialSection({
|
|
|
13287
13287
|
{
|
|
13288
13288
|
label: pbrWorkflow === "specular" ? "Albedo color" : "Base color",
|
|
13289
13289
|
value: selectedMaterial?.baseColor ?? "#ffffff",
|
|
13290
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13291
|
-
...
|
|
13290
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13291
|
+
...material2,
|
|
13292
13292
|
baseColor: value
|
|
13293
13293
|
}))
|
|
13294
13294
|
}
|
|
@@ -13302,8 +13302,8 @@ function MaterialSection({
|
|
|
13302
13302
|
min: 0,
|
|
13303
13303
|
max: 1,
|
|
13304
13304
|
step: 0.01,
|
|
13305
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13306
|
-
...
|
|
13305
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13306
|
+
...material2,
|
|
13307
13307
|
metalness: value
|
|
13308
13308
|
}))
|
|
13309
13309
|
}
|
|
@@ -13326,8 +13326,8 @@ function MaterialSection({
|
|
|
13326
13326
|
min: 0,
|
|
13327
13327
|
max: 1,
|
|
13328
13328
|
step: 0.01,
|
|
13329
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13330
|
-
...
|
|
13329
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13330
|
+
...material2,
|
|
13331
13331
|
specularIntensity: value
|
|
13332
13332
|
}))
|
|
13333
13333
|
}
|
|
@@ -13337,8 +13337,8 @@ function MaterialSection({
|
|
|
13337
13337
|
{
|
|
13338
13338
|
label: "Specular color",
|
|
13339
13339
|
value: selectedMaterial?.specularColor ?? "#ffffff",
|
|
13340
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13341
|
-
...
|
|
13340
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13341
|
+
...material2,
|
|
13342
13342
|
specularColor: value
|
|
13343
13343
|
}))
|
|
13344
13344
|
}
|
|
@@ -13378,8 +13378,8 @@ function MaterialSection({
|
|
|
13378
13378
|
min: 0,
|
|
13379
13379
|
max: 1,
|
|
13380
13380
|
step: 0.01,
|
|
13381
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13382
|
-
...
|
|
13381
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13382
|
+
...material2,
|
|
13383
13383
|
reflectivity: value
|
|
13384
13384
|
}))
|
|
13385
13385
|
}
|
|
@@ -13390,8 +13390,8 @@ function MaterialSection({
|
|
|
13390
13390
|
{
|
|
13391
13391
|
label: "Base color",
|
|
13392
13392
|
value: selectedMaterial?.baseColor ?? "#ffffff",
|
|
13393
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13394
|
-
...
|
|
13393
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13394
|
+
...material2,
|
|
13395
13395
|
baseColor: value
|
|
13396
13396
|
}))
|
|
13397
13397
|
}
|
|
@@ -13404,8 +13404,8 @@ function MaterialSection({
|
|
|
13404
13404
|
min: 0,
|
|
13405
13405
|
max: 1,
|
|
13406
13406
|
step: 0.01,
|
|
13407
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13408
|
-
...
|
|
13407
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13408
|
+
...material2,
|
|
13409
13409
|
metalness: value
|
|
13410
13410
|
}))
|
|
13411
13411
|
}
|
|
@@ -13448,8 +13448,8 @@ function MaterialSection({
|
|
|
13448
13448
|
min: 0,
|
|
13449
13449
|
max: 1,
|
|
13450
13450
|
step: 0.01,
|
|
13451
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13452
|
-
...
|
|
13451
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13452
|
+
...material2,
|
|
13453
13453
|
roughness: value
|
|
13454
13454
|
}))
|
|
13455
13455
|
}
|
|
@@ -13461,8 +13461,8 @@ function MaterialSection({
|
|
|
13461
13461
|
min: 0,
|
|
13462
13462
|
max: 1,
|
|
13463
13463
|
step: 0.01,
|
|
13464
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13465
|
-
...
|
|
13464
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13465
|
+
...material2,
|
|
13466
13466
|
roughness: value === void 0 ? void 0 : 1 - value
|
|
13467
13467
|
}))
|
|
13468
13468
|
}
|
|
@@ -13494,8 +13494,8 @@ function MaterialSection({
|
|
|
13494
13494
|
label: "Emissive color",
|
|
13495
13495
|
value: selectedMaterial?.emissive ?? "#000000",
|
|
13496
13496
|
fallback: "#000000",
|
|
13497
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13498
|
-
...
|
|
13497
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13498
|
+
...material2,
|
|
13499
13499
|
emissive: value
|
|
13500
13500
|
}))
|
|
13501
13501
|
}
|
|
@@ -13508,8 +13508,8 @@ function MaterialSection({
|
|
|
13508
13508
|
min: 0,
|
|
13509
13509
|
max: 10,
|
|
13510
13510
|
step: 0.1,
|
|
13511
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13512
|
-
...
|
|
13511
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13512
|
+
...material2,
|
|
13513
13513
|
emissiveIntensity: value
|
|
13514
13514
|
}))
|
|
13515
13515
|
}
|
|
@@ -13543,8 +13543,8 @@ function MaterialSection({
|
|
|
13543
13543
|
min: 0,
|
|
13544
13544
|
max: 1,
|
|
13545
13545
|
step: 0.01,
|
|
13546
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13547
|
-
...
|
|
13546
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13547
|
+
...material2,
|
|
13548
13548
|
opacity: value
|
|
13549
13549
|
}))
|
|
13550
13550
|
}
|
|
@@ -13557,8 +13557,8 @@ function MaterialSection({
|
|
|
13557
13557
|
min: 0,
|
|
13558
13558
|
max: 1,
|
|
13559
13559
|
step: 0.01,
|
|
13560
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13561
|
-
...
|
|
13560
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13561
|
+
...material2,
|
|
13562
13562
|
alphaTest: value
|
|
13563
13563
|
}))
|
|
13564
13564
|
}
|
|
@@ -13578,8 +13578,8 @@ function MaterialSection({
|
|
|
13578
13578
|
label: "Blending mode",
|
|
13579
13579
|
value: selectedMaterial?.blendingMode ?? "normal",
|
|
13580
13580
|
options: MATERIAL_BLENDING_MODES,
|
|
13581
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13582
|
-
...
|
|
13581
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13582
|
+
...material2,
|
|
13583
13583
|
blendingMode: value
|
|
13584
13584
|
}))
|
|
13585
13585
|
}
|
|
@@ -13591,8 +13591,8 @@ function MaterialSection({
|
|
|
13591
13591
|
{
|
|
13592
13592
|
label: "Use alpha hash",
|
|
13593
13593
|
checked: selectedMaterial?.alphaHash ?? false,
|
|
13594
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13595
|
-
...
|
|
13594
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13595
|
+
...material2,
|
|
13596
13596
|
alphaHash: checked
|
|
13597
13597
|
}))
|
|
13598
13598
|
}
|
|
@@ -13605,8 +13605,8 @@ function MaterialSection({
|
|
|
13605
13605
|
{
|
|
13606
13606
|
label: "Use dithering",
|
|
13607
13607
|
checked: selectedMaterial?.dithering ?? false,
|
|
13608
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13609
|
-
...
|
|
13608
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13609
|
+
...material2,
|
|
13610
13610
|
dithering: checked
|
|
13611
13611
|
}))
|
|
13612
13612
|
}
|
|
@@ -13643,8 +13643,8 @@ function MaterialSection({
|
|
|
13643
13643
|
min: 0,
|
|
13644
13644
|
max: 5,
|
|
13645
13645
|
step: 0.01,
|
|
13646
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13647
|
-
...
|
|
13646
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13647
|
+
...material2,
|
|
13648
13648
|
normalScale: value
|
|
13649
13649
|
}))
|
|
13650
13650
|
}
|
|
@@ -13666,8 +13666,8 @@ function MaterialSection({
|
|
|
13666
13666
|
min: 0,
|
|
13667
13667
|
max: 5,
|
|
13668
13668
|
step: 0.01,
|
|
13669
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13670
|
-
...
|
|
13669
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13670
|
+
...material2,
|
|
13671
13671
|
bumpScale: value
|
|
13672
13672
|
}))
|
|
13673
13673
|
}
|
|
@@ -13678,8 +13678,8 @@ function MaterialSection({
|
|
|
13678
13678
|
{
|
|
13679
13679
|
label: "Flip normal Y",
|
|
13680
13680
|
checked: selectedMaterial?.flipNormalY ?? false,
|
|
13681
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13682
|
-
...
|
|
13681
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13682
|
+
...material2,
|
|
13683
13683
|
flipNormalY: checked
|
|
13684
13684
|
}))
|
|
13685
13685
|
}
|
|
@@ -13713,8 +13713,8 @@ function MaterialSection({
|
|
|
13713
13713
|
min: -5,
|
|
13714
13714
|
max: 5,
|
|
13715
13715
|
step: 0.01,
|
|
13716
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13717
|
-
...
|
|
13716
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13717
|
+
...material2,
|
|
13718
13718
|
displacementScale: value
|
|
13719
13719
|
}))
|
|
13720
13720
|
}
|
|
@@ -13727,8 +13727,8 @@ function MaterialSection({
|
|
|
13727
13727
|
min: -5,
|
|
13728
13728
|
max: 5,
|
|
13729
13729
|
step: 0.01,
|
|
13730
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13731
|
-
...
|
|
13730
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13731
|
+
...material2,
|
|
13732
13732
|
displacementBias: value
|
|
13733
13733
|
}))
|
|
13734
13734
|
}
|
|
@@ -13762,8 +13762,8 @@ function MaterialSection({
|
|
|
13762
13762
|
min: 0,
|
|
13763
13763
|
max: 5,
|
|
13764
13764
|
step: 0.01,
|
|
13765
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13766
|
-
...
|
|
13765
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13766
|
+
...material2,
|
|
13767
13767
|
aoMapIntensity: value
|
|
13768
13768
|
}))
|
|
13769
13769
|
}
|
|
@@ -13798,8 +13798,8 @@ function MaterialSection({
|
|
|
13798
13798
|
min: 0,
|
|
13799
13799
|
max: 1,
|
|
13800
13800
|
step: 0.01,
|
|
13801
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13802
|
-
...
|
|
13801
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13802
|
+
...material2,
|
|
13803
13803
|
clearcoat: value
|
|
13804
13804
|
}))
|
|
13805
13805
|
}
|
|
@@ -13825,8 +13825,8 @@ function MaterialSection({
|
|
|
13825
13825
|
min: 0,
|
|
13826
13826
|
max: 1,
|
|
13827
13827
|
step: 0.01,
|
|
13828
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13829
|
-
...
|
|
13828
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13829
|
+
...material2,
|
|
13830
13830
|
clearcoatRoughness: value
|
|
13831
13831
|
}))
|
|
13832
13832
|
}
|
|
@@ -13848,8 +13848,8 @@ function MaterialSection({
|
|
|
13848
13848
|
min: 0,
|
|
13849
13849
|
max: 5,
|
|
13850
13850
|
step: 0.01,
|
|
13851
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13852
|
-
...
|
|
13851
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13852
|
+
...material2,
|
|
13853
13853
|
clearcoatNormalScale: value
|
|
13854
13854
|
}))
|
|
13855
13855
|
}
|
|
@@ -13860,8 +13860,8 @@ function MaterialSection({
|
|
|
13860
13860
|
{
|
|
13861
13861
|
label: "Flip clearcoat normal Y",
|
|
13862
13862
|
checked: selectedMaterial?.flipClearcoatNormalY ?? false,
|
|
13863
|
-
onChange: (checked) => updateSelectedMaterial(selectedItem, (
|
|
13864
|
-
...
|
|
13863
|
+
onChange: (checked) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13864
|
+
...material2,
|
|
13865
13865
|
flipClearcoatNormalY: checked
|
|
13866
13866
|
}))
|
|
13867
13867
|
}
|
|
@@ -13886,8 +13886,8 @@ function MaterialSection({
|
|
|
13886
13886
|
min: 0,
|
|
13887
13887
|
max: 1,
|
|
13888
13888
|
step: 0.01,
|
|
13889
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13890
|
-
...
|
|
13889
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13890
|
+
...material2,
|
|
13891
13891
|
sheen: value
|
|
13892
13892
|
}))
|
|
13893
13893
|
}
|
|
@@ -13897,8 +13897,8 @@ function MaterialSection({
|
|
|
13897
13897
|
{
|
|
13898
13898
|
label: "Sheen color",
|
|
13899
13899
|
value: selectedMaterial?.sheenColor ?? "#ffffff",
|
|
13900
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13901
|
-
...
|
|
13900
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13901
|
+
...material2,
|
|
13902
13902
|
sheenColor: value
|
|
13903
13903
|
}))
|
|
13904
13904
|
}
|
|
@@ -13920,8 +13920,8 @@ function MaterialSection({
|
|
|
13920
13920
|
min: 0,
|
|
13921
13921
|
max: 1,
|
|
13922
13922
|
step: 0.01,
|
|
13923
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13924
|
-
...
|
|
13923
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13924
|
+
...material2,
|
|
13925
13925
|
sheenRoughness: value
|
|
13926
13926
|
}))
|
|
13927
13927
|
}
|
|
@@ -13955,8 +13955,8 @@ function MaterialSection({
|
|
|
13955
13955
|
min: 0,
|
|
13956
13956
|
max: 1,
|
|
13957
13957
|
step: 0.01,
|
|
13958
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13959
|
-
...
|
|
13958
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13959
|
+
...material2,
|
|
13960
13960
|
anisotropy: value
|
|
13961
13961
|
}))
|
|
13962
13962
|
}
|
|
@@ -13978,8 +13978,8 @@ function MaterialSection({
|
|
|
13978
13978
|
min: 0,
|
|
13979
13979
|
max: 6.28,
|
|
13980
13980
|
step: 0.01,
|
|
13981
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
13982
|
-
...
|
|
13981
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
13982
|
+
...material2,
|
|
13983
13983
|
anisotropyRotation: value
|
|
13984
13984
|
}))
|
|
13985
13985
|
}
|
|
@@ -14013,8 +14013,8 @@ function MaterialSection({
|
|
|
14013
14013
|
min: 0,
|
|
14014
14014
|
max: 1,
|
|
14015
14015
|
step: 0.01,
|
|
14016
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14017
|
-
...
|
|
14016
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14017
|
+
...material2,
|
|
14018
14018
|
transmission: value
|
|
14019
14019
|
}))
|
|
14020
14020
|
}
|
|
@@ -14036,8 +14036,8 @@ function MaterialSection({
|
|
|
14036
14036
|
min: 0,
|
|
14037
14037
|
max: 5,
|
|
14038
14038
|
step: 0.01,
|
|
14039
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14040
|
-
...
|
|
14039
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14040
|
+
...material2,
|
|
14041
14041
|
thickness: value
|
|
14042
14042
|
}))
|
|
14043
14043
|
}
|
|
@@ -14056,8 +14056,8 @@ function MaterialSection({
|
|
|
14056
14056
|
{
|
|
14057
14057
|
label: "Volume tint",
|
|
14058
14058
|
value: selectedMaterial?.attenuationColor ?? "#ffffff",
|
|
14059
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14060
|
-
...
|
|
14059
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14060
|
+
...material2,
|
|
14061
14061
|
attenuationColor: value
|
|
14062
14062
|
}))
|
|
14063
14063
|
}
|
|
@@ -14070,8 +14070,8 @@ function MaterialSection({
|
|
|
14070
14070
|
min: 0,
|
|
14071
14071
|
step: 0.01,
|
|
14072
14072
|
placeholder: "Infinity when unset",
|
|
14073
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14074
|
-
...
|
|
14073
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14074
|
+
...material2,
|
|
14075
14075
|
attenuationDistance: value
|
|
14076
14076
|
}))
|
|
14077
14077
|
}
|
|
@@ -14093,8 +14093,8 @@ function MaterialSection({
|
|
|
14093
14093
|
label: "Side",
|
|
14094
14094
|
value: selectedMaterial?.side ?? "front",
|
|
14095
14095
|
options: MATERIAL_SIDES,
|
|
14096
|
-
onChange: (value) => updateSelectedMaterial(selectedItem, (
|
|
14097
|
-
...
|
|
14096
|
+
onChange: (value) => updateSelectedMaterial(selectedItem, (material2) => ({
|
|
14097
|
+
...material2,
|
|
14098
14098
|
side: value
|
|
14099
14099
|
}))
|
|
14100
14100
|
}
|
|
@@ -15093,9 +15093,9 @@ function formatVector3(position) {
|
|
|
15093
15093
|
|
|
15094
15094
|
// src/components/BindingBuilder/utils/exportAssets.ts
|
|
15095
15095
|
function collectTexturePaths(binding) {
|
|
15096
|
-
const
|
|
15097
|
-
if (!
|
|
15098
|
-
return Object.values(
|
|
15096
|
+
const material2 = binding.style?.material;
|
|
15097
|
+
if (!material2) return [];
|
|
15098
|
+
return Object.values(material2).filter(
|
|
15099
15099
|
(value) => !!value && typeof value === "object" && typeof value.path === "string" && value.path.trim().length > 0
|
|
15100
15100
|
).map((value) => value.path);
|
|
15101
15101
|
}
|
|
@@ -15213,30 +15213,30 @@ function materialFieldHasValue(value) {
|
|
|
15213
15213
|
}
|
|
15214
15214
|
return false;
|
|
15215
15215
|
}
|
|
15216
|
-
function normalizeMaterialForStorage(
|
|
15217
|
-
if (!
|
|
15218
|
-
return Object.values(
|
|
15216
|
+
function normalizeMaterialForStorage(material2) {
|
|
15217
|
+
if (!material2) return void 0;
|
|
15218
|
+
return Object.values(material2).some(materialFieldHasValue) ? material2 : void 0;
|
|
15219
15219
|
}
|
|
15220
|
-
function isMaterialPanelEnabled(
|
|
15221
|
-
if (!
|
|
15220
|
+
function isMaterialPanelEnabled(material2, panel) {
|
|
15221
|
+
if (!material2) return false;
|
|
15222
15222
|
return MATERIAL_PANEL_FIELDS[panel].some(
|
|
15223
|
-
(field) => materialFieldHasValue(
|
|
15223
|
+
(field) => materialFieldHasValue(material2[field])
|
|
15224
15224
|
);
|
|
15225
15225
|
}
|
|
15226
|
-
function createMaterialPanelEnabledState(
|
|
15226
|
+
function createMaterialPanelEnabledState(material2) {
|
|
15227
15227
|
return {
|
|
15228
|
-
pbr: isMaterialPanelEnabled(
|
|
15229
|
-
roughness: isMaterialPanelEnabled(
|
|
15230
|
-
emission: isMaterialPanelEnabled(
|
|
15231
|
-
opacity: isMaterialPanelEnabled(
|
|
15232
|
-
normalBump: isMaterialPanelEnabled(
|
|
15233
|
-
displacement: isMaterialPanelEnabled(
|
|
15234
|
-
ao: isMaterialPanelEnabled(
|
|
15235
|
-
clearcoat: isMaterialPanelEnabled(
|
|
15236
|
-
sheen: isMaterialPanelEnabled(
|
|
15237
|
-
anisotropy: isMaterialPanelEnabled(
|
|
15238
|
-
transmission: isMaterialPanelEnabled(
|
|
15239
|
-
faces: isMaterialPanelEnabled(
|
|
15228
|
+
pbr: isMaterialPanelEnabled(material2, "pbr"),
|
|
15229
|
+
roughness: isMaterialPanelEnabled(material2, "roughness"),
|
|
15230
|
+
emission: isMaterialPanelEnabled(material2, "emission"),
|
|
15231
|
+
opacity: isMaterialPanelEnabled(material2, "opacity"),
|
|
15232
|
+
normalBump: isMaterialPanelEnabled(material2, "normalBump"),
|
|
15233
|
+
displacement: isMaterialPanelEnabled(material2, "displacement"),
|
|
15234
|
+
ao: isMaterialPanelEnabled(material2, "ao"),
|
|
15235
|
+
clearcoat: isMaterialPanelEnabled(material2, "clearcoat"),
|
|
15236
|
+
sheen: isMaterialPanelEnabled(material2, "sheen"),
|
|
15237
|
+
anisotropy: isMaterialPanelEnabled(material2, "anisotropy"),
|
|
15238
|
+
transmission: isMaterialPanelEnabled(material2, "transmission"),
|
|
15239
|
+
faces: isMaterialPanelEnabled(material2, "faces")
|
|
15240
15240
|
};
|
|
15241
15241
|
}
|
|
15242
15242
|
function withMaterial(binding, nextMaterial) {
|
|
@@ -15253,9 +15253,9 @@ function withMaterial(binding, nextMaterial) {
|
|
|
15253
15253
|
style: Object.keys(rest).length > 0 ? rest : void 0
|
|
15254
15254
|
};
|
|
15255
15255
|
}
|
|
15256
|
-
function removeMaterialPanelFields(
|
|
15257
|
-
if (!
|
|
15258
|
-
const nextMaterial = { ...
|
|
15256
|
+
function removeMaterialPanelFields(material2, panel) {
|
|
15257
|
+
if (!material2) return void 0;
|
|
15258
|
+
const nextMaterial = { ...material2 };
|
|
15259
15259
|
for (const field of MATERIAL_PANEL_FIELDS[panel]) {
|
|
15260
15260
|
delete nextMaterial[field];
|
|
15261
15261
|
}
|
|
@@ -15513,8 +15513,8 @@ function BindingBuilder({ licenseKey }) {
|
|
|
15513
15513
|
});
|
|
15514
15514
|
};
|
|
15515
15515
|
const setSelectedTexturePath = (nodeKey, key, value) => {
|
|
15516
|
-
updateSelectedMaterial(nodeKey, (
|
|
15517
|
-
...
|
|
15516
|
+
updateSelectedMaterial(nodeKey, (material2) => ({
|
|
15517
|
+
...material2,
|
|
15518
15518
|
[key]: value ? { path: value } : void 0
|
|
15519
15519
|
}));
|
|
15520
15520
|
};
|
|
@@ -16144,8 +16144,8 @@ function BindingBuilder({ licenseKey }) {
|
|
|
16144
16144
|
MaterialPresetGallery,
|
|
16145
16145
|
{
|
|
16146
16146
|
disabled: !selectedItem,
|
|
16147
|
-
onApply: (preset) => selectedItem && updateSelectedMaterial(selectedItem, (
|
|
16148
|
-
...
|
|
16147
|
+
onApply: (preset) => selectedItem && updateSelectedMaterial(selectedItem, (material2) => ({
|
|
16148
|
+
...material2,
|
|
16149
16149
|
...preset
|
|
16150
16150
|
}))
|
|
16151
16151
|
}
|
|
@@ -17694,71 +17694,128 @@ function useObjectBindingIds(objectBindings) {
|
|
|
17694
17694
|
);
|
|
17695
17695
|
}
|
|
17696
17696
|
|
|
17697
|
-
// src/hooks/
|
|
17698
|
-
import { useCallback as useCallback12, useMemo as useMemo20 } from "react";
|
|
17697
|
+
// src/hooks/useObjectBindings.ts
|
|
17698
|
+
import { useCallback as useCallback12, useMemo as useMemo20, useState as useState28 } from "react";
|
|
17699
|
+
|
|
17700
|
+
// src/utils/deepMerge.ts
|
|
17701
|
+
function isPlainObject2(value) {
|
|
17702
|
+
if (typeof value !== "object" || value === null) return false;
|
|
17703
|
+
const prototype = Object.getPrototypeOf(value);
|
|
17704
|
+
return prototype === Object.prototype || prototype === null;
|
|
17705
|
+
}
|
|
17706
|
+
function deepMerge(base, patch) {
|
|
17707
|
+
if (!isPlainObject2(patch)) return patch;
|
|
17708
|
+
const target = isPlainObject2(base) ? { ...base } : {};
|
|
17709
|
+
for (const key of Object.keys(patch)) {
|
|
17710
|
+
const value = patch[key];
|
|
17711
|
+
target[key] = isPlainObject2(value) ? deepMerge(target[key], value) : value;
|
|
17712
|
+
}
|
|
17713
|
+
return target;
|
|
17714
|
+
}
|
|
17715
|
+
|
|
17716
|
+
// src/utils/patchBindings.ts
|
|
17717
|
+
function isBindingEditArray(value) {
|
|
17718
|
+
return Array.isArray(value) && value.length > 0 && typeof value[0] !== "string";
|
|
17719
|
+
}
|
|
17720
|
+
function patchBindings(bindings, objectIdOrEdits, patch) {
|
|
17721
|
+
const edits = isBindingEditArray(objectIdOrEdits) ? objectIdOrEdits : [{ ids: objectIdOrEdits, patch: patch ?? {} }];
|
|
17722
|
+
let next = bindings;
|
|
17723
|
+
for (const edit of edits) {
|
|
17724
|
+
const ids = Array.isArray(edit.ids) ? edit.ids : [edit.ids];
|
|
17725
|
+
for (const id of ids) {
|
|
17726
|
+
const bindingKey = resolveBindingKey(next, id);
|
|
17727
|
+
if (!bindingKey) continue;
|
|
17728
|
+
const binding = next[bindingKey];
|
|
17729
|
+
if (!binding) continue;
|
|
17730
|
+
const patchedBinding = deepMerge(binding, edit.patch);
|
|
17731
|
+
if (next === bindings) next = { ...bindings };
|
|
17732
|
+
next[bindingKey] = patchedBinding;
|
|
17733
|
+
}
|
|
17734
|
+
}
|
|
17735
|
+
return next;
|
|
17736
|
+
}
|
|
17737
|
+
function material(value) {
|
|
17738
|
+
return { style: { material: value } };
|
|
17739
|
+
}
|
|
17740
|
+
|
|
17741
|
+
// src/hooks/useObjectBindings.ts
|
|
17699
17742
|
function getHiddenObjects(objectBindings) {
|
|
17700
17743
|
return Object.fromEntries(
|
|
17701
17744
|
Object.entries(objectBindings).filter(([, binding]) => binding.visible === false).map(([bindingKey]) => [bindingKey, true])
|
|
17702
17745
|
);
|
|
17703
17746
|
}
|
|
17704
|
-
function
|
|
17705
|
-
const
|
|
17706
|
-
|
|
17747
|
+
function useObjectBindings(initialBindings) {
|
|
17748
|
+
const [objectBindings, setObjectBindings] = useState28(initialBindings);
|
|
17749
|
+
const updateObjectBindings = useCallback12(
|
|
17750
|
+
(objectIdOrEdits, patchValue) => {
|
|
17751
|
+
setObjectBindings(
|
|
17752
|
+
(current) => patchValue === void 0 ? patchBindings(current, objectIdOrEdits) : patchBindings(
|
|
17753
|
+
current,
|
|
17754
|
+
objectIdOrEdits,
|
|
17755
|
+
patchValue
|
|
17756
|
+
)
|
|
17757
|
+
);
|
|
17758
|
+
},
|
|
17759
|
+
[]
|
|
17760
|
+
);
|
|
17761
|
+
const setMaterial = useCallback12(
|
|
17762
|
+
(objectId, value) => updateObjectBindings(objectId, material(value)),
|
|
17763
|
+
[updateObjectBindings]
|
|
17764
|
+
);
|
|
17765
|
+
const setBaseColor = useCallback12(
|
|
17766
|
+
(objectId, color) => setMaterial(objectId, { baseColor: color }),
|
|
17767
|
+
[setMaterial]
|
|
17768
|
+
);
|
|
17769
|
+
const resetMaterial = useCallback12(
|
|
17770
|
+
(objectId) => updateObjectBindings(objectId, { style: { material: void 0 } }),
|
|
17771
|
+
[updateObjectBindings]
|
|
17772
|
+
);
|
|
17773
|
+
const getMaterial = useCallback12(
|
|
17774
|
+
(objectId) => {
|
|
17707
17775
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17708
|
-
|
|
17709
|
-
const targetBinding = objectBindings[bindingKey];
|
|
17710
|
-
if (!targetBinding) return;
|
|
17711
|
-
onObjectBindingsChange({
|
|
17712
|
-
...objectBindings,
|
|
17713
|
-
[bindingKey]: {
|
|
17714
|
-
...targetBinding,
|
|
17715
|
-
visible
|
|
17716
|
-
}
|
|
17717
|
-
});
|
|
17776
|
+
return bindingKey ? objectBindings[bindingKey]?.style?.material ?? null : null;
|
|
17718
17777
|
},
|
|
17719
|
-
[objectBindings
|
|
17778
|
+
[objectBindings]
|
|
17720
17779
|
);
|
|
17721
17780
|
const hideObject = useCallback12(
|
|
17722
|
-
(objectId) =>
|
|
17723
|
-
[
|
|
17781
|
+
(objectId) => updateObjectBindings(objectId, { visible: false }),
|
|
17782
|
+
[updateObjectBindings]
|
|
17724
17783
|
);
|
|
17725
17784
|
const showObject = useCallback12(
|
|
17726
|
-
(objectId) =>
|
|
17727
|
-
[
|
|
17785
|
+
(objectId) => updateObjectBindings(objectId, { visible: true }),
|
|
17786
|
+
[updateObjectBindings]
|
|
17728
17787
|
);
|
|
17729
17788
|
const toggleObjectVisibility = useCallback12(
|
|
17730
17789
|
(objectId) => {
|
|
17731
|
-
|
|
17732
|
-
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
|
|
17737
|
-
|
|
17738
|
-
|
|
17739
|
-
|
|
17740
|
-
|
|
17790
|
+
setObjectBindings((current) => {
|
|
17791
|
+
const objectIds = Array.isArray(objectId) ? objectId : [objectId];
|
|
17792
|
+
const edits = objectIds.reduce((acc, id) => {
|
|
17793
|
+
const bindingKey = resolveBindingKey(current, id);
|
|
17794
|
+
const binding = bindingKey ? current[bindingKey] : null;
|
|
17795
|
+
if (!bindingKey || !binding) return acc;
|
|
17796
|
+
acc.push({
|
|
17797
|
+
ids: bindingKey,
|
|
17798
|
+
patch: { visible: binding.visible === false }
|
|
17799
|
+
});
|
|
17800
|
+
return acc;
|
|
17801
|
+
}, []);
|
|
17802
|
+
return patchBindings(current, edits);
|
|
17741
17803
|
});
|
|
17742
17804
|
},
|
|
17743
|
-
[
|
|
17805
|
+
[setObjectBindings]
|
|
17744
17806
|
);
|
|
17745
17807
|
const clearHiddenObjects = useCallback12(() => {
|
|
17746
|
-
|
|
17747
|
-
Object.
|
|
17748
|
-
Object.entries(objectBindings).map(([bindingKey, binding]) => [
|
|
17749
|
-
bindingKey,
|
|
17750
|
-
{ ...binding, visible: true }
|
|
17751
|
-
])
|
|
17752
|
-
)
|
|
17808
|
+
setObjectBindings(
|
|
17809
|
+
(current) => patchBindings(current, Object.keys(current), { visible: true })
|
|
17753
17810
|
);
|
|
17754
|
-
}, [
|
|
17811
|
+
}, [setObjectBindings]);
|
|
17755
17812
|
const hiddenObjects = useMemo20(
|
|
17756
17813
|
() => getHiddenObjects(objectBindings),
|
|
17757
17814
|
[objectBindings]
|
|
17758
17815
|
);
|
|
17759
17816
|
const hiddenObjectIds = useMemo20(
|
|
17760
|
-
() => Object.
|
|
17761
|
-
(
|
|
17817
|
+
() => Object.keys(hiddenObjects).map(
|
|
17818
|
+
(bindingKey) => objectBindings[bindingKey]?.id ?? bindingKey
|
|
17762
17819
|
),
|
|
17763
17820
|
[hiddenObjects, objectBindings]
|
|
17764
17821
|
);
|
|
@@ -17770,6 +17827,13 @@ function useObjectVisibility(objectBindings, onObjectBindingsChange) {
|
|
|
17770
17827
|
[objectBindings]
|
|
17771
17828
|
);
|
|
17772
17829
|
return {
|
|
17830
|
+
objectBindings,
|
|
17831
|
+
setObjectBindings,
|
|
17832
|
+
updateObjectBindings,
|
|
17833
|
+
setMaterial,
|
|
17834
|
+
setBaseColor,
|
|
17835
|
+
resetMaterial,
|
|
17836
|
+
getMaterial,
|
|
17773
17837
|
hiddenObjects,
|
|
17774
17838
|
hiddenObjectIds,
|
|
17775
17839
|
hideObject,
|
|
@@ -17780,11 +17844,45 @@ function useObjectVisibility(objectBindings, onObjectBindingsChange) {
|
|
|
17780
17844
|
};
|
|
17781
17845
|
}
|
|
17782
17846
|
|
|
17847
|
+
// src/hooks/useSceneConfig.ts
|
|
17848
|
+
import { useCallback as useCallback13, useRef as useRef20, useState as useState29 } from "react";
|
|
17849
|
+
|
|
17850
|
+
// src/utils/patchSceneConfig.ts
|
|
17851
|
+
function patchSceneConfig(sceneConfig, patch) {
|
|
17852
|
+
return deepMerge(sceneConfig, patch);
|
|
17853
|
+
}
|
|
17854
|
+
|
|
17855
|
+
// src/hooks/useSceneConfig.ts
|
|
17856
|
+
function useSceneConfig(initialSceneConfig) {
|
|
17857
|
+
const initialSceneConfigRef = useRef20(null);
|
|
17858
|
+
const [sceneConfig, setSceneConfig] = useState29(() => {
|
|
17859
|
+
const initial = typeof initialSceneConfig === "function" ? initialSceneConfig() : initialSceneConfig;
|
|
17860
|
+
initialSceneConfigRef.current = initial;
|
|
17861
|
+
return initial;
|
|
17862
|
+
});
|
|
17863
|
+
const updateSceneConfig = useCallback13((update) => {
|
|
17864
|
+
setSceneConfig((current) => {
|
|
17865
|
+
const patch = typeof update === "function" ? update(current) : update;
|
|
17866
|
+
return patchSceneConfig(current, patch);
|
|
17867
|
+
});
|
|
17868
|
+
}, []);
|
|
17869
|
+
const resetSceneConfig = useCallback13(() => {
|
|
17870
|
+
const initial = initialSceneConfigRef.current;
|
|
17871
|
+
if (initial) setSceneConfig(initial);
|
|
17872
|
+
}, []);
|
|
17873
|
+
return {
|
|
17874
|
+
sceneConfig,
|
|
17875
|
+
setSceneConfig,
|
|
17876
|
+
updateSceneConfig,
|
|
17877
|
+
resetSceneConfig
|
|
17878
|
+
};
|
|
17879
|
+
}
|
|
17880
|
+
|
|
17783
17881
|
// src/hooks/useViewerHover.ts
|
|
17784
|
-
import { useCallback as
|
|
17882
|
+
import { useCallback as useCallback14, useState as useState30 } from "react";
|
|
17785
17883
|
function useViewerHover() {
|
|
17786
|
-
const [hoveredObjectBinding, setHoveredObjectBinding] =
|
|
17787
|
-
const handleHoveredObject =
|
|
17884
|
+
const [hoveredObjectBinding, setHoveredObjectBinding] = useState30(null);
|
|
17885
|
+
const handleHoveredObject = useCallback14(
|
|
17788
17886
|
(binding) => {
|
|
17789
17887
|
setHoveredObjectBinding(binding);
|
|
17790
17888
|
},
|
|
@@ -17797,18 +17895,18 @@ function useViewerHover() {
|
|
|
17797
17895
|
}
|
|
17798
17896
|
|
|
17799
17897
|
// src/hooks/useViewerModel.ts
|
|
17800
|
-
import { useCallback as
|
|
17898
|
+
import { useCallback as useCallback15, useState as useState31 } from "react";
|
|
17801
17899
|
import { Box3 as Box36, Vector3 as Vector310 } from "three";
|
|
17802
17900
|
function toTuple2(vector) {
|
|
17803
17901
|
return [vector.x, vector.y, vector.z];
|
|
17804
17902
|
}
|
|
17805
17903
|
function useViewerModel() {
|
|
17806
|
-
const [isLoading, setIsLoading] =
|
|
17807
|
-
const [isReady, setIsReady] =
|
|
17808
|
-
const [error, setError] =
|
|
17809
|
-
const [bounds, setBounds] =
|
|
17810
|
-
const [objectCount, setObjectCount] =
|
|
17811
|
-
const handleModelLoaded =
|
|
17904
|
+
const [isLoading, setIsLoading] = useState31(true);
|
|
17905
|
+
const [isReady, setIsReady] = useState31(false);
|
|
17906
|
+
const [error, setError] = useState31(null);
|
|
17907
|
+
const [bounds, setBounds] = useState31(null);
|
|
17908
|
+
const [objectCount, setObjectCount] = useState31(0);
|
|
17909
|
+
const handleModelLoaded = useCallback15((scene) => {
|
|
17812
17910
|
const box = new Box36().setFromObject(scene);
|
|
17813
17911
|
const min = box.min.clone();
|
|
17814
17912
|
const max = box.max.clone();
|
|
@@ -17833,14 +17931,14 @@ function useViewerModel() {
|
|
|
17833
17931
|
setIsLoading(false);
|
|
17834
17932
|
setIsReady(true);
|
|
17835
17933
|
}, []);
|
|
17836
|
-
const handleLoadError =
|
|
17934
|
+
const handleLoadError = useCallback15((nextError) => {
|
|
17837
17935
|
setError(nextError);
|
|
17838
17936
|
setBounds(null);
|
|
17839
17937
|
setObjectCount(0);
|
|
17840
17938
|
setIsLoading(false);
|
|
17841
17939
|
setIsReady(false);
|
|
17842
17940
|
}, []);
|
|
17843
|
-
const resetModelState =
|
|
17941
|
+
const resetModelState = useCallback15(() => {
|
|
17844
17942
|
setIsLoading(true);
|
|
17845
17943
|
setIsReady(false);
|
|
17846
17944
|
setError(null);
|
|
@@ -17860,10 +17958,10 @@ function useViewerModel() {
|
|
|
17860
17958
|
}
|
|
17861
17959
|
|
|
17862
17960
|
// src/hooks/useViewerActions.ts
|
|
17863
|
-
import { useCallback as
|
|
17961
|
+
import { useCallback as useCallback16 } from "react";
|
|
17864
17962
|
function useViewerActions(objectBindings, options = {}) {
|
|
17865
17963
|
const { onAction, onObjectBindingsChange } = options;
|
|
17866
|
-
const getActionsForObject =
|
|
17964
|
+
const getActionsForObject = useCallback16(
|
|
17867
17965
|
(objectId) => {
|
|
17868
17966
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17869
17967
|
if (!bindingKey) {
|
|
@@ -17873,7 +17971,7 @@ function useViewerActions(objectBindings, options = {}) {
|
|
|
17873
17971
|
},
|
|
17874
17972
|
[objectBindings]
|
|
17875
17973
|
);
|
|
17876
|
-
const runAction =
|
|
17974
|
+
const runAction = useCallback16(
|
|
17877
17975
|
(objectId, actionId) => {
|
|
17878
17976
|
const bindingKey = resolveBindingKey(objectBindings, objectId);
|
|
17879
17977
|
if (!bindingKey) {
|
|
@@ -17915,7 +18013,7 @@ function useViewerActions(objectBindings, options = {}) {
|
|
|
17915
18013
|
}
|
|
17916
18014
|
|
|
17917
18015
|
// src/hooks/useShareableViewerState.ts
|
|
17918
|
-
import { useCallback as
|
|
18016
|
+
import { useCallback as useCallback17, useEffect as useEffect22, useRef as useRef21, useState as useState32 } from "react";
|
|
17919
18017
|
function serializeState(cameraState, objectBindings, selectedObjectBinding) {
|
|
17920
18018
|
const hidden = Object.values(objectBindings).filter((binding) => binding.visible === false).map((binding) => binding.id);
|
|
17921
18019
|
return {
|
|
@@ -17935,8 +18033,8 @@ function useShareableViewerState({
|
|
|
17935
18033
|
debounceMs = 400,
|
|
17936
18034
|
autoSync = true
|
|
17937
18035
|
}) {
|
|
17938
|
-
const lastWrittenRawRef =
|
|
17939
|
-
const buildHash =
|
|
18036
|
+
const lastWrittenRawRef = useRef21(null);
|
|
18037
|
+
const buildHash = useCallback17(() => {
|
|
17940
18038
|
const state = serializeState(
|
|
17941
18039
|
cameraState,
|
|
17942
18040
|
objectBindings,
|
|
@@ -17944,12 +18042,12 @@ function useShareableViewerState({
|
|
|
17944
18042
|
);
|
|
17945
18043
|
return `${paramKey}=${encodeURIComponent(JSON.stringify(state))}`;
|
|
17946
18044
|
}, [cameraState, objectBindings, selectedObjectBinding, paramKey]);
|
|
17947
|
-
const getShareUrl =
|
|
18045
|
+
const getShareUrl = useCallback17(() => {
|
|
17948
18046
|
const url = new URL(window.location.href);
|
|
17949
18047
|
url.hash = buildHash();
|
|
17950
18048
|
return url.toString();
|
|
17951
18049
|
}, [buildHash]);
|
|
17952
|
-
const syncUrl =
|
|
18050
|
+
const syncUrl = useCallback17(() => {
|
|
17953
18051
|
const url = new URL(window.location.href);
|
|
17954
18052
|
url.hash = buildHash();
|
|
17955
18053
|
window.history.replaceState(null, "", url.toString());
|
|
@@ -17957,7 +18055,7 @@ function useShareableViewerState({
|
|
|
17957
18055
|
paramKey
|
|
17958
18056
|
);
|
|
17959
18057
|
}, [buildHash, paramKey]);
|
|
17960
|
-
const latestStateRef =
|
|
18058
|
+
const latestStateRef = useRef21({
|
|
17961
18059
|
cameraState,
|
|
17962
18060
|
objectBindings,
|
|
17963
18061
|
selectedObjectBinding
|
|
@@ -17967,8 +18065,8 @@ function useShareableViewerState({
|
|
|
17967
18065
|
objectBindings,
|
|
17968
18066
|
selectedObjectBinding
|
|
17969
18067
|
};
|
|
17970
|
-
const [restoreAttempted, setRestoreAttempted] =
|
|
17971
|
-
const lastSyncedHashRef =
|
|
18068
|
+
const [restoreAttempted, setRestoreAttempted] = useState32(false);
|
|
18069
|
+
const lastSyncedHashRef = useRef21(null);
|
|
17972
18070
|
useEffect22(() => {
|
|
17973
18071
|
if (!autoSync || !restoreAttempted) return;
|
|
17974
18072
|
const tick = () => {
|
|
@@ -17991,9 +18089,9 @@ function useShareableViewerState({
|
|
|
17991
18089
|
const id = window.setInterval(tick, debounceMs);
|
|
17992
18090
|
return () => window.clearInterval(id);
|
|
17993
18091
|
}, [autoSync, restoreAttempted, debounceMs, paramKey]);
|
|
17994
|
-
const lastRestoredRawRef =
|
|
17995
|
-
const restoringRawRef =
|
|
17996
|
-
const restoreFromUrl =
|
|
18092
|
+
const lastRestoredRawRef = useRef21(null);
|
|
18093
|
+
const restoringRawRef = useRef21(null);
|
|
18094
|
+
const restoreFromUrl = useCallback17(async () => {
|
|
17997
18095
|
setRestoreAttempted(true);
|
|
17998
18096
|
const rawHash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
|
|
17999
18097
|
const raw = new URLSearchParams(rawHash).get(paramKey);
|
|
@@ -18063,9 +18161,13 @@ export {
|
|
|
18063
18161
|
MATERIAL_SIDES,
|
|
18064
18162
|
ModelViewer,
|
|
18065
18163
|
SimpleModelViewer,
|
|
18164
|
+
material,
|
|
18165
|
+
patchBindings,
|
|
18166
|
+
patchSceneConfig,
|
|
18066
18167
|
useObjectBinding,
|
|
18067
18168
|
useObjectBindingIds,
|
|
18068
|
-
|
|
18169
|
+
useObjectBindings,
|
|
18170
|
+
useSceneConfig,
|
|
18069
18171
|
useShareableViewerState,
|
|
18070
18172
|
useViewerActions,
|
|
18071
18173
|
useViewerAnimations,
|