Esempio n. 1
0
        private void Start()
        {
            //define the particle radius here in order to create fluid body particles
            particleRadius = 0.1f;
            float density = 1000.0f;

            blastPoint = new Vector3(0, 10000, 0);
            //containerScale = new Vector3(1, 1, 1);
            containerPos   = containerTransform.position;
            containerScale = containerTransform.localScale;

            Vector3 fluidBodyPos   = FluidChunkTransform.position;
            Vector3 fluidBodyScale = FluidChunkTransform.localScale;

            //NOTE1: the particle amount may raise issues in Bitonic Sorting

            //NOTE2: A smaller radius may also requre more solver steps

            switch (particleAmount)
            {
            case PARTICLE_AMOUNT.LOW:
                particleRadius = 0.1f;
                break;

            case PARTICLE_AMOUNT.MEDIUM:
                particleRadius = 0.08f;
                break;

            case PARTICLE_AMOUNT.HIGH:
                particleRadius = 0.06f;
                break;
            }

            try
            {
                CreateBoundary(particleRadius, density, containerPos, containerScale);
                CreateFluid(particleRadius, density, containerPos, containerScale, fluidBodyPos, fluidBodyScale);

                fusion_FluidBody.Bounds = fusion_FluidBoundary.Bounds;

                fusion_FluidSolver = new FluidSolver(fusion_FluidBody, fusion_FluidBoundary, DensityComputeIterations, ConstraintComputeIterations);

                //fusion_volume = new RenderVolume(fusion_FluidBoundary.Bounds, radius);
                //fusion_volume.CreateMesh(fusion_volumeMat);
            }
            catch
            {
                wasError = true;
                throw;
            }
            FluidChunkRenderer.enabled = false;
        }
Esempio n. 2
0
        private void SystemStateOnKeyPresses()
        {
            //press the Space key, system got paused
            //At paused state, the fusion_run variable should be set to false
            //until the Enter key is pressed, then fusion_run variable get back to true
            //then the fluid boundary is reconstructed and simulation resumes
            if (Input.GetKeyDown(KeyCode.Space) && SystemRun == true)
            {
                SystemRun = false;
                Debug.Log("space pressed");
            }
            //if the system is paused and you press Space
            //the fluidboundary object need to be reconstructed
            //then system resumes
            if (Input.GetKeyDown(KeyCode.B) && SystemRun == false)
            {
                float density = 1000.0f;
                try
                {
                    CreateBoundary(particleRadius, density, containerPos, containerScale);
                    fusion_FluidBody.Bounds = fusion_FluidBoundary.Bounds;

                    fusion_FluidSolver = new FluidSolver(fusion_FluidBody, fusion_FluidBoundary, DensityComputeIterations, ConstraintComputeIterations);
                }
                catch
                {
                    wasError = true;
                    throw;
                }

                if (wasError)
                {
                    return;
                }

                //fusion_FluidSolver.UpdateBoundary(fusion_FluidBoundary);

                SystemRun = true;
            }

            if (SystemRun == false) //when system paused, move the wall of the cube
            {
                if (Input.GetKey(KeyCode.L))
                {
                    containerScale[0] += 0.05f;
                }
                if (Input.GetKey(KeyCode.J))
                {
                    containerScale[0] -= 0.05f;
                }
                if (Input.GetKey(KeyCode.I))
                {
                    containerScale[1] -= 0.05f;
                }
                if (Input.GetKey(KeyCode.K))
                {
                    containerScale[1] += 0.05f;
                }
                if (Input.GetKey(KeyCode.U))
                {
                    containerScale[2] -= 0.05f;
                }
                if (Input.GetKey(KeyCode.O))
                {
                    containerScale[2] += 0.05f;
                }

                containerTransform.localScale = containerScale;
            }
        }