1
1
# Usage
2
2
3
- こんな感じでフックは更新関数を受け取ります
3
+ それぞれの fxHook からは{updateFx,setParams,fxObject}を受け取ります。
4
+
5
+ - updateFx - A function to be called inside ` useFrame ` that returns a ` THREE.Texture ` .
6
+ - setParams - A function to update the parameters, useful for performance tuning, etc.
7
+ - fxObject - An object containing various FX components such as scene, camera, material, and render target.
4
8
5
9
``` js
6
- const updateFruid = useFruid ();
10
+ const { updateFx , setParams , fxObject } = useFruid ();
7
11
```
8
12
9
- それを useFrame で毎フレーム呼び出します。
10
- 返り値としてフレームバッファーテクスチャーを返します。
13
+ updateFx は useFrame で実行します。第 1 引数には useFrame から受け取る RootState,第 2 引数に HookPrams を受け取ります。
11
14
12
15
``` js
13
16
useFrame ((props ) => {
14
- const texture = updateFruid (props);
17
+ const texture = updateFx (props, params );
15
18
const main = mainShaderRef .current ;
16
19
if (main) {
17
20
main .u_bufferTexture = texture;
@@ -27,12 +30,23 @@ useFrame((props) => {
27
30
## useDoubleFBO
28
31
29
32
FBO を生成して、ダブルバッファリングしたバッファーテクスチャーを swap して返してくれます。
33
+ 第 3 引数には options が入ります。
34
+
35
+ - isDpr: Whether to multiply dpr, default: false
36
+ - isSizeUpdate: Whether to resize when resizing occurs. If isDpr is true, set FBO to setSize even if dpr is changed, default: false
37
+
38
+ drei の useFBO はデフォルトで dpr と size の変更で setSize してしまうため、バッファーテクスチャーが更新されてしまいます。そこで、dpr と size の更新に対して non reactive な hook を作成しました。options でそれぞれ reactive にすることが可能です。
39
+
40
+ もし resize させたい場合は、fxHook が第 3 引数に受け取る fxObject に renderTarget も格納しています。
30
41
31
42
``` js
32
- const updateRenderTarget = useDoubleFBO ();
43
+ const [velocityFBO , updateVelocityFBO ] = useDoubleFBO (scene, camera, {
44
+ isDpr: true ,
45
+ isSizeUpdate: true ,
46
+ });
33
47
34
48
// how to render
35
- updateRenderTarget (gl, ({ read, write }) => {
49
+ updateVelocityFBO (gl, ({ read, write }) => {
36
50
// callback before gl.render()
37
51
});
38
52
```
@@ -42,7 +56,7 @@ updateRenderTarget(gl, ({ read, write }) => {
42
56
FBO を生成して、焼き付けられた texture を返す、更新関数を生成します。
43
57
44
58
``` js
45
- const updateRenderTarget = useSingleFBO ();
59
+ const updateRenderTarget = useSingleFBO (scene, camera, options );
46
60
47
61
// how to render
48
62
updateRenderTarget (gl, ({ read }) => {
@@ -71,8 +85,10 @@ const { currentPointer, prevPointer, diffPointer, isVelocityUpdate, velocity } =
71
85
72
86
キャンバスのサイズの state のフック
73
87
88
+ - isDpr: Whether to multiply dpr, default: false
89
+
74
90
``` js
75
- const resolution = useResolution ();
91
+ const resolution = useResolution (isDpr );
76
92
```
77
93
78
94
## useAddMesh
@@ -92,3 +108,22 @@ const setUniform = (material, key, value) => {
92
108
material .uniforms [key].value = value;
93
109
};
94
110
```
111
+
112
+ ## useParams
113
+
114
+ params の refObject とその更新用関数を返します。
115
+
116
+ ``` ts
117
+ const [params, setParams] =
118
+ useParams < FruidParams >
119
+ {
120
+ density_dissipation : 0.0 ,
121
+ velocity_dissipation : 0.0 ,
122
+ velocity_acceleration : 0.0 ,
123
+ pressure_dissipation : 0.0 ,
124
+ pressure_iterations : 20 ,
125
+ curl_strength : 0.0 ,
126
+ splat_radius : 0.001 ,
127
+ fruid_color : new THREE .Vector3 (1.0 , 1.0 , 1.0 ),
128
+ };
129
+ ```
0 commit comments