コード例 #1
0
        private void CreateFluid(float radius, float density)
        {
            Bounds  bounds = new Bounds();
            Vector3 min    = new Vector3(-8, 0, -1);
            Vector3 max    = new Vector3(-4, 8, 2);

            min.x += radius;
            min.y += radius;
            min.z += radius;

            max.x -= radius;
            max.y -= radius;
            max.z -= radius;

            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.
            float diameter             = radius * 2;
            ParticlesFromBounds source = new ParticlesFromBounds(diameter * 0.9f, bounds);

            Debug.Log("Fluid Particles = " + source.NumParticles);

            m_fluid = new FluidBody(source, radius, density, Matrix4x4.identity);

            m_fluidSource = bounds;
        }
コード例 #2
0
        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;
        }