protected async Task SetupSimulation() { IFluidRenderer renderer = new SkiaFluidDensityRenderer(fluidView); // Initialize renderer. renderer.SetColor(fluidColor); // Set color to red. fluidSim = new FluidSimulation(renderer, simResolution, viscosityConstant, diffusionRateConstant, gravityConstant, terminalVelocityConstant, 33); // Initialize simulation. // 0.40f, 0.0000001f, 0.01f, 0.00018000f, 0.052f await Task.Factory.StartNew(fluidSim.Start, TaskCreationOptions.LongRunning); }
public FluidSimulationHvel(int width, FluidSimulation.Settings settings) { _width = width; _settings = settings; _heights = new float[width, width]; _xvelocities = new float[width + 1, width]; _yvelocities = new float[width, width + 1]; _velocities = new float[width, width]; _solid = new bool[width, width]; }
static void Main(string[] args) { int width = 10; int height = 10; //Perlin int octaveCount = 5; float[][] perlinNoise = PerlinNoise.PerlinNoise.GeneratePerlinNoise(width, height, octaveCount); //====================== var map = new Cell[width, height]; for (int line = 0; line < height; line++) { for (int col = 0; col < width; col++) { map[line, col] = new Cell() { Altitude = perlinNoise[line][col], X = col, Y = line }; } } var fluidPlugin = new FluidSimulation(map); Program.ShowMap(fluidPlugin.GetMap()); fluidPlugin.AddWater(5, 5, 10f); int cpt = 0; while (cpt < 100) { fluidPlugin.Update(1); Console.WriteLine("Iteration : " + cpt); Program.ShowMap(fluidPlugin.GetMap()); //Thread.Sleep(1000); cpt++; } Console.ReadKey(); }
// Use this for initialization void Start() { FluidSimulation = new FluidSimulation(); FluidSimulation.ComputeShader = ComputeShader; FluidSimulation.setResolution(Resolution); FluidSimulation.SetDyeTexture(DyeTexture); FluidSimulation.setVelocity(Velocity); PlanetMaterial.SetTexture("_MainTex", FluidSimulation._colorRT1); Vector4[] aoKernel = new Vector4[16]; for (int i = 0; i < 16; i++) { aoKernel[i] = new Vector4(Random.Range(0, 2.0f) - 1, Random.Range(0, 2.0f) - 1, 0, 0); } PlanetMaterial.SetVectorArray("_AOKernel", aoKernel); }
public void AddLeft(int dropsCount, FluidSimulation fluidSimulation) { x -= dropsCount; length += dropsCount; // check if the line is now connected to a new line above List <FluidLine> aboveLines; if (fluidSimulation.TryGetFluidLines(this.y + 1, out aboveLines)) { foreach (FluidLine aboveLine in aboveLines) { // check if it contains the new x-value if (this.VerticallyConnectedTo(aboveLine)) { this.AddAboveLine(aboveLine); aboveLine.AddBelowLine(this); } } } // check if the line is now connected to a new line below List <FluidLine> belowLines; if (fluidSimulation.TryGetFluidLines(this.y - 1, out belowLines)) { foreach (FluidLine belowLine in belowLines) { // check if it contains the new x-value if (this.VerticallyConnectedTo(belowLine)) { this.AddBelowLine(belowLine); belowLine.AddAboveLine(this); } } } }
public virtual bool OnFluidSimContact(FluidSimulation sim, FluidSimulation.PhysicObject newObject) { return(true); }
public override void UpdateBehavior(FluidSimulation sim, FluidSimulation.PhysicObject physicObject) { // PARAMS FOR OBJECTS // How much they are in the water // How fast they rotate float y; Vector3 normal = sim.GetYNormal(physicObject.gao.transform.position.x, physicObject.gao.transform.position.z, out y); var rigidBody = physicObject.gao.GetComponent <Rigidbody>(); if (rigidBody) { /* * rigidBody.isKinematic = true; * physicObjects[i].transform.position = new Vector3(physicObjects[i].transform.position.x, y, physicObjects[i].transform.position.z); * physicObjects[i].transform.rotation = Quaternion.FromToRotation(Vector3.up, normal); */ if (y > 0.0f) { float mv = physicObject.volume / rigidBody.mass; float height = 0.0f; var objCollider = physicObject.gao.GetComponent <Collider>(); if (objCollider) { height = objCollider.bounds.size.y; } //Debug.Log("Mass=" + rigidBody.mass + ", volume=" + physicObjects[i].volume + ", mv=" + mv + ", height = " + height); float PercentageInFluid = 1.0f - (physicObject.gao.transform.position.y - y + (height / 2.0f)) / height; float Ratio = 1.0f - physicObject.gao.transform.position.y / y; //Debug.Log("pos = " + physicObjects[i].gao.transform.position.y + ", y=" + y + ", Ratio = " + Ratio + ", Height=" + PercentageInFluid); // compute mass in fluid float massInsideFluid = PercentageInFluid * physicObject.volume; //1.0 = liquid vm float massOutsideFluid = (1.0f - PercentageInFluid) * rigidBody.mass; float archimedRatio = massInsideFluid / (massInsideFluid + massOutsideFluid); // Update submerged volume float newSubmergedVolume = PercentageInFluid * physicObject.volume; float deltaSubmergedVolume = newSubmergedVolume - physicObject.submergedVolume; physicObject.submergedVolume = newSubmergedVolume; //Debug.Log("Mass in fluid=" + massInsideFluid + ", Mass outside fluid= " + massOutsideFluid + ", ArchiRatio=" + archimedRatio + ", Volume=" + physicObjects[i].volume); // submerge volume effect int index = sim.GetArrayIndexFromPos(physicObject.gao.transform.position); /* * if (index >= 0) * speedY[index] += deltaSubmergedVolume * 2.0f; */ /* physic effect temporarily removed * if(index >= 0) * simulation.SetSpeed(index, simulation.GetSpeed(index) + deltaSubmergedVolume * 2.0f); * * rigidBody.AddForce((0.2f * archimedRatio * mv * normal * Physics.gravity.magnitude), ForceMode.Force); * if (rigidBody.velocity.y < 0.0f) * rigidBody.velocity = rigidBody.velocity * 0.98f; */ /* * if (Ratio > 0.0f) * { * rigidBody.AddForce(mv * normal * Physics.gravity.magnitude * (0.25f + Ratio * 0.25f), ForceMode.Force); * if (rigidBody.velocity.y < 0.0f) * rigidBody.velocity = rigidBody.velocity * 0.98f; * } */ } /* * objectsSpeed[i] = (objectsSpeed[i] + normal) * 0.95f; * Vector3 Dest = floatingObjects[i].transform.position + objectsSpeed[i] * Time.deltaTime; * Dest.y = y; * floatingObjects[i].transform.position = Vector3.Lerp(floatingObjects[i].transform.position, Dest, 0.3f); * floatingObjects[i].transform.rotation = Quaternion.RotateTowards(floatingObjects[i].transform.rotation, Quaternion.FromToRotation(Vector3.up, normal), 0.3f); */ } else { physicObject.gao.transform.position = new Vector3(physicObject.gao.transform.position.x, y, physicObject.gao.transform.position.z); physicObject.gao.transform.rotation = Quaternion.FromToRotation(Vector3.up, normal); } }
public override bool OnFluidSimContact(FluidSimulation sim, FluidSimulation.PhysicObject newObject) { return(true); }
public virtual void UpdateBehavior(FluidSimulation sim, FluidSimulation.PhysicObject physicObject) { }
// Use this for initialization void Start() { m_fluidSimulation = gameObject.AddComponent<FluidSimulation>(); m_fluidSimulation.Init(FluidParticle); }