@@ -26,6 +26,9 @@ public class FluidController : MonoBehaviour
26
26
[ HideInInspector ]
27
27
public Int3 gridSize ;
28
28
29
+ private HashSet < Int3 > _currUpdateMCBlocks ;
30
+ private float _timer ;
31
+
29
32
private void Start ( )
30
33
{
31
34
//ExampleMc()
@@ -35,12 +38,6 @@ private void Start()
35
38
gridSize . _x , gridSize . _y , gridSize . _z , shaderSPH ,
36
39
shaderRadixSort ) ;
37
40
38
- //CreateTest25Square();
39
- //CreateDirFlow();
40
- //CreateTest125Cube();
41
- //CreateTest1000Cube();
42
- //CreateTwoCollisionFlow();
43
- //CreatePenetrateWall();
44
41
//CreateTest125CubeGPU();
45
42
CreateTest1000CubeGPU ( ) ;
46
43
@@ -50,10 +47,8 @@ private void Start()
50
47
mcEngine . engineScale = ( float ) gridSize . _x / ( float ) mcEngine . width ;
51
48
mcEngine . Init ( sphSolver ) ;
52
49
53
- //if (sphSolver.currParticleNum > 0)
54
- // StartCoroutine(Simulate_CR());
55
- if ( sphSolver . currParticleNum > 0 )
56
- StartCoroutine ( SimulatorOnGPU_CR ( ) ) ;
50
+ _currUpdateMCBlocks = new HashSet < Int3 > ( ) ;
51
+ _timer = 0f ;
57
52
}
58
53
59
54
private void OnDestroy ( )
@@ -63,25 +58,6 @@ private void OnDestroy()
63
58
}
64
59
65
60
#region Test Cases
66
- private void CreateTest25Square ( )
67
- {
68
- for ( int x = 0 ; x < 5 ; ++ x )
69
- for ( int z = 0 ; z < 5 ; ++ z )
70
- {
71
- sphSolver . CreateParticle ( 1 , new Vector3d ( 5 + 0.1 * x , 4.9 , 5 + 0.1 * z ) , Vector3d . zero ) ;
72
- }
73
- }
74
-
75
- private void CreateTest125Cube ( )
76
- {
77
- for ( int x = 0 ; x < 5 ; ++ x )
78
- for ( int y = 0 ; y < 5 ; ++ y )
79
- for ( int z = 0 ; z < 5 ; ++ z )
80
- {
81
- sphSolver . CreateParticle ( 1 , new Vector3d ( 5 + 0.1 * x , 5 + 0.1 * y , 5 + 0.1 * z ) , Vector3d . zero ) ;
82
- }
83
- }
84
-
85
61
private void CreateTest125CubeGPU ( )
86
62
{
87
63
for ( int x = 0 ; x < 5 ; ++ x )
@@ -92,17 +68,6 @@ private void CreateTest125CubeGPU()
92
68
}
93
69
}
94
70
95
- private void CreateTest1000Cube ( )
96
- {
97
- for ( int x = 0 ; x < 10 ; ++ x )
98
- for ( int y = 0 ; y < 10 ; ++ y )
99
- for ( int z = 0 ; z < 10 ; ++ z )
100
- {
101
- sphSolver . CreateParticle ( 1 , new Vector3d ( 4 + 0.2 * x , 4 + 0.2 * y , 4 + 0.2 * z ) , Vector3d . zero ) ;
102
- }
103
- }
104
-
105
-
106
71
private void CreateTest1000CubeGPU ( )
107
72
{
108
73
for ( int x = 0 ; x < 10 ; ++ x )
@@ -112,99 +77,27 @@ private void CreateTest1000CubeGPU()
112
77
sphSolver . CreateGPUParticle ( 1 , new Vector3 ( 4f + 0.2f * x , 4f + 0.2f * y , 4f + 0.2f * z ) , Vector3 . zero ) ;
113
78
}
114
79
}
115
-
116
- private void CreateDirFlow ( )
117
- {
118
- for ( int x = 0 ; x < 20 ; ++ x )
119
- sphSolver . CreateParticle ( 1 , new Vector3d ( 5 + 0.1 * x , 4.9 , 5 ) , new Vector3d ( 5 , 0 , 0 ) ) ;
120
- }
121
-
122
- private void CreateTwoCollisionFlow ( )
123
- {
124
- for ( int x = 0 ; x < 50 ; ++ x )
125
- sphSolver . CreateParticle ( 1 , new Vector3d ( Vector3 . one * Random . value * 0.2f ) + new Vector3d ( 3 + 0.1 * x , 5 , 5 ) , new Vector3d ( 3 + Random . Range ( 0 , 2f ) , 0 , 0 ) ) ;
126
-
127
- for ( int x = 0 ; x < 50 ; ++ x )
128
- sphSolver . CreateParticle ( 1 , new Vector3d ( Vector3 . one * Random . value * 0.2f ) + new Vector3d ( 7 - 0.1 * x , 7 , 5 ) , new Vector3d ( - 3 - Random . Range ( 0 , 2f ) , - 5 , 0 ) ) ;
129
- }
130
-
131
- private void CreatePenetrateWall ( )
132
- {
133
- for ( int x = 0 ; x < 10 ; ++ x )
134
- for ( int y = 0 ; y < 10 ; ++ y )
135
- sphSolver . CreateParticle ( 1 , new Vector3d ( 4 + 0.2 * x , 4 + 0.2 * y , 5 ) , Vector3d . zero ) ;
136
-
137
- for ( int z = 0 ; z < 10 ; ++ z )
138
- sphSolver . CreateParticle ( 1 , new Vector3d ( 5 , 5 , 1 + 0.05 * z ) , new Vector3d ( 0 , 0 , 5 + Random . Range ( 0 , 2f ) ) ) ;
139
- }
140
-
141
80
#endregion
142
81
143
- private IEnumerator SimulatorOnGPU_CR ( )
82
+ private void Update ( )
144
83
{
145
- HashSet < Int3 > currUpdateMCBlocks = new HashSet < Int3 > ( ) ;
146
- while ( true )
84
+ _timer += Time . deltaTime ;
85
+ if ( _timer > updateInterval )
147
86
{
148
- yield return new WaitForSeconds ( updateInterval ) ;
149
- //yield return null;
150
- //if (!Input.GetKeyDown(KeyCode.S))
151
- //continue;
152
- //Debug.Log("wa");
153
- //#if UNITY_EDITOR
154
- // float startTime = Time.realtimeSinceStartup;
155
- //#endif
87
+ _timer -= updateInterval ;
156
88
sphSolver . StepOnGPU ( ) ;
157
- //update MarchingCubeEngine
158
- currUpdateMCBlocks . Clear ( ) ;
89
+ _currUpdateMCBlocks . Clear ( ) ;
159
90
for ( int i = 0 ; i < sphSolver . currParticleNum ; ++ i )
160
91
{
161
92
if ( sphSolver . _allCSParticlesContainer [ i ] . onSurface )
162
93
{
163
94
Vector3 blockOffset = ( sphSolver . _allCSParticlesContainer [ i ] . position /*- mcEngine.engineOrigin*/ ) /
164
95
( mcEngine . engineScale * MarchingCubeEngine . blockSize ) ;
165
96
Int3 blockIdx = new Int3 ( Mathf . FloorToInt ( blockOffset . x ) , Mathf . FloorToInt ( blockOffset . y ) , Mathf . FloorToInt ( blockOffset . z ) ) ;
166
- currUpdateMCBlocks . Add ( blockIdx ) ;
97
+ _currUpdateMCBlocks . Add ( blockIdx ) ;
167
98
}
168
99
}
169
-
170
- //#if UNITY_EDITOR
171
- // print("Time taken: " + (Time.realtimeSinceStartup - startTime) * 1000.0f);
172
- //#endif
173
- mcEngine . BatchUpdate ( new List < Int3 > ( currUpdateMCBlocks ) ) ;
174
- }
175
- }
176
-
177
-
178
- private IEnumerator Simulate_CR ( )
179
- {
180
- HashSet < Int3 > currUpdateMCBlocks = new HashSet < Int3 > ( ) ;
181
- while ( true )
182
- {
183
- yield return new WaitForSeconds ( updateInterval ) ;
184
- //yield return null;
185
- //if (!Input.GetKeyDown(KeyCode.S))
186
- // continue;
187
-
188
- //#if UNITY_EDITOR
189
- // float startTime = Time.realtimeSinceStartup;
190
- //#endif
191
- sphSolver . Step ( ) ;
192
- //update MarchingCubeEngine
193
- currUpdateMCBlocks . Clear ( ) ;
194
- for ( int i = 0 ; i < sphSolver . currParticleNum ; ++ i )
195
- {
196
- if ( sphSolver . allParticles [ i ] . onSurface )
197
- {
198
- Vector3d blockOffset = ( sphSolver . allParticles [ i ] . position /*- mcEngine.engineOrigin*/ ) /
199
- ( mcEngine . engineScale * MarchingCubeEngine . blockSize ) ;
200
- currUpdateMCBlocks . Add ( Vector3d . FloorToInt3 ( blockOffset ) ) ;
201
- }
202
- }
203
-
204
- //#if UNITY_EDITOR
205
- // print("Time taken: " + (Time.realtimeSinceStartup - startTime) * 1000.0f);
206
- //#endif
207
- mcEngine . BatchUpdate ( new List < Int3 > ( currUpdateMCBlocks ) ) ;
100
+ mcEngine . BatchUpdate ( new List < Int3 > ( _currUpdateMCBlocks ) ) ;
208
101
}
209
102
}
210
103
@@ -217,18 +110,6 @@ private void OnDrawGizmos()
217
110
Gizmos . DrawWireCube ( center , extent * 2 ) ;
218
111
Gizmos . color = Color . white ;
219
112
220
- //if (sphSolver != null && sphSolver.allParticles != null && sphSolver.allParticles.Count > 0)
221
- //{
222
- // for (int i = 0; i < sphSolver.allParticles.Count; ++i)
223
- // {
224
- // Vector3 pos = transform.position;
225
- // pos += new Vector3((float)sphSolver.allParticles[i].position.x,
226
- // (float)sphSolver.allParticles[i].position.y,
227
- // (float)sphSolver.allParticles[i].position.z);
228
- // Gizmos.DrawWireSphere(pos, 0.2f);
229
- // }
230
- //}
231
-
232
113
//if (sphSolver != null && sphSolver._allCSParticlesContainer != null && sphSolver._allCSParticlesContainer.Length > 0)
233
114
//{
234
115
// for (int i = 0; i < sphSolver._allCSParticlesContainer.Length; ++i)
0 commit comments