/// <summary> /// Generates mesh on CPU for a given chunk. /// Use for solid (terrain) mesh generation, since the generated mesh stays on CPU and can be assigned to a MeshCollider. /// </summary> public void GenerateMeshCPU(Chunk chunk, bool solid) { if (solid) { GameObject terrainMeshGo = chunk.RenderData.Terrain; if (terrainMeshGo != null) { Mesh mesh = GetMesh(chunk.WorldPos, true); terrainMeshGo.GetComponent <MeshFilter>().mesh = mesh; terrainMeshGo.GetComponent <MeshRenderer>().sharedMaterial = TerrainMaterial; terrainMeshGo.GetComponent <MeshCollider>().sharedMesh = mesh; } } else { foreach (var renderData in chunk.RenderData.Fluid) { Viscosity viscosity = renderData.Key; GameObject fluidMeshGo = (GameObject)chunk.RenderData.Fluid[viscosity].data[0]; Mesh mesh = GetMesh(chunk.WorldPos, false, viscosity); fluidMeshGo.GetComponent <MeshFilter>().mesh = mesh; fluidMeshGo.GetComponent <MeshRenderer>().sharedMaterial = FluidProcessor.Types[viscosity].material; } } }
public static void viscosity_values_test() //****************************************************************************80 // // Purpose: // // VISCOSITY_VALUES_TEST tests VISCOSITY_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 12 June 2007 // // Author: // // John Burkardt // { double eta = 0; double p = 0; double tc = 0; Console.WriteLine(""); Console.WriteLine("VISCOSITY_VALUES_TEST:"); Console.WriteLine(" VISCOSITY_VALUES stores values of"); Console.WriteLine(" the viscosity of water"); Console.WriteLine(" as a function of temperature and pressure."); Console.WriteLine(""); Console.WriteLine(" T P ETA(T,P)"); Console.WriteLine(""); int n_data = 0; for (;;) { Viscosity.viscosity_values(ref n_data, ref tc, ref p, ref eta); if (n_data == 0) { break; } Console.WriteLine(" " + tc.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + p.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + eta.ToString(CultureInfo.InvariantCulture).PadLeft(12) + ""); } }
private Mesh GetMesh(Vector3 chunkWorldPos, bool solid, Viscosity viscosity = default) { _vertices.Clear(); _triangles.Clear(); for (int voxelId = 0; voxelId < WorldGridInfo.kTotalVoxelsInChunk; voxelId++) { VectorI3 posI = WorldGridInfo.VoxelIdToChunkVoxel(voxelId); Vector3 pos = new Vector3(posI.x, posI.y, posI.z); _cubeVertices[0] = pos + new Vector3(0, 0, 1); _cubeVertices[1] = pos + new Vector3(1, 0, 1); _cubeVertices[2] = pos + new Vector3(1, 0, 0); _cubeVertices[3] = pos + new Vector3(0, 0, 0); _cubeVertices[4] = pos + new Vector3(0, 1, 1); _cubeVertices[5] = pos + new Vector3(1, 1, 1); _cubeVertices[6] = pos + new Vector3(1, 1, 0); _cubeVertices[7] = pos + new Vector3(0, 1, 0); for (int i = 0; i < _cubeVertices.Length; i++) { pos = _cubeVertices[i] + Vector3.one; Voxel voxel = _borderedChunk[(int)(pos.x * Chunk.kColumnBordered + pos.y * Chunk.kRowBordered + pos.z)]; _cubeVertices[i] *= WorldGridInfo.kVoxelSize; _cubeVertices[i] += chunkWorldPos; if (solid) { _cubeValues[i] = !_worldApi.IsBorder(in _cubeVertices[i]) ? voxel.Solid * Voxel.kByteToFloat : 0; } else { _cubeValues[i] = voxel.Viscosity == (byte)viscosity ? voxel.Fluid * Voxel.kByteToFloat : 0; } } Polygonise(); } Mesh mesh = new Mesh(); mesh.vertices = new List <Vector3>(_vertices.Keys).ToArray(); mesh.triangles = _triangles.ToArray(); mesh.RecalculateNormals(); return(mesh); }
/// <summary> /// Get the significant details of what needs approval /// </summary> /// <returns>A list of strings</returns> public override IDictionary <string, string> SignificantDetails() { IDictionary <string, string> returnList = base.SignificantDetails(); returnList.Add("Conductive", Conductive.ToString()); returnList.Add("Magnetic", Magnetic.ToString()); returnList.Add("Flammable", Flammable.ToString()); returnList.Add("Viscosity", Viscosity.ToString()); returnList.Add("Density", Density.ToString()); returnList.Add("Mallebility", Mallebility.ToString()); returnList.Add("Ductility", Ductility.ToString()); returnList.Add("Porosity", Porosity.ToString()); returnList.Add("Solid Point", SolidPoint.ToString()); returnList.Add("Gas Point", GasPoint.ToString()); returnList.Add("Temperature Retention", TemperatureRetention.ToString()); foreach (ISensoryEvent desc in Descriptives) { returnList.Add("Descriptives", string.Format("{0} ({1}): {2}", desc.SensoryType, desc.Strength, desc.Event.ToString())); } return(returnList); }