Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }