Example #1
0
        public static Face3D Transform(this Transform transform, Face3D face3D, bool convertUnits = true)
        {
            if (transform == null || face3D == null)
                return null;

            if (transform.IsIdentity)
                return new Face3D(face3D);

            Spatial.Plane plane = Transform(transform, face3D.GetPlane());
            if (plane == null)
                return null;

            Planar.IClosed2D externalEdge2D = plane.Convert(Transform(transform, face3D.GetExternalEdge3D(), convertUnits));
            if (externalEdge2D == null)
                return null;

            List<Planar.IClosed2D> internalEdges2D = null;

            List<IClosedPlanar3D> internalEdges3D = face3D.GetInternalEdge3Ds();
            if(internalEdges3D != null)
            {
                internalEdges2D = new List<Planar.IClosed2D>();
                foreach (IClosedPlanar3D internalEdge3D in internalEdges3D)
                {
                    Planar.IClosed2D internalEdge2D = plane.Convert(Transform(transform, internalEdge3D, convertUnits));
                    if (internalEdge2D == null)
                        continue;

                    internalEdges2D.Add(internalEdge2D);
                }
            }

            return Face3D.Create(plane, externalEdge2D, internalEdges2D, EdgeOrientationMethod.Undefined);
        }
Example #2
0
        public static Face3D ToSAM(this HoneybeeSchema.Face3D face3D)
        {
            if (face3D == null)
            {
                return(null);
            }

            Plane plane = face3D.Plane?.ToSAM();

            IClosedPlanar3D externalEdge3D = null;

            List <Point3D> point3Ds = face3D.Boundary?.ToSAM();

            if (point3Ds == null || point3Ds.Count < 3)
            {
                return(null);
            }

            if (plane != null)
            {
                externalEdge3D = new Polygon3D(plane, point3Ds.ConvertAll(x => plane.Convert(x)));
            }
            else
            {
                externalEdge3D = new Polygon3D(point3Ds);
            }

            plane = externalEdge3D.GetPlane();
            if (plane == null)
            {
                return(null);
            }

            List <IClosedPlanar3D> internalEdge3Ds = null;

            if (face3D.Holes != null)
            {
                internalEdge3Ds = new List <IClosedPlanar3D>();
                foreach (List <List <double> > values in face3D.Holes)
                {
                    point3Ds = values?.ToSAM();
                    if (point3Ds == null || point3Ds.Count < 3)
                    {
                        continue;
                    }

                    internalEdge3Ds.Add(new Polygon3D(plane, point3Ds.ConvertAll(x => plane.Convert(x))));
                }
            }

            return(Face3D.Create(externalEdge3D.GetPlane(), plane.Convert(externalEdge3D), internalEdge3Ds?.ConvertAll(x => plane.Convert(x))));
        }
Example #3
0
        public static Face3D ToSAM(this global::Topologic.Face face)
        {
            if (face == null)
            {
                return(null);
            }

            Polygon3D polygon3D = null;

            Vector3D normal = new Vector3D(FaceUtility.NormalAtParameters(face, 0.5, 0.5));

            if (normal != null)
            {
                polygon3D = Spatial.Create.Polygon3D(normal, face.ExternalBoundary.Vertices?.ToList().ConvertAll(x => x.ToSAM()));
            }

            if (polygon3D == null)
            {
                polygon3D = ToSAM_Polygon3D(face.ExternalBoundary);
            }

            if (polygon3D == null)
            {
                return(null);
            }

            List <Polygon3D> polygon3Ds = new List <Polygon3D>()
            {
                polygon3D
            };

            IList <Wire> wires = face.InternalBoundaries;

            if (wires != null && wires.Count > 0)
            {
                foreach (Wire wire in wires)
                {
                    polygon3D = null;

                    if (normal != null)
                    {
                        polygon3D = Spatial.Create.Polygon3D(normal, wire.Vertices?.ToList().ConvertAll(x => x.ToSAM()));
                    }

                    if (polygon3D == null)
                    {
                        polygon3D = ToSAM_Polygon3D(wire);
                    }

                    if (polygon3D == null)
                    {
                        continue;
                    }

                    polygon3Ds.Add(polygon3D);
                }
            }

            Face3D result = Face3D.Create(polygon3Ds);

            return(result);
        }