private void CreateBoundary(float radius, float density) { Bounds innerBounds = new Bounds(); Vector3 min = new Vector3(-8, 0, -2); Vector3 max = new Vector3(8, 10, 2); innerBounds.SetMinMax(min, max); //Make the boundary 1 particle thick. //The multiple by 1.2 adds a little of extra //thickness in case the radius does not evenly //divide into the bounds size. You might have //particles missing from one side of the source //bounds other wise. float thickness = 1; float diameter = radius * 2; min.x -= diameter * thickness * 1.2f; min.y -= diameter * thickness * 1.2f; min.z -= diameter * thickness * 1.2f; max.x += diameter * thickness * 1.2f; max.y += diameter * thickness * 1.2f; max.z += diameter * thickness * 1.2f; Bounds outerBounds = new Bounds(); outerBounds.SetMinMax(min, max); //The source will create a array of particles //evenly spaced between the inner and outer bounds. ParticleSource source = new ParticlesFromBounds(diameter, outerBounds, innerBounds); Debug.Log("Boundary Particles = " + source.NumParticles); m_boundary = new FluidBoundary(source, radius, density, Matrix4x4.identity); m_innerSource = innerBounds; m_outerSource = outerBounds; }
public FluidSolver(FluidBody body, FluidBoundary boundary) { SolverIterations = 2; ConstraintIterations = 2; Body = body; Boundary = boundary; float cellSize = Body.ParticleRadius * 4.0f; int total = Body.NumParticles + Boundary.NumParticles; Hash = new GridHash(Boundary.Bounds, total, cellSize); Kernel = new SmoothingKernel(cellSize); int numParticles = Body.NumParticles; Groups = numParticles / THREAD_1D; if (numParticles % THREAD_1D != 0) { Groups++; } m_shader = Resources.Load("FluidSolver") as ComputeShader; }