void ShowCellData(string cellName, FluidSimulator simulator, FluidCellIndex cellIndex, ref bool showCell, bool showOperationData) { return; int gridSize = simulator.fluidParameters.gridSize; if (cellIndex.x >= 0 && cellIndex.y >= 0 && cellIndex.z >= 0 && cellIndex.x < gridSize && cellIndex.y < gridSize && cellIndex.z < gridSize) { FluidCell cell = simulator.GetCell(cellIndex); showCell = EditorGUILayout.Foldout(showCell, string.Format("{0} {1}", cellName, cellIndex.ToString())); if (showCell) { EditorGUILayout.LabelField("Density", "" + cell.density); EditorGUILayout.LabelField("Velocity", "" + cell.velocity); EditorGUILayout.LabelField("Raw Divergence", "" + cell.rawDivergence); EditorGUILayout.LabelField("Relaxed Divergence", "" + cell.relaxedDivergence); if (showOperationData) { FluidCellOperationData operationData = simulator.GetCellOperationData(cellIndex); EditorGUILayout.LabelField("Advect Index Velocity", "" + operationData.advectIdVelocity.ToString()); EditorGUILayout.LabelField("Advect Past Index", "" + operationData.advectPastId.ToString()); EditorGUILayout.LabelField("Advect SamplePercentages", "" + operationData.advectSamplePercentages); } EditorGUILayout.Space(); } } }
public void Initialize(FluidSimulator simulator) { if (Simulator == null) { Simulator = simulator; } }
public override void OnInspectorGUI() { FluidSimulator sim = (FluidSimulator)target; base.OnInspectorGUI(); string[] options = { "High", "Mid", "Low" }; int quality = 0; if (sim.Resolution == 256) { quality = 1; } else if (sim.Resolution == 128) { quality = 2; } quality = EditorGUILayout.Popup("Quality", quality, options); switch (quality) { case 0: sim.Resolution = 512; break; case 1: sim.Resolution = 256; break; default: sim.Resolution = 128; break; } sim.Vorticity = EditorGUILayout.Slider("Vorticity", sim.Vorticity, 0.0f, 50.0f); sim.Viscosity = EditorGUILayout.Slider("Viscosity", sim.Viscosity * 10.0f, 0.0f, 1.0f) / 10.0f; m_showAdvanced = Foldout(m_showAdvanced, "Advanced", true, EditorStyles.foldout); if (m_showAdvanced) { EditorGUI.indentLevel++; sim.m_cacheVelocity = EditorGUILayout.Toggle("Cache Velocity", sim.m_cacheVelocity); sim.Iterations = EditorGUILayout.IntSlider("Simulation Quality", sim.Iterations, 0, 100); sim.Speed = EditorGUILayout.Slider("Simulation Speed", sim.Speed, 0.0f, 1000.0f); float disp_min = 0.9f; float disp_max = 1.0f; float range = disp_max - disp_min; float vel_min = 0.97f; float vel_max = 1.0f; range = vel_max - vel_min; float velocity_dissipation = Mathf.Clamp(sim.VelocityDissipation, vel_min, vel_max); velocity_dissipation = (velocity_dissipation - vel_min) / range; velocity_dissipation = EditorGUILayout.Slider("Velocity Dissipation", velocity_dissipation, 0.0f, 1.0f); sim.VelocityDissipation = velocity_dissipation * range + vel_min; EditorGUI.indentLevel--; } EditorUtility.SetDirty(sim); }
void Update() { Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, depthTarget.transform.position.z)); mouseMove = mousePosition - oldMousePos; oldMousePos = mousePosition; SelectedFluid = null; FluidCollider selectedCollider = null; RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { selectedCollider = hit.collider.GetComponent <FluidCollider>(); if (selectedCollider != null) { SelectedFluid = selectedCollider.Simulator; //FluidCellIndex selectedIndex = new FluidCellIndex(selected.XIndex, selected.YIndex, 0); //SelectedFluid.SelectedCellIndex = selectedIndex; selectedCollider.SelectCell(hit.point); } } if (SelectedFluid != null) { bool leftMouse = Input.GetMouseButton(0); bool rightMouse = Input.GetMouseButton(1); bool middleMouse = Input.GetMouseButton(2); if (leftMouse || rightMouse || middleMouse) { float densityChange = 0; Vector3 force = Vector3.zero; if (leftMouse) { densityChange += densityChangeRate; force += mouseMove * forceRate; } if (rightMouse) { densityChange -= densityChangeRate; force += mouseMove * forceRate; } if (middleMouse && !leftMouse && !rightMouse) { force += mouseMove * forceRate; } if (densityChange != 0 || force.sqrMagnitude > 0) { //SelectedFluid.AddExternal(SelectedFluid.SelectedCellIndex, densityChange, densityChangeRadius, force, forceRadius); //selectedCollider.AddExternal(hit.point, densityChange, densityChangeRadius, force, forceRadius); FluidInputSustainerFactory.Instance.Create(selectedCollider, hit.point, densityChange, densityChangeRadius, force, forceRadius, 0.3f, 0f, 2f, 4f); } } } }
public void BuildFluid(Block block, int x, int y, int z, MeshData meshData) { Vector3i local = Map.ToLocalPos(x, y, z); Vector3i worldPos = new Vector3i(x, y, z); AdjacentBlocks neighbors = Map.GetAdjacentBlocks(x, y, z); int curLevel = block.FluidLevel; float offset = FluidSimulator.GetOffset(curLevel); if (IsFluidFaceVisible(curLevel, x, y, z + 1, neighbors.front, Direction.Back)) { BuildFrontFluid(block, local.x, local.y, local.z, meshData, Direction.Front, offset, neighbors.front); BuildSquareLight(Axis.Z, worldPos, meshData, squareOffsetFront); } if (IsFluidFaceVisible(curLevel, x, y, z - 1, neighbors.back, Direction.Front)) { BuildBackFluid(block, local.x, local.y, local.z, meshData, Direction.Back, offset, neighbors.back); BuildSquareLight(Axis.Z, worldPos, meshData, squareOffsetBack); } if (IsFluidFaceVisible(curLevel, x + 1, y, z, neighbors.right, Direction.Left)) { BuildRightFluid(block, local.x, local.y, local.z, meshData, Direction.Right, offset, neighbors.right); BuildSquareLight(Axis.X, worldPos, meshData, squareOffsetRight); } if (IsFluidFaceVisible(curLevel, x - 1, y, z, neighbors.left, Direction.Right)) { BuildLeftFluid(block, local.x, local.y, local.z, meshData, Direction.Left, offset, neighbors.left); BuildSquareLight(Axis.X, worldPos, meshData, squareOffsetLeft); } if (IsFluidFaceVisible(curLevel, x, y + 1, z, neighbors.top, Direction.Down)) { BuildTopFluid(block, local.x, local.y, local.z, meshData, Direction.Up, offset); BuildSquareLight(Axis.Y, worldPos, meshData, squareOffsetTop); } if (IsFluidFaceVisible(curLevel, x, y - 1, z, neighbors.bottom, Direction.Up)) { BuildBottomFluid(block, local.x, local.y, local.z, meshData, Direction.Down); BuildSquareLight(Axis.Y, worldPos, meshData, squareOffsetBottom); } }
void Awake() { FamilyName = name.Substring(0, name.IndexOf("Dispatcher")).TrimEnd(); gameObject.name = string.Format("{0} Dispatcher", FamilyName); string nullReference = "Attempting to use {0} {1} that does not exist."; for (int i = 0; i < simulatorOptions.Count; i++) { if (simulator == null && simulatorOptions[i].mode == simulatorMode) { simulator = simulatorOptions[i].simulator; simulator.gameObject.SetActive(true); } else { Destroy(simulatorOptions[i].simulator.gameObject); simulatorOptions.RemoveAt(i); i--; } } if (simulator == null) { throw new System.NullReferenceException(string.Format(nullReference, simulatorMode, "Simulator")); } for (int i = 0; i < rendererOptions.Count; i++) { if (renderer == null && rendererOptions[i].mode == rendererMode) { renderer = rendererOptions[i].renderer; renderer.gameObject.SetActive(true); } else { Destroy(rendererOptions[i].renderer.gameObject); rendererOptions.RemoveAt(i); i--; } } if (renderer == null) { throw new System.NullReferenceException(string.Format(nullReference, rendererMode, "Renderer")); } }
private void BuildLeftFluid(Block block, int x, int y, int z, MeshData meshData, int dir, float offset, Block adj) { AddIndices(meshData); float adjOffset = -0.5f; if (adj.IsFluid()) { int adjLevel = adj.FluidLevel; adjOffset = FluidSimulator.GetOffset(adjLevel); } meshData.AddVertex(new Vector3(-0.5f, adjOffset, -0.5f), x, y, z); meshData.AddVertex(new Vector3(-0.5f, offset, -0.5f), x, y, z); meshData.AddVertex(new Vector3(-0.5f, offset, 0.5f), x, y, z); meshData.AddVertex(new Vector3(-0.5f, adjOffset, 0.5f), x, y, z); AddFluidUVs(block, dir, meshData, offset - adjOffset); }
public void OnPlace(Vector3i normal, int x, int y, int z) { switch (ID) { case BlockID.Water: FluidLevel = FluidSimulator.MaxFluidLevel; FluidSimulator.AddFluidAndFlow(x, y, z, this); break; case BlockID.Pumpkin: case BlockID.StoneSlope: case BlockID.GrassSlope: BlockDirection = Direction.GetOpposite(Player.GetRotation()); break; default: return; } }
public void Initialize(FluidSimulator simulator, FluidRenderer fluidRenderer, FluidCell cellTemplate, int xIndex, int yIndex) { if (this.FluidRenderer != null) { Debug.LogError("Attempting to re-initialize FluidCellRenderer."); } this.fluidRenderer = fluidRenderer; XIndex = xIndex; YIndex = yIndex; cell = new FluidCell() { density = cellTemplate.density, velocity = cellTemplate.velocity, rawDivergence = cellTemplate.rawDivergence, relaxedDivergence = cellTemplate.relaxedDivergence, }; this.simulator = simulator; GetComponent <FluidColliderCell>().Initialize(simulator, new FluidCellIndex(xIndex, yIndex, 0)); }
public override void OnInspectorGUI() { FluidSimulator simulator = (FluidSimulator)target; GUILayout.BeginHorizontal(); if (GUILayout.Button("Reset")) { simulator.resetFluid = true; } if (GUILayout.Button(!simulator.pauseFluid ? "Pause" : "Resume")) { simulator.pauseFluid = !simulator.pauseFluid; } if (GUILayout.Button("Step")) { simulator.stepFluid = true; } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Family", simulator.FamilyName); // Default Inspector Rendering. base.OnInspectorGUI(); if (Application.isPlaying && simulator.isActiveAndEnabled) { EditorGUILayout.LabelField("Global Density", "" + simulator.GlobalDensity); // TODO Display cell and cell data in a layout //EditorGUILayout.LabelField("Selected Cell", simulator.SelectedCell.ToString()); EditorGUILayout.Space(); GUILayout.Label("Cell Data", EditorStyles.boldLabel); FluidCellIndex selectedIndex = simulator.SelectedCellIndex; FluidCellOperationData operationData = simulator.GetCellOperationData(selectedIndex); ShowCellData("Selected", simulator, selectedIndex, ref showSelected, true); ShowCellData("Left", simulator, operationData.leftId, ref showLeft, false); ShowCellData("Right", simulator, operationData.rightId, ref showRight, false); ShowCellData("Down", simulator, operationData.downId, ref showDown, false); ShowCellData("Up", simulator, operationData.upId, ref showUp, false); } }
public void OnDelete(int x, int y, int z) { switch (ID) { case BlockID.Water: if (Map.GetBlockSafe(x, y + 1, z).IsFluid()) { Map.SetBlock(x, y, z, new Block(BlockID.Water, FluidSimulator.MaxFluidLevel)); return; } else { FluidSimulator.RemoveFluidAndUnflow(x, y, z, this); break; } default: for (int i = 0; i < Vector3i.directions.Length; i++) { Vector3i dir = Vector3i.directions[i]; int facing; Block block = Map.GetBlockSafe(x + dir.x, y + dir.y, z + dir.z); if (block.IsAttached(out facing)) { if (dir.GetNormalDirection() == facing) { Map.SetBlock(x + dir.x, y + dir.y, z + dir.z, new Block(BlockID.Air)); } } } FluidSimulator.TryFlowSurrounding(x, y, z); break; } }
public string Initialize(FluidSimulator simulator, FluidInfo info) { string result = null; if (Simulator != null) { result = "Attempting to re-initialize FluidRenderer"; } this.Simulator = simulator; fluidParameters = info.fluidParameters; cellParameters = info.cellParameters; visualizationFlags = info.visualizationFlags; if (string.IsNullOrEmpty(result)) { Profiler.BeginSample("FluidRenderer.GenerateCells"); result = generateCells(); Profiler.EndSample(); } Profiler.EndSample(); return(result); }
public void Initialize(FluidSimulator simulator, FluidCellIndex index) { this.index = index; base.Initialize(simulator); }
void Start() { simulator = FindObjectOfType <FluidSimulator> (); }
// Use this for initialization void Start() { force = this.GetComponent <ConstantForce> (); simulator = FindObjectOfType <FluidSimulator> (); }