@react-three/drei 9.72.1 → 9.72.2
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/core/useEnvironment.cjs.js +1 -1
- package/core/useEnvironment.js +18 -9
- package/index.cjs.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-three/fiber"),r=require("three"),n=require("three-stdlib"),t=require("suspend-react"),s=require("../helpers/environment-assets.cjs.js");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-three/fiber"),r=require("three"),n=require("three-stdlib"),t=require("suspend-react"),s=require("../helpers/environment-assets.cjs.js");const o=e=>Array.isArray(e);exports.useEnvironment=function({files:i=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"],path:p="",preset:a,encoding:u,extensions:l}={}){let c,d=null,b=!1;if(a){if(!(a in s.presetsObj))throw new Error("Preset must be one of: "+Object.keys(s.presetsObj).join(", "));i=s.presetsObj[a],p="https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/"}var f,g;if("object"==typeof(g=i)&&"function"==typeof g.then?(i=t.suspend((async e=>(await e).default),[i]),d=n.EXRLoader):(b=o(i),c=!o(i)&&(null==(f=i.split(".").pop())?void 0:f.toLowerCase()),d=b?r.CubeTextureLoader:"hdr"===c?n.RGBELoader:"exr"===c?n.EXRLoader:null),!d)throw new Error("useEnvironment: Unrecognized file extension: "+i);const h=e.useLoader(d,b?[i]:i,(e=>{null==e.setPath||e.setPath(p),l&&l(e)})),j=b?h[0]:h;return j.mapping=b?r.CubeReflectionMapping:r.EquirectangularReflectionMapping,"colorSpace"in j?j.colorSpace=(null!=u?u:b)?"srgb":"srgb-linear":j.encoding=(null!=u?u:b)?3001:3e3,j};
|
package/core/useEnvironment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useLoader } from '@react-three/fiber';
|
|
2
|
-
import {
|
|
2
|
+
import { CubeReflectionMapping, EquirectangularReflectionMapping, CubeTextureLoader } from 'three';
|
|
3
3
|
import { EXRLoader, RGBELoader } from 'three-stdlib';
|
|
4
4
|
import { suspend } from 'suspend-react';
|
|
5
5
|
import { presetsObj } from '../helpers/environment-assets.js';
|
|
@@ -17,35 +17,44 @@ function useEnvironment({
|
|
|
17
17
|
encoding = undefined,
|
|
18
18
|
extensions
|
|
19
19
|
} = {}) {
|
|
20
|
-
|
|
20
|
+
let loader = null;
|
|
21
|
+
let isCubeMap = false;
|
|
22
|
+
let extension;
|
|
21
23
|
|
|
22
24
|
if (preset) {
|
|
23
25
|
if (!(preset in presetsObj)) throw new Error('Preset must be one of: ' + Object.keys(presetsObj).join(', '));
|
|
24
26
|
files = presetsObj[preset];
|
|
25
27
|
path = CUBEMAP_ROOT;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
+
}
|
|
28
29
|
|
|
29
30
|
if (isPromise(files)) {
|
|
31
|
+
// Using promises that return inline-EXR URLs by default
|
|
30
32
|
files = suspend(async promise => {
|
|
31
33
|
const result = await promise;
|
|
32
34
|
return result.default;
|
|
33
35
|
}, [files]);
|
|
36
|
+
loader = EXRLoader;
|
|
37
|
+
} else {
|
|
38
|
+
var _files$split$pop;
|
|
39
|
+
|
|
40
|
+
// Everything else
|
|
41
|
+
isCubeMap = isArray(files);
|
|
42
|
+
extension = !isArray(files) && ((_files$split$pop = files.split('.').pop()) == null ? void 0 : _files$split$pop.toLowerCase());
|
|
43
|
+
loader = isCubeMap ? CubeTextureLoader : extension === 'hdr' ? RGBELoader : extension === 'exr' ? EXRLoader : null;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
|
-
const isCubeMap = isArray(files);
|
|
37
|
-
const extension = !isArray(files) && ((_files$split$pop = files.split('.').pop()) == null ? void 0 : _files$split$pop.toLowerCase());
|
|
38
|
-
const loader = isCubeMap ? CubeTextureLoader : isPromise(files) || extension === 'exr' ? EXRLoader : extension === 'hdr' ? RGBELoader : null;
|
|
39
46
|
if (!loader) throw new Error('useEnvironment: Unrecognized file extension: ' + files);
|
|
40
47
|
const loaderResult = useLoader( // @ts-expect-error
|
|
41
48
|
loader, isCubeMap ? [files] : files, loader => {
|
|
42
|
-
loader.setPath(path);
|
|
49
|
+
loader.setPath == null ? void 0 : loader.setPath(path);
|
|
43
50
|
if (extensions) extensions(loader);
|
|
44
51
|
});
|
|
45
52
|
const texture = isCubeMap ? // @ts-ignore
|
|
46
53
|
loaderResult[0] : loaderResult;
|
|
47
54
|
texture.mapping = isCubeMap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
48
|
-
|
|
55
|
+
const sRGBEncoding = 3001;
|
|
56
|
+
const LinearEncoding = 3000;
|
|
57
|
+
if ('colorSpace' in texture) texture.colorSpace = (encoding !== null && encoding !== void 0 ? encoding : isCubeMap) ? 'srgb' : 'srgb-linear';else texture.encoding = (encoding !== null && encoding !== void 0 ? encoding : isCubeMap) ? sRGBEncoding : LinearEncoding;
|
|
49
58
|
return texture;
|
|
50
59
|
}
|
|
51
60
|
|