Esempio n. 1
0
        public override void Regenerate()
        {
            if (!MatBases.SunShadow.shader.isSupported)
            {
                return;
            }
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            float      y          = AltitudeLayer.Shadows.AltitudeFor();
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.SunShadow);

            subMesh.Clear(MeshParts.All);
            subMesh.verts.Capacity  = cellRect.Area * 2;
            subMesh.tris.Capacity   = cellRect.Area * 4;
            subMesh.colors.Capacity = cellRect.Area * 2;
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    if (thing != null && thing.def.staticSunShadowHeight > 0f)
                    {
                        float   staticSunShadowHeight = thing.def.staticSunShadowHeight;
                        Color32 item  = new Color32(0, 0, 0, (byte)(255f * staticSunShadowHeight));
                        int     count = subMesh.verts.Count;
                        subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                        subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                        subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                        subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        subMesh.colors.Add(SectionLayer_SunShadows.LowVertexColor);
                        int count2 = subMesh.verts.Count;
                        subMesh.tris.Add(count2 - 4);
                        subMesh.tris.Add(count2 - 3);
                        subMesh.tris.Add(count2 - 2);
                        subMesh.tris.Add(count2 - 4);
                        subMesh.tris.Add(count2 - 2);
                        subMesh.tris.Add(count2 - 1);
                        if (i > 0)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i - 1, j)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count3 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                                subMesh.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count + 1);
                                subMesh.tris.Add(count);
                                subMesh.tris.Add(count3);
                                subMesh.tris.Add(count3);
                                subMesh.tris.Add(count3 + 1);
                                subMesh.tris.Add(count + 1);
                            }
                        }
                        if (i < base.Map.Size.x - 1)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i + 1, j)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count4 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count + 2);
                                subMesh.tris.Add(count4);
                                subMesh.tris.Add(count4 + 1);
                                subMesh.tris.Add(count4 + 1);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count + 2);
                            }
                        }
                        if (j > 0)
                        {
                            thing = innerArray[cellIndices.CellToIndex(i, j - 1)];
                            if (thing == null || thing.def.staticSunShadowHeight < staticSunShadowHeight)
                            {
                                int count5 = subMesh.verts.Count;
                                subMesh.verts.Add(new Vector3((float)i, y, (float)j));
                                subMesh.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                subMesh.colors.Add(item);
                                subMesh.colors.Add(item);
                                subMesh.tris.Add(count);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count5);
                                subMesh.tris.Add(count + 3);
                                subMesh.tris.Add(count5 + 1);
                                subMesh.tris.Add(count5);
                            }
                        }
                    }
                }
            }
            if (subMesh.verts.Count > 0)
            {
                subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors);
                float   num  = Mathf.Max(15f, 15f);
                Vector3 size = subMesh.mesh.bounds.size;
                size.x += 2f * num + 2f;
                size.z += 2f * num + 2f;
                subMesh.mesh.bounds = new Bounds(subMesh.mesh.bounds.center, size);
            }
        }
