@react-three/drei 9.104.1 → 9.105.1
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 +5 -1
- package/core/Environment.cjs.js +1 -1
- package/core/Environment.d.ts +9 -4
- package/core/Environment.js +63 -17
- package/index.cjs.js +1 -1
- package/package.json +2 -2
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
package/README.md
CHANGED
|
@@ -4722,7 +4722,11 @@ Sets up a global cubemap, which affects the default `scene.environment`, and opt
|
|
|
4722
4722
|
```jsx
|
|
4723
4723
|
<Environment
|
|
4724
4724
|
background={false} // can be true, false or "only" (which only sets the background) (default: false)
|
|
4725
|
-
|
|
4725
|
+
backgroundBlurriness={0} // optional blur factor between 0 and 1 (default: 0, only works with three 0.146 and up)
|
|
4726
|
+
backgroundIntensity={1} // optional intensity factor (default: 1, only works with three 0.163 and up)
|
|
4727
|
+
backgroundRotation={[0, Math.PI / 2, 0]} // optional rotation (default: 0, only works with three 0.163 and up)
|
|
4728
|
+
environmentIntensity={1} // optional intensity factor (default: 1, only works with three 0.163 and up)
|
|
4729
|
+
environmentRotation={[0, Math.PI / 2, 0]} // optional rotation (default: 0, only works with three 0.163 and up)
|
|
4726
4730
|
files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']}
|
|
4727
4731
|
path="/"
|
|
4728
4732
|
preset={null}
|
package/core/Environment.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),n=require("react"),t=require("@react-three/fiber"),r=require("three"),o=require("three-stdlib"),u=require("./useEnvironment.cjs.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}require("@monogrid/gainmap-js"),require("../helpers/environment-assets.cjs.js"),require("../helpers/deprecated.cjs.js");var c=a(e),s=i(n);const l=e=>{return(n=e).current&&n.current.isScene?e.current:e;var n};function d(e,n,r,o,u={}){var a,i,c,s,d;u={backgroundBlurriness:null!==(a=u.blur)&&void 0!==a?a:0,backgroundIntensity:1,backgroundRotation:[0,0,0],environmentIntensity:1,environmentRotation:[0,0,0],...u};const m=l(n||r),b=m.background,g=m.environment,v={backgroundBlurriness:m.backgroundBlurriness,backgroundIntensity:m.backgroundIntensity,backgroundRotation:null!==(i=null==(c=m.backgroundRotation)||null==c.clone?void 0:c.clone())&&void 0!==i?i:[0,0,0],environmentIntensity:m.environmentIntensity,environmentRotation:null!==(s=null==(d=m.environmentRotation)||null==d.clone?void 0:d.clone())&&void 0!==s?s:[0,0,0]};return"only"!==e&&(m.environment=o),e&&(m.background=o,t.applyProps(m,u)),()=>{"only"!==e&&(m.environment=g),e&&(m.background=b,t.applyProps(m,v))}}function m({scene:e,background:n=!1,map:r,...o}){const u=t.useThree((e=>e.scene));return s.useLayoutEffect((()=>{if(r)return d(n,e,u,r,o)})),null}function b({background:e=!1,scene:n,blur:r,backgroundBlurriness:o,backgroundIntensity:a,backgroundRotation:i,environmentIntensity:c,environmentRotation:l,...m}){const b=u.useEnvironment(m),g=t.useThree((e=>e.scene));return s.useLayoutEffect((()=>d(e,n,g,b,{blur:r,backgroundBlurriness:o,backgroundIntensity:a,backgroundRotation:i,environmentIntensity:c,environmentRotation:l}))),null}function g({children:e,near:n=1,far:o=1e3,resolution:u=256,frames:a=1,map:i,background:c=!1,blur:l,backgroundBlurriness:g,backgroundIntensity:v,backgroundRotation:p,environmentIntensity:f,environmentRotation:k,scene:y,files:E,path:h,preset:j,extensions:I}){const R=t.useThree((e=>e.gl)),x=t.useThree((e=>e.scene)),P=s.useRef(null),[q]=s.useState((()=>new r.Scene)),B=s.useMemo((()=>{const e=new r.WebGLCubeRenderTarget(u);return e.texture.type=r.HalfFloatType,e}),[u]);s.useLayoutEffect((()=>(1===a&&P.current.update(R,q),d(c,y,x,B.texture,{blur:l,backgroundBlurriness:g,backgroundIntensity:v,backgroundRotation:p,environmentIntensity:f,environmentRotation:k}))),[e,q,B.texture,y,x,c,a,R]);let O=1;return t.useFrame((()=>{(a===1/0||O<a)&&(P.current.update(R,q),O++)})),s.createElement(s.Fragment,null,t.createPortal(s.createElement(s.Fragment,null,e,s.createElement("cubeCamera",{ref:P,args:[n,o,B]}),E||j?s.createElement(b,{background:!0,files:E,preset:j,path:h,extensions:I}):i?s.createElement(m,{background:!0,map:i,extensions:I}):null),q))}function v(e){var n,r,a,i;const l=u.useEnvironment(e),d=e.map||l;s.useMemo((()=>t.extend({GroundProjectedEnvImpl:o.GroundProjectedEnv})),[]);const b=s.useMemo((()=>[d]),[d]),g=null==(n=e.ground)?void 0:n.height,v=null==(r=e.ground)?void 0:r.radius,p=null!==(a=null==(i=e.ground)?void 0:i.scale)&&void 0!==a?a:1e3;return s.createElement(s.Fragment,null,s.createElement(m,c.default({},e,{map:d})),s.createElement("groundProjectedEnvImpl",{args:b,scale:p,height:g,radius:v}))}exports.Environment=function(e){return e.ground?s.createElement(v,e):e.map?s.createElement(m,e):e.children?s.createElement(g,e):s.createElement(b,e)},exports.EnvironmentCube=b,exports.EnvironmentMap=m,exports.EnvironmentPortal=g;
|
package/core/Environment.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Object3DNode } from '@react-three/fiber';
|
|
2
|
+
import { Object3DNode, Euler } from '@react-three/fiber';
|
|
3
3
|
import { Texture, Scene } from 'three';
|
|
4
4
|
import { GroundProjectedEnv as GroundProjectedEnvImpl } from 'three-stdlib';
|
|
5
5
|
import { PresetsType } from '../helpers/environment-assets';
|
|
@@ -12,6 +12,11 @@ export type EnvironmentProps = {
|
|
|
12
12
|
resolution?: number;
|
|
13
13
|
background?: boolean | 'only';
|
|
14
14
|
blur?: number;
|
|
15
|
+
backgroundBlurriness?: number;
|
|
16
|
+
backgroundIntensity?: number;
|
|
17
|
+
backgroundRotation?: Euler;
|
|
18
|
+
environmentIntensity?: number;
|
|
19
|
+
environmentRotation?: Euler;
|
|
15
20
|
map?: Texture;
|
|
16
21
|
preset?: PresetsType;
|
|
17
22
|
scene?: Scene | React.MutableRefObject<Scene>;
|
|
@@ -21,9 +26,9 @@ export type EnvironmentProps = {
|
|
|
21
26
|
scale?: number;
|
|
22
27
|
};
|
|
23
28
|
} & EnvironmentLoaderProps;
|
|
24
|
-
export declare function EnvironmentMap({ scene, background,
|
|
25
|
-
export declare function EnvironmentCube({ background, scene, blur, ...rest }: EnvironmentProps): null;
|
|
26
|
-
export declare function EnvironmentPortal({ children, near, far, resolution, frames, map, background, blur, scene, files, path, preset, extensions, }: EnvironmentProps): React.JSX.Element;
|
|
29
|
+
export declare function EnvironmentMap({ scene, background, map, ...config }: EnvironmentProps): null;
|
|
30
|
+
export declare function EnvironmentCube({ background, scene, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, ...rest }: EnvironmentProps): null;
|
|
31
|
+
export declare function EnvironmentPortal({ children, near, far, resolution, frames, map, background, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, scene, files, path, preset, extensions, }: EnvironmentProps): React.JSX.Element;
|
|
27
32
|
declare global {
|
|
28
33
|
namespace JSX {
|
|
29
34
|
interface IntrinsicElements {
|
package/core/Environment.js
CHANGED
|
@@ -1,52 +1,86 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { useThree, useFrame, createPortal, extend } from '@react-three/fiber';
|
|
3
|
+
import { useThree, useFrame, createPortal, applyProps, extend } from '@react-three/fiber';
|
|
4
4
|
import { Scene, WebGLCubeRenderTarget, HalfFloatType } from 'three';
|
|
5
5
|
import { GroundProjectedEnv } from 'three-stdlib';
|
|
6
6
|
import { useEnvironment } from './useEnvironment.js';
|
|
7
7
|
|
|
8
8
|
const isRef = obj => obj.current && obj.current.isScene;
|
|
9
9
|
const resolveScene = scene => isRef(scene) ? scene.current : scene;
|
|
10
|
-
function setEnvProps(background, scene, defaultScene, texture,
|
|
10
|
+
function setEnvProps(background, scene, defaultScene, texture, sceneProps = {}) {
|
|
11
|
+
var _sceneProps$blur, _target$backgroundRot, _target$backgroundRot2, _target$environmentRo, _target$environmentRo2;
|
|
12
|
+
// defaults
|
|
13
|
+
sceneProps = {
|
|
14
|
+
backgroundBlurriness: (_sceneProps$blur = sceneProps.blur) !== null && _sceneProps$blur !== void 0 ? _sceneProps$blur : 0,
|
|
15
|
+
backgroundIntensity: 1,
|
|
16
|
+
backgroundRotation: [0, 0, 0],
|
|
17
|
+
environmentIntensity: 1,
|
|
18
|
+
environmentRotation: [0, 0, 0],
|
|
19
|
+
...sceneProps
|
|
20
|
+
};
|
|
11
21
|
const target = resolveScene(scene || defaultScene);
|
|
12
22
|
const oldbg = target.background;
|
|
13
23
|
const oldenv = target.environment;
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
const oldSceneProps = {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
backgroundBlurriness: target.backgroundBlurriness,
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
backgroundIntensity: target.backgroundIntensity,
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
backgroundRotation: (_target$backgroundRot = (_target$backgroundRot2 = target.backgroundRotation) == null || _target$backgroundRot2.clone == null ? void 0 : _target$backgroundRot2.clone()) !== null && _target$backgroundRot !== void 0 ? _target$backgroundRot : [0, 0, 0],
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
environmentIntensity: target.environmentIntensity,
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
environmentRotation: (_target$environmentRo = (_target$environmentRo2 = target.environmentRotation) == null || _target$environmentRo2.clone == null ? void 0 : _target$environmentRo2.clone()) !== null && _target$environmentRo !== void 0 ? _target$environmentRo : [0, 0, 0]
|
|
35
|
+
};
|
|
16
36
|
if (background !== 'only') target.environment = texture;
|
|
17
|
-
if (background)
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
if (background) {
|
|
38
|
+
target.background = texture;
|
|
39
|
+
applyProps(target, sceneProps);
|
|
40
|
+
}
|
|
20
41
|
return () => {
|
|
21
42
|
if (background !== 'only') target.environment = oldenv;
|
|
22
|
-
if (background)
|
|
23
|
-
|
|
24
|
-
|
|
43
|
+
if (background) {
|
|
44
|
+
target.background = oldbg;
|
|
45
|
+
applyProps(target, oldSceneProps);
|
|
46
|
+
}
|
|
25
47
|
};
|
|
26
48
|
}
|
|
27
49
|
function EnvironmentMap({
|
|
28
50
|
scene,
|
|
29
51
|
background = false,
|
|
30
|
-
|
|
31
|
-
|
|
52
|
+
map,
|
|
53
|
+
...config
|
|
32
54
|
}) {
|
|
33
55
|
const defaultScene = useThree(state => state.scene);
|
|
34
56
|
React.useLayoutEffect(() => {
|
|
35
|
-
if (map) return setEnvProps(background, scene, defaultScene, map,
|
|
36
|
-
}
|
|
57
|
+
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
58
|
+
});
|
|
37
59
|
return null;
|
|
38
60
|
}
|
|
39
61
|
function EnvironmentCube({
|
|
40
62
|
background = false,
|
|
41
63
|
scene,
|
|
42
64
|
blur,
|
|
65
|
+
backgroundBlurriness,
|
|
66
|
+
backgroundIntensity,
|
|
67
|
+
backgroundRotation,
|
|
68
|
+
environmentIntensity,
|
|
69
|
+
environmentRotation,
|
|
43
70
|
...rest
|
|
44
71
|
}) {
|
|
45
72
|
const texture = useEnvironment(rest);
|
|
46
73
|
const defaultScene = useThree(state => state.scene);
|
|
47
74
|
React.useLayoutEffect(() => {
|
|
48
|
-
return setEnvProps(background, scene, defaultScene, texture,
|
|
49
|
-
|
|
75
|
+
return setEnvProps(background, scene, defaultScene, texture, {
|
|
76
|
+
blur,
|
|
77
|
+
backgroundBlurriness,
|
|
78
|
+
backgroundIntensity,
|
|
79
|
+
backgroundRotation,
|
|
80
|
+
environmentIntensity,
|
|
81
|
+
environmentRotation
|
|
82
|
+
});
|
|
83
|
+
});
|
|
50
84
|
return null;
|
|
51
85
|
}
|
|
52
86
|
function EnvironmentPortal({
|
|
@@ -58,6 +92,11 @@ function EnvironmentPortal({
|
|
|
58
92
|
map,
|
|
59
93
|
background = false,
|
|
60
94
|
blur,
|
|
95
|
+
backgroundBlurriness,
|
|
96
|
+
backgroundIntensity,
|
|
97
|
+
backgroundRotation,
|
|
98
|
+
environmentIntensity,
|
|
99
|
+
environmentRotation,
|
|
61
100
|
scene,
|
|
62
101
|
files,
|
|
63
102
|
path,
|
|
@@ -75,7 +114,14 @@ function EnvironmentPortal({
|
|
|
75
114
|
}, [resolution]);
|
|
76
115
|
React.useLayoutEffect(() => {
|
|
77
116
|
if (frames === 1) camera.current.update(gl, virtualScene);
|
|
78
|
-
return setEnvProps(background, scene, defaultScene, fbo.texture,
|
|
117
|
+
return setEnvProps(background, scene, defaultScene, fbo.texture, {
|
|
118
|
+
blur,
|
|
119
|
+
backgroundBlurriness,
|
|
120
|
+
backgroundIntensity,
|
|
121
|
+
backgroundRotation,
|
|
122
|
+
environmentIntensity,
|
|
123
|
+
environmentRotation
|
|
124
|
+
});
|
|
79
125
|
}, [children, virtualScene, fbo.texture, scene, defaultScene, background, frames, gl]);
|
|
80
126
|
let count = 1;
|
|
81
127
|
useFrame(() => {
|