@react-three/drei 9.106.1 → 9.107.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 +45 -55
- package/core/Caustics.cjs.js +1 -1
- package/core/Caustics.js +1 -1
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.js +1 -1
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.d.ts +15 -3
- package/core/CubeCamera.js +47 -4
- package/core/CubeTexture.cjs.js +1 -0
- package/core/CubeTexture.d.ts +15 -0
- package/core/{useCubeTexture.js → CubeTexture.js} +12 -1
- package/core/DetectGPU.cjs.js +1 -0
- package/core/DetectGPU.d.ts +8 -0
- package/core/DetectGPU.js +14 -0
- package/core/Example.d.ts +1 -1
- package/core/Example.js +3 -0
- package/core/Fbo.cjs.js +1 -0
- package/core/{useFBO.d.ts → Fbo.d.ts} +6 -0
- package/core/{useFBO.js → Fbo.js} +10 -1
- package/core/Fbx.cjs.js +1 -0
- package/core/Fbx.d.ts +11 -0
- package/core/Fbx.js +23 -0
- package/core/GizmoHelper.cjs.js +1 -1
- package/core/GizmoViewcube.cjs.js +1 -1
- package/core/GizmoViewport.cjs.js +1 -1
- package/core/Gltf.cjs.js +1 -1
- package/core/Gltf.d.ts +17 -5
- package/core/Gltf.js +37 -3
- package/core/GradientTexture.cjs.js +1 -1
- package/core/GradientTexture.d.ts +2 -1
- package/core/GradientTexture.js +3 -1
- package/core/Image.cjs.js +1 -1
- package/core/Image.js +1 -1
- package/core/Ktx2.cjs.js +1 -0
- package/core/{useKTX2.d.ts → Ktx2.d.ts} +6 -0
- package/core/{useKTX2.js → Ktx2.js} +15 -3
- package/core/MatcapTexture.cjs.js +1 -0
- package/core/MatcapTexture.d.ts +9 -0
- package/core/{useMatcapTexture.js → MatcapTexture.js} +14 -2
- package/core/MeshPortalMaterial.cjs.js +1 -1
- package/core/MeshPortalMaterial.js +1 -1
- package/core/MeshTransmissionMaterial.cjs.js +1 -1
- package/core/MeshTransmissionMaterial.js +1 -1
- package/core/NormalTexture.cjs.js +1 -0
- package/core/NormalTexture.d.ts +14 -0
- package/core/{useNormalTexture.js → NormalTexture.js} +14 -2
- package/core/OrthographicCamera.cjs.js +1 -1
- package/core/OrthographicCamera.js +1 -1
- package/core/PerspectiveCamera.cjs.js +1 -1
- package/core/PerspectiveCamera.js +1 -1
- package/core/Progress.cjs.js +1 -0
- package/core/{useProgress.d.ts → Progress.d.ts} +4 -0
- package/core/{useProgress.js → Progress.js} +11 -1
- package/core/RenderTexture.cjs.js +1 -1
- package/core/RenderTexture.js +1 -1
- package/core/Stats.cjs.js +1 -1
- package/core/Stats.js +3 -1
- package/core/StatsGl.cjs.js +1 -1
- package/core/StatsGl.js +3 -1
- package/core/Texture.cjs.js +1 -0
- package/core/{useTexture.d.ts → Texture.d.ts} +10 -4
- package/core/{useTexture.js → Texture.js} +18 -5
- package/core/TrailTexture.cjs.js +1 -0
- package/core/{useTrailTexture.d.ts → TrailTexture.d.ts} +4 -0
- package/core/{useTrailTexture.js → TrailTexture.js} +14 -3
- package/core/VideoTexture.cjs.js +1 -0
- package/core/VideoTexture.d.ts +18 -0
- package/core/{useVideoTexture.js → VideoTexture.js} +25 -23
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +12 -14
- package/core/index.js +14 -16
- package/core/useDepthBuffer.cjs.js +1 -1
- package/core/useDepthBuffer.js +1 -1
- package/index.cjs.js +1 -1
- package/index.js +14 -16
- package/native/index.cjs.js +1 -1
- package/native/index.js +14 -16
- package/package.json +1 -1
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
- package/web/FaceControls.cjs.js +1 -1
- package/web/FaceControls.d.ts +1 -1
- package/web/FaceControls.js +12 -1
- package/web/Loader.cjs.js +1 -1
- package/web/Loader.js +1 -1
- package/web/index.cjs.js +1 -1
- package/web/index.js +14 -16
- package/core/useCubeCamera.cjs.js +0 -1
- package/core/useCubeCamera.d.ts +0 -14
- package/core/useCubeCamera.js +0 -49
- package/core/useCubeTexture.cjs.js +0 -1
- package/core/useCubeTexture.d.ts +0 -9
- package/core/useDetectGPU.cjs.js +0 -1
- package/core/useDetectGPU.d.ts +0 -2
- package/core/useDetectGPU.js +0 -6
- package/core/useFBO.cjs.js +0 -1
- package/core/useFBX.cjs.js +0 -1
- package/core/useFBX.d.ts +0 -6
- package/core/useFBX.js +0 -10
- package/core/useGLTF.cjs.js +0 -1
- package/core/useGLTF.d.ts +0 -8
- package/core/useGLTF.js +0 -32
- package/core/useKTX2.cjs.js +0 -1
- package/core/useMatcapTexture.cjs.js +0 -1
- package/core/useMatcapTexture.d.ts +0 -2
- package/core/useNormalTexture.cjs.js +0 -1
- package/core/useNormalTexture.d.ts +0 -8
- package/core/useProgress.cjs.js +0 -1
- package/core/useTexture.cjs.js +0 -1
- package/core/useTrailTexture.cjs.js +0 -1
- package/core/useVideoTexture.cjs.js +0 -1
- package/core/useVideoTexture.d.ts +0 -12
- /package/core/{useBVH.cjs.js → Bvh.cjs.js} +0 -0
- /package/core/{useBVH.d.ts → Bvh.d.ts} +0 -0
- /package/core/{useBVH.js → Bvh.js} +0 -0
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
63
63
|
<li><a href="#dragcontrols">DragControls</a></li>
|
|
64
64
|
<li><a href="#transformcontrols">TransformControls</a></li>
|
|
65
65
|
<li><a href="#grid">Grid</a></li>
|
|
66
|
-
<li><a href="#usehelper">useHelper</a></li>
|
|
66
|
+
<li><a href="#helper--usehelper">Helper / useHelper</a></li>
|
|
67
67
|
<li><a href="#helper">Helper</a></li>
|
|
68
68
|
</ul>
|
|
69
69
|
<li><a href="#abstractions">Abstractions</a></li>
|
|
@@ -119,29 +119,29 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
119
119
|
<li><a href="#wireframe">Wireframe</a></li>
|
|
120
120
|
<li><a href="#usedepthbuffer">useDepthBuffer</a></li>
|
|
121
121
|
<li><a href="#usecontextbridge">useContextBridge</a></li>
|
|
122
|
-
<li><a href="#usefbo">useFBO</a></li>
|
|
122
|
+
<li><a href="#fbo--usefbo">Fbo / useFBO</a></li>
|
|
123
123
|
<li><a href="#usecamera">useCamera</a></li>
|
|
124
|
-
<li><a href="#usecubecamera">useCubeCamera</a></li>
|
|
125
|
-
<li><a href="#usedetectgpu">useDetectGPU</a></li>
|
|
124
|
+
<li><a href="#cubecamera--usecubecamera">CubeCamera / useCubeCamera</a></li>
|
|
125
|
+
<li><a href="#detectgpu--usedetectgpu">DetectGPU / useDetectGPU</a></li>
|
|
126
126
|
<li><a href="#useaspect">useAspect</a></li>
|
|
127
127
|
<li><a href="#usecursor">useCursor</a></li>
|
|
128
128
|
<li><a href="#useintersect">useIntersect</a></li>
|
|
129
129
|
<li><a href="#useboxprojectedenv">useBoxProjectedEnv</a></li>
|
|
130
|
-
<li><a href="#useTrail">useTrail</a></li>
|
|
130
|
+
<li><a href="#trail--useTrail">Trail / useTrail</a></li>
|
|
131
131
|
<li><a href="#useSurfaceSampler">useSurfaceSampler</a></li>
|
|
132
132
|
<li><a href="#facelandmarker">FaceLandmarker</a></li>
|
|
133
133
|
</ul>
|
|
134
134
|
<li><a href="#loading">Loaders</a></li>
|
|
135
135
|
<ul>
|
|
136
136
|
<li><a href="#loader">Loader</a></li>
|
|
137
|
-
<li><a href="#useprogress">useProgress</a></li>
|
|
138
|
-
<li><a href="#usegltf">useGLTF</a></li>
|
|
139
|
-
<li><a href="#usefbx">useFBX</a></li>
|
|
140
|
-
<li><a href="#usetexture">useTexture</a></li>
|
|
141
|
-
<li><a href="#usektx2">useKTX2</a></li>
|
|
142
|
-
<li><a href="#usecubetexture">useCubeTexture</a></li>
|
|
143
|
-
<li><a href="#usevideotexture">useVideoTexture</a></li>
|
|
144
|
-
<li><a href="#usetrailtexture">useTrailTexture</a></li>
|
|
137
|
+
<li><a href="#progress--useprogress">Progress / useProgress</a></li>
|
|
138
|
+
<li><a href="#gltf--usegltf">Gltf / useGLTF</a></li>
|
|
139
|
+
<li><a href="#fbx--usefbx">FBX / useFBX</a></li>
|
|
140
|
+
<li><a href="#texture--usetexture">Texture / useTexture</a></li>
|
|
141
|
+
<li><a href="#ktx2--usektx2">Ktx2 / useKTX2</a></li>
|
|
142
|
+
<li><a href="#cubetexture--usecubetexture">CubeTexture / useCubeTexture</a></li>
|
|
143
|
+
<li><a href="#videotexture--usevideotexture">VideoTexture / useVideoTexture</a></li>
|
|
144
|
+
<li><a href="#trailtexture--usetrailtexture">TrailTexture / useTrailTexture</a></li>
|
|
145
145
|
<li><a href="#usefont">useFont</a></li>
|
|
146
146
|
<li><a href="#usespriteloader">useSpriteLoader</a></li>
|
|
147
147
|
</ul>
|
|
@@ -230,8 +230,8 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
230
230
|
<li><a href="#sparkles">Sparkles</a></li>
|
|
231
231
|
<li><a href="#cloud">Cloud</a></li>
|
|
232
232
|
<li><a href="#useenvironment">useEnvironment</a></li>
|
|
233
|
-
<li><a href="#usematcaptexture">useMatcapTexture</a></li>
|
|
234
|
-
<li><a href="#usenormaltexture">useNormalTexture</a></li>
|
|
233
|
+
<li><a href="#matcaptexture--usematcaptexture">MatcapTexture / useMatcapTexture</a></li>
|
|
234
|
+
<li><a href="#normaltexture--usenormaltexture">NormalTexture / useNormalTexture</a></li>
|
|
235
235
|
<li><a href="#shadowalpha">ShadowAlpha</a></li>
|
|
236
236
|
</ul>
|
|
237
237
|
</ul>
|
|
@@ -1107,9 +1107,9 @@ export type GridProps = GridMaterialType & {
|
|
|
1107
1107
|
<Grid />
|
|
1108
1108
|
```
|
|
1109
1109
|
|
|
1110
|
-
#### useHelper
|
|
1110
|
+
#### Helper / useHelper
|
|
1111
1111
|
|
|
1112
|
-
[](https://drei.vercel.app/?path=/story/
|
|
1112
|
+
[](https://drei.vercel.app/?path=/story/gizmos-helper)
|
|
1113
1113
|
|
|
1114
1114
|
A hook for a quick way to add helpers to existing nodes in the scene. It handles removal of the helper on unmount and auto-updates it by default.
|
|
1115
1115
|
|
|
@@ -1121,11 +1121,7 @@ useHelper(condition && mesh, BoxHelper, 'red') // you can pass false instead of
|
|
|
1121
1121
|
<mesh ref={mesh} ... />
|
|
1122
1122
|
```
|
|
1123
1123
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
[](https://drei.vercel.app/?path=/story/gizmos-helper--default-story)
|
|
1127
|
-
|
|
1128
|
-
A component for declaratively adding helpers to existing nodes in the scene. It handles removal of the helper on unmount and auto-updates it by default.
|
|
1124
|
+
or with `Helper`:
|
|
1129
1125
|
|
|
1130
1126
|
```jsx
|
|
1131
1127
|
<mesh>
|
|
@@ -1943,14 +1939,6 @@ Accepts an SVG url or svg raw data.
|
|
|
1943
1939
|
<Svg src={urlOrRawSvgString} />
|
|
1944
1940
|
```
|
|
1945
1941
|
|
|
1946
|
-
#### Gltf
|
|
1947
|
-
|
|
1948
|
-
This is a convenience component that will load a gltf file and clone the scene using [drei/Clone](#clone). That means you can re-use and mount the same gltf file multiple times. It accepts all props that Clone does, including shortcuts (castShadow, receiveShadow) and material overrides.
|
|
1949
|
-
|
|
1950
|
-
```js
|
|
1951
|
-
<Gltf src="/model.glb" receiveShadow castShadow />
|
|
1952
|
-
```
|
|
1953
|
-
|
|
1954
1942
|
#### AsciiRenderer
|
|
1955
1943
|
|
|
1956
1944
|
<p>
|
|
@@ -2826,9 +2814,9 @@ const depthBuffer = useDepthBuffer({
|
|
|
2826
2814
|
return <SomethingThatNeedsADepthBuffer depthBuffer={depthBuffer} />
|
|
2827
2815
|
```
|
|
2828
2816
|
|
|
2829
|
-
#### useFBO
|
|
2817
|
+
#### Fbo / useFBO
|
|
2830
2818
|
|
|
2831
|
-
[](https://drei.vercel.app/?path=/story/misc-
|
|
2819
|
+
[](https://drei.vercel.app/?path=/story/misc-fbo)
|
|
2832
2820
|
|
|
2833
2821
|
Creates a `THREE.WebGLRenderTarget`.
|
|
2834
2822
|
|
|
@@ -2870,9 +2858,9 @@ A hook for the rare case when you are using non-default cameras for heads-up-dis
|
|
|
2870
2858
|
<mesh raycast={useCamera(customCamera)} />
|
|
2871
2859
|
```
|
|
2872
2860
|
|
|
2873
|
-
#### useCubeCamera
|
|
2861
|
+
#### CubeCamera / useCubeCamera
|
|
2874
2862
|
|
|
2875
|
-
[](https://drei.
|
|
2863
|
+
[](https://drei.pmnd.rs/?path=/story/camera-cubecamera)
|
|
2876
2864
|
|
|
2877
2865
|
Creates a [`THREE.CubeCamera`](https://threejs.org/docs/#api/en/cameras/CubeCamera) that renders into a `fbo` renderTarget and that you can `update()`.
|
|
2878
2866
|
|
|
@@ -2895,9 +2883,9 @@ export function useCubeCamera({
|
|
|
2895
2883
|
const { fbo, camera, update } = useCubeCamera()
|
|
2896
2884
|
```
|
|
2897
2885
|
|
|
2898
|
-
#### useDetectGPU
|
|
2886
|
+
#### DetectGPU / useDetectGPU
|
|
2899
2887
|
|
|
2900
|
-
[](https://drei.pmnd.rs/?path=/story/misc-
|
|
2888
|
+
[](https://drei.pmnd.rs/?path=/story/misc-detectgpu)
|
|
2901
2889
|
|
|
2902
2890
|
This hook uses [DetectGPU by @TimvanScherpenzeel](https://github.com/TimvanScherpenzeel/detect-gpu), wrapped into suspense, to determine what tier should be assigned to the user's GPU.
|
|
2903
2891
|
|
|
@@ -2982,9 +2970,9 @@ const projection = useBoxProjectedEnv(
|
|
|
2982
2970
|
</CubeCamera>
|
|
2983
2971
|
```
|
|
2984
2972
|
|
|
2985
|
-
#### useTrail
|
|
2973
|
+
#### Trail / useTrail
|
|
2986
2974
|
|
|
2987
|
-
[](https://drei.vercel.app/?path=/story/misc-trail
|
|
2975
|
+
[](https://drei.vercel.app/?path=/story/misc-trail)
|
|
2988
2976
|
|
|
2989
2977
|
A hook to obtain an array of points that make up a [Trail](#trail). You can use this array to drive your own `MeshLine` or make a trail out of anything you please.
|
|
2990
2978
|
|
|
@@ -3104,9 +3092,9 @@ You can override styles, too.
|
|
|
3104
3092
|
>
|
|
3105
3093
|
```
|
|
3106
3094
|
|
|
3107
|
-
#### useProgress
|
|
3095
|
+
#### Progress / useProgress
|
|
3108
3096
|
|
|
3109
|
-
[](https://drei.vercel.app/?path=/story/misc-
|
|
3097
|
+
[](https://drei.vercel.app/?path=/story/misc-progress)
|
|
3110
3098
|
|
|
3111
3099
|
A convenience hook that wraps `THREE.DefaultLoadingManager`'s progress status.
|
|
3112
3100
|
|
|
@@ -3131,7 +3119,7 @@ const errors = useProgress((state) => state.errors)
|
|
|
3131
3119
|
|
|
3132
3120
|
👉 Note that your loading component does not have to be a suspense fallback. You can use it anywhere, even in your dom tree, for instance for overlays.
|
|
3133
3121
|
|
|
3134
|
-
#### useGLTF
|
|
3122
|
+
#### Gltf / useGLTF
|
|
3135
3123
|
|
|
3136
3124
|
[](https://drei.pmnd.rs/?path=/story/loaders-gltf)
|
|
3137
3125
|
|
|
@@ -3166,7 +3154,7 @@ If you want to use your own draco decoder globally, you can pass it through `use
|
|
|
3166
3154
|
>
|
|
3167
3155
|
> It is recommended that you check your browser's network tab to confirm that the correct URLs are being used, and that the files do get loaded from the prefetch cache on subsequent requests.
|
|
3168
3156
|
|
|
3169
|
-
#### useFBX
|
|
3157
|
+
#### Fbx / useFBX
|
|
3170
3158
|
|
|
3171
3159
|
[](https://drei.pmnd.rs/?path=/story/loaders-fbx)
|
|
3172
3160
|
|
|
@@ -3181,7 +3169,7 @@ function SuzanneFBX() {
|
|
|
3181
3169
|
}
|
|
3182
3170
|
```
|
|
3183
3171
|
|
|
3184
|
-
#### useTexture
|
|
3172
|
+
#### Texture / useTexture
|
|
3185
3173
|
|
|
3186
3174
|
[](https://drei.pmnd.rs/?path=/story/loaders-texture)
|
|
3187
3175
|
|
|
@@ -3202,9 +3190,9 @@ const props = useTexture({
|
|
|
3202
3190
|
return <meshStandardMaterial {...props} />
|
|
3203
3191
|
```
|
|
3204
3192
|
|
|
3205
|
-
#### useKTX2
|
|
3193
|
+
#### Ktx2 / useKTX2
|
|
3206
3194
|
|
|
3207
|
-
[](https://drei.pmnd.rs/?path=/story/loaders-ktx2
|
|
3195
|
+
[](https://drei.pmnd.rs/?path=/story/loaders-ktx2)
|
|
3208
3196
|
|
|
3209
3197
|
A convenience hook that uses `useLoader` and `KTX2Loader`
|
|
3210
3198
|
|
|
@@ -3215,9 +3203,9 @@ const [texture1, texture2] = useKTX2([texture1, texture2])
|
|
|
3215
3203
|
return <meshStandardMaterial map={texture} />
|
|
3216
3204
|
```
|
|
3217
3205
|
|
|
3218
|
-
#### useCubeTexture
|
|
3206
|
+
#### CubeTexture / useCubeTexture
|
|
3219
3207
|
|
|
3220
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
3208
|
+
[](https://drei.pmnd.rs/?path=/story/abstractions-cubetexture)
|
|
3221
3209
|
|
|
3222
3210
|
A convenience hook that uses `useLoader` and `CubeTextureLoader`
|
|
3223
3211
|
|
|
@@ -3225,9 +3213,9 @@ A convenience hook that uses `useLoader` and `CubeTextureLoader`
|
|
|
3225
3213
|
const envMap = useCubeTexture(['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'], { path: 'cube/' })
|
|
3226
3214
|
```
|
|
3227
3215
|
|
|
3228
|
-
#### useVideoTexture
|
|
3216
|
+
#### VideoTexture / useVideoTexture
|
|
3229
3217
|
|
|
3230
|
-
[](https://drei.pmnd.rs/?path=/story/
|
|
3218
|
+
[](https://drei.pmnd.rs/?path=/story/misc-videotexture) 
|
|
3231
3219
|
|
|
3232
3220
|
<p>
|
|
3233
3221
|
<a href="https://codesandbox.io/s/39hg8"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/39hg8/screenshot.png" alt="Demo"/></a>
|
|
@@ -3297,7 +3285,9 @@ You can fine-tune via the hls configuration:
|
|
|
3297
3285
|
|
|
3298
3286
|
> Available options: https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning
|
|
3299
3287
|
|
|
3300
|
-
#### useTrailTexture
|
|
3288
|
+
#### TrailTexture / useTrailTexture
|
|
3289
|
+
|
|
3290
|
+
[](https://drei.pmnd.rs/?path=/story/misc-trailtexture)
|
|
3301
3291
|
|
|
3302
3292
|
<p>
|
|
3303
3293
|
<a href="https://codesandbox.io/s/fj1qlg"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/fj1qlg/screenshot.png" alt="Demo"/></a>
|
|
@@ -3632,7 +3622,7 @@ Drop this component into your scene and it will switch off the raycaster while t
|
|
|
3632
3622
|
|
|
3633
3623
|
#### Bvh
|
|
3634
3624
|
|
|
3635
|
-
[](https://drei.vercel.app/?path=/story/performance-
|
|
3625
|
+
[](https://drei.vercel.app/?path=/story/performance-bvh)
|
|
3636
3626
|
|
|
3637
3627
|
An abstraction around [gkjohnson/three-mesh-bvh](https://github.com/gkjohnson/three-mesh-bvh) to speed up raycasting exponentially. Use this component to wrap your scene, a sub-graph, a model or single mesh, and it will automatically compute boundsTree and assign acceleratedRaycast. This component is side-effect free, once unmounted or disabled it will revert to the original raycast.
|
|
3638
3628
|
|
|
@@ -5012,9 +5002,9 @@ const rgbeTexture = useEnvironment({ files: 'model.hdr' })
|
|
|
5012
5002
|
const cubeTexture = useEnvironment({ files: ['px', 'nx', 'py', 'ny', 'pz', 'nz'].map((n) => `${n}.png`) })
|
|
5013
5003
|
```
|
|
5014
5004
|
|
|
5015
|
-
#### useMatcapTexture
|
|
5005
|
+
#### MatcapTexture / useMatcapTexture
|
|
5016
5006
|
|
|
5017
|
-
[](https://drei.pmnd.rs/?path=/story/staging-
|
|
5007
|
+
[](https://drei.pmnd.rs/?path=/story/staging-matcaptexture) 
|
|
5018
5008
|
|
|
5019
5009
|
Loads matcap textures from this repository: https://github.com/emmelleppi/matcaps
|
|
5020
5010
|
|
|
@@ -5043,9 +5033,9 @@ const [matcap] = useMatcapTexture('3E2335_D36A1B_8E4A2E_2842A5')
|
|
|
5043
5033
|
|
|
5044
5034
|
👉 Use the `url` to download the texture when you are ready for production!
|
|
5045
5035
|
|
|
5046
|
-
#### useNormalTexture
|
|
5036
|
+
#### NormalTexture / useNormalTexture
|
|
5047
5037
|
|
|
5048
|
-
[](https://drei.pmnd.rs/?path=/story/staging-
|
|
5038
|
+
[](https://drei.pmnd.rs/?path=/story/staging-normaltexture) 
|
|
5049
5039
|
|
|
5050
5040
|
Loads normal textures from this repository: https://github.com/emmelleppi/normal-maps
|
|
5051
5041
|
|
package/core/Caustics.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("three"),t=require("react"),n=require("@react-three/fiber"),o=require("./useFBO.cjs.js"),i=require("./Helper.cjs.js"),a=require("./shaderMaterial.cjs.js"),l=require("./Edges.cjs.js"),c=require("three-stdlib"),s=require("../helpers/constants.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function d(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("./Line.cjs.js");var m=u(e),p=d(r),v=d(t);function f(e=p.FrontSide){const r={value:new p.Matrix4};return Object.assign(new p.MeshNormalMaterial({side:e}),{viewMatrix:r,onBeforeCompile:e=>{e.uniforms.viewMatrix=r,e.fragmentShader="vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n }\n"+e.fragmentShader.replace("#include <normal_fragment_maps>","#include <normal_fragment_maps>\n normal = inverseTransformDirection( normal, viewMatrix );\n")}})}const x=a.shaderMaterial({causticsTexture:null,causticsTextureB:null,color:new p.Color,lightProjMatrix:new p.Matrix4,lightViewMatrix:new p.Matrix4},"varying vec3 vWorldPosition;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vec4 worldPosition = modelMatrix * vec4(position, 1.);\n vWorldPosition = worldPosition.xyz;\n }",`varying vec3 vWorldPosition;\n uniform vec3 color;\n uniform sampler2D causticsTexture;\n uniform sampler2D causticsTextureB;\n uniform mat4 lightProjMatrix;\n uniform mat4 lightViewMatrix;\n void main() {\n // Apply caustics\n vec4 lightSpacePos = lightProjMatrix * lightViewMatrix * vec4(vWorldPosition, 1.0);\n lightSpacePos.xyz /= lightSpacePos.w;\n lightSpacePos.xyz = lightSpacePos.xyz * 0.5 + 0.5;\n vec3 front = texture2D(causticsTexture, lightSpacePos.xy).rgb;\n vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;\n gl_FragColor = vec4((front + back) * color, 1.0);\n #include <tonemapping_fragment>\n #include <${s.version>=154?"colorspace_fragment":"encodings_fragment"}>\n }`),h=a.shaderMaterial({cameraMatrixWorld:new p.Matrix4,cameraProjectionMatrixInv:new p.Matrix4,normalTexture:null,depthTexture:null,lightDir:new p.Vector3(0,1,0),lightPlaneNormal:new p.Vector3(0,1,0),lightPlaneConstant:0,near:.1,far:100,modelMatrix:new p.Matrix4,worldRadius:1/40,ior:1.1,bounces:0,resolution:1024,size:10,intensity:.5},"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }","\n uniform mat4 cameraMatrixWorld;\n uniform mat4 cameraProjectionMatrixInv;\n uniform vec3 lightDir;\n uniform vec3 lightPlaneNormal;\n uniform float lightPlaneConstant;\n uniform float near;\n uniform float far;\n uniform float time;\n uniform float worldRadius;\n uniform float resolution;\n uniform float size;\n uniform float intensity;\n uniform float ior;\n precision highp isampler2D;\n precision highp usampler2D;\n uniform sampler2D normalTexture;\n uniform sampler2D depthTexture;\n uniform float bounces;\n varying vec2 vUv;\n vec3 WorldPosFromDepth(float depth, vec2 coord) {\n float z = depth * 2.0 - 1.0;\n vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = cameraProjectionMatrixInv * clipSpacePosition;\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n vec4 worldSpacePosition = cameraMatrixWorld * viewSpacePosition;\n return worldSpacePosition.xyz;\n }\n float sdPlane( vec3 p, vec3 n, float h ) {\n // n must be normalized\n return dot(p,n) + h;\n }\n float planeIntersect( vec3 ro, vec3 rd, vec4 p ) {\n return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);\n }\n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 pos, vec3 normal, float ior, out vec3 rayOrigin, out vec3 rayDirection) {\n rayOrigin = ro;\n rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = pos + rayDirection * 0.1;\n return rayDirection;\n }\n void main() {\n // Each sample consists of random offset in the x and y direction\n float caustic = 0.0;\n float causticTexelSize = (1.0 / resolution) * size * 2.0;\n float texelsNeeded = worldRadius / causticTexelSize;\n float sampleRadius = texelsNeeded / resolution;\n float sum = 0.0;\n if (texture2D(depthTexture, vUv).x == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec2 offset1 = vec2(-0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset2 = vec2(-0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset3 = vec2(0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset4 = vec2(0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 uv1 = vUv + offset1 * sampleRadius;\n vec2 uv2 = vUv + offset2 * sampleRadius;\n vec2 uv3 = vUv + offset3 * sampleRadius;\n vec2 uv4 = vUv + offset4 * sampleRadius;\n vec3 normal1 = texture2D(normalTexture, uv1, -10.0).rgb * 2.0 - 1.0;\n vec3 normal2 = texture2D(normalTexture, uv2, -10.0).rgb * 2.0 - 1.0;\n vec3 normal3 = texture2D(normalTexture, uv3, -10.0).rgb * 2.0 - 1.0;\n vec3 normal4 = texture2D(normalTexture, uv4, -10.0).rgb * 2.0 - 1.0;\n float depth1 = texture2D(depthTexture, uv1, -10.0).x;\n float depth2 = texture2D(depthTexture, uv2, -10.0).x;\n float depth3 = texture2D(depthTexture, uv3, -10.0).x;\n float depth4 = texture2D(depthTexture, uv4, -10.0).x;\n // Sanity check the depths\n if (depth1 == 1.0 || depth2 == 1.0 || depth3 == 1.0 || depth4 == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec3 pos1 = WorldPosFromDepth(depth1, uv1);\n vec3 pos2 = WorldPosFromDepth(depth2, uv2);\n vec3 pos3 = WorldPosFromDepth(depth3, uv3);\n vec3 pos4 = WorldPosFromDepth(depth4, uv4);\n vec3 originPos1 = WorldPosFromDepth(0.0, uv1);\n vec3 originPos2 = WorldPosFromDepth(0.0, uv2);\n vec3 originPos3 = WorldPosFromDepth(0.0, uv3);\n vec3 originPos4 = WorldPosFromDepth(0.0, uv4);\n vec3 endPos1, endPos2, endPos3, endPos4;\n vec3 endDir1, endDir2, endDir3, endDir4;\n totalInternalReflection(originPos1, lightDir, pos1, normal1, ior, endPos1, endDir1);\n totalInternalReflection(originPos2, lightDir, pos2, normal2, ior, endPos2, endDir2);\n totalInternalReflection(originPos3, lightDir, pos3, normal3, ior, endPos3, endDir3);\n totalInternalReflection(originPos4, lightDir, pos4, normal4, ior, endPos4, endDir4);\n float lightPosArea = length(cross(originPos2 - originPos1, originPos3 - originPos1)) + length(cross(originPos3 - originPos1, originPos4 - originPos1));\n float t1 = planeIntersect(endPos1, endDir1, vec4(lightPlaneNormal, lightPlaneConstant));\n float t2 = planeIntersect(endPos2, endDir2, vec4(lightPlaneNormal, lightPlaneConstant));\n float t3 = planeIntersect(endPos3, endDir3, vec4(lightPlaneNormal, lightPlaneConstant));\n float t4 = planeIntersect(endPos4, endDir4, vec4(lightPlaneNormal, lightPlaneConstant));\n vec3 finalPos1 = endPos1 + endDir1 * t1;\n vec3 finalPos2 = endPos2 + endDir2 * t2;\n vec3 finalPos3 = endPos3 + endDir3 * t3;\n vec3 finalPos4 = endPos4 + endDir4 * t4;\n float finalArea = length(cross(finalPos2 - finalPos1, finalPos3 - finalPos1)) + length(cross(finalPos3 - finalPos1, finalPos4 - finalPos1));\n caustic += intensity * (lightPosArea / finalArea);\n // Calculate the area of the triangle in light spaces\n gl_FragColor = vec4(vec3(max(caustic, 0.0)), 1.0);\n }"),g={depth:!0,minFilter:p.LinearFilter,magFilter:p.LinearFilter,type:p.UnsignedByteType},P={minFilter:p.LinearMipmapLinearFilter,magFilter:p.LinearFilter,type:p.FloatType,generateMipmaps:!0},y=v.forwardRef((({debug:e,children:r,frames:t=1,ior:a=1.1,color:s="white",causticsOnly:u=!1,backside:d=!1,backsideIOR:y=1.1,worldRadius:M=.3125,intensity:D=.05,resolution:w=2024,lightSource:T=[5,5,5],...j},S)=>{n.extend({CausticsProjectionMaterial:x});const b=v.useRef(null),F=v.useRef(null),z=v.useRef(null),W=v.useRef(null),R=n.useThree((e=>e.gl)),I=i.useHelper(e&&F,p.CameraHelper),O=o.useFBO(w,w,g),C=o.useFBO(w,w,g),_=o.useFBO(w,w,P),V=o.useFBO(w,w,P),[B]=v.useState((()=>f())),[E]=v.useState((()=>f(p.BackSide))),[q]=v.useState((()=>new h)),[A]=v.useState((()=>new c.FullScreenQuad(q)));v.useLayoutEffect((()=>{b.current.updateWorldMatrix(!1,!0)}));let N=0;const k=new p.Vector3,U=new p.Frustum,L=new p.Matrix4,H=new p.Plane,G=new p.Vector3,Q=new p.Vector3,$=new p.Box3,J=new p.Vector3,K=[],X=[],Y=[],Z=[],ee=new p.Vector3;for(let e=0;e<8;e++)K.push(new p.Vector3),X.push(new p.Vector3),Y.push(new p.Vector3),Z.push(new p.Vector3);return n.useFrame((()=>{if(t===1/0||N++<t){var r,n;Array.isArray(T)?G.fromArray(T).normalize():G.copy(b.current.worldToLocal(T.current.getWorldPosition(k)).normalize()),Q.copy(G).multiplyScalar(-1),null==(r=z.current.parent)||r.matrixWorld.identity(),$.setFromObject(z.current,!0),K[0].set($.min.x,$.min.y,$.min.z),K[1].set($.min.x,$.min.y,$.max.z),K[2].set($.min.x,$.max.y,$.min.z),K[3].set($.min.x,$.max.y,$.max.z),K[4].set($.max.x,$.min.y,$.min.z),K[5].set($.max.x,$.min.y,$.max.z),K[6].set($.max.x,$.max.y,$.min.z),K[7].set($.max.x,$.max.y,$.max.z);for(let e=0;e<8;e++)X[e].copy(K[e]);$.getCenter(J),K.map((e=>e.sub(J)));const t=H.set(Q,0);K.map(((e,r)=>t.projectPoint(e,Y[r])));const o=Y.reduce(((e,r)=>e.add(r)),k.set(0,0,0)).divideScalar(Y.length),i=Y.map((e=>e.distanceTo(o))).reduce(((e,r)=>Math.max(e,r))),l=K.map((e=>e.dot(G))).reduce(((e,r)=>Math.max(e,r)));F.current.position.copy(ee.copy(G).multiplyScalar(l).add(J)),F.current.lookAt(z.current.localToWorld(J));const c=L.lookAt(F.current.position,J,k.set(0,1,0));F.current.left=-i,F.current.right=i,F.current.top=i,F.current.bottom=-i;const s=k.set(0,i,0).applyMatrix4(c),m=(F.current.position.y+s.y)/G.y;F.current.near=.1,F.current.far=m,F.current.updateProjectionMatrix(),F.current.updateMatrixWorld();const p=X.map(((e,r)=>e.add(Z[r].copy(G).multiplyScalar(-e.y/G.y)))),v=p.reduce(((e,r)=>e.add(r)),k.set(0,0,0)).divideScalar(p.length),f=2*p.map((e=>Math.hypot(e.x-v.x,e.z-v.z))).reduce(((e,r)=>Math.max(e,r)));W.current.scale.setScalar(f),W.current.position.copy(v),e&&(null==(n=I.current)||n.update()),E.viewMatrix.value=B.viewMatrix.value=F.current.matrixWorldInverse;const x=U.setFromProjectionMatrix(L.multiplyMatrices(F.current.projectionMatrix,F.current.matrixWorldInverse)).planes[4];q.cameraMatrixWorld=F.current.matrixWorld,q.cameraProjectionMatrixInv=F.current.projectionMatrixInverse,q.lightDir=Q,q.lightPlaneNormal=x.normal,q.lightPlaneConstant=x.constant,q.near=F.current.near,q.far=F.current.far,q.resolution=w,q.size=i,q.intensity=D,q.worldRadius=M,z.current.visible=!0,R.setRenderTarget(O),R.clear(),z.current.overrideMaterial=B,R.render(z.current,F.current),R.setRenderTarget(C),R.clear(),d&&(z.current.overrideMaterial=E,R.render(z.current,F.current)),z.current.overrideMaterial=null,q.ior=a,W.current.material.lightProjMatrix=F.current.projectionMatrix,W.current.material.lightViewMatrix=F.current.matrixWorldInverse,q.normalTexture=O.texture,q.depthTexture=O.depthTexture,R.setRenderTarget(_),R.clear(),A.render(R),q.ior=y,q.normalTexture=C.texture,q.depthTexture=C.depthTexture,R.setRenderTarget(V),R.clear(),d&&A.render(R),R.setRenderTarget(null),u&&(z.current.visible=!1)}})),v.useImperativeHandle(S,(()=>b.current),[]),v.createElement("group",m.default({ref:b},j),v.createElement("scene",{ref:z},v.createElement("orthographicCamera",{ref:F,up:[0,1,0]}),r),v.createElement("mesh",{renderOrder:2,ref:W,"rotation-x":-Math.PI/2},v.createElement("planeGeometry",null),v.createElement("causticsProjectionMaterial",{transparent:!0,color:s,causticsTexture:_.texture,causticsTextureB:V.texture,blending:p.CustomBlending,blendSrc:p.OneFactor,blendDst:p.SrcAlphaFactor,depthWrite:!1}),e&&v.createElement(l.Edges,null,v.createElement("lineBasicMaterial",{color:"#ffff00",toneMapped:!1}))))}));exports.Caustics=y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("three"),t=require("react"),n=require("@react-three/fiber"),o=require("./Fbo.cjs.js"),i=require("./Helper.cjs.js"),a=require("./shaderMaterial.cjs.js"),l=require("./Edges.cjs.js"),c=require("three-stdlib"),s=require("../helpers/constants.cjs.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function d(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("./Line.cjs.js");var m=u(e),p=d(r),v=d(t);function f(e=p.FrontSide){const r={value:new p.Matrix4};return Object.assign(new p.MeshNormalMaterial({side:e}),{viewMatrix:r,onBeforeCompile:e=>{e.uniforms.viewMatrix=r,e.fragmentShader="vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n }\n"+e.fragmentShader.replace("#include <normal_fragment_maps>","#include <normal_fragment_maps>\n normal = inverseTransformDirection( normal, viewMatrix );\n")}})}const x=a.shaderMaterial({causticsTexture:null,causticsTextureB:null,color:new p.Color,lightProjMatrix:new p.Matrix4,lightViewMatrix:new p.Matrix4},"varying vec3 vWorldPosition;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vec4 worldPosition = modelMatrix * vec4(position, 1.);\n vWorldPosition = worldPosition.xyz;\n }",`varying vec3 vWorldPosition;\n uniform vec3 color;\n uniform sampler2D causticsTexture;\n uniform sampler2D causticsTextureB;\n uniform mat4 lightProjMatrix;\n uniform mat4 lightViewMatrix;\n void main() {\n // Apply caustics\n vec4 lightSpacePos = lightProjMatrix * lightViewMatrix * vec4(vWorldPosition, 1.0);\n lightSpacePos.xyz /= lightSpacePos.w;\n lightSpacePos.xyz = lightSpacePos.xyz * 0.5 + 0.5;\n vec3 front = texture2D(causticsTexture, lightSpacePos.xy).rgb;\n vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;\n gl_FragColor = vec4((front + back) * color, 1.0);\n #include <tonemapping_fragment>\n #include <${s.version>=154?"colorspace_fragment":"encodings_fragment"}>\n }`),h=a.shaderMaterial({cameraMatrixWorld:new p.Matrix4,cameraProjectionMatrixInv:new p.Matrix4,normalTexture:null,depthTexture:null,lightDir:new p.Vector3(0,1,0),lightPlaneNormal:new p.Vector3(0,1,0),lightPlaneConstant:0,near:.1,far:100,modelMatrix:new p.Matrix4,worldRadius:1/40,ior:1.1,bounces:0,resolution:1024,size:10,intensity:.5},"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }","\n uniform mat4 cameraMatrixWorld;\n uniform mat4 cameraProjectionMatrixInv;\n uniform vec3 lightDir;\n uniform vec3 lightPlaneNormal;\n uniform float lightPlaneConstant;\n uniform float near;\n uniform float far;\n uniform float time;\n uniform float worldRadius;\n uniform float resolution;\n uniform float size;\n uniform float intensity;\n uniform float ior;\n precision highp isampler2D;\n precision highp usampler2D;\n uniform sampler2D normalTexture;\n uniform sampler2D depthTexture;\n uniform float bounces;\n varying vec2 vUv;\n vec3 WorldPosFromDepth(float depth, vec2 coord) {\n float z = depth * 2.0 - 1.0;\n vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);\n vec4 viewSpacePosition = cameraProjectionMatrixInv * clipSpacePosition;\n // Perspective division\n viewSpacePosition /= viewSpacePosition.w;\n vec4 worldSpacePosition = cameraMatrixWorld * viewSpacePosition;\n return worldSpacePosition.xyz;\n }\n float sdPlane( vec3 p, vec3 n, float h ) {\n // n must be normalized\n return dot(p,n) + h;\n }\n float planeIntersect( vec3 ro, vec3 rd, vec4 p ) {\n return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);\n }\n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 pos, vec3 normal, float ior, out vec3 rayOrigin, out vec3 rayDirection) {\n rayOrigin = ro;\n rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = pos + rayDirection * 0.1;\n return rayDirection;\n }\n void main() {\n // Each sample consists of random offset in the x and y direction\n float caustic = 0.0;\n float causticTexelSize = (1.0 / resolution) * size * 2.0;\n float texelsNeeded = worldRadius / causticTexelSize;\n float sampleRadius = texelsNeeded / resolution;\n float sum = 0.0;\n if (texture2D(depthTexture, vUv).x == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec2 offset1 = vec2(-0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset2 = vec2(-0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset3 = vec2(0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 offset4 = vec2(0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);\n vec2 uv1 = vUv + offset1 * sampleRadius;\n vec2 uv2 = vUv + offset2 * sampleRadius;\n vec2 uv3 = vUv + offset3 * sampleRadius;\n vec2 uv4 = vUv + offset4 * sampleRadius;\n vec3 normal1 = texture2D(normalTexture, uv1, -10.0).rgb * 2.0 - 1.0;\n vec3 normal2 = texture2D(normalTexture, uv2, -10.0).rgb * 2.0 - 1.0;\n vec3 normal3 = texture2D(normalTexture, uv3, -10.0).rgb * 2.0 - 1.0;\n vec3 normal4 = texture2D(normalTexture, uv4, -10.0).rgb * 2.0 - 1.0;\n float depth1 = texture2D(depthTexture, uv1, -10.0).x;\n float depth2 = texture2D(depthTexture, uv2, -10.0).x;\n float depth3 = texture2D(depthTexture, uv3, -10.0).x;\n float depth4 = texture2D(depthTexture, uv4, -10.0).x;\n // Sanity check the depths\n if (depth1 == 1.0 || depth2 == 1.0 || depth3 == 1.0 || depth4 == 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n vec3 pos1 = WorldPosFromDepth(depth1, uv1);\n vec3 pos2 = WorldPosFromDepth(depth2, uv2);\n vec3 pos3 = WorldPosFromDepth(depth3, uv3);\n vec3 pos4 = WorldPosFromDepth(depth4, uv4);\n vec3 originPos1 = WorldPosFromDepth(0.0, uv1);\n vec3 originPos2 = WorldPosFromDepth(0.0, uv2);\n vec3 originPos3 = WorldPosFromDepth(0.0, uv3);\n vec3 originPos4 = WorldPosFromDepth(0.0, uv4);\n vec3 endPos1, endPos2, endPos3, endPos4;\n vec3 endDir1, endDir2, endDir3, endDir4;\n totalInternalReflection(originPos1, lightDir, pos1, normal1, ior, endPos1, endDir1);\n totalInternalReflection(originPos2, lightDir, pos2, normal2, ior, endPos2, endDir2);\n totalInternalReflection(originPos3, lightDir, pos3, normal3, ior, endPos3, endDir3);\n totalInternalReflection(originPos4, lightDir, pos4, normal4, ior, endPos4, endDir4);\n float lightPosArea = length(cross(originPos2 - originPos1, originPos3 - originPos1)) + length(cross(originPos3 - originPos1, originPos4 - originPos1));\n float t1 = planeIntersect(endPos1, endDir1, vec4(lightPlaneNormal, lightPlaneConstant));\n float t2 = planeIntersect(endPos2, endDir2, vec4(lightPlaneNormal, lightPlaneConstant));\n float t3 = planeIntersect(endPos3, endDir3, vec4(lightPlaneNormal, lightPlaneConstant));\n float t4 = planeIntersect(endPos4, endDir4, vec4(lightPlaneNormal, lightPlaneConstant));\n vec3 finalPos1 = endPos1 + endDir1 * t1;\n vec3 finalPos2 = endPos2 + endDir2 * t2;\n vec3 finalPos3 = endPos3 + endDir3 * t3;\n vec3 finalPos4 = endPos4 + endDir4 * t4;\n float finalArea = length(cross(finalPos2 - finalPos1, finalPos3 - finalPos1)) + length(cross(finalPos3 - finalPos1, finalPos4 - finalPos1));\n caustic += intensity * (lightPosArea / finalArea);\n // Calculate the area of the triangle in light spaces\n gl_FragColor = vec4(vec3(max(caustic, 0.0)), 1.0);\n }"),g={depth:!0,minFilter:p.LinearFilter,magFilter:p.LinearFilter,type:p.UnsignedByteType},P={minFilter:p.LinearMipmapLinearFilter,magFilter:p.LinearFilter,type:p.FloatType,generateMipmaps:!0},y=v.forwardRef((({debug:e,children:r,frames:t=1,ior:a=1.1,color:s="white",causticsOnly:u=!1,backside:d=!1,backsideIOR:y=1.1,worldRadius:M=.3125,intensity:D=.05,resolution:w=2024,lightSource:T=[5,5,5],...j},b)=>{n.extend({CausticsProjectionMaterial:x});const S=v.useRef(null),F=v.useRef(null),z=v.useRef(null),W=v.useRef(null),R=n.useThree((e=>e.gl)),I=i.useHelper(e&&F,p.CameraHelper),C=o.useFBO(w,w,g),O=o.useFBO(w,w,g),_=o.useFBO(w,w,P),V=o.useFBO(w,w,P),[B]=v.useState((()=>f())),[E]=v.useState((()=>f(p.BackSide))),[q]=v.useState((()=>new h)),[A]=v.useState((()=>new c.FullScreenQuad(q)));v.useLayoutEffect((()=>{S.current.updateWorldMatrix(!1,!0)}));let N=0;const k=new p.Vector3,U=new p.Frustum,L=new p.Matrix4,H=new p.Plane,G=new p.Vector3,Q=new p.Vector3,$=new p.Box3,J=new p.Vector3,K=[],X=[],Y=[],Z=[],ee=new p.Vector3;for(let e=0;e<8;e++)K.push(new p.Vector3),X.push(new p.Vector3),Y.push(new p.Vector3),Z.push(new p.Vector3);return n.useFrame((()=>{if(t===1/0||N++<t){var r,n;Array.isArray(T)?G.fromArray(T).normalize():G.copy(S.current.worldToLocal(T.current.getWorldPosition(k)).normalize()),Q.copy(G).multiplyScalar(-1),null==(r=z.current.parent)||r.matrixWorld.identity(),$.setFromObject(z.current,!0),K[0].set($.min.x,$.min.y,$.min.z),K[1].set($.min.x,$.min.y,$.max.z),K[2].set($.min.x,$.max.y,$.min.z),K[3].set($.min.x,$.max.y,$.max.z),K[4].set($.max.x,$.min.y,$.min.z),K[5].set($.max.x,$.min.y,$.max.z),K[6].set($.max.x,$.max.y,$.min.z),K[7].set($.max.x,$.max.y,$.max.z);for(let e=0;e<8;e++)X[e].copy(K[e]);$.getCenter(J),K.map((e=>e.sub(J)));const t=H.set(Q,0);K.map(((e,r)=>t.projectPoint(e,Y[r])));const o=Y.reduce(((e,r)=>e.add(r)),k.set(0,0,0)).divideScalar(Y.length),i=Y.map((e=>e.distanceTo(o))).reduce(((e,r)=>Math.max(e,r))),l=K.map((e=>e.dot(G))).reduce(((e,r)=>Math.max(e,r)));F.current.position.copy(ee.copy(G).multiplyScalar(l).add(J)),F.current.lookAt(z.current.localToWorld(J));const c=L.lookAt(F.current.position,J,k.set(0,1,0));F.current.left=-i,F.current.right=i,F.current.top=i,F.current.bottom=-i;const s=k.set(0,i,0).applyMatrix4(c),m=(F.current.position.y+s.y)/G.y;F.current.near=.1,F.current.far=m,F.current.updateProjectionMatrix(),F.current.updateMatrixWorld();const p=X.map(((e,r)=>e.add(Z[r].copy(G).multiplyScalar(-e.y/G.y)))),v=p.reduce(((e,r)=>e.add(r)),k.set(0,0,0)).divideScalar(p.length),f=2*p.map((e=>Math.hypot(e.x-v.x,e.z-v.z))).reduce(((e,r)=>Math.max(e,r)));W.current.scale.setScalar(f),W.current.position.copy(v),e&&(null==(n=I.current)||n.update()),E.viewMatrix.value=B.viewMatrix.value=F.current.matrixWorldInverse;const x=U.setFromProjectionMatrix(L.multiplyMatrices(F.current.projectionMatrix,F.current.matrixWorldInverse)).planes[4];q.cameraMatrixWorld=F.current.matrixWorld,q.cameraProjectionMatrixInv=F.current.projectionMatrixInverse,q.lightDir=Q,q.lightPlaneNormal=x.normal,q.lightPlaneConstant=x.constant,q.near=F.current.near,q.far=F.current.far,q.resolution=w,q.size=i,q.intensity=D,q.worldRadius=M,z.current.visible=!0,R.setRenderTarget(C),R.clear(),z.current.overrideMaterial=B,R.render(z.current,F.current),R.setRenderTarget(O),R.clear(),d&&(z.current.overrideMaterial=E,R.render(z.current,F.current)),z.current.overrideMaterial=null,q.ior=a,W.current.material.lightProjMatrix=F.current.projectionMatrix,W.current.material.lightViewMatrix=F.current.matrixWorldInverse,q.normalTexture=C.texture,q.depthTexture=C.depthTexture,R.setRenderTarget(_),R.clear(),A.render(R),q.ior=y,q.normalTexture=O.texture,q.depthTexture=O.depthTexture,R.setRenderTarget(V),R.clear(),d&&A.render(R),R.setRenderTarget(null),u&&(z.current.visible=!1)}})),v.useImperativeHandle(b,(()=>S.current),[]),v.createElement("group",m.default({ref:S},j),v.createElement("scene",{ref:z},v.createElement("orthographicCamera",{ref:F,up:[0,1,0]}),r),v.createElement("mesh",{renderOrder:2,ref:W,"rotation-x":-Math.PI/2},v.createElement("planeGeometry",null),v.createElement("causticsProjectionMaterial",{transparent:!0,color:s,causticsTexture:_.texture,causticsTextureB:V.texture,blending:p.CustomBlending,blendSrc:p.OneFactor,blendDst:p.SrcAlphaFactor,depthWrite:!1}),e&&v.createElement(l.Edges,null,v.createElement("lineBasicMaterial",{color:"#ffff00",toneMapped:!1}))))}));exports.Caustics=y;
|
package/core/Caustics.js
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from '@babel/runtime/helpers/esm/extends';
|
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { extend, useThree, useFrame } from '@react-three/fiber';
|
|
5
|
-
import { useFBO } from './
|
|
5
|
+
import { useFBO } from './Fbo.js';
|
|
6
6
|
import { useHelper } from './Helper.js';
|
|
7
7
|
import { shaderMaterial } from './shaderMaterial.js';
|
|
8
8
|
import { Edges } from './Edges.js';
|
package/core/Cloud.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("@react-three/fiber"),a=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("@react-three/fiber"),a=require("./Texture.cjs.js"),o=require("uuid"),u=require("../helpers/deprecated.cjs.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var l=i(e),s=c(t);const d=new r.Matrix4,f=new r.Vector3,m=new r.Quaternion,p=new r.Vector3,g=new r.Quaternion,h=new r.Vector3,y=s.createContext(null),x=s.forwardRef((({children:e,material:t=r.MeshLambertMaterial,texture:o="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",range:i,limit:c=200,frustumCulled:x,...v},b)=>{var M,w;const C=s.useMemo((()=>class extends t{constructor(){super();const e=parseInt(r.REVISION.replace(/\D+/g,""))>=154?"opaque_fragment":"output_fragment";this.onBeforeCompile=t=>{t.vertexShader="attribute float opacity;\n varying float vOpacity;\n "+t.vertexShader.replace("#include <fog_vertex>","#include <fog_vertex>\n vOpacity = opacity;\n "),t.fragmentShader="varying float vOpacity;\n "+t.fragmentShader.replace(`#include <${e}>`,`#include <${e}>\n gl_FragColor = vec4(outgoingLight, diffuseColor.a * vOpacity);\n `)}}}),[t]);n.extend({CloudMaterial:C});const E=s.useRef(null),A=s.useRef([]),O=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>1)))),[c]),j=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>[1,1,1])).flat())),[c]),R=a.useTexture(o);let U,V=0,_=0;const q=new r.Quaternion,F=new r.Vector3(0,0,1),S=new r.Vector3;n.useFrame(((e,t)=>{for(V=e.clock.getElapsedTime(),d.copy(E.current.matrixWorld).invert(),e.camera.matrixWorld.decompose(p,g,h),_=0;_<A.current.length;_++)U=A.current[_],U.ref.current.matrixWorld.decompose(f,m,h),f.add(S.copy(U.position).applyQuaternion(m).multiply(h)),m.copy(g).multiply(q.setFromAxisAngle(F,U.rotation+=t*U.rotationFactor)),h.multiplyScalar(U.volume+(1+Math.sin(V*U.density*U.speed))/2*U.growth),U.matrix.compose(f,m,h).premultiply(d),U.dist=f.distanceTo(p);for(A.current.sort(((e,t)=>t.dist-e.dist)),_=0;_<A.current.length;_++)U=A.current[_],O[_]=U.opacity*(U.dist<U.fade-1?U.dist/U.fade:1),E.current.setMatrixAt(_,U.matrix),E.current.setColorAt(_,U.color);E.current.geometry.attributes.opacity.needsUpdate=!0,E.current.instanceMatrix.needsUpdate=!0,E.current.instanceColor&&(E.current.instanceColor.needsUpdate=!0)})),s.useLayoutEffect((()=>{const e=Math.min(c,void 0!==i?i:c,A.current.length);E.current.count=e,u.setUpdateRange(E.current.instanceMatrix,{offset:0,count:16*e}),E.current.instanceColor&&u.setUpdateRange(E.current.instanceColor,{offset:0,count:3*e}),u.setUpdateRange(E.current.geometry.attributes.opacity,{offset:0,count:e})}));let D=[null!==(M=R.image.width)&&void 0!==M?M:1,null!==(w=R.image.height)&&void 0!==w?w:1],I=Math.max(D[0],D[1]);return D=[D[0]/I,D[1]/I],s.createElement("group",l.default({ref:b},v),s.createElement(y.Provider,{value:A},e,s.createElement("instancedMesh",{matrixAutoUpdate:!1,ref:E,args:[null,null,c],frustumCulled:x},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"instanceColor",args:[j,3]}),s.createElement("planeGeometry",{args:[...D]},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"attributes-opacity",args:[O,1]})),s.createElement("cloudMaterial",{key:t.name,map:R,transparent:!0,depthWrite:!1}))))})),v=s.forwardRef((({opacity:e=1,speed:t=0,bounds:a=[5,1,1],segments:u=20,color:i="#ffffff",fade:c=10,volume:d=6,smallestVolume:f=.25,distribute:m=null,growth:p=4,concentrate:g="inside",seed:h=Math.random(),...x},v)=>{function b(){const e=1e4*Math.sin(h++);return e-Math.floor(e)}const M=s.useContext(y),w=s.useRef(null),[C]=s.useState((()=>o.v4())),E=s.useMemo((()=>[...new Array(u)].map(((e,t)=>({segments:u,bounds:new r.Vector3(1,1,1),position:new r.Vector3,uuid:C,index:t,ref:w,dist:0,matrix:new r.Matrix4,color:new r.Color,rotation:t*(Math.PI/u)})))),[u,C]);return s.useLayoutEffect((()=>{E.forEach(((r,o)=>{var l;n.applyProps(r,{volume:d,color:i,speed:t,growth:p,opacity:e,fade:c,bounds:a,density:Math.max(.5,b()),rotationFactor:Math.max(.2,.5*b())*t});const s=null==m?void 0:m(r,o);(s||u>1)&&r.position.copy(r.bounds).multiply(null!==(l=null==s?void 0:s.point)&&void 0!==l?l:{x:2*b()-1,y:2*b()-1,z:2*b()-1});const h=Math.abs(r.position.x),y=Math.abs(r.position.y),x=Math.abs(r.position.z),v=Math.max(h,y,x);r.length=1,h===v&&(r.length-=h/r.bounds.x),y===v&&(r.length-=y/r.bounds.y),x===v&&(r.length-=x/r.bounds.z),r.volume=(void 0!==(null==s?void 0:s.volume)?s.volume:Math.max(Math.max(0,f),"random"===g?b():"inside"===g?r.length:1-r.length))*d}))}),[g,a,c,i,e,p,d,h,u,t]),s.useLayoutEffect((()=>{const e=E;return M.current=[...M.current,...e],()=>{M.current=M.current.filter((e=>e.uuid!==C))}}),[E]),s.useImperativeHandle(v,(()=>w.current),[]),s.createElement("group",l.default({ref:w},x))})),b=s.forwardRef(((e,t)=>s.useContext(y)?s.createElement(v,l.default({ref:t},e)):s.createElement(x,null,s.createElement(v,l.default({ref:t},e)))));exports.Cloud=b,exports.CloudInstance=v,exports.Clouds=x;
|
package/core/Cloud.js
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from '@babel/runtime/helpers/esm/extends';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { REVISION, Quaternion, Vector3, DynamicDrawUsage, MeshLambertMaterial, Matrix4, Color } from 'three';
|
|
4
4
|
import { extend, useFrame, applyProps } from '@react-three/fiber';
|
|
5
|
-
import { useTexture } from './
|
|
5
|
+
import { useTexture } from './Texture.js';
|
|
6
6
|
import { v4 } from 'uuid';
|
|
7
7
|
import { setUpdateRange } from '../helpers/deprecated.js';
|
|
8
8
|
|
package/core/CubeCamera.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("react"),t=require("@react-three/fiber");function u(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var u=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,u.get?u:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=u(e),a=u(r);function o({resolution:u=256,near:o=.1,far:c=1e3,envMap:s,fog:f}={}){const i=t.useThree((({gl:e})=>e)),l=t.useThree((({scene:e})=>e)),b=r.useMemo((()=>{const r=new e.WebGLCubeRenderTarget(u);return r.texture.type=e.HalfFloatType,r}),[u]);r.useEffect((()=>()=>{b.dispose()}),[b]);const p=r.useMemo((()=>new n.CubeCamera(o,c,b)),[o,c,b]);let d,g;const m=a.useCallback((()=>{d=l.fog,g=l.background,l.background=s||g,l.fog=f||d,p.update(i,l),l.fog=d,l.background=g}),[i,l,p]);return{fbo:b,camera:p,update:m}}exports.CubeCamera=function({children:e,frames:r=1/0,resolution:u,near:n,far:c,envMap:s,fog:f,...i}){const l=a.useRef(null),{fbo:b,camera:p,update:d}=o({resolution:u,near:n,far:c,envMap:s,fog:f});let g=0;return t.useFrame((()=>{l.current&&(r===1/0||g<r)&&(l.current.visible=!1,d(),l.current.visible=!0,g++)})),a.createElement("group",i,a.createElement("primitive",{object:p}),a.createElement("group",{ref:l},null==e?void 0:e(b.texture)))},exports.useCubeCamera=o;
|
package/core/CubeCamera.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Fog, FogExp2, Texture } from 'three';
|
|
2
3
|
import * as React from 'react';
|
|
3
|
-
|
|
4
|
+
export type CubeCameraOptions = {
|
|
5
|
+
resolution?: number;
|
|
6
|
+
near?: number;
|
|
7
|
+
far?: number;
|
|
8
|
+
envMap?: THREE.Texture;
|
|
9
|
+
fog?: Fog | FogExp2;
|
|
10
|
+
};
|
|
11
|
+
export declare function useCubeCamera({ resolution, near, far, envMap, fog }?: CubeCameraOptions): {
|
|
12
|
+
fbo: THREE.WebGLCubeRenderTarget;
|
|
13
|
+
camera: THREE.CubeCamera;
|
|
14
|
+
update: () => void;
|
|
15
|
+
};
|
|
4
16
|
type Props = Omit<JSX.IntrinsicElements['group'], 'children'> & {
|
|
5
|
-
children
|
|
17
|
+
children?: (tex: Texture) => React.ReactNode;
|
|
6
18
|
frames?: number;
|
|
7
19
|
} & CubeCameraOptions;
|
|
8
20
|
export declare function CubeCamera({ children, frames, resolution, near, far, envMap, fog, ...props }: Props): React.JSX.Element;
|
package/core/CubeCamera.js
CHANGED
|
@@ -1,7 +1,50 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { WebGLCubeRenderTarget, HalfFloatType } from 'three';
|
|
1
3
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
+
import { useMemo, useEffect } from 'react';
|
|
5
|
+
import { useThree, useFrame } from '@react-three/fiber';
|
|
4
6
|
|
|
7
|
+
function useCubeCamera({
|
|
8
|
+
resolution = 256,
|
|
9
|
+
near = 0.1,
|
|
10
|
+
far = 1000,
|
|
11
|
+
envMap,
|
|
12
|
+
fog
|
|
13
|
+
} = {}) {
|
|
14
|
+
const gl = useThree(({
|
|
15
|
+
gl
|
|
16
|
+
}) => gl);
|
|
17
|
+
const scene = useThree(({
|
|
18
|
+
scene
|
|
19
|
+
}) => scene);
|
|
20
|
+
const fbo = useMemo(() => {
|
|
21
|
+
const fbo = new WebGLCubeRenderTarget(resolution);
|
|
22
|
+
fbo.texture.type = HalfFloatType;
|
|
23
|
+
return fbo;
|
|
24
|
+
}, [resolution]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
return () => {
|
|
27
|
+
fbo.dispose();
|
|
28
|
+
};
|
|
29
|
+
}, [fbo]);
|
|
30
|
+
const camera = useMemo(() => new THREE.CubeCamera(near, far, fbo), [near, far, fbo]);
|
|
31
|
+
let originalFog;
|
|
32
|
+
let originalBackground;
|
|
33
|
+
const update = React.useCallback(() => {
|
|
34
|
+
originalFog = scene.fog;
|
|
35
|
+
originalBackground = scene.background;
|
|
36
|
+
scene.background = envMap || originalBackground;
|
|
37
|
+
scene.fog = fog || originalFog;
|
|
38
|
+
camera.update(gl, scene);
|
|
39
|
+
scene.fog = originalFog;
|
|
40
|
+
scene.background = originalBackground;
|
|
41
|
+
}, [gl, scene, camera]);
|
|
42
|
+
return {
|
|
43
|
+
fbo,
|
|
44
|
+
camera,
|
|
45
|
+
update
|
|
46
|
+
};
|
|
47
|
+
}
|
|
5
48
|
function CubeCamera({
|
|
6
49
|
children,
|
|
7
50
|
frames = Infinity,
|
|
@@ -37,7 +80,7 @@ function CubeCamera({
|
|
|
37
80
|
object: camera
|
|
38
81
|
}), /*#__PURE__*/React.createElement("group", {
|
|
39
82
|
ref: ref
|
|
40
|
-
}, children(fbo.texture)));
|
|
83
|
+
}, children == null ? void 0 : children(fbo.texture)));
|
|
41
84
|
}
|
|
42
85
|
|
|
43
|
-
export { CubeCamera };
|
|
86
|
+
export { CubeCamera, useCubeCamera };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("three"),t=require("@react-three/fiber");function u(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var u=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,u.get?u:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var n=u(e);function a(e,{path:u}){const[n]=t.useLoader(r.CubeTextureLoader,[e],(e=>e.setPath(u)));return n}a.preload=(e,{path:u})=>t.useLoader.preload(r.CubeTextureLoader,[e],(e=>e.setPath(u))),exports.CubeTexture=function({children:e,files:r,...t}){const u=a(r,{...t});return n.createElement(n.Fragment,null,null==e?void 0:e(u))},exports.useCubeTexture=a;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CubeTexture as _CubeTexture, Texture } from 'three';
|
|
3
|
+
type Options = {
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function useCubeTexture(files: string[], { path }: Options): _CubeTexture;
|
|
7
|
+
export declare namespace useCubeTexture {
|
|
8
|
+
var preload: (files: string[], { path }: Options) => undefined;
|
|
9
|
+
}
|
|
10
|
+
type CubeTextureProps = {
|
|
11
|
+
children?: (tex: Texture) => React.ReactNode;
|
|
12
|
+
files: Parameters<typeof useCubeTexture>[0];
|
|
13
|
+
} & Options;
|
|
14
|
+
export declare function CubeTexture({ children, files, ...options }: CubeTextureProps): React.JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { CubeTextureLoader } from 'three';
|
|
2
3
|
import { useLoader } from '@react-three/fiber';
|
|
3
4
|
|
|
@@ -15,5 +16,15 @@ useCubeTexture.preload = (files, {
|
|
|
15
16
|
}) => useLoader.preload(
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
CubeTextureLoader, [files], loader => loader.setPath(path));
|
|
19
|
+
function CubeTexture({
|
|
20
|
+
children,
|
|
21
|
+
files,
|
|
22
|
+
...options
|
|
23
|
+
}) {
|
|
24
|
+
const texture = useCubeTexture(files, {
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children == null ? void 0 : children(texture));
|
|
28
|
+
}
|
|
18
29
|
|
|
19
|
-
export { useCubeTexture };
|
|
30
|
+
export { CubeTexture, useCubeTexture };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("detect-gpu"),r=require("suspend-react");function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=n(e);const c=e=>r.suspend((()=>t.getGPUTier(e)),["useDetectGPU"]);exports.DetectGPU=function({children:e,...t}){const r=c(t);return u.createElement(u.Fragment,null,null==e?void 0:e(r))},exports.useDetectGPU=c;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GetGPUTier } from 'detect-gpu';
|
|
3
|
+
export declare const useDetectGPU: (props?: GetGPUTier) => import("detect-gpu").TierResult;
|
|
4
|
+
type DetectGPUProps = {
|
|
5
|
+
children?: (result: ReturnType<typeof useDetectGPU>) => React.ReactNode;
|
|
6
|
+
} & Parameters<typeof useDetectGPU>[0];
|
|
7
|
+
export declare function DetectGPU({ children, ...options }: DetectGPUProps): React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getGPUTier } from 'detect-gpu';
|
|
3
|
+
import { suspend } from 'suspend-react';
|
|
4
|
+
|
|
5
|
+
const useDetectGPU = props => suspend(() => getGPUTier(props), ['useDetectGPU']);
|
|
6
|
+
function DetectGPU({
|
|
7
|
+
children,
|
|
8
|
+
...options
|
|
9
|
+
}) {
|
|
10
|
+
const result = useDetectGPU(options);
|
|
11
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children == null ? void 0 : children(result));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { DetectGPU, useDetectGPU };
|
package/core/Example.d.ts
CHANGED
package/core/Example.js
CHANGED
|
@@ -3,6 +3,9 @@ import { Text3D } from './Text3D.js';
|
|
|
3
3
|
import { Center } from './Center.js';
|
|
4
4
|
|
|
5
5
|
/* eslint react-hooks/exhaustive-deps: 1 */
|
|
6
|
+
/**
|
|
7
|
+
* A simple counter example component. Click to increment, meta-click to decrement.
|
|
8
|
+
*/
|
|
6
9
|
const Example = /* @__PURE__ */React.forwardRef(({
|
|
7
10
|
font,
|
|
8
11
|
color = '#cbcbcb',
|
package/core/Fbo.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("three"),r=require("@react-three/fiber");function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=n(e),i=n(t);function o(e,t,n){const o=r.useThree((e=>e.size)),s=r.useThree((e=>e.viewport)),a="number"==typeof e?e:o.width*s.dpr,l="number"==typeof t?t:o.height*s.dpr,c=("number"==typeof e?n:e)||{},{samples:p=0,depth:f,...d}=c,h=u.useMemo((()=>{const e=new i.WebGLRenderTarget(a,l,{minFilter:i.LinearFilter,magFilter:i.LinearFilter,type:i.HalfFloatType,...d});return f&&(e.depthTexture=new i.DepthTexture(a,l,i.FloatType)),e.samples=p,e}),[]);return u.useLayoutEffect((()=>{h.setSize(a,l),p&&(h.samples=p)}),[p,h,a,l]),u.useEffect((()=>()=>h.dispose()),[]),h}exports.Fbo=({children:e,width:t,height:r,...n})=>{const i=o(t,r,n);return u.createElement(u.Fragment,null,null==e?void 0:e(i))},exports.useFBO=o;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import * as THREE from 'three';
|
|
2
3
|
import { TextureEncoding } from '../helpers/deprecated';
|
|
3
4
|
type ColorSpace = 'srgb' | 'srgb-linear' | '' | string;
|
|
@@ -19,4 +20,9 @@ type FBOSettings = {
|
|
|
19
20
|
colorSpace?: ColorSpace | undefined;
|
|
20
21
|
};
|
|
21
22
|
export declare function useFBO(width?: number | FBOSettings, height?: number, settings?: FBOSettings): THREE.WebGLRenderTarget;
|
|
23
|
+
export declare const Fbo: ({ children, width, height, ...settings }: {
|
|
24
|
+
children?: ((target: ReturnType<typeof useFBO>) => React.ReactNode) | undefined;
|
|
25
|
+
width: Parameters<typeof useFBO>[0];
|
|
26
|
+
height: Parameters<typeof useFBO>[1];
|
|
27
|
+
} & FBOSettings) => React.JSX.Element;
|
|
22
28
|
export {};
|
|
@@ -42,5 +42,14 @@ settings) {
|
|
|
42
42
|
}, []);
|
|
43
43
|
return target;
|
|
44
44
|
}
|
|
45
|
+
const Fbo = ({
|
|
46
|
+
children,
|
|
47
|
+
width,
|
|
48
|
+
height,
|
|
49
|
+
...settings
|
|
50
|
+
}) => {
|
|
51
|
+
const target = useFBO(width, height, settings);
|
|
52
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children == null ? void 0 : children(target));
|
|
53
|
+
};
|
|
45
54
|
|
|
46
|
-
export { useFBO };
|
|
55
|
+
export { Fbo, useFBO };
|
package/core/Fbx.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("three-stdlib"),u=require("@react-three/fiber"),n=require("./Clone.cjs.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var u=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,u.get?u:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("three");var c=o(e),i=a(r);function l(e){return u.useLoader(t.FBXLoader,e)}l.preload=e=>u.useLoader.preload(t.FBXLoader,e),l.clear=e=>u.useLoader.clear(t.FBXLoader,e),exports.Fbx=function({path:e,...r}){const t=l(e).children[0];return i.createElement(n.Clone,c.default({},r,{object:t}))},exports.useFBX=l;
|
package/core/Fbx.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Group } from 'three';
|
|
3
|
+
import { Clone } from './Clone';
|
|
4
|
+
export declare function useFBX(path: string): Group;
|
|
5
|
+
export declare namespace useFBX {
|
|
6
|
+
var preload: (path: string) => undefined;
|
|
7
|
+
var clear: (input: string | string[]) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function Fbx({ path, ...props }: {
|
|
10
|
+
path: Parameters<typeof useFBX>[0];
|
|
11
|
+
} & Omit<React.ComponentProps<typeof Clone>, 'object'>): React.JSX.Element;
|