Esempio n. 2
0
        public override void Regenerate()
        {
            if (!MatBases.SunShadow.shader.isSupported)
            {
                return;
            }
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.IndoorMask);

            subMesh.Clear(MeshParts.All);
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            subMesh.verts.Capacity = cellRect.Area * 2;
            subMesh.tris.Capacity  = cellRect.Area * 4;
            float       y           = AltitudeLayer.MetaOverlays.AltitudeFor();
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                int j = cellRect.minZ;
                while (j <= cellRect.maxZ)
                {
                    IntVec3 intVec = new IntVec3(i, 0, j);
                    if (this.HideRainPrimary(intVec))
                    {
                        goto IL_16E;
                    }
                    bool flag  = intVec.Roofed(base.Map);
                    bool flag2 = false;
                    if (flag)
                    {
                        for (int k = 0; k < 8; k++)
                        {
                            IntVec3 c = intVec + GenAdj.AdjacentCells[k];
                            if (c.InBounds(base.Map))
                            {
                                if (this.HideRainPrimary(c))
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (flag && flag2)
                    {
                        goto IL_16E;
                    }
IL_29D:
                    j++;
                    continue;
IL_16E:
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    float num;
                    if (thing != null && (thing.def.passability == Traversability.Impassable || thing.def.IsDoor))
                    {
                        num = 0f;
                    }
                    else
                    {
                        num = 0.16f;
                    }
                    subMesh.verts.Add(new Vector3((float)i - num, y, (float)j - num));
                    subMesh.verts.Add(new Vector3((float)i - num, y, (float)(j + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)(j + 1) + num));
                    subMesh.verts.Add(new Vector3((float)(i + 1) + num, y, (float)j - 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);
                    goto IL_29D;
                }
            }
            if (subMesh.verts.Count > 0)
            {
                subMesh.FinalizeMesh(MeshParts.Verts | MeshParts.Tris);
            }
        }
Esempio n. 3
0
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.FogOfWar);

            if (subMesh.mesh.vertexCount == 0)
            {
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.FogOfWar);
            }
            subMesh.Clear(MeshParts.Colors);
            bool[]      fogGrid     = base.Map.fogGrid.fogGrid;
            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++)
                {
                    if (fogGrid[cellIndices.CellToIndex(i, j)])
                    {
                        for (int k = 0; k < 9; k++)
                        {
                            this.vertsCovered[k] = true;
                        }
                    }
                    else
                    {
                        for (int l = 0; l < 9; l++)
                        {
                            this.vertsCovered[l] = false;
                        }
                        if (j < num && fogGrid[cellIndices.CellToIndex(i, j + 1)])
                        {
                            this.vertsCovered[2] = true;
                            this.vertsCovered[3] = true;
                            this.vertsCovered[4] = true;
                        }
                        if (j > 0 && fogGrid[cellIndices.CellToIndex(i, j - 1)])
                        {
                            this.vertsCovered[6] = true;
                            this.vertsCovered[7] = true;
                            this.vertsCovered[0] = true;
                        }
                        if (i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j)])
                        {
                            this.vertsCovered[4] = true;
                            this.vertsCovered[5] = true;
                            this.vertsCovered[6] = true;
                        }
                        if (i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j)])
                        {
                            this.vertsCovered[0] = true;
                            this.vertsCovered[1] = true;
                            this.vertsCovered[2] = true;
                        }
                        if (j > 0 && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j - 1)])
                        {
                            this.vertsCovered[0] = true;
                        }
                        if (j < num && i > 0 && fogGrid[cellIndices.CellToIndex(i - 1, j + 1)])
                        {
                            this.vertsCovered[2] = true;
                        }
                        if (j < num && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j + 1)])
                        {
                            this.vertsCovered[4] = true;
                        }
                        if (j > 0 && i < num2 && fogGrid[cellIndices.CellToIndex(i + 1, j - 1)])
                        {
                            this.vertsCovered[6] = true;
                        }
                    }
                    for (int m = 0; m < 9; m++)
                    {
                        byte a;
                        if (this.vertsCovered[m])
                        {
                            a    = byte.MaxValue;
                            flag = true;
                        }
                        else
                        {
                            a = 0;
                        }
                        subMesh.colors.Add(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, a));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
        public override void Regenerate()
        {
            Building[] innerArray = base.Map.edificeGrid.InnerArray;
            float      y          = AltitudeLayer.Shadows.AltitudeFor();
            CellRect   cellRect   = new CellRect(this.section.botLeft.x, this.section.botLeft.z, 17, 17);

            cellRect.ClipInsideMap(base.Map);
            LayerSubMesh sm = base.GetSubMesh(MatBases.EdgeShadow);

            sm.Clear(MeshParts.All);
            sm.verts.Capacity  = cellRect.Area * 4;
            sm.colors.Capacity = cellRect.Area * 4;
            sm.tris.Capacity   = cellRect.Area * 8;
            bool[]      array       = new bool[4];
            bool[]      array2      = new bool[4];
            bool[]      array3      = new bool[4];
            CellIndices cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minX; i <= cellRect.maxX; i++)
            {
                for (int j = cellRect.minZ; j <= cellRect.maxZ; j++)
                {
                    Thing thing = innerArray[cellIndices.CellToIndex(i, j)];
                    if (thing != null && thing.def.castEdgeShadows)
                    {
                        sm.verts.Add(new Vector3((float)i, y, (float)j));
                        sm.verts.Add(new Vector3((float)i, 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));
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                        int count = sm.verts.Count;
                        sm.tris.Add(count - 4);
                        sm.tris.Add(count - 3);
                        sm.tris.Add(count - 2);
                        sm.tris.Add(count - 4);
                        sm.tris.Add(count - 2);
                        sm.tris.Add(count - 1);
                    }
                    else
                    {
                        array[0]  = false;
                        array[1]  = false;
                        array[2]  = false;
                        array[3]  = false;
                        array2[0] = false;
                        array2[1] = false;
                        array2[2] = false;
                        array2[3] = false;
                        array3[0] = false;
                        array3[1] = false;
                        array3[2] = false;
                        array3[3] = false;
                        IntVec3   a = new IntVec3(i, 0, j);
                        IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround;
                        for (int k = 0; k < 4; k++)
                        {
                            IntVec3 c = a + cardinalDirectionsAround[k];
                            if (c.InBounds(base.Map))
                            {
                                thing = innerArray[cellIndices.CellToIndex(c)];
                                if (thing != null && thing.def.castEdgeShadows)
                                {
                                    array2[k]          = true;
                                    array[(k + 3) % 4] = true;
                                    array[k]           = true;
                                }
                            }
                        }
                        IntVec3[] diagonalDirectionsAround = GenAdj.DiagonalDirectionsAround;
                        for (int l = 0; l < 4; l++)
                        {
                            if (!array[l])
                            {
                                IntVec3 c = a + diagonalDirectionsAround[l];
                                if (c.InBounds(base.Map))
                                {
                                    thing = innerArray[cellIndices.CellToIndex(c)];
                                    if (thing != null && thing.def.castEdgeShadows)
                                    {
                                        array[l]  = true;
                                        array3[l] = true;
                                    }
                                }
                            }
                        }
                        Action <int> action = delegate(int idx)
                        {
                            sm.tris.Add(sm.verts.Count - 2);
                            sm.tris.Add(idx);
                            sm.tris.Add(sm.verts.Count - 1);
                            sm.tris.Add(sm.verts.Count - 1);
                            sm.tris.Add(idx);
                            sm.tris.Add(idx + 1);
                        };
                        Action action2 = delegate()
                        {
                            sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                            sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                            sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                            sm.tris.Add(sm.verts.Count - 3);
                            sm.tris.Add(sm.verts.Count - 2);
                            sm.tris.Add(sm.verts.Count - 1);
                        };
                        int count2 = sm.verts.Count;
                        if (array[0])
                        {
                            if (array2[0] || array2[1])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[0])
                                {
                                    num = 0.45f;
                                }
                                if (array2[1])
                                {
                                    num2 = 0.45f;
                                }
                                sm.verts.Add(new Vector3((float)i, y, (float)j));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)i + num2, y, (float)j + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[1] && !array3[1])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)i, y, (float)j));
                                sm.verts.Add(new Vector3((float)i, y, (float)j + 0.45f));
                                sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)j));
                                action2();
                            }
                        }
                        if (array[1])
                        {
                            if (array2[1] || array2[2])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[1])
                                {
                                    num2 = 0.45f;
                                }
                                if (array2[2])
                                {
                                    num = -0.45f;
                                }
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)i + num2, y, (float)(j + 1) + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[2] && !array3[2])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)i, y, (float)(j + 1) - 0.45f));
                                action2();
                            }
                        }
                        if (array[2])
                        {
                            if (array2[2] || array2[3])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[2])
                                {
                                    num = -0.45f;
                                }
                                if (array2[3])
                                {
                                    num2 = -0.45f;
                                }
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)(j + 1) + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[3] && !array3[3])
                                {
                                    action(sm.verts.Count);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1)));
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1) - 0.45f));
                                sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)(j + 1)));
                                action2();
                            }
                        }
                        if (array[3])
                        {
                            if (array2[3] || array2[0])
                            {
                                float num2;
                                float num = num2 = 0f;
                                if (array2[3])
                                {
                                    num2 = -0.45f;
                                }
                                if (array2[0])
                                {
                                    num = 0.45f;
                                }
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                sm.colors.Add(SectionLayer_EdgeShadows.Shadowed);
                                sm.verts.Add(new Vector3((float)(i + 1) + num2, y, (float)j + num));
                                sm.colors.Add(SectionLayer_EdgeShadows.Lit);
                                if (array[0] && !array3[0])
                                {
                                    action(count2);
                                }
                            }
                            else
                            {
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j));
                                sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)j));
                                sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.45f));
                                action2();
                            }
                        }
                    }
                }
            }
            if (sm.verts.Count > 0)
            {
                sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors);
            }
        }
