internal void FinalizeMesh(MeshParts tags, LayerSubMesh subMesh) { if (subMesh.verts.Count > 0) { subMesh.FinalizeMesh(tags); } }
// 仮 private static void MakeBaseGeometry(Section section, LayerSubMesh sm, AltitudeLayer altitudeLayer) { sm.Clear(MeshParts.Verts | MeshParts.Tris); CellRect cellRect = new CellRect(section.botLeft.x, section.botLeft.z, 17, 17); cellRect.ClipInsideMap(section.map); float y = Altitudes.AltitudeFor(altitudeLayer); sm.verts.Capacity = cellRect.Area * 9; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)j + 0.5f)); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i + 0.5f, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.5f)); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.verts.Add(new Vector3((float)i + 0.5f, y, (float)j)); sm.verts.Add(new Vector3((float)i + 0.5f, y, (float)j + 0.5f)); } } int num = cellRect.Area * 8 * 3; sm.tris.Capacity = num; int num2 = 0; while (sm.tris.Count < num) { sm.tris.Add(num2 + 7); sm.tris.Add(num2); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 2); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 4); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 6); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 8); num2 += 9; } sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris); }
public static void MakeBaseGeometry(Section section, LayerSubMesh sm, AltitudeLayer altitudeLayer) { CellRect cellRect = new CellRect(section.botLeft.x, section.botLeft.z, 17, 17); cellRect.ClipInsideMap(section.map); float y = Altitudes.AltitudeFor(altitudeLayer); sm.verts.Capacity = cellRect.Area * 9; for (int x = cellRect.minX; x <= cellRect.maxX; x++) { for (int z = cellRect.minZ; z <= cellRect.maxZ; z++) { sm.verts.Add(new Vector3((float)x, y, (float)z)); sm.verts.Add(new Vector3((float)x, y, (float)z + 0.5f)); sm.verts.Add(new Vector3((float)x, y, (float)(z + 1))); sm.verts.Add(new Vector3((float)x + 0.5f, y, (float)(z + 1))); sm.verts.Add(new Vector3((float)(x + 1), y, (float)(z + 1))); sm.verts.Add(new Vector3((float)(x + 1), y, (float)z + 0.5f)); sm.verts.Add(new Vector3((float)(x + 1), y, (float)z)); sm.verts.Add(new Vector3((float)x + 0.5f, y, (float)z)); sm.verts.Add(new Vector3((float)x + 0.5f, y, (float)z + 0.5f)); } } int num = cellRect.Area * 8 * 3; sm.tris.Capacity = num; int num2 = 0; while (sm.tris.Count < num) { sm.tris.Add(num2 + 7); sm.tris.Add(num2); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 2); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 4); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 6); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 1); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 3); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 8); sm.tris.Add(num2 + 5); sm.tris.Add(num2 + 7); sm.tris.Add(num2 + 8); num2 += 9; } sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris); }
public override IEnumerable Regenerate() { Log.Message("Start world rendering"); foreach (object obj in base.Regenerate()) { yield return(obj); } IEnumerator enumerator = null; if (PurpleIvyData.BiomesToRenderNow.Count == 0) { yield break; } foreach (object obj2 in this.CalculateInterpolatedVerticesParams()) { yield return(obj2); } foreach (int num in PurpleIvyData.BiomesToRenderNow) { if (num >= 0) { //Log.Message("RENDER: " + num.ToString()); int ind = 0; Material material = Find.WorldGrid[num].biome.DrawMaterial; LayerSubMesh subMesh = base.GetSubMesh(material); subMesh.finalized = false; Find.World.grid.GetTileVertices(num, this._vertices); int startVertIndex = subMesh.verts.Count; int currentIndex = 0; int maxCount = this._vertices.Count; while (currentIndex < maxCount) { subMesh.verts.Add(this._vertices[currentIndex] + this._vertices[currentIndex].normalized * 0.012f); subMesh.uvs.Add(this.elevationValues[ind]); ind++; if (currentIndex < maxCount - 2) { subMesh.tris.Add(startVertIndex + currentIndex + 2); subMesh.tris.Add(startVertIndex + currentIndex + 1); subMesh.tris.Add(startVertIndex); } currentIndex++; } subMesh.FinalizeMesh(MeshParts.All); //PurpleIvyData.BiomesToRenderNow.Remove(num); } //base.FinalizeMesh(MeshParts.All); } List <int> .Enumerator enumerator2 = default(List <int> .Enumerator); this.elevationValues.Clear(); this.elevationValues.TrimExcess(); yield break; yield break; }
public static bool ShouldDraw(SectionLayer __instance) { TerrainDef def = TerrainDef.Named("HardVacuum"); Map map = Find.CurrentMap; // if we aren't in space, abort! if (map.terrainGrid.TerrainAt(IntVec3.Zero).defName != def.defName) { return(true); } if (__instance.GetType().Name == "SectionLayer_SunShadows") { return(false); } if (__instance.GetType().Name == "SectionLayer_LightingOverlay") { oldSkyGlow = map.skyManager.CurSkyGlow; MatBases.LightOverlay.color = new Color(1.0f, 1.0f, 1.0f); map.skyManager.ForceSetCurSkyGlow(1.0f); } if (__instance.GetType().Name == "SectionLayer_Terrain") { float num = (float)UI.screenWidth / (float)UI.screenHeight; Vector3 center = Find.CameraDriver.GetComponent <Camera>().transform.position; float cellsHigh = UI.screenHeight / Find.CameraDriver.CellSizePixels; float cellsWide = cellsHigh * num; //recalculate uvs for planet texture. LayerSubMesh mesh = __instance.GetSubMesh(RenderPlanetBehindMap.PlanetMaterial); if (mesh != null) { mesh.Clear(MeshParts.UVs); for (int i = 0; i < mesh.verts.Count; i++) { float xdiff = mesh.verts[i].x - center.x; float xfromEdge = xdiff + cellsWide / 2f; float zdiff = mesh.verts[i].z - center.z; float zfromEdge = zdiff + cellsHigh / 2f; mesh.uvs.Add(new Vector3(xfromEdge / cellsWide, zfromEdge / cellsHigh, 0.0f)); } mesh.FinalizeMesh(MeshParts.UVs); } } return(true); }
/* * public override void DrawLayer() * { * if (!this.Visible) * { * return; * } * int count = this.subMeshes.Count; * for (int i = 0; i < count; i++) * { * LayerSubMesh layerSubMesh = this.subMeshes[i]; * Vector3 s = new Vector3(.28f, 1f, .28f); * Matrix4x4 matrix = default(Matrix4x4); * matrix.SetTRS(vector, Quaternion.AngleAxis(angle, Vector3.up), s); * if (layerSubMesh.finalized && !layerSubMesh.disabled) * { * Graphics.DrawMesh(layerSubMesh.mesh, Vector3.zero, Quaternion.identity, layerSubMesh.material, 0); * } * } * } */ // Token: 0x060047BA RID: 18362 RVA: 0x0021ADFC File Offset: 0x002191FC public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(AMXBMatBases.Hive); if (subMesh.mesh.vertexCount == 0) { SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.Terrain); } subMesh.Clear(MeshParts.Colors); MapComponent_HiveGrid _AvPHiveCreep = base.Map.GetComponent <MapComponent_HiveGrid>(); // Log.Message(string.Format(" 6 {0}", _AvPHiveCreep.DepthGridDirect_Unsafe)); float[] depthGridDirect_Unsafe = _AvPHiveCreep.DepthGridDirect_Unsafe; CellRect cellRect = this.section.CellRect; int num = base.Map.Size.z - 1; int num2 = base.Map.Size.x - 1; bool flag = false; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)]; int num4 = cellIndices.CellToIndex(i, j - 1); float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j - 1); float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j); float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j + 1); float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i, j + 1); float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j + 1); float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j); float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j - 1); float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f; this.vertDepth[1] = (num7 + num3) / 2f; this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f; this.vertDepth[3] = (num9 + num3) / 2f; this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f; this.vertDepth[5] = (num11 + num3) / 2f; this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f; this.vertDepth[7] = (num5 + num3) / 2f; this.vertDepth[8] = num3; for (int k = 0; k < 9; k++) { if (this.vertDepth[k] > 0.01f) { ; flag = true; } subMesh.colors.Add(SectionLayer_Hive.HiveDepthColor(this.vertDepth[k])); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }
private static void _Regenerate(this object obj) { if (!MatBases.SunShadow.shader.isSupported) { return; } Section section = obj.Section(); var sectionLayer = obj as SectionLayer; LayerSubMesh subMesh = sectionLayer.GetSubMesh(MatBases.IndoorMask); subMesh.Clear(MeshParts.All); Building[] innerArray = Find.EdificeGrid.InnerArray; CellRect cellRect = new CellRect( section.botLeft.x, section.botLeft.z, 17, 17); cellRect.ClipInsideMap(); subMesh.verts.Capacity = cellRect.Area * 2; subMesh.tris.Capacity = cellRect.Area * 4; float y = Altitudes.AltitudeFor(AltitudeLayer.MetaOverlays); for (int index1 = cellRect.minX; index1 <= cellRect.maxX; ++index1) { for (int index2 = cellRect.minZ; index2 <= cellRect.maxZ; ++index2) { IntVec3 c1 = new IntVec3(index1, 0, index2); if (!(bool)_HideRainPrimary.Invoke(obj, new System.Object[] { c1 })) { bool flag1 = c1.Roofed(); bool flag2 = false; if (flag1) { for (int index3 = 0; index3 < 8; ++index3) { IntVec3 c2 = c1 + GenAdj.AdjacentCells[index3]; if ( (c2.InBounds()) && (!(bool)_HideRainPrimary.Invoke(obj, new System.Object[] { c2 })) ) { flag2 = true; break; } } } if ( (!flag1) || (!flag2) ) { continue; } } Thing thing = innerArray[CellIndices.CellToIndex(index1, index2)]; float num = (thing == null) || (thing.def.passability != Traversability.Impassable) && ( (thing.def.thingClass != typeof(Building_Door)) || (!thing.def.thingClass.IsSubclassOf(typeof(Building_Door))) ) ? 0.16f : 0.0f; subMesh.verts.Add(new Vector3((float)index1 - num, y, (float)index2 - num)); subMesh.verts.Add(new Vector3((float)index1 - num, y, (float)(index2 + 1) + num)); subMesh.verts.Add(new Vector3((float)(index1 + 1) + num, y, (float)(index2 + 1) + num)); subMesh.verts.Add(new Vector3((float)(index1 + 1) + num, y, (float)index2 - num)); int count = subMesh.verts.Count; subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 3); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 4); subMesh.tris.Add(count - 2); subMesh.tris.Add(count - 1); } } if (subMesh.verts.Count <= 0) { return; } subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris); }
public override void Regenerate() { LayerSubMesh subMesh = base.GetSubMesh(Verse.MatBases.Snow); // LayerSubMesh subMesh = base.GetSubMesh(MatBases.Frost); // for some reason the custom one was causing a huge memory issue and rendering in giant squares :( if (subMesh.mesh.vertexCount == 0) { // SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.MoteLow); SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.LayingPawn); //so frost forms over items/plants } subMesh.Clear(MeshParts.Colors); float[] depthGridDirect_Unsafe = base.Map.GetComponent <FrostGrid>().DepthGridDirect_Unsafe; CellRect cellRect = this.section.CellRect; int num = base.Map.Size.z - 1; int num2 = base.Map.Size.x - 1; bool flag = false; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) // this is what renders it all blobby, I think { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { float num3 = depthGridDirect_Unsafe[cellIndices.CellToIndex(i, j)]; int num4 = cellIndices.CellToIndex(i, j - 1); float num5 = (j <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j - 1); float num6 = (j <= 0 || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j); float num7 = (i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i - 1, j + 1); float num8 = (j >= num || i <= 0) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i, j + 1); float num9 = (j >= num) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j + 1); float num10 = (j >= num || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j); float num11 = (i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; num4 = cellIndices.CellToIndex(i + 1, j - 1); float num12 = (j <= 0 || i >= num2) ? num3 : depthGridDirect_Unsafe[num4]; this.vertDepth[0] = (num5 + num6 + num7 + num3) / 4f; this.vertDepth[1] = (num7 + num3) / 2f; this.vertDepth[2] = (num7 + num8 + num9 + num3) / 4f; this.vertDepth[3] = (num9 + num3) / 2f; this.vertDepth[4] = (num9 + num10 + num11 + num3) / 4f; this.vertDepth[5] = (num11 + num3) / 2f; this.vertDepth[6] = (num11 + num12 + num5 + num3) / 4f; this.vertDepth[7] = (num5 + num3) / 2f; this.vertDepth[8] = num3; for (int k = 0; k < 9; k++) { if (this.vertDepth[k] > 0.01f) { flag = true; } subMesh.colors.Add(SectionLayer_Frost.FrostDepthColor(this.vertDepth[k])); } } } if (flag) { subMesh.disabled = false; subMesh.FinalizeMesh(MeshParts.Colors); } else { subMesh.disabled = true; } }