Ejemplo n.º 1
0
        public override Vector4 getEdgeData(Point3 cube, int edgeId)
        {
            var signs = a.GetEdgeSigns(cube, edgeId);

            if (signs[0] != signs[1])
            {
                return(a.getEdgeData(cube, edgeId));
            }



            signs = b.GetEdgeSigns(cube - _offset, edgeId);
            if (signs[0] != signs[1])
            {
                return(b.getEdgeData(cube - _offset, edgeId));
            }


            throw new InvalidOperationException("No crossing edge here!");
        }
Ejemplo n.º 2
0
        private static void buildTriangleIndices(List <int> indices, AbstractHermiteGrid grid, Dictionary <Point3, int> vIndex, List <DCVoxelMaterial> triangleMaterials)
        {
            // Possible quads
            var offsets   = new[] { Point3.UnitX(), Point3.UnitY(), Point3.UnitZ(), };
            var rights    = new[] { Point3.UnitY(), Point3.UnitZ(), Point3.UnitX(), };
            var ups       = new[] { Point3.UnitZ(), Point3.UnitX(), Point3.UnitY(), };
            var unitEdges = offsets.Select(o => grid.GetEdgeId(new Point3(), o)).ToArray();

            //TODO: should be unit test
            for (int i = 0; i < 3; i++)
            {
                Debug.Assert(grid.GetEdgeOffsets(unitEdges[i])[0] == new Point3());
                Debug.Assert(grid.GetEdgeOffsets(unitEdges[i])[1] == offsets[i]);
            }

            grid.ForEachCube(o =>
            {
                if (!vIndex.ContainsKey(o))
                {
                    return;                             // No sign changes so no relevant edges here
                }
                for (int i = 0; i < 3; i++)
                {
                    var edgeId = unitEdges[i];
                    if (!grid.HasEdgeData(o, edgeId))
                    {
                        continue;
                    }
                    // Generate quad

                    var right = rights[i];
                    var up    = ups[i];

                    DCVoxelMaterial mat;
                    var signs = grid.GetEdgeSigns(o, edgeId);
                    // Face towards air by swapping right and up
                    if (signs[1])
                    {
                        var swap = right;
                        right    = up;
                        up       = swap;
                        mat      = grid.GetMaterial(o + offsets[i]);
                    }
                    else
                    {
                        mat = grid.GetMaterial(o);
                    }

                    // build quad faces

                    var a  = o - right;
                    var b  = o - up;
                    var ab = o - right - up;
                    if (!new[] { a, b, ab }.All(vIndex.ContainsKey))
                    {
                        continue;     // This should never happen unless on the side of the field, maybe add a check for this?
                    }
                    indices.AddRange(new[] { vIndex[o], vIndex[a], vIndex[ab] });
                    indices.AddRange(new[] { vIndex[o], vIndex[ab], vIndex[b] });
                    triangleMaterials.Add(mat);
                    triangleMaterials.Add(mat);
                }
            });
        }