Esempio n. 1
0
        public List <Triangle> Polygonise(Gridcell grid, float isolevel)
        {
            List <Triangle> list = new List <Triangle>();

            new List <Vector3>();
            Vector3[] vectorArray = new Vector3[12];
            int       index       = 0;

            if (grid.val[0] < isolevel)
            {
                index |= 1;
            }
            if (grid.val[1] < isolevel)
            {
                index |= 2;
            }
            if (grid.val[2] < isolevel)
            {
                index |= 4;
            }
            if (grid.val[3] < isolevel)
            {
                index |= 8;
            }
            if (grid.val[4] < isolevel)
            {
                index |= 0x10;
            }
            if (grid.val[5] < isolevel)
            {
                index |= 0x20;
            }
            if (grid.val[6] < isolevel)
            {
                index |= 0x40;
            }
            if (grid.val[7] < isolevel)
            {
                index |= 0x80;
            }
            if (this.edgeTable[index] == 0)
            {
                return(new List <Triangle>());
            }
            if ((this.edgeTable[index] & 1) != 0)
            {
                vectorArray[0] = this.VertexInterp(isolevel, grid.p[0], grid.p[1], grid.val[0], grid.val[1]);
            }
            if ((this.edgeTable[index] & 2) != 0)
            {
                vectorArray[1] = this.VertexInterp(isolevel, grid.p[1], grid.p[2], grid.val[1], grid.val[2]);
            }
            if ((this.edgeTable[index] & 4) != 0)
            {
                vectorArray[2] = this.VertexInterp(isolevel, grid.p[2], grid.p[3], grid.val[2], grid.val[3]);
            }
            if ((this.edgeTable[index] & 8) != 0)
            {
                vectorArray[3] = this.VertexInterp(isolevel, grid.p[3], grid.p[0], grid.val[3], grid.val[0]);
            }
            if ((this.edgeTable[index] & 0x10) != 0)
            {
                vectorArray[4] = this.VertexInterp(isolevel, grid.p[4], grid.p[5], grid.val[4], grid.val[5]);
            }
            if ((this.edgeTable[index] & 0x20) != 0)
            {
                vectorArray[5] = this.VertexInterp(isolevel, grid.p[5], grid.p[6], grid.val[5], grid.val[6]);
            }
            if ((this.edgeTable[index] & 0x40) != 0)
            {
                vectorArray[6] = this.VertexInterp(isolevel, grid.p[6], grid.p[7], grid.val[6], grid.val[7]);
            }
            if ((this.edgeTable[index] & 0x80) != 0)
            {
                vectorArray[7] = this.VertexInterp(isolevel, grid.p[7], grid.p[4], grid.val[7], grid.val[4]);
            }
            if ((this.edgeTable[index] & 0x100) != 0)
            {
                vectorArray[8] = this.VertexInterp(isolevel, grid.p[0], grid.p[4], grid.val[0], grid.val[4]);
            }
            if ((this.edgeTable[index] & 0x200) != 0)
            {
                vectorArray[9] = this.VertexInterp(isolevel, grid.p[1], grid.p[5], grid.val[1], grid.val[5]);
            }
            if ((this.edgeTable[index] & 0x400) != 0)
            {
                vectorArray[10] = this.VertexInterp(isolevel, grid.p[2], grid.p[6], grid.val[2], grid.val[6]);
            }
            if ((this.edgeTable[index] & 0x800) != 0)
            {
                vectorArray[11] = this.VertexInterp(isolevel, grid.p[3], grid.p[7], grid.val[3], grid.val[7]);
            }
            int num2 = 0;

            for (int i = 0; this.triTable[index][i] != -1; i += 3)
            {
                list.Add(new Triangle(vectorArray[this.triTable[index][i]], vectorArray[this.triTable[index][i + 1]], vectorArray[this.triTable[index][i + 2]]));
                num2++;
            }
            return(list);
        }
