@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react";
2
2
import * as THREE from "three" ;
3
3
import { useFrame , useLoader , extend } from "@react-three/fiber" ;
4
4
import { RippleParams , useRipple } from "./hooks/useRipple" ;
5
- import { useFlowmap } from "./hooks/useFlowmap" ;
5
+ import { useFlowmap , FlowmapParams } from "./hooks/useFlowmap" ;
6
6
import { useSimpleFruid } from "./hooks/useSimpleFruid" ;
7
7
import { FruidParams , useFruid } from "./hooks/useFruid" ;
8
8
import { useBrush } from "./hooks/useBrush" ;
@@ -11,15 +11,14 @@ import { MainShaderMaterial, TMainShaderUniforms } from "./ShaderMaterial";
11
11
import { useGUI } from "./gui/useGUI" ;
12
12
import { CONFIG } from "./config" ;
13
13
import { DuoToneParams , useDuoTone } from "./hooks/useDuoTone" ;
14
- import { useFogProjection } from "./hooks/useFogProjection" ;
14
+ import {
15
+ FogProjectionParams ,
16
+ useFogProjection ,
17
+ } from "./hooks/useFogProjection" ;
15
18
import { usePerformanceMonitor } from "@react-three/drei" ;
16
19
17
20
extend ( { MainShaderMaterial } ) ;
18
21
19
- /*===============================================
20
- TODO*useFruidの整理から!
21
- ===============================================*/
22
-
23
22
export const Scene = ( ) => {
24
23
const [ bg , bg2 , smoke , ripple , noise , pNoise ] = useLoader (
25
24
THREE . TextureLoader ,
@@ -35,34 +34,27 @@ export const Scene = () => {
35
34
const updateGUI = useGUI ( ) ;
36
35
const mainShaderRef = useRef < TMainShaderUniforms > ( ) ;
37
36
38
- //fx
39
- const updateRipple = useRipple ( { texture : smoke , max : 100 , size : 64 } ) ;
40
- const updateFruid = useFruid ( ) ;
41
- const updateFlowmap = useFlowmap ( ) ;
42
- const updateSimpleFruid = useSimpleFruid ( ) ;
43
- const updateBrush = useBrush ( smoke ) ;
37
+ // fx
38
+ const { updateFx : updateRipple } = useRipple ( { texture : smoke } ) ;
39
+ const { updateFx : updateFruid , setParams : setFruid } = useFruid ( ) ;
40
+ const { updateFx : updateFlowmap } = useFlowmap ( ) ;
41
+ const { updateFx : updateSimpleFruid } = useSimpleFruid ( ) ;
42
+ const { updateFx : updateBrush } = useBrush ( ) ;
43
+
44
+ // post fx
45
+ const { updateFx : updateTransitionBg } = useTransitionBg ( ) ;
46
+ const { updateFx : updateDuoTone } = useDuoTone ( ) ;
47
+ const { updateFx : updateFogProjection } = useFogProjection ( ) ;
44
48
45
- //post fx
46
- const updateTransitionBg = useTransitionBg ( ) ;
47
- const updateDuoTone = useDuoTone ( ) ;
48
- /*===============================================
49
- TODO*これ配列じゃなくてオブジェクトにしよっ
50
- そんでシーンとかマテリアルとか、FBOの配列とかを受けられるようにして、こっからでもサイズを変更できるような仕組みにしよっt
51
- ===============================================*/
52
- const [ updateFogProjection , setFogProjectionUniform , fogObject ] =
53
- useFogProjection ( ) ;
54
- /*===============================================
55
- performance
56
- ===============================================*/
57
- // usePerformanceMonitor({
58
- // onChange: () => {
59
- // setFogProjectionUniform({});
60
- // }
61
- // });
49
+ // Monitor performance changes and execute update functions of params
50
+ usePerformanceMonitor ( {
51
+ onChange ( api ) {
52
+ setFruid ( {
53
+ pressure_iterations : Math . round ( 20 * api . factor ) ,
54
+ } ) ;
55
+ } ,
56
+ } ) ;
62
57
63
- /*===============================================
64
- frame
65
- ===============================================*/
66
58
useFrame ( ( props ) => {
67
59
// fx
68
60
let fx = null ;
@@ -82,12 +74,40 @@ export const Scene = () => {
82
74
velocity_dissipation : CONFIG . fruid . velocity_dissipation ,
83
75
velocity_acceleration : CONFIG . fruid . velocity_acceleration ,
84
76
pressure_dissipation : CONFIG . fruid . pressure_dissipation ,
85
- pressure_iterations : CONFIG . fruid . pressure_iterations ,
86
77
curl_strength : CONFIG . fruid . curl_strength ,
87
78
splat_radius : CONFIG . fruid . splat_radius ,
88
79
fruid_color : CONFIG . fruid . fruid_color ,
89
80
} ) ;
90
81
break ;
82
+ case 2 :
83
+ fx = updateBrush ( props , {
84
+ texture : smoke ,
85
+ radius : CONFIG . brush . radius ,
86
+ alpha : CONFIG . brush . alpha ,
87
+ smudge : CONFIG . brush . smudge ,
88
+ dissipation : CONFIG . brush . dissipation ,
89
+ magnification : CONFIG . brush . magnification ,
90
+ motionBlur : CONFIG . brush . motionBlur ,
91
+ } ) ;
92
+ break ;
93
+ case 3 :
94
+ fx = updateFlowmap ( props , {
95
+ radius : CONFIG . flowmap . radius ,
96
+ magnification : CONFIG . flowmap . magnification ,
97
+ alpha : CONFIG . flowmap . alpha ,
98
+ dissipation : CONFIG . flowmap . dissipation ,
99
+ } ) ;
100
+ break ;
101
+ case 4 :
102
+ fx = updateSimpleFruid ( props , {
103
+ attenuation : CONFIG . simpleFruid . attenuation ,
104
+ alpha : CONFIG . simpleFruid . alpha ,
105
+ beta : CONFIG . simpleFruid . beta ,
106
+ viscosity : CONFIG . simpleFruid . viscosity ,
107
+ forceRadius : CONFIG . simpleFruid . forceRadius ,
108
+ forceCoefficient : CONFIG . simpleFruid . forceCoefficient ,
109
+ } ) ;
110
+ break ;
91
111
default :
92
112
break ;
93
113
}
@@ -99,15 +119,16 @@ export const Scene = () => {
99
119
noiseStrength : CONFIG . transitionBg . noiseStrength ,
100
120
progress : CONFIG . transitionBg . progress ,
101
121
dir : CONFIG . transitionBg . dir ,
102
- texture : [ bg , bg2 ] ,
122
+ texture0 : bg ,
123
+ texture1 : bg2 ,
103
124
noise : noise ,
104
125
} ) ;
105
126
106
127
if ( CONFIG . duoTone . active ) {
107
128
postFx = updateDuoTone ( props , {
129
+ texture : postFx ,
108
130
color0 : CONFIG . duoTone . color0 ,
109
131
color1 : CONFIG . duoTone . color1 ,
110
- texture : postFx ,
111
132
} ) ;
112
133
}
113
134
0 commit comments