コード例 #1
0
    public static Edge GetEdge(Point A, Point B, IIsoSurface surface, List <Edge> edges)
    {
        Vector3 p;

        if (A.iso == 0)
        {
            p = A.p;
        }
        else if (B.iso == 0)
        {
            p = B.p;
        }
        else
        {
            Vector3 diff  = B.p - A.p;
            Vector3 start = A.p;

            float ratio = 0.5f;
            p = start + (diff * ratio);

            float f = 0.25f;
            float iso;
            while ((iso = surface.sample(p.x, p.y, p.z)) > 0.0001)
            {
                ratio += f * Mathf.Sign(iso * A.iso);
                f     /= 2;
                p      = start + (diff * ratio);
            }
        }

        Vector3 n = surface.sampleDerivative(p.x, p.y, p.z);

        //Debug.DrawLine(A.p, B.p, new Color(0,0,1,0.5f), 30);
        return(new Edge(p, n, A, B, edges));
    }
コード例 #2
0
    Point getPoint(int x, int y, int z, float cellSize, Point[,,] points, IIsoSurface surface)
    {
        Point point = points[x, y, z];

        if (point == null)
        {
            Vector3 p = new Vector3(x * (float)cellSize, y * (float)cellSize, z * (float)cellSize);
            point           = new Point(surface.sample(p.x, p.y, p.z), p, x, y, z);
            points[x, y, z] = point;
        }

        return(point);
    }