Example #1
0
        public void UpdateBoundary(FluidBoundary newBoundary)
        {
            Boundary = newBoundary;
            float cellSize = Body.ParticleRadius * 4.0f;
            int   total    = Body.NumParticles + Boundary.NumParticles;

            Hash.Dispose();
            Hash = new GridHash(Boundary.Bounds, total, cellSize);
        }
Example #2
0
        //given a cube region, generate boundary particles around it
        private void CreateBoundary(float radius, float density, Vector3 containerPos, Vector3 resizeFactor)
        {
            //innerBounds defines the region that fluid particles could move
            Bounds innerBounds = new Bounds();
            //create the fluid boundary according to the position and size of the container
            //the information about the container is passed in via the Transformation
            Vector3 min = new Vector3(containerPos[0] - 0.5f * resizeFactor[0], containerPos[1] - 0.5f * resizeFactor[1], containerPos[2] - 0.5f * resizeFactor[2]);
            Vector3 max = new Vector3(containerPos[0] + 0.5f * resizeFactor[0], containerPos[1] + 0.5f * resizeFactor[1], containerPos[2] + 0.5f * resizeFactor[2]);

            innerBounds.SetMinMax(min, max);

            //Make the boundary 1 particle thick.
            //The multiple by 1.2 adds a little of extra
            //thickness incase 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 BoundaryThickness = 1;
            float diameter          = radius * 2;

            min.x -= diameter * BoundaryThickness * 1.2f;
            min.y -= diameter * BoundaryThickness * 1.2f;
            min.z -= diameter * BoundaryThickness * 1.2f;

            max.x += diameter * BoundaryThickness * 1.2f;
            max.y += diameter * BoundaryThickness * 1.2f;
            max.z += diameter * BoundaryThickness * 1.2f;
            //outerBounds is the outmost bound of all particles
            //A.K.A the boundary of the entire simulation
            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);

            //print out the number of particles
            Debug.Log("Boundary Particles = " + source.NumParticles);
            //given the particle positions contained in "source" object
            //create the fluid boundary object
            fusion_FluidBoundary = new FluidBoundary(source, radius, density, Matrix4x4.identity);
            //pass bounds objects
            //fusion_innerSource = innerBounds;
            //fusion_outerSource = outerBounds;
        }
Example #3
0
        public FluidSolver(FluidBody body, FluidBoundary boundary, int densityComputeIteration, int constraintComputeIteration)
        {
            DensityComputeIterations    = densityComputeIteration;
            ConstraintComputeIterations = constraintComputeIteration;

            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 / THREADS;
            if (numParticles % THREADS != 0)
            {
                Groups++;
            }

            fluidSolverShader = Resources.Load("FluidSolver") as ComputeShader;
        }