示例#1
0
        public FluidBoundary(ParticleSource source, float radius, float density, Matrix4x4 RTS)
        {
            NumParticles   = source.NumParticles;
            ParticleRadius = radius;
            Density        = density;

            CreateParticles(source, RTS);
            CreateBoundryPsi();
        }
示例#2
0
        private void CreateParticles(ParticleSource source, Matrix4x4 RTS)
        {
            Vector4[] positions = new Vector4[NumParticles];

            float   inf = float.PositiveInfinity;
            Vector3 min = new Vector3(inf, inf, inf);
            Vector3 max = new Vector3(-inf, -inf, -inf);

            for (int i = 0; i < NumParticles; i++)
            {
                Vector4 pos = RTS * source.Positions[i];
                positions[i] = pos;

                if (pos.x < min.x)
                {
                    min.x = pos.x;
                }
                if (pos.y < min.y)
                {
                    min.y = pos.y;
                }
                if (pos.z < min.z)
                {
                    min.z = pos.z;
                }

                if (pos.x > max.x)
                {
                    max.x = pos.x;
                }
                if (pos.y > max.y)
                {
                    max.y = pos.y;
                }
                if (pos.z > max.z)
                {
                    max.z = pos.z;
                }
            }

            min.x -= ParticleRadius;
            min.y -= ParticleRadius;
            min.z -= ParticleRadius;

            max.x += ParticleRadius;
            max.y += ParticleRadius;
            max.z += ParticleRadius;

            Bounds = new Bounds();
            Bounds.SetMinMax(min, max);

            Positions = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Positions.SetData(positions);
        }
示例#3
0
        public FluidBody(ParticleSource source, float radius, float density, Matrix4x4 RTS)
        {
            NumParticles = source.NumParticles;
            Density      = density;
            Viscosity    = 0.002f;
            Dampning     = 0.0f;

            ParticleRadius = radius;
            ParticleVolume = (4.0f / 3.0f) * Mathf.PI * Mathf.Pow(radius, 3);
            ParticleMass   = ParticleVolume * Density;

            Densities = new ComputeBuffer(NumParticles, sizeof(float));
            Pressures = new ComputeBuffer(NumParticles, sizeof(float));

            CreateParticles(source, RTS);
        }
示例#4
0
        private void CreateParticles(ParticleSource source, Matrix4x4 RTS)
        {
            Vector4[] positions  = new Vector4[NumParticles];
            Vector4[] predicted  = new Vector4[NumParticles];
            Vector4[] velocities = new Vector4[NumParticles];

            float   inf = float.PositiveInfinity;
            Vector3 min = new Vector3(inf, inf, inf);
            Vector3 max = new Vector3(-inf, -inf, -inf);

            for (int i = 0; i < NumParticles; i++)
            {
                Vector4 pos = RTS * source.Positions[i];
                positions[i] = pos;
                predicted[i] = pos;

                if (pos.x < min.x)
                {
                    min.x = pos.x;
                }
                if (pos.y < min.y)
                {
                    min.y = pos.y;
                }
                if (pos.z < min.z)
                {
                    min.z = pos.z;
                }

                if (pos.x > max.x)
                {
                    max.x = pos.x;
                }
                if (pos.y > max.y)
                {
                    max.y = pos.y;
                }
                if (pos.z > max.z)
                {
                    max.z = pos.z;
                }
            }

            min.x -= ParticleRadius;
            min.y -= ParticleRadius;
            min.z -= ParticleRadius;

            max.x += ParticleRadius;
            max.y += ParticleRadius;
            max.z += ParticleRadius;

            Bounds = new Bounds();
            Bounds.SetMinMax(min, max);

            Positions = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Positions.SetData(positions);

            //Predicted and velocities use a double buffer as solver step
            //needs to read from many locations of buffer and write the result
            //in same pass. Could be removed if needed as long as buffer writes
            //are atomic. Not sure if they are.

            Predicted    = new ComputeBuffer[2];
            Predicted[0] = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Predicted[0].SetData(predicted);
            Predicted[1] = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Predicted[1].SetData(predicted);

            Velocities    = new ComputeBuffer[2];
            Velocities[0] = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Velocities[0].SetData(velocities);
            Velocities[1] = new ComputeBuffer(NumParticles, 4 * sizeof(float));
            Velocities[1].SetData(velocities);
        }