예제 #1
0
파일: Point2.cs 프로젝트: gg12123/Snake
    public void Split(Vector3 P0, Vector3 n, Shape2 shapeAbove, Shape2 shapeBelow, NewPointsGetter newPoints, ref int numInside)
    {
        LinkedPoint1 = null;
        LinkedPoint2 = null;

        var comp = Vector3.Dot(Point - P0, n);

        if (Mathf.Abs(comp) <= Utils.PointInPlaneTol)
        {
            var newAbove = this;
            var newBelow = new Point2(Point);

            newPoints.AddPoints(this, newAbove, newBelow);

            shapeAbove.AddPoint(newAbove);
            shapeBelow.AddPoint(newBelow);

            PlaneRelationship = PointPlaneRelationship.Inside;
            numInside++;
        }
        else if (comp > 0.0f)
        {
            shapeAbove.AddPoint(this);
            PlaneRelationship = PointPlaneRelationship.Above;
        }
        else
        {
            shapeBelow.AddPoint(this);
            PlaneRelationship = PointPlaneRelationship.Below;
        }
    }
예제 #2
0
 private void SplitAtEnd(NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow)
 {
     if (EdgeP1.PlaneRelationship == PointPlaneRelationship.Inside)
     {
         if (EdgeP2.PlaneRelationship == PointPlaneRelationship.Above)
         {
             EdgeP1 = newPoints.GetPointAbove(EdgeP1);
             shapeAbove.Edges.Add(this);
         }
         else
         {
             EdgeP1 = newPoints.GetPointBelow(EdgeP1);
             shapeBelow.Edges.Add(this);
         }
     }
     else if (EdgeP2.PlaneRelationship == PointPlaneRelationship.Inside)
     {
         if (EdgeP1.PlaneRelationship == PointPlaneRelationship.Above)
         {
             EdgeP2 = newPoints.GetPointAbove(EdgeP2);
             shapeAbove.Edges.Add(this);
         }
         else
         {
             EdgeP2 = newPoints.GetPointBelow(EdgeP2);
             shapeBelow.Edges.Add(this);
         }
     }
     else
     {
         throw new System.Exception();
     }
 }
예제 #3
0
    private void SplitInHalf(Vector3 x, NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow)
    {
        var a = new Point2(x);
        var b = new Point2(x);

        newPoints.AddPoints(EdgeP1, EdgeP2, a, b);

        shapeAbove.AddPoint(a);
        shapeBelow.AddPoint(b);

        if (EdgeP1.PlaneRelationship == PointPlaneRelationship.Above)
        {
            var newForBelow = new Edge2(EdgeP2, b);
            EdgeP2 = a;

            shapeAbove.Edges.Add(this);
            shapeBelow.Edges.Add(newForBelow);
        }
        else
        {
            var newForAbove = new Edge2(EdgeP2, a);
            EdgeP2 = b;

            shapeAbove.Edges.Add(newForAbove);
            shapeBelow.Edges.Add(this);
        }
    }
예제 #4
0
    public void Split(Vector3 P0, Vector3 n, NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow)
    {
        if (Point2.PointsBridgePlane(EdgeP1, EdgeP2))
        {
            Vector3 x;
            Utils.LinePlaneIntersect(n, P0, EdgeP1.Point, EdgeP2.Point, out x);

            SplitInHalf(x, newPoints, shapeAbove, shapeBelow);
        }
        else if (Point2.BothAbove(EdgeP1, EdgeP2))
        {
            shapeAbove.Edges.Add(this);
        }
        else if (Point2.BothBelow(EdgeP1, EdgeP2))
        {
            shapeBelow.Edges.Add(this);
        }
        else if (Point2.BothInside(EdgeP1, EdgeP2))
        {
            // do nothing - new edges for each shape will be created by the face split
        }
        else
        {
            SplitAtEnd(newPoints, shapeAbove, shapeBelow);
        }
    }
예제 #5
0
    private void Awake()
    {
        Faces            = new List <Face2>();
        Points           = new List <Point2>();
        Edges            = new List <Edge2>();
        CachedPoints     = new List <Vector3>();
        CachedEdgePoints = new List <Vector3>();

        m_MeshPool        = GetComponentInParent <FaceMeshPool>();
        m_NewPointsGetter = GetComponentInParent <NewPointsGetter>();
    }
예제 #6
0
    public void Split(NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow)
    {
        m_InUse = false;

        var abovePoints = new List <Point2>();
        var belowPoints = new List <Point2>();

        var newAboveEdge = new Edge2();
        var newBelowEdge = new Edge2();

        for (int i = 0; i < m_Points.Count; i++)
        {
            var next = (i + 1) % m_Points.Count;

            var p1 = m_Points[i];
            var p2 = m_Points[next];

            if (p1.PlaneRelationship == PointPlaneRelationship.Above)
            {
                abovePoints.Add(p1);
            }
            else if (p1.PlaneRelationship == PointPlaneRelationship.Below)
            {
                belowPoints.Add(p1);
            }
            else
            {
                var a = newPoints.GetPointAbove(p1);
                var b = newPoints.GetPointBelow(p1);

                abovePoints.Add(a);
                belowPoints.Add(b);

                newAboveEdge.AddPoint(a);
                newBelowEdge.AddPoint(b);
            }

            if (Point2.PointsBridgePlane(p1, p2))
            {
                var a = newPoints.GetPointAbove(p1, p2);
                var b = newPoints.GetPointBelow(p1, p2);

                abovePoints.Add(a);
                belowPoints.Add(b);

                newAboveEdge.AddPoint(a);
                newBelowEdge.AddPoint(b);
            }
        }

        ProcessNewFace(shapeAbove, abovePoints, newAboveEdge);
        ProcessNewFace(shapeBelow, belowPoints, newBelowEdge);
    }