Ejemplo n.º 1
0
        static public IEnumerable <Vector3> GetTriangleIntersection(this Bounds item, Triangle3 triangle)
        {
            if (triangle.IsDegenerate() == false)
            {
                Plane plane = triangle.GetPlane();

                if (plane.normal != Vector3.zero)
                {
                    if (item.FullyContains(triangle))
                    {
                        return(triangle.GetPoints());
                    }

                    PlaneSpace plane_space = plane.GetPlaneSpace();

                    ConvexPolygon plane_polygon = new ConvexPolygon(
                        plane_space.ProjectPoints(item.GetPlaneIntersection(plane))
                        );

                    ConvexPolygon triangle_polygon = new ConvexPolygon(
                        plane_space.ProjectPoints(triangle.GetPoints())
                        );

                    return(plane_space.InflatePoints(
                               plane_polygon.GetIntersection(triangle_polygon).GetVertexs()
                               ).Narrow(p => item.Contains(p)));
                }
            }

            return(Empty.IEnumerable <Vector3>());
        }
Ejemplo n.º 2
0
 static public Triangle3 InflateTriangle(this PlaneSpace item, Triangle2 triangle)
 {
     return(new Triangle3(
                item.InflatePoint(triangle.v0),
                item.InflatePoint(triangle.v1),
                item.InflatePoint(triangle.v2)
                ));
 }
Ejemplo n.º 3
0
        static public void CalculateUVs(this Mesh item)
        {
            Vector2[] uvs = new Vector2[item.vertexCount];

            for (int i = 0; i < item.vertexCount; i++)
            {
                Vector3 normal   = item.normals[i];
                Vector3 position = item.vertices[i];

                PlaneSpace place = new PlaneSpace(PlaneExtensions.CreateNormalAndDistance(normal, 0.0f));

                uvs[i] = place.ProjectPoint(position);
            }

            item.uv = uvs;
        }
Ejemplo n.º 4
0
        static public bool IsIntersecting(this PlaneSpace item, Plane plane, out Plane2 output)
        {
            Ray ray;

            if (item.plane.IsIntersecting(plane, out ray))
            {
                output = Plane2Extensions.CreatePointsAndInsidePoint(
                    item.ProjectPoint(ray.origin),
                    item.ProjectPoint(ray.origin + ray.direction),
                    item.ProjectPoint(ray.origin - plane.normal)
                    );
                return(true);
            }

            output = default(Plane2);
            return(false);
        }
Ejemplo n.º 5
0
        static public void Seal(this MeshBuilder item, Plane plane, float edge_tolerance, float plane_tolerance)
        {
            FaceCloud  faces       = new FaceCloud(edge_tolerance);
            PlaneSpace plane_space = plane.GetPlaneSpace();

            foreach (LineSegment3 edge in item.GetTriangles().Convert(t => t.GetEdges()).Flatten().Unique())
            {
                if (plane.IsCoplanar(edge, plane_tolerance))
                {
                    faces.AddFace(plane_space.ProjectLineSegment(edge).GetFace());
                }
            }

            item.AddTriangles(
                plane_space.InflateTriangles(faces.Tesselate())
                .Convert(t => t.GetReversedWinding())
                );
        }
Ejemplo n.º 6
0
 static public IEnumerable <Triangle3> InflateTriangles(this PlaneSpace item, IEnumerable <PolygonTriangle> triangles)
 {
     return(triangles.Convert(t => item.InflateTriangle(t)));
 }
Ejemplo n.º 7
0
 static public Vector2 ProjectPoint(this PlaneSpace item, Vector3 point)
 {
     return(new Vector2(item.x.GetDot(point), item.y.GetDot(point)));
 }
Ejemplo n.º 8
0
 static public Triangle3 InflateTriangle(this PlaneSpace item, PolygonTriangle triangle)
 {
     return(item.InflateTriangle(triangle.triangle));
 }
Ejemplo n.º 9
0
 static public LineSegment3 InflateLineSegment(this PlaneSpace item, LineSegment2 line_segment)
 {
     return(new LineSegment3(item.InflatePoint(line_segment.v0), item.InflatePoint(line_segment.v1)));
 }
Ejemplo n.º 10
0
 static public IEnumerable <LineSegment3> InflateLineSegments(this PlaneSpace item, IEnumerable <LineSegment2> line_segments)
 {
     return(line_segments.Convert(l => item.InflateLineSegment(l)));
 }
Ejemplo n.º 11
0
 static public Vector3 InflateVector(this PlaneSpace item, Vector2 vector)
 {
     return(item.InflatePoint(vector) - item.origin);
 }
Ejemplo n.º 12
0
 static public IEnumerable <Vector3> InflateVectors(this PlaneSpace item, IEnumerable <Vector2> vectors)
 {
     return(vectors.Convert(v => item.InflateVector(v)));
 }
Ejemplo n.º 13
0
 static public Vector3 InflatePoint(this PlaneSpace item, Vector2 point)
 {
     return(point.x * item.x + point.y * item.y + item.origin);
 }
Ejemplo n.º 14
0
 static public IEnumerable <Vector3> InflatePoints(this PlaneSpace item, IEnumerable <Vector2> points)
 {
     return(points.Convert(p => item.InflatePoint(p)));
 }
Ejemplo n.º 15
0
 static public Vector2 ProjectVector(this PlaneSpace item, Vector3 vector)
 {
     return(item.ProjectPoint(vector + item.origin));
 }
Ejemplo n.º 16
0
 static public IEnumerable <Vector2> ProjectVectors(this PlaneSpace item, IEnumerable <Vector3> vectors)
 {
     return(vectors.Convert(v => item.ProjectVector(v)));
 }
Ejemplo n.º 17
0
 static public IEnumerable <Triangle2> ProjectTriangles(this PlaneSpace item, IEnumerable <Triangle3> triangles)
 {
     return(triangles.Convert(t => item.ProjectTriangle(t)));
 }
Ejemplo n.º 18
0
 static public Triangle2 ProjectTriangle(this PlaneSpace item, Triangle3 triangle)
 {
     return(new Triangle2(item.ProjectPoint(triangle.v0), item.ProjectPoint(triangle.v1), item.ProjectPoint(triangle.v2)));
 }
Ejemplo n.º 19
0
 static public LineSegment2 ProjectLineSegment(this PlaneSpace item, LineSegment3 line_segment)
 {
     return(new LineSegment2(item.ProjectPoint(line_segment.v0), item.ProjectPoint(line_segment.v1)));
 }