@@ -10,7 +10,6 @@ import * as THREE from 'three';
10
10
11
11
const defaultInteractionRadius = 1.5 ;
12
12
13
- // Define the shader material
14
13
const BlobShaderMaterial = shaderMaterial (
15
14
{
16
15
u_time : 0 ,
@@ -21,6 +20,7 @@ const BlobShaderMaterial = shaderMaterial(
21
20
u_intensity : 2 ,
22
21
u_interactionPosition : new THREE . Vector3 ( 0 , 0 , 0 ) ,
23
22
u_interactionRadius : defaultInteractionRadius ,
23
+ u_gravity : 0.1 ,
24
24
} ,
25
25
vertexShader ,
26
26
fragmentShader ,
@@ -62,9 +62,9 @@ const ParticleCloud = () => {
62
62
const cylinderRef = useRef ( ) ;
63
63
const planeMeshRef = useRef ( ) ;
64
64
const radiusRef = useRef ( defaultInteractionRadius ) ;
65
- const prevCameraPosition = useRef ( new Vector3 ( ) ) ; // To store the previous camera position
66
- const planeRef = useRef ( new Plane ( ) ) ; // To store the plane reference
67
- const planeNormal = useRef ( new Vector3 ( ) ) ; // To store the previous plane normal
65
+ const prevCameraPosition = useRef ( new Vector3 ( ) ) ;
66
+ const planeRef = useRef ( new Plane ( ) ) ;
67
+ const planeNormal = useRef ( new Vector3 ( ) ) ;
68
68
69
69
useEffect ( ( ) => {
70
70
let gui ;
@@ -109,17 +109,12 @@ const ParticleCloud = () => {
109
109
}
110
110
} ) ;
111
111
112
- // Add a GUI slider to adjust the cylinder and touch radius
113
112
const cylinderFolder = gui . addFolder ( 'Interaction' ) ;
114
113
cylinderFolder . add ( params , 'radius' , 0.1 , 10 ) . onChange ( ( value ) => {
115
- radiusRef . current = value ; // Update the stored radius
116
-
114
+ radiusRef . current = value ;
117
115
if ( cylinderRef . current ) {
118
- // Update cylinder geometry with new radius
119
- const length = cylinderRef . current . geometry . parameters . height ; // Preserve the existing length
116
+ const length = cylinderRef . current . geometry . parameters . height ;
120
117
cylinderRef . current . geometry = new THREE . CylinderGeometry ( value , value , length , 16 ) ;
121
-
122
- // Update shader uniform with new radius
123
118
if ( materialRef . current ) {
124
119
materialRef . current . uniforms . u_interactionRadius . value = value ;
125
120
}
@@ -149,15 +144,9 @@ const ParticleCloud = () => {
149
144
}
150
145
151
146
const currentCameraPosition = camera . position . clone ( ) ;
152
-
153
- // Check if the camera position has changed
154
147
if ( ! prevCameraPosition . current . equals ( currentCameraPosition ) ) {
155
148
console . log ( 'Camera position changed' ) ;
156
-
157
- // Update previous camera position
158
149
prevCameraPosition . current . copy ( currentCameraPosition ) ;
159
-
160
- // Update the plane normal and plane reference when the camera position changes
161
150
planeNormal . current . copy ( camera . getWorldDirection ( new Vector3 ( ) ) ) ;
162
151
planeRef . current . normal . copy ( planeNormal . current ) ;
163
152
planeRef . current . constant = 0 ;
@@ -182,8 +171,9 @@ const ParticleCloud = () => {
182
171
cylinderRef . current . rotation . copy ( rotation ) ;
183
172
cylinderRef . current . geometry = new THREE . CylinderGeometry ( radiusRef . current , radiusRef . current , length , 16 ) ;
184
173
185
- // Update the shader uniforms for touch position and radius
186
- materialRef . current . uniforms . u_interactionPosition . value . copy ( cylinderRef . current . position ) ;
174
+ if ( materialRef . current ) {
175
+ materialRef . current . uniforms . u_interactionPosition . value . copy ( cylinderRef . current . position ) ;
176
+ }
187
177
}
188
178
}
189
179
}
0 commit comments