door_models 5.3.2 → 5.3.4
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.cjs.js +101 -56
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +101 -56
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -7,6 +7,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var csg = require('@react-three/csg');
|
|
8
8
|
var three = require('@react-spring/three');
|
|
9
9
|
var THREE = require('three');
|
|
10
|
+
var drei = require('@react-three/drei');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
13
|
|
|
@@ -803,20 +804,19 @@ new THREE__namespace.MeshStandardMaterial({
|
|
|
803
804
|
roughness: 0.8
|
|
804
805
|
});
|
|
805
806
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
807
|
+
// Type definition for a material prop (string or object with opacity)
|
|
808
|
+
|
|
809
|
+
// Helper function to check for hex color codes
|
|
809
810
|
const isHexColor = str => /^#([0-9A-F]{3}){1,2}$/i.test(str);
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
const createDynamicMaterial = prop => {
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* A simple "builder" that creates a THREE.MeshStandardMaterial from a prop and an
|
|
814
|
+
* optional map of pre-loaded textures. It does NOT load textures itself.
|
|
815
|
+
* @param prop - The material definition (string or object).
|
|
816
|
+
* @param textures - A map of URL -> THREE.Texture, provided by useTexture.
|
|
817
|
+
* @returns A THREE.MeshStandardMaterial instance.
|
|
818
|
+
*/
|
|
819
|
+
const buildMaterial = (prop, textures) => {
|
|
820
820
|
if (!prop) {
|
|
821
821
|
return new THREE__namespace.MeshStandardMaterial({
|
|
822
822
|
color: "#cccccc",
|
|
@@ -830,12 +830,13 @@ const createDynamicMaterial = prop => {
|
|
|
830
830
|
};
|
|
831
831
|
if (isHexColor(sourceValue)) {
|
|
832
832
|
params.color = sourceValue;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
833
|
+
}
|
|
834
|
+
// Check if it's a URL and if it exists in the pre-loaded texture map
|
|
835
|
+
else if (textures && textures[sourceValue]) {
|
|
836
|
+
params.map = textures[sourceValue];
|
|
837
|
+
}
|
|
838
|
+
// Fallback for invalid values
|
|
839
|
+
else {
|
|
839
840
|
params.color = "#cccccc";
|
|
840
841
|
}
|
|
841
842
|
if (opacity !== undefined && opacity < 1) {
|
|
@@ -845,45 +846,71 @@ const createDynamicMaterial = prop => {
|
|
|
845
846
|
return new THREE__namespace.MeshStandardMaterial(params);
|
|
846
847
|
};
|
|
847
848
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
849
|
+
// getFirstValidValue remains useful for fallbacks, so we keep it.
|
|
850
|
+
const getFirstValidValue = values => {
|
|
851
|
+
for (const val of values) {
|
|
852
|
+
if (val) {
|
|
853
|
+
return val;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return undefined;
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
// Re-export the type for easy access in other components
|
|
860
|
+
|
|
853
861
|
const useDoorMaterials = function () {
|
|
854
862
|
let materialsProp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
855
|
-
//
|
|
863
|
+
// 1. Collect all unique texture URLs from the props.
|
|
864
|
+
const textureUrls = React.useMemo(() => {
|
|
865
|
+
const urls = new Set();
|
|
866
|
+
// Iterate over all passed material props
|
|
867
|
+
Object.values(materialsProp).forEach(prop => {
|
|
868
|
+
// Get the value, whether it's a string or inside an object
|
|
869
|
+
const value = typeof prop === "string" ? prop : prop === null || prop === void 0 ? void 0 : prop.value;
|
|
870
|
+
// If it's a valid URL, add it to our set to avoid duplicates
|
|
871
|
+
if (value && (value.startsWith("http") || value.startsWith("/"))) {
|
|
872
|
+
urls.add(value);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
return Array.from(urls);
|
|
876
|
+
}, [materialsProp]);
|
|
856
877
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
878
|
+
// 2. Load all textures at once.
|
|
879
|
+
// !! THIS IS THE MAGIC !!
|
|
880
|
+
// `useTexture` will pause ("suspend") this component's rendering
|
|
881
|
+
// until all textures in the array are fully loaded.
|
|
882
|
+
const loadedTextures = drei.useTexture(textureUrls);
|
|
883
|
+
|
|
884
|
+
// 3. Create a map from URL back to the loaded THREE.Texture for easy lookup.
|
|
885
|
+
const textureMap = React.useMemo(() => {
|
|
886
|
+
const map = {};
|
|
887
|
+
textureUrls.forEach((url, index) => {
|
|
888
|
+
map[url] = loadedTextures[index];
|
|
889
|
+
});
|
|
890
|
+
return map;
|
|
891
|
+
}, [textureUrls, loadedTextures]);
|
|
892
|
+
|
|
893
|
+
// 4. Now that textures are guaranteed to be loaded, build all materials.
|
|
894
|
+
// This memo ensures the materials are only created when props or textures change.
|
|
895
|
+
return React.useMemo(() => {
|
|
896
|
+
const build = prop => buildMaterial(prop, textureMap);
|
|
897
|
+
return {
|
|
898
|
+
doorMaterial: build(materialsProp.Body),
|
|
899
|
+
frameMaterial: build(getFirstValidValue([materialsProp.D_PRF_COLOR, materialsProp.D_FR_SRF_DECOR, materialsProp.D_FR_SRF_DECOR_S2])),
|
|
900
|
+
gasketMaterial: build(materialsProp.D_GASKET),
|
|
901
|
+
doorStopMaterial: build(getFirstValidValue([materialsProp.D_PRF_COLOR, materialsProp.D_FR_SRF_DECOR, materialsProp.D_FR_SRF_DECOR_S2])),
|
|
902
|
+
interiorFanlightMaterial: build(materialsProp.D_SRF_DECOR),
|
|
903
|
+
exteriorFanlightMaterial: build(materialsProp.D_SRF_DECOR),
|
|
904
|
+
occulusInfillMaterial: build(materialsProp.D_FR_COLOR),
|
|
905
|
+
glassInfillMaterial: build(materialsProp.D_FR_COLOR),
|
|
906
|
+
frontCoverPanelMaterial: build(getFirstValidValue([materialsProp.D_PRF_COLOR, materialsProp.D_FR_SRF_DECOR, materialsProp.D_FR_SRF_DECOR_S2])),
|
|
907
|
+
backCoverPanelMaterial: build(getFirstValidValue([materialsProp.D_PRF_COLOR, materialsProp.D_FR_SRF_DECOR, materialsProp.D_FR_SRF_DECOR_S2])),
|
|
908
|
+
frontDoorPlaneMaterial: build(materialsProp.D_SRF_DECOR_2),
|
|
909
|
+
backDoorPlaneMaterial: build(materialsProp.D_SRF_DECOR),
|
|
910
|
+
hingeBodyMaterial: build(materialsProp.Hinge),
|
|
911
|
+
hingeAccentMaterial: build(materialsProp.HingeCuts)
|
|
912
|
+
};
|
|
913
|
+
}, [materialsProp, textureMap]);
|
|
887
914
|
};
|
|
888
915
|
|
|
889
916
|
function StandardHandle(_ref) {
|
|
@@ -1893,7 +1920,8 @@ function DoorLeaf(_ref8) {
|
|
|
1893
1920
|
doorWidth,
|
|
1894
1921
|
doorHeight,
|
|
1895
1922
|
theDoorDepth,
|
|
1896
|
-
doorOpening
|
|
1923
|
+
doorOpening,
|
|
1924
|
+
doorName
|
|
1897
1925
|
} = door;
|
|
1898
1926
|
const {
|
|
1899
1927
|
frameDepth,
|
|
@@ -1907,6 +1935,23 @@ function DoorLeaf(_ref8) {
|
|
|
1907
1935
|
secondDoorStopDepth
|
|
1908
1936
|
} = doorFrame;
|
|
1909
1937
|
const initialDoorHeight = React.useRef(null);
|
|
1938
|
+
React.useEffect(() => {
|
|
1939
|
+
initialDoorHeight.current = null;
|
|
1940
|
+
}, [doorName]);
|
|
1941
|
+
React.useEffect(() => {
|
|
1942
|
+
if (initialDoorHeight.current === null && doorHeight > 0) {
|
|
1943
|
+
initialDoorHeight.current = doorHeight;
|
|
1944
|
+
}
|
|
1945
|
+
}, [doorHeight]);
|
|
1946
|
+
React.useMemo(() => {
|
|
1947
|
+
if (initialDoorHeight.current === null) {
|
|
1948
|
+
return 0;
|
|
1949
|
+
}
|
|
1950
|
+
return (doorHeight - initialDoorHeight.current) / 2 / 1000;
|
|
1951
|
+
}, [doorHeight]);
|
|
1952
|
+
|
|
1953
|
+
// Old
|
|
1954
|
+
|
|
1910
1955
|
React.useEffect(() => {
|
|
1911
1956
|
if (doorHeight > 0 && initialDoorHeight.current === null) {
|
|
1912
1957
|
initialDoorHeight.current = doorHeight;
|