Esempio n. 5
0
        public override void Regenerate()
        {
            ClearSubMeshes(MeshParts.All);
            TerrainGrid terrainGrid = base.Map.terrainGrid;
            CellRect    cellRect    = section.CellRect;

            TerrainDef[]         array   = new TerrainDef[8];
            HashSet <TerrainDef> hashSet = new HashSet <TerrainDef>();

            bool[] array2 = new bool[8];
            foreach (IntVec3 item in cellRect)
            {
                IntVec3 current = item;
                hashSet.Clear();
                TerrainDef   terrainDef = terrainGrid.TerrainAt(current);
                LayerSubMesh subMesh    = GetSubMesh(GetMaterialFor(terrainDef));
                if (subMesh != null && AllowRenderingFor(terrainDef))
                {
                    int count = subMesh.verts.Count;
                    subMesh.verts.Add(new Vector3((float)current.x, 0f, (float)current.z));
                    subMesh.verts.Add(new Vector3((float)current.x, 0f, (float)(current.z + 1)));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)(current.z + 1)));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z));
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.colors.Add(ColorWhite);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 1);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count + 3);
                }
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c = current + GenAdj.AdjacentCellsAroundBottom[i];
                    if (!c.InBounds(base.Map))
                    {
                        array[i] = terrainDef;
                    }
                    else
                    {
                        TerrainDef terrainDef2 = terrainGrid.TerrainAt(c);
                        Thing      edifice     = c.GetEdifice(base.Map);
                        if (edifice != null && edifice.def.coversFloor)
                        {
                            terrainDef2 = TerrainDefOf.Underwall;
                        }
                        array[i] = terrainDef2;
                        if (terrainDef2 != terrainDef && terrainDef2.edgeType != 0 && terrainDef2.renderPrecedence >= terrainDef.renderPrecedence && !hashSet.Contains(terrainDef2))
                        {
                            hashSet.Add(terrainDef2);
                        }
                    }
                }
                foreach (TerrainDef item2 in hashSet)
                {
                    LayerSubMesh subMesh2 = GetSubMesh(GetMaterialFor(item2));
                    if (subMesh2 != null && AllowRenderingFor(item2))
                    {
                        int count = subMesh2.verts.Count;
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)current.z + 0.5f));
                        subMesh2.verts.Add(new Vector3((float)current.x, 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)(current.z + 1)));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z + 0.5f));
                        subMesh2.verts.Add(new Vector3((float)(current.x + 1), 0f, (float)current.z));
                        subMesh2.verts.Add(new Vector3((float)current.x + 0.5f, 0f, (float)current.z + 0.5f));
                        for (int j = 0; j < 8; j++)
                        {
                            array2[j] = false;
                        }
                        for (int k = 0; k < 8; k++)
                        {
                            if (k % 2 == 0)
                            {
                                if (array[k] == item2)
                                {
                                    array2[(k - 1 + 8) % 8] = true;
                                    array2[k]           = true;
                                    array2[(k + 1) % 8] = true;
                                }
                            }
                            else if (array[k] == item2)
                            {
                                array2[k] = true;
                            }
                        }
                        for (int l = 0; l < 8; l++)
                        {
                            if (array2[l])
                            {
                                subMesh2.colors.Add(ColorWhite);
                            }
                            else
                            {
                                subMesh2.colors.Add(ColorClear);
                            }
                        }
                        subMesh2.colors.Add(ColorClear);
                        for (int m = 0; m < 8; m++)
                        {
                            subMesh2.tris.Add(count + m);
                            subMesh2.tris.Add(count + (m + 1) % 8);
                            subMesh2.tris.Add(count + 8);
                        }
                    }
                }
            }
            FinalizeMesh(MeshParts.All);
        }
