void Start()
        {
            Matrix4x4d T, R;

            double spacing = 0.125;
            double radius  = spacing;
            double mass    = 1.0;

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

            Vector3 min    = new Vector3(-1, -1, -1);
            Vector3 max    = new Vector3(1, 1, 1);
            Box3d   bounds = new Box3d(min, max);

            ParticlesFromBounds source = new ParticlesFromBounds(spacing, bounds);

            T = Matrix4x4d.Translate(new Vector3d(0.0, 4.0, 0.0));
            R = Matrix4x4d.Rotate(new Vector3d(0.0, 0.0, 25.0));

            RidgidBody3d body = new RidgidBody3d(source, radius, mass, T * R);

            body.Dampning = 1.0;
            body.RandomizePositions(rnd, radius * 0.01);

            Solver = new Solver3d();
            Solver.AddBody(body);
            Solver.AddForce(new GravitationalForce3d());
            Solver.AddCollision(new PlanarCollision3d(Vector3.up, 0));
            Solver.SolverIterations    = 2;
            Solver.CollisionIterations = 2;
            Solver.SleepThreshold      = 1;

            CreateSpheres();
        }
        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;
            }
        }
        public void CreateBoundary(double radius, double density)
        {
            InnerBounds = new Box3d(-8, 8, 0, 10, -2, 2);
            OuterBounds = InnerBounds;

            int thickness = 1;

            OuterBounds.Min -= new Vector3d(radius * 2 * thickness);
            OuterBounds.Max += new Vector3d(radius * 2 * thickness);

            ParticleSource source = new ParticlesFromBounds(radius, OuterBounds, InnerBounds);

            Boundary = new FluidBoundary3d(source, radius, density, Matrix4x4d.Identity);

            BoundarySpheres = new GameObject[Boundary.NumParticles];
            float diam = (float)Boundary.ParticleDiameter;

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

                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

                sphere.SetActive(drawBoundary);
                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 = boundaryMaterial;

                BoundarySpheres[i] = sphere;
            }
        }
Ejemplo n.º 4
0
        public void CreateBoundary(float radius, float density)
        {
            InnerBounds = new Box3f(-8, 4, 0, 10, -2, 4);
            //new Box3f(-8, 8, 0, 10, -2, 4);
            OuterBounds = InnerBounds;

            float thickness = 1.2f;

            OuterBounds.Min -= new Vector3f(radius * 2 * thickness);
            OuterBounds.Max += new Vector3f(radius * 2 * thickness);

            ParticleSource source = new ParticlesFromBounds(radius, OuterBounds, InnerBounds);

            Boundary = new FluidBoundary3d(source, radius, density, Matrix4x4f.Identity);

            CreateBoundaryVisualize();
        }