Esempio n. 2
0
        public List <Triangle> GenerateTriangles(float isolevel, Gridcell grid)
        {
            List <Triangle> list = new List <Triangle>();

            new List <Vector3>();
            int index = 0;

            if (grid.val[0] < isolevel)
            {
                index++;
            }
            if (grid.val[1] < isolevel)
            {
                index += 2;
            }
            if (grid.val[2] < isolevel)
            {
                index += 4;
            }
            if (grid.val[3] < isolevel)
            {
                index += 8;
            }
            if (grid.val[4] < isolevel)
            {
                index += 0x10;
            }
            if (grid.val[5] < isolevel)
            {
                index += 0x20;
            }
            if (grid.val[6] < isolevel)
            {
                index += 0x40;
            }
            if (grid.val[7] < isolevel)
            {
                index += 0x80;
            }
            if ((index != 0) && (index != 0xff))
            {
                Vector3[] vectorArray = new Vector3[12];
                if (this.IsBitSet(this.edgeTable[index], 1))
                {
                    vectorArray[0] = this.VertexInterp(isolevel, grid.p[0], grid.p[1], grid.val[0], grid.val[1]);
                }
                if (this.IsBitSet(this.edgeTable[index], 2))
                {
                    vectorArray[1] = this.VertexInterp(isolevel, grid.p[1], grid.p[2], grid.val[1], grid.val[2]);
                }
                if (this.IsBitSet(this.edgeTable[index], 4))
                {
                    vectorArray[2] = this.VertexInterp(isolevel, grid.p[2], grid.p[3], grid.val[2], grid.val[3]);
                }
                if (this.IsBitSet(this.edgeTable[index], 8))
                {
                    vectorArray[3] = this.VertexInterp(isolevel, grid.p[3], grid.p[0], grid.val[3], grid.val[0]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x10))
                {
                    vectorArray[4] = this.VertexInterp(isolevel, grid.p[4], grid.p[5], grid.val[4], grid.val[5]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x20))
                {
                    vectorArray[5] = this.VertexInterp(isolevel, grid.p[5], grid.p[6], grid.val[5], grid.val[6]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x40))
                {
                    vectorArray[6] = this.VertexInterp(isolevel, grid.p[6], grid.p[7], grid.val[6], grid.val[7]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x80))
                {
                    vectorArray[7] = this.VertexInterp(isolevel, grid.p[7], grid.p[4], grid.val[7], grid.val[4]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x100))
                {
                    vectorArray[8] = this.VertexInterp(isolevel, grid.p[0], grid.p[4], grid.val[0], grid.val[4]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x200))
                {
                    vectorArray[9] = this.VertexInterp(isolevel, grid.p[1], grid.p[5], grid.val[1], grid.val[5]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x400))
                {
                    vectorArray[10] = this.VertexInterp(isolevel, grid.p[2], grid.p[6], grid.val[2], grid.val[6]);
                }
                if (this.IsBitSet(this.edgeTable[index], 0x800))
                {
                    vectorArray[11] = this.VertexInterp(isolevel, grid.p[3], grid.p[7], grid.val[3], grid.val[7]);
                }
                for (int i = 0; this.triTable[index][i] != -1; i += 3)
                {
                    list.Add(new Triangle(vectorArray[this.triTable[index][i]], vectorArray[this.triTable[index][i + 1]], vectorArray[this.triTable[index][i + 2]]));
                }
            }
            return(list);
        }
Esempio n. 3
0
        public void Load(float[,,] vals = null)
        {
            if (vals != null)
            {
                this.density = vals;
            }
            else
            {
                new System.Random();
                this.density = new float[this.length, this.length, this.length];
                for (int k = 0; k < this.length; k++)
                {
                    for (int n = 0; n < this.length; n++)
                    {
                        for (int num3 = 0; num3 < this.length; num3++)
                        {
                            this.density[k, num3, n] = 0f;
                        }
                    }
                }
                for (int m = 5; m < 8; m++)
                {
                    for (int num5 = 5; num5 < 8; num5++)
                    {
                        for (int num6 = 0; num6 < this.length; num6++)
                        {
                            this.density[m, num6, num5] = 1f;
                        }
                    }
                }
                this.density[7, 5, 7] = 0f;
            }
            this.ratioX    = vals.GetLength(0) / this.length;
            this.ratioY    = vals.GetLength(1) / this.length;
            this.ratioZ    = vals.GetLength(2) / this.length;
            this.gridArray = new Gridcell[this.length - 1, this.length - 1, this.length - 1];
            for (int i = 0; i < (this.length - 1); i++)
            {
                for (int num8 = 0; num8 < (this.length - 1); num8++)
                {
                    for (int num9 = 0; num9 < (this.length - 1); num9++)
                    {
                        this.gridArray[i, num9, num8] = this.GenerateGridCell(i * this.ratioX, num9 * this.ratioY, num8 * this.ratioZ);
                    }
                }
            }
            Gridcell[,,] gridArray = this.gridArray;
            int upperBound = gridArray.GetUpperBound(0);
            int num11      = gridArray.GetUpperBound(1);
            int num12      = gridArray.GetUpperBound(2);

            for (int j = gridArray.GetLowerBound(0); j <= upperBound; j++)
            {
                for (int num14 = gridArray.GetLowerBound(1); num14 <= num11; num14++)
                {
                    for (int num15 = gridArray.GetLowerBound(2); num15 <= num12; num15++)
                    {
                        Gridcell grid = gridArray[j, num14, num15];
                        this.triangles.AddRange(this.Polygonise(grid, this.Isolevel));
                    }
                }
            }
        }