private static PolySurface GetObjGroupMesh(Group group, LoadResult result)
        {
            var polygons = new List <Surface>();
            var points   = new List <Point>();

            foreach (var face in group.Faces)
            {
                for (int i = 0; i < face.Count; i++)
                {
                    var index = face[i].VertexIndex - 1;
                    points.Add(Point.ByCoordinates(result.Vertices[index].X, result.Vertices[index].Y, result.Vertices[index].Z));
                }
            }

            for (int i = 0; i < points.Count; i += 3)
            {
                int j = i + 1;
                int k = i + 2;

                var point1 = points[i];
                var point2 = points[j];
                var point3 = points[k];

                var facePoints = new List <Point>()
                {
                    point1, point2, point3
                };
                try
                {
                    polygons.Add(Surface.ByPerimeterPoints(facePoints));
                    point1.Dispose();
                    point2.Dispose();
                    point3.Dispose();
                }
                catch
                {
                    point1.Dispose();
                    point2.Dispose();
                    point3.Dispose();
                    continue;
                }
            }

            return(PolySurface.ByJoinedSurfaces(polygons));
        }
        public void BySurfNameCategoryMaterial_ValidInput()
        {
            var cube  = Cuboid.ByLengths();
            var faces = cube.Faces;
            var surfs = faces.Select(x => x.SurfaceGeometry()).ToList();
            var surf  = PolySurface.ByJoinedSurfaces(surfs);

            var mat = DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Material>().First();

            var ds = DirectShape.ByGeometry(surf, Category.ByName("OST_GenericModel"), Material.ByName(mat.Name), "a polysurface");

            Assert.NotNull(ds);
            Assert.AreEqual("a polysurface", ds.Name);
            Assert.AreEqual((surf.Tags.LookupTag(ds.InternalElement.Id.ToString()) as DirectShapeState).materialId, mat.Id.IntegerValue);
            BoundingBoxCentroid(ds).DistanceTo(Point.Origin()).ShouldBeApproximately(0);
            surf.Dispose();
            surfs.ForEach(x => x.Dispose());
            faces.ForEach(x => x.Dispose());
            cube.Dispose();
        }
Example #3
0
        public static List <Autodesk.DesignScript.Geometry.Geometry> DivideSurface(
            Surface surface,
            List <double> U,
            List <double> V)
        {
            List <IDisposable> disposables = new List <IDisposable>();
            List <Autodesk.DesignScript.Geometry.Geometry> dividedSurfaces = new List <Autodesk.DesignScript.Geometry.Geometry>();

            List <PolySurface>    polySurfaces = new List <PolySurface>();
            List <List <double> > UV           = new List <List <double> > {
                U, V
            };
            Curve uCurve = Curve.ByIsoCurveOnSurface(surface, 1, 0);

            for (int i = 0; i <= 1; i++)
            {
                List <Surface> crvSurf = new List <Surface>();
                foreach (double item in UV[i])
                {
                    Curve crv = Curve.ByIsoCurveOnSurface(surface, i, item);
                    crvSurf.Add(crv.Extrude(Vector.ByCoordinates(0, 0, 1)));
                    crv.Dispose();
                }
                polySurfaces.Add(PolySurface.ByJoinedSurfaces(crvSurf));
                disposables.AddRange(crvSurf);
            }
            List <Autodesk.DesignScript.Geometry.Geometry> splitSurfaces  = surface.Split(polySurfaces[1]).ToList();
            List <Autodesk.DesignScript.Geometry.Geometry> sortedSurfaces = splitSurfaces.OrderBy(x => uCurve.DistanceTo(x)).ToList();

            disposables.AddRange(splitSurfaces);

            foreach (var surf in sortedSurfaces)
            {
                dividedSurfaces.AddRange(surf.Split(polySurfaces[0]));
            }
            disposables.AddRange(sortedSurfaces);
            disposables.AddRange(polySurfaces);

            disposables.ForEach(x => x.Dispose());
            return(dividedSurfaces);
        }
Example #4
0
        /// <summary>
        /// 将Mesh转化为PolySurface
        /// </summary>
        /// <param name="mesh">网格</param>
        /// <returns>转化后的PolySurface</returns>
        public static PolySurface ConvertToPolySurface(Mesh mesh)
        {
            List <Surface> surfaces = new List <Surface>();

            Point[]      vertexs    = mesh.VertexPositions;
            IndexGroup[] indexGroup = mesh.FaceIndices;
            foreach (var item in indexGroup)
            {
                if (item.Count == 3)
                {
                    Point   pt1     = vertexs[item.A];
                    Point   pt2     = vertexs[item.B];
                    Point   pt3     = vertexs[item.C];
                    Surface surface = Surface.ByPerimeterPoints(new Point[] { pt1, pt2, pt3 });
                    surfaces.Add(surface);
                    pt1.Dispose();
                    pt2.Dispose();
                    pt3.Dispose();
                    surface.Dispose();
                }
                else
                {
                    Point pt1 = vertexs[item.A];
                    Point pt2 = vertexs[item.B];
                    Point pt3 = vertexs[item.C];
                    Point pt4 = vertexs[item.D];

                    Surface surface = Surface.ByPerimeterPoints(new Point[] { pt1, pt2, pt3, pt4 });
                    surfaces.Add(surface);
                    pt1.Dispose();
                    pt2.Dispose();
                    pt3.Dispose();
                    surface.Dispose();
                }
            }
            return(PolySurface.ByJoinedSurfaces(surfaces));
        }