Exemplo n.º 1
0
        public static void addHermiteNormals(AbstractHermiteGrid grid, float cellSize, LineManager3DLines lines)
        {
            grid.ForEachGridPoint(p =>
            {
                var sign = grid.GetSign(p);
                var dirs = new[] { new Point3(1, 0, 0), new Point3(0, 1, 0), new Point3(0, 0, 1) };


                foreach (var dir in dirs)
                {
                    if (sign == grid.GetSign(p + dir))
                    {
                        continue;
                    }

                    //lines.AddLine(vertPos, end, Color.Black.dx());

                    var edge = grid.GetEdgeId(p, p + dir);

                    var edgeStart = grid.GetEdgeOffsets(edge)[0] + p;
                    var edgeEnd   = grid.GetEdgeOffsets(edge)[1] + p;

                    var normal = grid.GetEdgeNormal(p, edge);
                    var pos    = grid.GetEdgeIntersectionCubeLocal(p, edge);

                    pos = (p + pos) * cellSize;
                    lines.AddLine(pos, pos + normal * 0.4f * cellSize, Color.Blue);
                    lines.AddLine(edgeStart.ToVector3() * cellSize, edgeEnd.ToVector3() * cellSize, Color.LightBlue);

                    lines.AddCenteredBox(pos, 0.02f, Color.Red);
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draw hermite info for given cube and outputs the info to a textarea
        /// </summary>
        private void drawHermiteInfoForCube(Point3 gridPoint, Textarea textarea)
        {
            textarea.Text = "";

            foreach (var edgeID in grid.GetAllEdgeIds())
            {
                var     points         = grid.GetEdgeOffsets(edgeID);
                Vector3 edgeWorldStart = (gridPoint + points[0]).ToVector3() * CellSize;
                TW.Graphics.LineManager3D.AddLine(edgeWorldStart, (gridPoint + points[1]).ToVector3() * CellSize,
                                                  Color.Purple.dx());
                var hasEdge = false;
                if (grid.HasEdgeData(gridPoint, edgeID))
                {
                    textarea.Text += grid.GetEdgeIntersectionCubeLocal(gridPoint, edgeID) + "n: " +
                                     grid.getEdgeData(gridPoint, edgeID).TakeXYZ() + "\n";
                    hasEdge = true;
                    var     normal            = grid.GetEdgeNormal(gridPoint, edgeID);
                    Vector3 worldIntersection = (grid.GetEdgeIntersectionCubeLocal(gridPoint, edgeID) + gridPoint) * CellSize;
                    TW.Graphics.LineManager3D.AddCenteredBox(worldIntersection, 0.04f, Color.LawnGreen.dx());
                    TW.Graphics.LineManager3D.AddLine(worldIntersection, worldIntersection + normal * 0.2f, Color.Blue.dx());
                }

                if (hasEdge)
                {
                    var qef = (Vector3)DualContouringAlgorithm.calculateQefPoint(grid, grid.GetCubeSigns(gridPoint), gridPoint);
                    TW.Graphics.LineManager3D.AddCenteredBox(((Vector3)gridPoint.ToVector3() + qef) * CellSize, 0.05f, Color.Orange.dx());
                }
            }
        }