public void CreateFluid(double radius, double density)
        {
            //To make less particles decrease the size of the bounds or increase the radius.
            //Make sure fluid bounds fits inside the boundrys bounds.

            FluidBounds = new Box3d(-8, -4, 0, 8, -2, 2);
            ParticlesFromBounds source = new ParticlesFromBounds(radius, FluidBounds);

            System.Random rnd = new System.Random(0);

            Body          = new FluidBody3d(source, radius, density, Matrix4x4d.Identity);
            Body.Dampning = 0.0;
            Body.AddBoundry(Boundary);
            Body.RandomizePositions(rnd, radius * 0.01);
            Body.RandomizePositionOrder(rnd);

            FluidSpheres = new GameObject[Body.NumParticles];

            float diam = (float)Body.ParticleDiameter;

            for (int i = 0; i < FluidSpheres.Length; i++)
            {
                Vector3d pos = Body.Positions[i];

                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphere.transform.parent     = transform;
                sphere.transform.position   = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
                sphere.transform.localScale = new Vector3(diam, diam, diam);
                sphere.GetComponent <Collider>().enabled = false;

                sphere.GetComponent <MeshRenderer>().material = sphereMaterial;

                FluidSpheres[i] = sphere;
            }
        }
Exemple #2
0
        public void CreateFluid(float radius, float density)
        {
            //To make less particles decrease the size of the bounds or increase the radius.
            //Make sure fluid bounds fits inside the boundrys bounds.
            FluidBounds = new Box3f(-8, 0, 0, 8, -2, 2);//new Box3f(-7, 6, 1, 7, -2, 4);


            FluidParticlesWithConstraint source = new FluidParticlesWithConstraint(radius, FluidBounds, Boundary.NumParticles);

            System.Random rnd = new System.Random(0);

            Body          = new FluidBody3d(source, radius, density, Matrix4x4f.Identity);
            Body.Dampning = 0.0f;
            Body.AddBoundry(Boundary);
            Body.RandomizePositions(rnd, radius * 0.01f);
            Body.RandomizePositionOrder(rnd);

            Debug.Log(Body.NumParticles);


            CreateFluidVisualize();
        }