Skip to content

Commit a8562d7

Browse files
author
takuma-hmng8
committed
update read me
1 parent 789536e commit a8562d7

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

README.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# Usage
22

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.
48

59
```js
6-
const updateFruid = useFruid();
10+
const { updateFx, setParams, fxObject } = useFruid();
711
```
812

9-
それを useFrame で毎フレーム呼び出します。
10-
返り値としてフレームバッファーテクスチャーを返します。
13+
updateFx は useFrame で実行します。第 1 引数には useFrame から受け取る RootState,第 2 引数に HookPrams を受け取ります。
1114

1215
```js
1316
useFrame((props) => {
14-
const texture = updateFruid(props);
17+
const texture = updateFx(props, params);
1518
const main = mainShaderRef.current;
1619
if (main) {
1720
main.u_bufferTexture = texture;
@@ -27,12 +30,23 @@ useFrame((props) => {
2730
## useDoubleFBO
2831

2932
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 も格納しています。
3041

3142
```js
32-
const updateRenderTarget = useDoubleFBO();
43+
const [velocityFBO, updateVelocityFBO] = useDoubleFBO(scene, camera, {
44+
isDpr: true,
45+
isSizeUpdate: true,
46+
});
3347

3448
// how to render
35-
updateRenderTarget(gl, ({ read, write }) => {
49+
updateVelocityFBO(gl, ({ read, write }) => {
3650
// callback before gl.render()
3751
});
3852
```
@@ -42,7 +56,7 @@ updateRenderTarget(gl, ({ read, write }) => {
4256
FBO を生成して、焼き付けられた texture を返す、更新関数を生成します。
4357

4458
```js
45-
const updateRenderTarget = useSingleFBO();
59+
const updateRenderTarget = useSingleFBO(scene, camera, options);
4660

4761
// how to render
4862
updateRenderTarget(gl, ({ read }) => {
@@ -71,8 +85,10 @@ const { currentPointer, prevPointer, diffPointer, isVelocityUpdate, velocity } =
7185

7286
キャンバスのサイズの state のフック
7387

88+
- isDpr: Whether to multiply dpr, default:false
89+
7490
```js
75-
const resolution = useResolution();
91+
const resolution = useResolution(isDpr);
7692
```
7793

7894
## useAddMesh
@@ -92,3 +108,22 @@ const setUniform = (material, key, value) => {
92108
material.uniforms[key].value = value;
93109
};
94110
```
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

Comments
 (0)