Exemple #1
0
        public Mesh MeshToSpeckle(DB.Mesh mesh, string units = null)
        {
            var vertices = new List <double>(mesh.Vertices.Count * 3);

            foreach (var vert in mesh.Vertices)
            {
                vertices.AddRange(PointToSpeckle(vert).ToList());
            }

            var faces = new List <int>(mesh.NumTriangles * 4);

            for (int i = 0; i < mesh.NumTriangles; i++)
            {
                var triangle = mesh.get_Triangle(i);
                var A        = triangle.get_Index(0);
                var B        = triangle.get_Index(1);
                var C        = triangle.get_Index(2);
                faces.Add(0);
                faces.AddRange(new int[]
                {
                    (int)A, (int)B, (int)C
                });
            }

            var u           = units ?? ModelUnits;
            var speckleMesh = new Mesh(vertices, faces, units: u);

            return(speckleMesh);
        }
        public Mesh MeshToSpeckle(DB.Mesh mesh, string units = null)
        {
            var speckleMesh = new Mesh();

            foreach (var vert in mesh.Vertices)
            {
                var vertex = PointToSpeckle(vert);
                speckleMesh.vertices.AddRange(new double[] { vertex.x, vertex.y, vertex.z });
            }

            for (int i = 0; i < mesh.NumTriangles; i++)
            {
                var triangle = mesh.get_Triangle(i);
                var A        = triangle.get_Index(0);
                var B        = triangle.get_Index(1);
                var C        = triangle.get_Index(2);
                speckleMesh.faces.Add(0);
                speckleMesh.faces.AddRange(new int[]
                {
                    (int)A, (int)B, (int)C
                });
            }

            speckleMesh.units = units ?? ModelUnits;
            return(speckleMesh);
        }
 private DirectShape DirectShapeToSpeckle(DB.DirectShape revitAc)
 {
     var cat        = ((BuiltInCategory)revitAc.Category.Id.IntegerValue).ToString();
     var category   = RevitUtils.GetCategory(cat);
     var element    = revitAc.get_Geometry(new Options());
     var geometries = element.ToList().Select <GeometryObject, Base>(obj =>
     {
         return(obj switch
         {
             DB.Mesh mesh => MeshToSpeckle(mesh),
             Solid solid => BrepToSpeckle(solid),
             _ => null
         });
     });
 private DirectShape DirectShapeToSpeckle(DB.DirectShape revitAc)
 {
     var cat        = ((BuiltInCategory)revitAc.Category.Id.IntegerValue).ToString();
     var category   = Categories.GetSchemaBuilderCategoryFromBuiltIn(cat);
     var element    = revitAc.get_Geometry(new Options());
     var geometries = element.ToList().Select <GeometryObject, Base>(obj =>
     {
         return(obj
                switch
         {
             DB.Mesh mesh => MeshToSpeckle(mesh),
             Solid solid => SolidToSpeckleMesh(solid), // Should be replaced with 'BrepToSpeckle' when it works.
             _ => null
         });
     });
        public Mesh MeshToSpeckle(DB.Mesh mesh)
        {
            var speckleMesh = new Mesh();

            foreach (var vert in mesh.Vertices)
            {
                speckleMesh.vertices.AddRange(new double[] { ScaleToSpeckle(vert.X), ScaleToSpeckle(vert.Y), ScaleToSpeckle(vert.Z) });
            }

            for (int i = 0; i < mesh.NumTriangles; i++)
            {
                var triangle = mesh.get_Triangle(i);
                var A        = triangle.get_Index(0);
                var B        = triangle.get_Index(1);
                var C        = triangle.get_Index(2);
                speckleMesh.faces.Add(0);
                speckleMesh.faces.AddRange(new int[] { (int)A, (int)B, (int)C });
            }

            speckleMesh.units = ModelUnits;
            return(speckleMesh);
        }