Esempio n. 6
0
        public override void Regenerate()
        {
            LayerSubMesh subMesh = base.GetSubMesh(MatBases.Snow);

            if (subMesh.mesh.vertexCount == 0)
            {
                SectionLayerGeometryMaker_Solid.MakeBaseGeometry(this.section, subMesh, AltitudeLayer.Terrain);
            }
            subMesh.Clear(MeshParts.Colors);
            float[]     depthGridDirect_Unsafe = base.Map.snowGrid.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_Snow.SnowDepthColor(this.vertDepth[k]));
                    }
                }
            }
            if (flag)
            {
                subMesh.disabled = false;
                subMesh.FinalizeMesh(MeshParts.Colors);
            }
            else
            {
                subMesh.disabled = true;
            }
        }
Esempio n. 7
0
        public override void Regenerate()
        {
            LayerSubMesh subMesh = GetSubMesh(MatBases.LightOverlay);

            if (subMesh.verts.Count == 0)
            {
                MakeBaseGeometry(subMesh);
            }
            Color32[] array = new Color32[subMesh.verts.Count];
            int       maxX  = sectRect.maxX;
            int       maxZ  = sectRect.maxZ;
            int       width = sectRect.Width;
            Map       map   = base.Map;
            IntVec3   size  = map.Size;
            int       x     = size.x;

            Thing[]     innerArray  = map.edificeGrid.InnerArray;
            int         num         = innerArray.Length;
            RoofGrid    roofGrid    = map.roofGrid;
            CellIndices cellIndices = map.cellIndices;

            CalculateVertexIndices(sectRect.minX, sectRect.minZ, out int botLeft, out int _, out int _, out int _, out int _);
            int num2 = cellIndices.CellToIndex(new IntVec3(sectRect.minX, 0, sectRect.minZ));

            int[]   obj   = new int[4];
            IntVec3 size2 = map.Size;

            obj[0] = -size2.x - 1;
            IntVec3 size3 = map.Size;

            obj[1] = -size3.x;
            obj[2] = -1;
            int[] array2 = obj;
            int[] array3 = new int[4]
            {
                -1,
                -1,
                0,
                0
            };
            for (int i = sectRect.minZ; i <= maxZ + 1; i++)
            {
                int num3 = num2 / x;
                int num4 = sectRect.minX;
                while (num4 <= maxX + 1)
                {
                    ColorInt colorInt = new ColorInt(0, 0, 0, 0);
                    int      num5     = 0;
                    bool     flag     = false;
                    for (int j = 0; j < 4; j++)
                    {
                        int num6 = num2 + array2[j];
                        if (num6 >= 0 && num6 < num && num6 / x == num3 + array3[j])
                        {
                            Thing   thing   = innerArray[num6];
                            RoofDef roofDef = roofGrid.RoofAt(num6);
                            if (roofDef != null && (roofDef.isThickRoof || thing == null || !thing.def.holdsRoof || thing.def.altitudeLayer == AltitudeLayer.DoorMoveable))
                            {
                                flag = true;
                            }
                            if (thing == null || !thing.def.blockLight)
                            {
                                colorInt += glowGrid[num6];
                                num5++;
                            }
                        }
                    }
                    if (num5 > 0)
                    {
                        array[botLeft] = (colorInt / num5).ToColor32;
                    }
                    else
                    {
                        array[botLeft] = new Color32(0, 0, 0, 0);
                    }
                    if (flag && array[botLeft].a < 100)
                    {
                        array[botLeft].a = 100;
                    }
                    num4++;
                    botLeft++;
                    num2++;
                }
                int num7 = maxX + 2 - sectRect.minX;
                botLeft -= num7;
                num2    -= num7;
                botLeft += width + 1;
                int     num8  = num2;
                IntVec3 size4 = map.Size;
                num2 = num8 + size4.x;
            }
            CalculateVertexIndices(sectRect.minX, sectRect.minZ, out int botLeft2, out int _, out int _, out int _, out int center2);
            int num9 = cellIndices.CellToIndex(sectRect.minX, sectRect.minZ);

            for (int k = sectRect.minZ; k <= maxZ; k++)
            {
                int num10 = sectRect.minX;
                while (num10 <= maxX)
                {
                    ColorInt colA = default(ColorInt) + array[botLeft2];
                    colA          += array[botLeft2 + 1];
                    colA          += array[botLeft2 + width + 1];
                    colA          += array[botLeft2 + width + 2];
                    array[center2] = new Color32((byte)(colA.r / 4), (byte)(colA.g / 4), (byte)(colA.b / 4), (byte)(colA.a / 4));
                    if (array[center2].a < 100 && roofGrid.Roofed(num9))
                    {
                        Thing thing2 = innerArray[num9];
                        if (thing2 == null || !thing2.def.holdsRoof)
                        {
                            array[center2].a = 100;
                        }
                    }
                    num10++;
                    botLeft2++;
                    center2++;
                    num9++;
                }
                botLeft2++;
                num9 -= width;
                int     num11 = num9;
                IntVec3 size5 = map.Size;
                num9 = num11 + size5.x;
            }
            subMesh.mesh.colors32 = array;
        }
