void Start() { _simulation = new FluidSimulationHvel(width, fluidSettings); GetComponent<FluidRenderer>().Init(_simulation); _driver = new MazeDriver(_simulation); }
public WaveDriver(IFluidSimulation simulation) { _simulation = simulation; for (int y = 0; y < _simulation.Height; ++y) { for (int x = 0; x < _simulation.Width; ++x) { _simulation.AddWater(x, y, 2.0f); } } _fixColumn0Height = true; }
protected FluidSimulationComponent(IEmbeddedResources embeddedResources) { this.embeddedResources = embeddedResources; //var size = new IntSize3(20, 20, 1); //var cellSize = 0.40f; //var particleRadius = 0.25f; fluidSimulation = new FluidSimulation(1f, 1f, 0.25f); visualElements = new List <IVisualElement>(); interactionElems = new IInteractionElement[] { //new SelectOnClickInteractionElement(this, viewService), new ActionOnEventInteractionElement( args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.None, () => { if (simulationRunning) { fluidSimulation.Stop(); } else { if (firstTime) { fluidSimulation.Reset(CreateConfig()); Reset(); firstTime = false; } prevFrame = nextFrame = null; fluidSimulation.Run(simulationTimestamp + 5); } simulationRunning = !simulationRunning; }), new ActionOnEventInteractionElement( args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.Shift, () => { Reset(); }), }; hittable = new SphereHittable <FluidSimulationComponent>(this, c => c.model.BoundingSphere * c.Node.GlobalTransform); Width = 20; Height = 20; CellSize = 0.8f; LevelSetScale = 16; SurfaceType = FluidSurfaceType.Hybrid; Reset(); }
public override void Init(IFluidSimulation simulation) { _simulation = simulation; _mesh = new Mesh(); GetComponent<MeshFilter>().mesh = _mesh; int numVerts = _simulation.Width * _simulation.Width; int numTris = 2 * (_simulation.Width - 1) * (_simulation.Width - 1); Vector3[] newVertices = new Vector3[numVerts]; Vector2[] newUV = new Vector2[numVerts]; Vector3[] newNormals = new Vector3[numVerts]; int[] indices = new int[numTris * 3]; for (int y = 0; y < _simulation.Width; ++y) { for (int x = 0; x < _simulation.Width; ++x) { int vbase = x + y * _simulation.Width; newVertices[vbase] = new Vector3(x, 0, y); newUV[vbase] = new Vector2(0, 0); newNormals[vbase] = new Vector3(0, 1, 0); } } for (int y = 0; y < _simulation.Width - 1; ++y) { for (int x = 0; x < _simulation.Width - 1; ++x) { int vbase = x + y * _simulation.Width; int ibase = 6 * (x + y * (_simulation.Width-1)); indices[ibase] = vbase; indices[ibase + 1] = vbase + _simulation.Width; indices[ibase + 2] = vbase + 1; indices[ibase + 3] = vbase + _simulation.Width + 1; indices[ibase + 4] = vbase + 1; indices[ibase + 5] = vbase + _simulation.Width; } } _mesh.vertices = newVertices; _mesh.uv = newUV; _mesh.normals = newNormals; _mesh.triangles = indices; _mesh.RecalculateBounds(); }
public override void Init(IFluidSimulation simulation) { _simulation = simulation; _transforms = new Transform[_simulation.Width]; for (int i = 0; i < _simulation.Width; ++i) { GameObject obj0 = GameObject.CreatePrimitive(PrimitiveType.Cube); obj0.transform.localPosition = new Vector3(0, 0.5f, 0); GameObject obj = new GameObject(); obj0.transform.parent = obj.transform; obj.transform.position = new Vector3(i, 0, 0); _transforms[i] = obj.transform; } }
public RiverDriver(IFluidSimulation simulation) { _simulation = simulation; for (int y = 0; y < _simulation.Height; ++y) { for (int x = 0; x < _simulation.Width; ++x) { if ((y < _simulation.Height / 3 && x < _simulation.Width * 5 / 8) || (y > _simulation.Height * 2 / 3) || (x > _simulation.Width * 7 / 8) || ((x > _simulation.Width * 5 / 8 && y > _simulation.Height / 3 && Mathf.Pow(((float)x / _simulation.Width - 5.0f / 8) * 4, 2) + Mathf.Pow(((float)y / _simulation.Height - 1.0f / 3) * 3, 2) > 1)) || (x > _simulation.Width * 24 / 32 && x < _simulation.Width * 25 / 32 && y > _simulation.Height * 2 / 16 && y < _simulation.Height * 4 / 16)) { _simulation.AddWater(x, y, 2.0f); _simulation.SetSolid(x, y, true); } } } }
public abstract void Init(IFluidSimulation simulation);
public MazeDriver(IFluidSimulation simulation) { _simulation = simulation; for (int y = 0; y < _simulation.Height; ++y) { for (int x = 0; x < _simulation.Width; ++x) { _simulation.SetHeight(x, y, 1.0f); _simulation.SetSolid(x, y, true); } } int[,] maze = new int[_mazeSize, _mazeSize]; for (int y = 0; y < _mazeSize; y += 2) { for (int x = 0; x < _mazeSize; x += 2) { maze[x,y] = 1; } } int numWalls = 2 * (_mazeSize/2) * ((_mazeSize/2) - 1); int[] walls = new int[numWalls]; for (int i = 0; i < numWalls; ++i) { walls[i] = i; } System.Random rng = new System.Random(); for (int i = 0; i < numWalls-1; ++i) { int swapWith = rng.Next(numWalls - i) + i; if (swapWith != i) { int old = walls[i]; walls[i] = walls[swapWith]; walls[swapWith] = old; } } maze[_mazeSize/4 * 2, _mazeSize/4 * 2] = 2; int count = (_mazeSize/2) * (_mazeSize/2) - 1; int pos = 0; while (count > 0) { ++pos; if (pos >= numWalls) pos = 0; int x, y, dx, dy; if (walls[pos] < numWalls / 2) { x = 2 * (walls[pos] % (_mazeSize/2)); y = 1 + 2 * (walls[pos] / (_mazeSize/2)); dx = 0; dy = 1; } else { y = 2 * ((walls[pos] - numWalls/2) % (_mazeSize/2)); x = 1 + 2 * ((walls[pos] - numWalls/2) / (_mazeSize/2)); dy = 0; dx = 1; } if (maze[x, y] != 0) continue; if (maze[x+dx, y+dy] != 2 && maze[x-dx, y-dy] != 2) continue; if (maze[x+dx, y+dy] == 2 && maze[x-dx, y-dy] == 2) continue; maze[x+dx, y+dy] = 2; maze[x-dx, y-dy] = 2; maze[x, y] = 2; --count; } for (int y = 0; y < _mazeSize; ++y) { for (int x = 0; x < _mazeSize; ++x) { if (maze[x, y] != 0) ClearSquare(x, y); } } }