door_models 5.2.1 → 5.2.3

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/dist/index.esm.js CHANGED
@@ -73,8 +73,10 @@ const ConfiguratorContext = /*#__PURE__*/createContext(undefined);
73
73
  const ConfiguratorProvider = _ref => {
74
74
  let {
75
75
  children,
76
- initialIs2D = false
76
+ initialIs2D = false,
77
+ initialMaterials = {}
77
78
  } = _ref;
79
+ const [materials, setMaterials] = useState(initialMaterials);
78
80
  const [is2D, setIs2D] = useState(initialIs2D);
79
81
  const [isPlaneVisible, setIsPlaneVisible] = useState(false);
80
82
  const [isFrameVisible, setIsFrameVisible] = useState(true);
@@ -162,8 +164,6 @@ const ConfiguratorProvider = _ref => {
162
164
  depth: 20
163
165
  });
164
166
  const defaultOptions = ["D_PRF_COLOR", "D_FR_SRF_DECOR", "D_FR_SRF_DECOR_S2"];
165
-
166
- // Function to pick the first valid value
167
167
  function getFirstValidValue(values, isValid) {
168
168
  for (const val of values) {
169
169
  if (isValid(val)) return val;
@@ -196,6 +196,11 @@ const ConfiguratorProvider = _ref => {
196
196
  useEffect(() => {
197
197
  setIs2D(initialIs2D);
198
198
  }, [initialIs2D]);
199
+ useEffect(() => {
200
+ if (initialMaterials) {
201
+ setMaterials(initialMaterials);
202
+ }
203
+ }, [initialMaterials]);
199
204
  const handleParseCpid = useCallback(cpidToParse => {
200
205
  const showMessage = function (text) {
201
206
  let type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "error";
@@ -658,6 +663,7 @@ const ConfiguratorProvider = _ref => {
658
663
  }, [totalWidth, doorFrame.sidesThk, isDoubleDoor]);
659
664
  return /*#__PURE__*/jsx(ConfiguratorContext.Provider, {
660
665
  value: {
666
+ materials,
661
667
  is2D,
662
668
  setIs2D,
663
669
  isPlaneVisible,
@@ -744,76 +750,63 @@ const useConfigurator = () => {
744
750
  return context;
745
751
  };
746
752
 
753
+ // Keep the textureLoader instance
747
754
  const textureLoader = new THREE.TextureLoader();
748
- const bodyInt = textureLoader.load("https://backend.tecnibo.com/api/plan2dimage?versionId=2cbb5eef-2f38-46ce-9e9f-6297753bde61&file=2cbb5eef-2f38-46ce-9e9f-6297753bde61-1759389624942.png");
749
- const bodyExt = textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
750
- const frameAlu = textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
751
- const frameWoodenInt = textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
752
- textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
753
- const wdg = textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
754
- const gasket = textureLoader.load("https://threejs.org/examples/textures/brick_diffuse.jpg");
755
- bodyInt.wrapS = THREE.RepeatWrapping;
756
- bodyInt.wrapT = THREE.RepeatWrapping;
757
- bodyExt.wrapS = THREE.RepeatWrapping;
758
- bodyExt.wrapT = THREE.RepeatWrapping;
755
+
756
+ // This is your new core logic. It's self-contained.
757
+ const isUrl = string => {
758
+ try {
759
+ new URL(string);
760
+ return true;
761
+ } catch (_) {
762
+ return false;
763
+ }
764
+ };
765
+ const createMaterialFromProp = value => {
766
+ if (!value) return null;
767
+
768
+ // Handle HEX colors
769
+ if (value.startsWith("#")) {
770
+ return new THREE.MeshStandardMaterial({
771
+ color: value,
772
+ roughness: 0.8
773
+ });
774
+ }
775
+
776
+ // Handle URLs
777
+ if (isUrl(value)) {
778
+ const texture = textureLoader.load(value);
779
+ texture.wrapS = THREE.RepeatWrapping;
780
+ texture.wrapT = THREE.RepeatWrapping;
781
+ return new THREE.MeshStandardMaterial({
782
+ map: texture,
783
+ roughness: 0.8
784
+ });
785
+ }
786
+
787
+ // It's good practice to return null if the format is not recognized.
788
+ return null;
789
+ };
790
+
791
+ // --- REMOVED THE ENTIRE `availableMaterials` OBJECT ---
792
+ // It is no longer needed.
793
+
794
+ // Keep placeholder materials as a fallback if a material prop isn't provided
795
+ const placeholderMaterial = new THREE.MeshStandardMaterial({
796
+ color: "#cccccc",
797
+ // A neutral grey
798
+ roughness: 0.8
799
+ });
800
+ const placeholderMaterialforFrames = new THREE.MeshStandardMaterial({
801
+ color: "#555555",
802
+ // A darker grey for frames
803
+ roughness: 0.8
804
+ });
805
+
759
806
  const availableMaterials = {
760
- D_SRF_DECOR_2: new THREE.MeshStandardMaterial({
761
- map: bodyInt,
762
- roughness: 0.8
763
- }),
764
- D_SRF_DECOR: new THREE.MeshStandardMaterial({
765
- map: bodyExt,
766
- roughness: 0.8
767
- }),
768
- D_PRF_COLOR: new THREE.MeshStandardMaterial({
769
- map: frameAlu,
770
- roughness: 0.8
771
- }),
772
- D_FR_SRF_DECOR: new THREE.MeshStandardMaterial({
773
- map: frameWoodenInt,
774
- roughness: 0.8
775
- }),
776
- D_FR_SRF_DECOR_S2: new THREE.MeshStandardMaterial({
777
- map: frameWoodenInt,
778
- roughness: 0.8
779
- }),
780
- D_FR_COLOR: new THREE.MeshStandardMaterial({
781
- map: wdg,
782
- roughness: 0.8
783
- }),
784
- D_GASKET: new THREE.MeshStandardMaterial({
785
- map: gasket,
786
- roughness: 0.8
787
- }),
788
807
  black: new THREE.MeshStandardMaterial({
789
808
  color: "#000000"
790
809
  }),
791
- metal: new THREE.MeshStandardMaterial({
792
- color: "#aaaaaa",
793
- metalness: 1.0,
794
- roughness: 0.4
795
- }),
796
- darkgrey: new THREE.MeshStandardMaterial({
797
- color: "#5e5e5e"
798
- }),
799
- grey: new THREE.MeshStandardMaterial({
800
- color: "#cccccc"
801
- }),
802
- yellow: new THREE.MeshStandardMaterial({
803
- color: "#ffff00"
804
- }),
805
- darkBrown: new THREE.MeshStandardMaterial({
806
- color: "#a0522d"
807
- }),
808
- brown: new THREE.MeshStandardMaterial({
809
- color: "#d2b48c"
810
- }),
811
- glass: new THREE.MeshStandardMaterial({
812
- color: "#ffffff",
813
- roughness: 0.1,
814
- transparent: true,
815
- opacity: 0.7
816
- }),
817
810
  aluminum: new THREE.MeshStandardMaterial({
818
811
  color: "#abb0aa",
819
812
  metalness: 0.8,
@@ -831,39 +824,10 @@ const availableMaterials = {
831
824
  metalness: 0.8,
832
825
  roughness: 0.5,
833
826
  envMapIntensity: 1.2
834
- }),
835
- silver: new THREE.MeshStandardMaterial({
836
- color: "#c0c0c0",
837
- metalness: 1.0,
838
- roughness: 0.2
839
- }),
840
- gold: new THREE.MeshStandardMaterial({
841
- color: "#ffd700",
842
- metalness: 1.0,
843
- roughness: 0.3
844
- }),
845
- diamond: new THREE.MeshStandardMaterial({
846
- color: "#e0f7fa",
847
- metalness: 0.9,
848
- roughness: 0.05,
849
- transparent: true,
850
- opacity: 0.9,
851
- envMapIntensity: 1.5
852
- }),
853
- test_material: new THREE.MeshStandardMaterial({
854
- color: "red",
855
- roughness: 0.1
856
827
  })
857
828
  };
858
- const placeholderMaterial = new THREE.MeshStandardMaterial({
859
- color: "#cccccc",
860
- roughness: 0.8
861
- });
862
- const placeholderMaterialforFrames = new THREE.MeshStandardMaterial({
863
- color: "#000",
864
- roughness: 0.8
865
- });
866
829
 
830
+ // Custom hook for door handle calculations
867
831
  function StandardHandle(_ref) {
868
832
  let {
869
833
  position,
@@ -1365,7 +1329,8 @@ function DoorModels(_ref7) {
1365
1329
  glassDepth,
1366
1330
  cpid,
1367
1331
  handleParseCpid,
1368
- isDoubleDoor
1332
+ isDoubleDoor,
1333
+ materials
1369
1334
  } = useConfigurator();
1370
1335
  useEffect(() => {
1371
1336
  if (doorName) {
@@ -1407,29 +1372,36 @@ function DoorModels(_ref7) {
1407
1372
  const {
1408
1373
  material: backDoorPlaneMaterialName
1409
1374
  } = backDoorPlane;
1410
-
1375
+ const pers = useMemo(() => {
1376
+ const dynamicMaterials = {};
1377
+ for (const key in materials) {
1378
+ if (Object.prototype.hasOwnProperty.call(materials, key)) {
1379
+ const value = materials[key];
1380
+ dynamicMaterials[key] = createMaterialFromProp(value);
1381
+ }
1382
+ }
1383
+ return dynamicMaterials;
1384
+ }, [materials]);
1411
1385
  // --- Material Logic ---
1412
- useMemo(() => availableMaterials[testDoorMaterial] || availableMaterials[doorMaterialName] || placeholderMaterial, [testDoorMaterial, doorMaterialName]);
1413
- const frameMaterial = useMemo(() => availableMaterials[testFrameMaterial] || availableMaterials[frameMaterialName] || placeholderMaterialforFrames, [testFrameMaterial, frameMaterialName]);
1414
- const gasketMaterial = useMemo(() => availableMaterials[testGasketMaterial] || availableMaterials[gasketMaterialName] || new THREE.MeshStandardMaterial({
1415
- color: "#111111"
1416
- }), [testGasketMaterial, gasketMaterialName]);
1386
+ useMemo(() => placeholderMaterial, [testDoorMaterial, doorMaterialName]);
1387
+ const frameMaterial = useMemo(() => pers.D_PRF_COLOR || pers.D_FR_SRF_DECOR || pers.D_FR_SRF_DECOR_S2 || placeholderMaterialforFrames, [testFrameMaterial, frameMaterialName]);
1388
+ const gasketMaterial = useMemo(() => pers.D_GASKET || availableMaterials.black, [testGasketMaterial, gasketMaterialName]);
1417
1389
  const doorStopMaterial = useMemo(() => {
1418
- return availableMaterials[testDoorStopMaterial] || availableMaterials[doorStopMaterialName || ""] || frameMaterial;
1390
+ return pers.D_PRF_COLOR || pers.D_FR_SRF_DECOR || pers.D_FR_SRF_DECOR_S2 || frameMaterial;
1419
1391
  }, [testDoorStopMaterial, doorStopMaterialName, frameType, frameMaterial]);
1420
- const interiorFanlightMaterial = useMemo(() => availableMaterials[testInteriorFanlightMaterial] || availableMaterials[interiorFanlightMaterialName] || placeholderMaterial, [testInteriorFanlightMaterial, interiorFanlightMaterialName]);
1421
- const exteriorFanlightMaterial = useMemo(() => availableMaterials[testExteriorFanlightMaterial] || availableMaterials[exteriorFanlightMaterialName] || placeholderMaterial, [testExteriorFanlightMaterial, exteriorFanlightMaterialName]);
1422
- useMemo(() => availableMaterials[testOcculusInfillMaterial] || availableMaterials[occulusInfillMaterialName] || placeholderMaterial, [testOcculusInfillMaterial, occulusInfillMaterialName]);
1423
- const glassInfillMaterial = useMemo(() => availableMaterials[testGlassInfillMaterial] || availableMaterials[glassInfillMaterialName] || placeholderMaterial, [testGlassInfillMaterial, glassInfillMaterialName]);
1424
- useMemo(() => availableMaterials[testHingeMaterial] || availableMaterials[hingeMaterialName] || new THREE.MeshStandardMaterial({
1392
+ const interiorFanlightMaterial = useMemo(() => pers.D_SRF_DECOR_2 || placeholderMaterial, [testInteriorFanlightMaterial, interiorFanlightMaterialName]);
1393
+ const exteriorFanlightMaterial = useMemo(() => placeholderMaterial, [testExteriorFanlightMaterial, exteriorFanlightMaterialName]);
1394
+ useMemo(() => placeholderMaterial, [testOcculusInfillMaterial, occulusInfillMaterialName]);
1395
+ const glassInfillMaterial = useMemo(() => pers.D_FR_COLOR || placeholderMaterial, [testGlassInfillMaterial, glassInfillMaterialName]);
1396
+ useMemo(() => new THREE.MeshStandardMaterial({
1425
1397
  color: "#d4d4d4",
1426
1398
  metalness: 1.0,
1427
1399
  roughness: 0.4
1428
1400
  }), [testHingeMaterial, hingeMaterialName]);
1429
- const frontCoverPanelMaterial = useMemo(() => availableMaterials[testFrontCoverPanelMaterial] || availableMaterials[frontCoverPanelMaterialName] || placeholderMaterial, [testFrontCoverPanelMaterial, frontCoverPanelMaterialName]);
1430
- const backCoverPanelMaterial = useMemo(() => availableMaterials[testBackCoverPanelMaterial] || availableMaterials[backCoverPanelMaterialName] || placeholderMaterial, [testBackCoverPanelMaterial, backCoverPanelMaterialName]);
1431
- useMemo(() => availableMaterials[testFrontDoorPlaneMaterial] || availableMaterials[frontDoorPlaneMaterialName] || placeholderMaterial, [testFrontDoorPlaneMaterial, frontDoorPlaneMaterialName]);
1432
- useMemo(() => availableMaterials[testBackDoorPlaneMaterial] || availableMaterials[backDoorPlaneMaterialName] || placeholderMaterial, [testBackDoorPlaneMaterial, backDoorPlaneMaterialName]);
1401
+ const frontCoverPanelMaterial = useMemo(() => pers.D_PRF_COLOR || pers.D_FR_SRF_DECOR || pers.D_FR_SRF_DECOR_S2 || placeholderMaterial, [testFrontCoverPanelMaterial, frontCoverPanelMaterialName]);
1402
+ const backCoverPanelMaterial = useMemo(() => pers.D_PRF_COLOR || pers.D_FR_SRF_DECOR || pers.D_FR_SRF_DECOR_S2 || placeholderMaterial, [testBackCoverPanelMaterial, backCoverPanelMaterialName]);
1403
+ useMemo(() => pers.D_SRF_DECOR_2 || placeholderMaterial, [testFrontDoorPlaneMaterial, frontDoorPlaneMaterialName]);
1404
+ useMemo(() => pers.D_SRF_DECOR || placeholderMaterial, [testBackDoorPlaneMaterial, backDoorPlaneMaterialName]);
1433
1405
  useMemo(() => new THREE.MeshStandardMaterial({
1434
1406
  color: "#1a1a1a",
1435
1407
  roughness: 0.1
@@ -2025,27 +1997,27 @@ function DoorLeaf(_ref8) {
2025
1997
  } = backDoorPlane;
2026
1998
 
2027
1999
  // --- Material Logic ---
2028
- const doorMaterial = useMemo(() => availableMaterials[testDoorMaterial] || availableMaterials[doorMaterialName] || placeholderMaterial, [testDoorMaterial, doorMaterialName]);
2029
- const frameMaterial = useMemo(() => availableMaterials[testFrameMaterial] || availableMaterials[frameMaterialName] || placeholderMaterialforFrames, [testFrameMaterial, frameMaterialName]);
2030
- const gasketMaterial = useMemo(() => availableMaterials[testGasketMaterial] || availableMaterials[gasketMaterialName] || new THREE.MeshStandardMaterial({
2000
+ const doorMaterial = useMemo(() => placeholderMaterial, [testDoorMaterial, doorMaterialName]);
2001
+ const frameMaterial = useMemo(() => placeholderMaterialforFrames, [testFrameMaterial, frameMaterialName]);
2002
+ const gasketMaterial = useMemo(() => new THREE.MeshStandardMaterial({
2031
2003
  color: "#111111"
2032
2004
  }), [testGasketMaterial, gasketMaterialName]);
2033
2005
  useMemo(() => {
2034
- return availableMaterials[testDoorStopMaterial] || availableMaterials[doorStopMaterialName || ""] || frameMaterial;
2006
+ return frameMaterial;
2035
2007
  }, [testDoorStopMaterial, doorStopMaterialName, frameType, frameMaterial]);
2036
- useMemo(() => availableMaterials[testInteriorFanlightMaterial] || availableMaterials[interiorFanlightMaterialName] || placeholderMaterial, [testInteriorFanlightMaterial, interiorFanlightMaterialName]);
2037
- useMemo(() => availableMaterials[testExteriorFanlightMaterial] || availableMaterials[exteriorFanlightMaterialName] || placeholderMaterial, [testExteriorFanlightMaterial, exteriorFanlightMaterialName]);
2038
- const occulusInfillMaterial = useMemo(() => availableMaterials[testOcculusInfillMaterial] || availableMaterials[occulusInfillMaterialName] || placeholderMaterial, [testOcculusInfillMaterial, occulusInfillMaterialName]);
2039
- const glassInfillMaterial = useMemo(() => availableMaterials[testGlassInfillMaterial] || availableMaterials[glassInfillMaterialName] || placeholderMaterial, [testGlassInfillMaterial, glassInfillMaterialName]);
2040
- const hingeBodyMaterial = useMemo(() => availableMaterials[testHingeMaterial] || availableMaterials[hingeMaterialName] || new THREE.MeshStandardMaterial({
2008
+ useMemo(() => placeholderMaterial, [testInteriorFanlightMaterial, interiorFanlightMaterialName]);
2009
+ useMemo(() => placeholderMaterial, [testExteriorFanlightMaterial, exteriorFanlightMaterialName]);
2010
+ const occulusInfillMaterial = useMemo(() => placeholderMaterial, [testOcculusInfillMaterial, occulusInfillMaterialName]);
2011
+ const glassInfillMaterial = useMemo(() => placeholderMaterial, [testGlassInfillMaterial, glassInfillMaterialName]);
2012
+ const hingeBodyMaterial = useMemo(() => new THREE.MeshStandardMaterial({
2041
2013
  color: "#d4d4d4",
2042
2014
  metalness: 1.0,
2043
2015
  roughness: 0.4
2044
2016
  }), [testHingeMaterial, hingeMaterialName]);
2045
- useMemo(() => availableMaterials[testFrontCoverPanelMaterial] || availableMaterials[frontCoverPanelMaterialName] || placeholderMaterial, [testFrontCoverPanelMaterial, frontCoverPanelMaterialName]);
2046
- useMemo(() => availableMaterials[testBackCoverPanelMaterial] || availableMaterials[backCoverPanelMaterialName] || placeholderMaterial, [testBackCoverPanelMaterial, backCoverPanelMaterialName]);
2047
- const frontDoorPlaneMaterial = useMemo(() => availableMaterials[testFrontDoorPlaneMaterial] || availableMaterials[frontDoorPlaneMaterialName] || placeholderMaterial, [testFrontDoorPlaneMaterial, frontDoorPlaneMaterialName]);
2048
- const backDoorPlaneMaterial = useMemo(() => availableMaterials[testBackDoorPlaneMaterial] || availableMaterials[backDoorPlaneMaterialName] || placeholderMaterial, [testBackDoorPlaneMaterial, backDoorPlaneMaterialName]);
2017
+ useMemo(() => placeholderMaterial, [testFrontCoverPanelMaterial, frontCoverPanelMaterialName]);
2018
+ useMemo(() => placeholderMaterial, [testBackCoverPanelMaterial, backCoverPanelMaterialName]);
2019
+ const frontDoorPlaneMaterial = useMemo(() => placeholderMaterial, [testFrontDoorPlaneMaterial, frontDoorPlaneMaterialName]);
2020
+ const backDoorPlaneMaterial = useMemo(() => placeholderMaterial, [testBackDoorPlaneMaterial, backDoorPlaneMaterialName]);
2049
2021
  const hingeAccentMaterial = useMemo(() => new THREE.MeshStandardMaterial({
2050
2022
  color: "#1a1a1a",
2051
2023
  roughness: 0.1
@@ -2441,11 +2413,12 @@ function DoorLeaf(_ref8) {
2441
2413
  const DoorConfigurator = _ref => {
2442
2414
  let {
2443
2415
  doorName,
2444
- showInterface = true,
2445
- is2D = false
2416
+ is2D = false,
2417
+ materials
2446
2418
  } = _ref;
2447
2419
  return /*#__PURE__*/jsx(ConfiguratorProvider, {
2448
2420
  initialIs2D: is2D,
2421
+ initialMaterials: materials,
2449
2422
  children: /*#__PURE__*/jsx(DoorModels, {
2450
2423
  doorName: doorName
2451
2424
  })