예제 #1
0
        //given a cube region, create a fluid body
        //the fluid body's size is defined relative to the size of the container
        private void CreateFluid(float radius, float density, Vector3 containerPos, Vector3 resizeFactor,
                                 Vector3 fluidBodyPos, Vector3 fluidBodyScale)
        {
            //the bounds of the (initial) fluid region
            Bounds bounds = new Bounds();
            //Vector3 min = new Vector3(-8, 0, -1);
            //Vector3 max = new Vector3(0, 8, 1);

            Bounds fluidChunkBound = new Bounds(fluidBodyPos, fluidBodyScale);
            // Vector3 min = new Vector3(fluidBodyPos[0] - 0.5f * fluidBodyScale[0], fluidBodyPos[1] - 0.5f * fluidBodyScale[1], fluidBodyPos[2] - 0.5f * fluidBodyScale[2]);
            //  Vector3 max = new Vector3(fluidBodyPos[0] + 0.5f * fluidBodyScale[0], fluidBodyPos[1] + 0.5f * fluidBodyScale[1], fluidBodyPos[2] + 0.5f * fluidBodyScale[2]);
            Vector3 min = fluidChunkBound.min;
            Vector3 max = fluidChunkBound.max;

            //create the fluid body according to the size and position of the container
            //Vector3 ContainerMin = new Vector3(containerPos[0] - 0.5f * resizeFactor[0], containerPos[1] - 0.4f * resizeFactor[1], containerPos[2] - 0.25f * resizeFactor[2]);
            //Vector3 ContainerMax = new Vector3(containerPos[0] + 0.02f * resizeFactor[0], containerPos[1] + 0.4f * resizeFactor[1], containerPos[2] + 0.25f * resizeFactor[2]);
            //need to minus/plus a radius since the particles are defined as spheres
            min.x += radius;
            min.y += radius;
            min.z += radius;

            max.x -= radius;
            max.y -= radius;
            max.z -= radius;
            //set the bound
            bounds.SetMinMax(min, max);

            //The source will create a array of particles evenly spaced inside the bounds.
            //Multiple the spacing by 0.9 to pack more particles into bounds.
            //create particles from the bound
            float diameter             = radius * 2;
            ParticlesFromBounds source = new ParticlesFromBounds(diameter * 0.9f, bounds);

            Debug.Log("Fluid Particles = " + source.NumParticles);
            //create a new fluid body object given the particles contained in "source"
            fusion_FluidBody = new FluidBody(source, radius, density, Matrix4x4.identity, FluidInitialVelocity);

            // fusion_FluidBodySource = bounds;
        }
예제 #2
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;
        }