Esempio n. 8
0
        public static void PrintShadow(SectionLayer layer, Vector3 center, Vector3 volume, Rot4 rotation)
        {
            if (!DebugViewSettings.drawShadows)
            {
                return;
            }
            LayerSubMesh subMesh = layer.GetSubMesh(MatBases.SunShadowFade);
            Color32      item    = new Color32(255, 0, 0, (byte)Mathf.Min(255f * (volume.y + Printer_Shadow.GlobalShadowSizeOffsetY), 255f));
            Vector3      vector  = (volume + new Vector3(Printer_Shadow.GlobalShadowSizeOffsetX, 0f, Printer_Shadow.GlobalShadowSizeOffsetZ)).RotatedBy(rotation).Abs() / 2f;
            float        x       = center.x;
            float        z       = center.z;
            int          count   = subMesh.verts.Count;

            subMesh.verts.Add(new Vector3(x - vector.x, 0f, z - vector.z));
            subMesh.verts.Add(new Vector3(x - vector.x, 0f, z + vector.z));
            subMesh.verts.Add(new Vector3(x + vector.x, 0f, z + vector.z));
            subMesh.verts.Add(new Vector3(x + vector.x, 0f, z - vector.z));
            subMesh.colors.Add(Printer_Shadow.LowVertexColor);
            subMesh.colors.Add(Printer_Shadow.LowVertexColor);
            subMesh.colors.Add(Printer_Shadow.LowVertexColor);
            subMesh.colors.Add(Printer_Shadow.LowVertexColor);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count + 1);
            subMesh.tris.Add(count + 2);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count + 2);
            subMesh.tris.Add(count + 3);
            int count2 = subMesh.verts.Count;

            subMesh.verts.Add(new Vector3(x - vector.x, 0f, z - vector.z));
            subMesh.verts.Add(new Vector3(x - vector.x, 0f, z + vector.z));
            subMesh.colors.Add(item);
            subMesh.colors.Add(item);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count2);
            subMesh.tris.Add(count2 + 1);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count2 + 1);
            subMesh.tris.Add(count + 1);
            int count3 = subMesh.verts.Count;

            subMesh.verts.Add(new Vector3(x + vector.x, 0f, z + vector.z));
            subMesh.verts.Add(new Vector3(x + vector.x, 0f, z - vector.z));
            subMesh.colors.Add(item);
            subMesh.colors.Add(item);
            subMesh.tris.Add(count + 2);
            subMesh.tris.Add(count3);
            subMesh.tris.Add(count3 + 1);
            subMesh.tris.Add(count3 + 1);
            subMesh.tris.Add(count + 3);
            subMesh.tris.Add(count + 2);
            int count4 = subMesh.verts.Count;

            subMesh.verts.Add(new Vector3(x - vector.x, 0f, z - vector.z));
            subMesh.verts.Add(new Vector3(x + vector.x, 0f, z - vector.z));
            subMesh.colors.Add(item);
            subMesh.colors.Add(item);
            subMesh.tris.Add(count);
            subMesh.tris.Add(count + 3);
            subMesh.tris.Add(count4);
            subMesh.tris.Add(count + 3);
            subMesh.tris.Add(count4 + 1);
            subMesh.tris.Add(count4);
        }