示例#1
0
        /// <summary>
        /// Add a new face to the BrepBuilder
        /// </summary>
        /// <param name="surface">The surface that is used to construct the brepbuilder face</param>
        /// <param name="orientation">The flag that indicates (TRUE) if the surface's normal agree with the face's normal or not (FALSE)</param>
        /// <param name="materialId">The face's material ID</param>
        /// <param name="localTransform">The local transform</param>
        public void StartCollectingFace(IFCSurface surface, Transform localTransform, bool orientation, ElementId materialId)
        {
            if (m_CurrentBrepBuilderFace != null)
            {
                throw new InvalidOperationException("StopCollectingFaceForBrepBuilder for previous face hasn't been called yet");
            }

            bool bReversed = !orientation;
            BRepBuilderSurfaceGeometry surfaceGeometry;

            if (surface is IFCBSplineSurfaceWithKnots)
            {
                surfaceGeometry = StartCollectingNURBSFace(surface as IFCBSplineSurfaceWithKnots, localTransform);
            }
            else
            {
                Surface transformedSurface = surface.GetSurface(localTransform);
                if (transformedSurface == null)
                {
                    throw new InvalidOperationException("Couldn't create surface for the current face.");
                }
                surfaceGeometry = BRepBuilderSurfaceGeometry.Create(transformedSurface, null);
            }
            m_CurrentBrepBuilderFace = m_BrepBuilder.AddFace(surfaceGeometry, bReversed);
            FaceMaterialId           = materialId;
            BrepBuilder.SetFaceMaterialId(m_CurrentBrepBuilderFace, FaceMaterialId);
        }
示例#2
0
        /***************************************************/

        private static bool TryAddSurface(this BRepBuilder brep, PlanarSurface ps)
        {
            try
            {
                BH.oM.Geometry.Plane    p  = ps.ExternalBoundary.IFitPlane();
                Autodesk.Revit.DB.Plane rp = p.ToRevit();

                BRepBuilderSurfaceGeometry bbsg = BRepBuilderSurfaceGeometry.Create(rp, null);
                BRepBuilderGeometryId      face = brep.AddFace(bbsg, false);

                brep.AddLoop(face, rp.Normal, ps.ExternalBoundary, true);

                foreach (ICurve c in ps.InternalBoundaries)
                {
                    brep.AddLoop(face, rp.Normal, c, false);
                }

                brep.FinishFace(face);
            }
            catch
            {
                BH.Engine.Reflection.Compute.RecordError("An attempt to create a planar surface failed.");
                return(false);
            }

            return(true);
        }
示例#3
0
        static internal BRepBuilderSurfaceGeometry ToHost(this Rhino.Geometry.BrepFace faceSurface)
        {
            using (var nurbsSurface = faceSurface.ToNurbsSurface())
            {
                {
                    var domainU = nurbsSurface.Domain(0);
                    Debug.Assert(!nurbsSurface.GetNextDiscontinuity(0, Continuity.C2_continuous, domainU.Min, domainU.Max, out var tU));
                    var domainV = nurbsSurface.Domain(1);
                    Debug.Assert(!nurbsSurface.GetNextDiscontinuity(1, Continuity.C2_continuous, domainV.Min, domainV.Max, out var tV));
                }

                var degreeU       = nurbsSurface.Degree(0);
                var degreeV       = nurbsSurface.Degree(1);
                var knotsU        = nurbsSurface.KnotsU.ToHost();
                var knotsV        = nurbsSurface.KnotsV.ToHost();
                var controlPoints = nurbsSurface.Points.ToHost();

                Debug.Assert(degreeU >= 1);
                Debug.Assert(degreeV >= 1);
                Debug.Assert(knotsU.Count >= 2 * (degreeU + 1));
                Debug.Assert(knotsV.Count >= 2 * (degreeV + 1));
                Debug.Assert(controlPoints.Count == (knotsU.Count - degreeU - 1) * (knotsV.Count - degreeV - 1));

                try
                {
                    if (nurbsSurface.IsRational)
                    {
                        var weights = new List <double>(controlPoints.Count);
                        foreach (var p in nurbsSurface.Points)
                        {
                            Debug.Assert(p.Weight > 0.0);
                            weights.Add(p.Weight);
                        }

                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, weights, false, null
                               ));
                    }
                    else
                    {
                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, false, null
                               ));
                    }
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException e)
                {
                    Debug.Fail(e.Source, e.Message);
                }
            }

            return(null);
        }
        static internal BRepBuilderSurfaceGeometry Convert(Rhino.Geometry.Surface faceSurface)
        {
            switch (faceSurface)
            {
            case Rhino.Geometry.NurbsSurface nurbsSurface:

                var degreeU       = nurbsSurface.Degree(0);
                var degreeV       = nurbsSurface.Degree(1);
                var knotsU        = Convert(nurbsSurface.KnotsU);
                var knotsV        = Convert(nurbsSurface.KnotsV);
                var controlPoints = Convert(nurbsSurface.Points);

                Debug.Assert(degreeU >= 1);
                Debug.Assert(degreeV >= 1);
                Debug.Assert(knotsU.Count >= 2 * (degreeU + 1));
                Debug.Assert(knotsV.Count >= 2 * (degreeV + 1));
                Debug.Assert(controlPoints.Count == (knotsU.Count - degreeU - 1) * (knotsV.Count - degreeV - 1));

                try
                {
                    if (nurbsSurface.IsRational)
                    {
                        var weights = new List <double>(controlPoints.Count);
                        foreach (var p in nurbsSurface.Points)
                        {
                            Debug.Assert(p.Weight > 0.0);
                            weights.Add(p.Weight);
                        }

                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, weights, false, null
                               ));
                    }
                    else
                    {
                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, false, null
                               ));
                    }
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException e)
                {
                    Debug.Fail(e.Source, e.Message);
                    return(null);
                }
            }

            return(Convert(faceSurface.ToNurbsSurface()));
        }
示例#5
0
        static private BRepBuilderSurfaceGeometry BuildFaceSurface(Rhino.Geometry.BrepFace faceSurface)
        {
            using (var nurbsSurface = faceSurface.ToNurbsSurface())
            {
                var degreeU       = nurbsSurface.Degree(0);
                var degreeV       = nurbsSurface.Degree(1);
                var knotsU        = nurbsSurface.KnotsU.ToHost();
                var knotsV        = nurbsSurface.KnotsV.ToHost();
                var controlPoints = nurbsSurface.Points.ToHost();

                Debug.Assert(degreeU >= 1);
                Debug.Assert(degreeV >= 1);
                Debug.Assert(knotsU.Count >= 2 * (degreeU + 1));
                Debug.Assert(knotsV.Count >= 2 * (degreeV + 1));
                Debug.Assert(controlPoints.Count == (knotsU.Count - degreeU - 1) * (knotsV.Count - degreeV - 1));

                try
                {
                    if (nurbsSurface.IsRational)
                    {
                        var weights = new List <double>(controlPoints.Count);
                        foreach (var p in nurbsSurface.Points)
                        {
                            Debug.Assert(p.Weight > 0.0);
                            weights.Add(p.Weight);
                        }

                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, weights, false, null
                               ));
                    }
                    else
                    {
                        return(BRepBuilderSurfaceGeometry.CreateNURBSSurface
                               (
                                   degreeU, degreeV, knotsU, knotsV, controlPoints, false, null
                               ));
                    }
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException e)
                {
                    Debug.Fail(e.Source, e.Message);
                }
            }

            return(null);
        }
示例#6
0
        private BRepBuilderSurfaceGeometry StartCollectingNURBSFace(IFCBSplineSurfaceWithKnots bSplineSurfaceWithKnots, Transform localTransform)
        {
            if (bSplineSurfaceWithKnots == null)
            {
                return(null);
            }

            IFCRationalBSplineSurfaceWithKnots rationalBSplineSurfaceWithKnots = (bSplineSurfaceWithKnots as IFCRationalBSplineSurfaceWithKnots);

            IList <double> knotsU = IFCGeometryUtil.ConvertIFCKnotsToRevitKnots(bSplineSurfaceWithKnots.UMultiplicities, bSplineSurfaceWithKnots.UKnots);

            if (knotsU == null || knotsU.Count == 0)
            {
                throw new InvalidOperationException("No knots in u-direction");
            }

            IList <double> knotsV = IFCGeometryUtil.ConvertIFCKnotsToRevitKnots(bSplineSurfaceWithKnots.VMultiplicities, bSplineSurfaceWithKnots.VKnots);

            if (knotsV == null || knotsV.Count == 0)
            {
                throw new InvalidOperationException("No knots in v-direction");
            }

            IList <double> weights = (rationalBSplineSurfaceWithKnots != null) ? rationalBSplineSurfaceWithKnots.WeightsList : null;

            IList <XYZ> controlPoints = new List <XYZ>();

            foreach (XYZ point in bSplineSurfaceWithKnots.ControlPointsList)
            {
                controlPoints.Add(localTransform.OfPoint(point));
            }

            int uDegree = bSplineSurfaceWithKnots.UDegree;
            int vDegree = bSplineSurfaceWithKnots.VDegree;

            BRepBuilderSurfaceGeometry surfaceGeometry = null;

            if (weights == null)
            {
                surfaceGeometry = BRepBuilderSurfaceGeometry.CreateNURBSSurface(uDegree, vDegree, knotsU, knotsV, controlPoints, false, null);
            }
            else
            {
                surfaceGeometry = BRepBuilderSurfaceGeometry.CreateNURBSSurface(uDegree, vDegree, knotsU, knotsV, controlPoints, weights, false, null);
            }

            return(surfaceGeometry);
        }
示例#7
0
        public ExternallyTaggedBRep CreateStairs()
        {
            BRepBuilder brepBuilder = new BRepBuilder(BRepType.Solid);
            BRepBuilderPersistentIds persistentIds = new BRepBuilderPersistentIds(brepBuilder);

            // 1. Planes
            Plane riser1 = Plane.CreateByOriginAndBasis(new XYZ(0, m_riser1DepthPos, m_halfStepHeight), new XYZ(1, 0, 0), new XYZ(0, 0, 1));                     // XZ plane
            Plane riser2 = Plane.CreateByOriginAndBasis(new XYZ(0, m_riser2DepthPos, m_tread1HeightPos + m_halfStepHeight), new XYZ(1, 0, 0), new XYZ(0, 0, 1)); // XZ plane
            Plane riser3 = Plane.CreateByOriginAndBasis(new XYZ(0, m_riser3DepthPos, m_tread2HeightPos + m_halfStepHeight), new XYZ(1, 0, 0), new XYZ(0, 0, 1)); // XZ plane
            Plane back   = Plane.CreateByOriginAndBasis(new XYZ(0, m_halfPodiumDepth, m_halfPodiumHeight), new XYZ(1, 0, 0), new XYZ(0, 0, 1));                  // XZ plane
            Plane bottom = Plane.CreateByOriginAndBasis(new XYZ(0, 0, 0), new XYZ(1, 0, 0), new XYZ(0, 1, 0));                                                   // XY plane
            Plane tread1 = Plane.CreateByOriginAndBasis(new XYZ(0, m_riser1DepthPos + m_halfStepDepth, m_tread1HeightPos), new XYZ(1, 0, 0), new XYZ(0, 1, 0));  // XY plane
            Plane tread2 = Plane.CreateByOriginAndBasis(new XYZ(0, m_riser2DepthPos + m_halfStepDepth, m_tread2HeightPos), new XYZ(1, 0, 0), new XYZ(0, 1, 0));  // XY plane
            Plane top    = Plane.CreateByOriginAndBasis(new XYZ(0, 0, m_podiumHeight), new XYZ(1, 0, 0), new XYZ(0, 1, 0));                                      // XY plane
            Plane left   = Plane.CreateByOriginAndBasis(new XYZ(-m_halfPodiumWidth, 0, m_halfPodiumHeight), new XYZ(0, 1, 0), new XYZ(0, 0, 1));                 // YZ plane
            Plane right  = Plane.CreateByOriginAndBasis(new XYZ(m_halfPodiumWidth, 0, m_halfPodiumHeight), new XYZ(0, 1, 0), new XYZ(0, 0, 1));                  // YZ plane

            // 2. Faces
            BRepBuilderGeometryId faceRiser1Id = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(riser1, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceRiser1"), faceRiser1Id);
            BRepBuilderGeometryId faceRiser2Id = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(riser2, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceRiser2"), faceRiser2Id);
            BRepBuilderGeometryId faceRiser3Id = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(riser3, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceRiser3"), faceRiser3Id);
            BRepBuilderGeometryId faceBackId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(back, null), true /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceBack"), faceBackId);
            BRepBuilderGeometryId faceBottomId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), true /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceBottom"), faceBottomId);
            BRepBuilderGeometryId faceTread1Id = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(tread1, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceTread1"), faceTread1Id);
            BRepBuilderGeometryId faceTread2Id = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(tread2, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceTread2"), faceTread2Id);
            BRepBuilderGeometryId faceTopId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceTop"), faceTopId);
            BRepBuilderGeometryId faceLeftId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(left, null), true /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceLeft"), faceLeftId);
            BRepBuilderGeometryId faceRightId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(right, null), false /*bFaceIsReversed*/);

            persistentIds.AddSubTag(new ExternalGeometryId("faceRight"), faceRightId);

            // 3. Edge geometry
            // Bottom horizontal edges
            BRepBuilderEdgeGeometry edgeBottomFront = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, 0), new XYZ(m_halfPodiumWidth, m_riser1DepthPos, 0));
            BRepBuilderEdgeGeometry edgeBottomRight = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser1DepthPos, 0), new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, 0));
            BRepBuilderEdgeGeometry edgeBottomBack  = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, 0), new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, 0));
            BRepBuilderEdgeGeometry edgeBottomLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, 0), new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, 0));

            // Tread 1 horizontal edges
            BRepBuilderEdgeGeometry edgeTread1Front = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight), new XYZ(m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight));
            BRepBuilderEdgeGeometry edgeTread1Right = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight), new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight));
            BRepBuilderEdgeGeometry edgeTread1Back  = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight), new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight));
            BRepBuilderEdgeGeometry edgeTread1Left  = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight), new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight));

            // Tread 2 horizontal edges
            BRepBuilderEdgeGeometry edgeTread2Front = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2), new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2));
            BRepBuilderEdgeGeometry edgeTread2Right = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2), new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2));
            BRepBuilderEdgeGeometry edgeTread2Back  = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2), new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2));
            BRepBuilderEdgeGeometry edgeTread2Left  = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2), new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2));

            // Top horizontal edges
            BRepBuilderEdgeGeometry edgeTopFront = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight), new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight));
            BRepBuilderEdgeGeometry edgeTopRight = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight), new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight));
            BRepBuilderEdgeGeometry edgeTopBack  = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight), new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight));
            BRepBuilderEdgeGeometry edgeTopLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight), new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight));

            // Left vertical edges
            BRepBuilderEdgeGeometry edgeLeftRiser1 = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, 0), new XYZ(-m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight));
            BRepBuilderEdgeGeometry edgeLeftRiser2 = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight), new XYZ(-m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2));
            BRepBuilderEdgeGeometry edgeLeftRiser3 = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2), new XYZ(-m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight));
            BRepBuilderEdgeGeometry edgeLeftBack   = BRepBuilderEdgeGeometry.Create(new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, 0), new XYZ(-m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight));

            // Right vertical edges
            BRepBuilderEdgeGeometry edgeRightRiser1 = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser1DepthPos, 0), new XYZ(m_halfPodiumWidth, m_riser1DepthPos, m_stepHeight));
            BRepBuilderEdgeGeometry edgeRightRiser2 = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight), new XYZ(m_halfPodiumWidth, m_riser2DepthPos, m_stepHeight * 2));
            BRepBuilderEdgeGeometry edgeRightRiser3 = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_stepHeight * 2), new XYZ(m_halfPodiumWidth, m_riser3DepthPos, m_podiumHeight));
            BRepBuilderEdgeGeometry edgeRightBack   = BRepBuilderEdgeGeometry.Create(new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, 0), new XYZ(m_halfPodiumWidth, m_halfPodiumDepth, m_podiumHeight));

            // 4. Edges
            BRepBuilderGeometryId edgeBottomFrontId = brepBuilder.AddEdge(edgeBottomFront);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeBottom"), edgeBottomFrontId);
            BRepBuilderGeometryId edgeBottomRightId = brepBuilder.AddEdge(edgeBottomRight);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeBottomRight"), edgeBottomRightId);
            BRepBuilderGeometryId edgeBottomBackId = brepBuilder.AddEdge(edgeBottomBack);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeBottomBack"), edgeBottomBackId);
            BRepBuilderGeometryId edgeBottomLeftId = brepBuilder.AddEdge(edgeBottomLeft);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeBottomLeft"), edgeBottomLeftId);
            BRepBuilderGeometryId edgeTread1FrontId = brepBuilder.AddEdge(edgeTread1Front);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread1Front"), edgeTread1FrontId);
            BRepBuilderGeometryId edgeTread1RightId = brepBuilder.AddEdge(edgeTread1Right);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread1Right"), edgeTread1RightId);
            BRepBuilderGeometryId edgeTread1BackId = brepBuilder.AddEdge(edgeTread1Back);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread1Back"), edgeTread1BackId);
            BRepBuilderGeometryId edgeTread1LeftId = brepBuilder.AddEdge(edgeTread1Left);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread1Left"), edgeTread1LeftId);
            BRepBuilderGeometryId edgeTread2FrontId = brepBuilder.AddEdge(edgeTread2Front);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread2Front"), edgeTread2FrontId);
            BRepBuilderGeometryId edgeTread2RightId = brepBuilder.AddEdge(edgeTread2Right);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread2Right"), edgeTread2RightId);
            BRepBuilderGeometryId edgeTread2BackId = brepBuilder.AddEdge(edgeTread2Back);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread2Back"), edgeTread2BackId);
            BRepBuilderGeometryId edgeTread2LeftId = brepBuilder.AddEdge(edgeTread2Left);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTread2Left"), edgeTread2LeftId);
            BRepBuilderGeometryId edgeTopFrontId = brepBuilder.AddEdge(edgeTopFront);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTopFront"), edgeTopFrontId);
            BRepBuilderGeometryId edgeTopRightId = brepBuilder.AddEdge(edgeTopRight);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTopRight"), edgeTopRightId);
            BRepBuilderGeometryId edgeTopBackId = brepBuilder.AddEdge(edgeTopBack);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTopBack"), edgeTopBackId);
            BRepBuilderGeometryId edgeTopLeftId = brepBuilder.AddEdge(edgeTopLeft);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeTopLeft"), edgeTopLeftId);
            BRepBuilderGeometryId edgeLeftRiser1Id = brepBuilder.AddEdge(edgeLeftRiser1);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeLeftRiser1"), edgeLeftRiser1Id);
            BRepBuilderGeometryId edgeLeftRiser2Id = brepBuilder.AddEdge(edgeLeftRiser2);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeLeftRiser2"), edgeLeftRiser2Id);
            BRepBuilderGeometryId edgeLeftRiser3Id = brepBuilder.AddEdge(edgeLeftRiser3);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeLeftRiser3"), edgeLeftRiser3Id);
            BRepBuilderGeometryId edgeLeftBackId = brepBuilder.AddEdge(edgeLeftBack);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeLeftBack"), edgeLeftBackId);
            BRepBuilderGeometryId edgeRightRiser1Id = brepBuilder.AddEdge(edgeRightRiser1);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeRightRiser1"), edgeRightRiser1Id);
            BRepBuilderGeometryId edgeRightRiser2Id = brepBuilder.AddEdge(edgeRightRiser2);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeRightRiser2"), edgeRightRiser2Id);
            BRepBuilderGeometryId edgeRightRiser3Id = brepBuilder.AddEdge(edgeRightRiser3);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeRightRiser3"), edgeRightRiser3Id);
            BRepBuilderGeometryId edgeRightBackId = brepBuilder.AddEdge(edgeRightBack);

            persistentIds.AddSubTag(new ExternalGeometryId("edgeRightBack"), edgeRightBackId);

            // 5. Loops
            BRepBuilderGeometryId loopBottomId = brepBuilder.AddLoop(faceBottomId);
            BRepBuilderGeometryId loopTread1Id = brepBuilder.AddLoop(faceTread1Id);
            BRepBuilderGeometryId loopTread2Id = brepBuilder.AddLoop(faceTread2Id);
            BRepBuilderGeometryId loopTopId    = brepBuilder.AddLoop(faceTopId);
            BRepBuilderGeometryId loopRiser1Id = brepBuilder.AddLoop(faceRiser1Id);
            BRepBuilderGeometryId loopRiser2Id = brepBuilder.AddLoop(faceRiser2Id);
            BRepBuilderGeometryId loopRiser3Id = brepBuilder.AddLoop(faceRiser3Id);
            BRepBuilderGeometryId loopBackId   = brepBuilder.AddLoop(faceBackId);
            BRepBuilderGeometryId loopLeftId   = brepBuilder.AddLoop(faceLeftId);
            BRepBuilderGeometryId loopRightId  = brepBuilder.AddLoop(faceRightId);

            // 6. Co-edges
            // Bottom face
            BRepBuilderGeometryId coEdgeId = brepBuilder.AddCoEdge(loopBottomId, edgeBottomFrontId, true /*bCoEdgeIsReversed*/);

            brepBuilder.AddCoEdge(loopBottomId, edgeBottomLeftId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopBottomId, edgeBottomBackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopBottomId, edgeBottomRightId, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopBottomId);
            brepBuilder.FinishFace(faceBottomId);

            // Tread 1 face
            brepBuilder.AddCoEdge(loopTread1Id, edgeTread1FrontId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread1Id, edgeTread1RightId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread1Id, edgeTread1BackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread1Id, edgeTread1LeftId, false /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopTread1Id);
            brepBuilder.FinishFace(faceTread1Id);

            // Tread 2 face
            brepBuilder.AddCoEdge(loopTread2Id, edgeTread2FrontId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread2Id, edgeTread2RightId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread2Id, edgeTread2BackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTread2Id, edgeTread2LeftId, false /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopTread2Id);
            brepBuilder.FinishFace(faceTread2Id);

            // Top face
            brepBuilder.AddCoEdge(loopTopId, edgeTopFrontId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTopId, edgeTopRightId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTopId, edgeTopBackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopTopId, edgeTopLeftId, false /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopTopId);
            brepBuilder.FinishFace(faceTopId);

            // Riser1 face
            brepBuilder.AddCoEdge(loopRiser1Id, edgeBottomFrontId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser1Id, edgeRightRiser1Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser1Id, edgeTread1FrontId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser1Id, edgeLeftRiser1Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopRiser1Id);
            brepBuilder.FinishFace(faceRiser1Id);

            // Riser2 face
            brepBuilder.AddCoEdge(loopRiser2Id, edgeTread1BackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser2Id, edgeRightRiser2Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser2Id, edgeTread2FrontId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser2Id, edgeLeftRiser2Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopRiser2Id);
            brepBuilder.FinishFace(faceRiser2Id);

            // Riser3 face
            brepBuilder.AddCoEdge(loopRiser3Id, edgeTread2BackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser3Id, edgeRightRiser3Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser3Id, edgeTopFrontId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRiser3Id, edgeLeftRiser3Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopRiser3Id);
            brepBuilder.FinishFace(faceRiser3Id);

            // Back face
            brepBuilder.AddCoEdge(loopBackId, edgeBottomBackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopBackId, edgeLeftBackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopBackId, edgeTopBackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopBackId, edgeRightBackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopBackId);
            brepBuilder.FinishFace(faceBackId);

            // Right face
            brepBuilder.AddCoEdge(loopRightId, edgeBottomRightId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeRightBackId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeTopRightId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeRightRiser3Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeTread2RightId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeRightRiser2Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeTread1RightId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopRightId, edgeRightRiser1Id, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopRightId);
            brepBuilder.FinishFace(faceRightId);

            // Left face
            brepBuilder.AddCoEdge(loopLeftId, edgeBottomLeftId, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeLeftRiser1Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeTread1LeftId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeLeftRiser2Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeTread2LeftId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeLeftRiser3Id, false /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeTopLeftId, true /*bCoEdgeIsReversed*/);
            brepBuilder.AddCoEdge(loopLeftId, edgeLeftBackId, true /*bCoEdgeIsReversed*/);
            brepBuilder.FinishLoop(loopLeftId);
            brepBuilder.FinishFace(faceLeftId);

            brepBuilder.Finish();

            return(brepBuilder.GetResult(Podium.ExternalId, persistentIds));
        }
示例#8
0
        private static DirectShapeInfo ConvertBrep(Document doc, RhinoObjectInfo rhinoInfo)
        {
            DirectShapeInfo shapeInfo = new DirectShapeInfo();

            try
            {
                BRepBuilder         brepBuilder = null;
                Rhino.Geometry.Brep rhinoBrep   = rhinoInfo.Geometry as Rhino.Geometry.Brep;
                if (rhinoBrep.IsSolid)
                {
                    brepBuilder = new BRepBuilder(BRepType.Solid);
                }
                else if (rhinoBrep.IsSurface)
                {
                    brepBuilder = new BRepBuilder(BRepType.OpenShell);
                }

                foreach (Rhino.Geometry.BrepFace brepFace in rhinoBrep.Faces)
                {
                    BRepBuilderGeometryId nurbSplineFaceId = BRepBuilderGeometryId.InvalidGeometryId();
                    BRepBuilderGeometryId loopId           = BRepBuilderGeometryId.InvalidGeometryId();

                    bool reverse = brepFace.OrientationIsReversed;
                    if (brepFace.ObjectType == Rhino.DocObjects.ObjectType.Surface)
                    {
                        Rhino.Geometry.NurbsSurface nurbsSurface = brepFace.ToNurbsSurface();

                        Rhino.Geometry.Collections.NurbsSurfacePointList points = nurbsSurface.Points;
                        int dirU    = points.CountU;
                        int dirV    = points.CountV;
                        int degreeU = nurbsSurface.Degree(0);
                        int degreeV = nurbsSurface.Degree(1);

                        // knots
                        Rhino.Geometry.Collections.NurbsSurfaceKnotList knotsU = nurbsSurface.KnotsU;
                        Rhino.Geometry.Collections.NurbsSurfaceKnotList knotsV = nurbsSurface.KnotsV;

                        List <XYZ> controlPoints = new List <XYZ>();
                        XYZ[][]    rvtPoints     = new XYZ[dirU][];
                        double[][] rvtWeights    = new double[dirU][];
                        for (int u = 0; u < dirU; u++)
                        {
                            rvtPoints[u]  = new XYZ[dirV];
                            rvtWeights[u] = new double[dirV];
                            for (int v = 0; v < dirV; v++)
                            {
                                // point coordinates at u, v
                                Rhino.Geometry.Point3d pt = points.GetControlPoint(u, v).Location;

                                XYZ xyz = new XYZ(pt.X, pt.Y, pt.Z);
                                rvtPoints[u][v] = xyz;
                                controlPoints.Add(xyz);
                                // weights at u, v
                                rvtWeights[u][v] = points.GetControlPoint(u, v).Weight;
                            }
                        }

                        // knots U
                        List <double> rvt_knotsU = new List <double>();
                        rvt_knotsU.Add(knotsU[0]);
                        for (int i = 0; i < knotsU.Count; i++)
                        {
                            rvt_knotsU.Add(knotsU[i]);
                        }
                        rvt_knotsU.Add(knotsU[knotsU.Count - 1]);

                        // knots V
                        List <double> rvt_knotsV = new List <double>();
                        rvt_knotsV.Add(knotsV[0]);
                        for (int i = 0; i < knotsV.Count; i++)
                        {
                            rvt_knotsV.Add(knotsV[i]);
                        }
                        rvt_knotsV.Add(knotsV[knotsV.Count - 1]);

                        BRepBuilderSurfaceGeometry brepSurface = BRepBuilderSurfaceGeometry.CreateNURBSSurface(degreeU, degreeV, rvt_knotsU, rvt_knotsV, controlPoints, reverse, null);
                        nurbSplineFaceId = brepBuilder.AddFace(brepSurface, reverse);
                        loopId           = brepBuilder.AddLoop(nurbSplineFaceId);
                    }

                    foreach (Rhino.Geometry.BrepLoop loop in brepFace.Loops)
                    {
                        Rhino.Geometry.Curve      curve      = loop.To3dCurve();
                        Rhino.Geometry.NurbsCurve nurbsCurve = curve.ToNurbsCurve();

                        int           degree        = nurbsCurve.Degree;
                        List <XYZ>    controlPoints = new List <XYZ>();
                        List <double> weights       = new List <double>();
                        List <double> knots         = new List <double>();

                        for (int i = 0; i < nurbsCurve.Points.Count; i++)
                        {
                            Rhino.Geometry.ControlPoint ctrlPoint = nurbsCurve.Points[i];
                            Rhino.Geometry.Point3d      point     = ctrlPoint.Location;
                            XYZ xyz = new XYZ(point.X, point.Y, point.Z);

                            controlPoints.Add(xyz);
                            weights.Add(ctrlPoint.Weight);
                        }

                        knots.Add(nurbsCurve.Knots[0]);
                        for (int i = 0; i < nurbsCurve.Knots.Count; i++)
                        {
                            double knot = nurbsCurve.Knots[i];
                            knots.Add(knot);
                        }
                        knots.Add(nurbsCurve.Knots[nurbsCurve.Knots.Count - 1]);



                        Curve rvtCurve = NurbSpline.CreateCurve(degree, knots, controlPoints, weights);
                        BRepBuilderEdgeGeometry edgeGeo = BRepBuilderEdgeGeometry.Create(rvtCurve);
                        BRepBuilderGeometryId   edgeId  = brepBuilder.AddEdge(edgeGeo);
                        brepBuilder.AddCoEdge(loopId, edgeId, false);
                    }

                    brepBuilder.FinishLoop(loopId);
                    brepBuilder.FinishFace(nurbSplineFaceId);
                }

                brepBuilder.Finish();


                DirectShape shape = DirectShape.CreateElement(doc, new ElementId((int)BuiltInCategory.OST_GenericModel));
                shape.ApplicationId     = "RhinoBrep";
                shape.ApplicationDataId = rhinoInfo.ObjectId.ToString();

                if (null != shape)
                {
                    shape.SetShape(brepBuilder);
                }

                shapeInfo.DirectShapeId = shape.Id;
                shapeInfo.RhinoObjectId = rhinoInfo.ObjectId;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show("Cannot Conver To Brep.\n" + ex.Message);
            }
            return(shapeInfo);
        }
示例#9
0
        /// <summary>
        /// Create a cube 100 x 100 x 100, from
        /// (0,0,0) to (100, 100, 100).
        /// </summary>
        public BRepBuilder CreateBrepSolid()
        {
            BRepBuilder b = new BRepBuilder(BRepType.Solid);

            // 1. Planes.
            // naming convention for faces and planes:
            // We are looking at this cube in an isometric view.
            // X is down and to the left of us, Y is horizontal
            // and points to the right, Z is up.
            // front and back faces are along the X axis, left
            // and right are along the Y axis, top and bottom
            // are along the Z axis.
            Plane bottom = Plane.CreateByOriginAndBasis(new XYZ(50, 50, 0), new XYZ(1, 0, 0), new XYZ(0, 1, 0));   // bottom. XY plane, Z = 0, normal pointing inside the cube.
            Plane top    = Plane.CreateByOriginAndBasis(new XYZ(50, 50, 100), new XYZ(1, 0, 0), new XYZ(0, 1, 0)); // top. XY plane, Z = 100, normal pointing outside the cube.
            Plane front  = Plane.CreateByOriginAndBasis(new XYZ(100, 50, 50), new XYZ(0, 0, 1), new XYZ(0, 1, 0)); // front side. ZY plane, X = 0, normal pointing inside the cube.
            Plane back   = Plane.CreateByOriginAndBasis(new XYZ(0, 50, 50), new XYZ(0, 0, 1), new XYZ(0, 1, 0));   // back side. ZY plane, X = 0, normal pointing outside the cube.
            Plane left   = Plane.CreateByOriginAndBasis(new XYZ(50, 0, 50), new XYZ(0, 0, 1), new XYZ(1, 0, 0));   // left side. ZX plane, Y = 0, normal pointing inside the cube
            Plane right  = Plane.CreateByOriginAndBasis(new XYZ(50, 100, 50), new XYZ(0, 0, 1), new XYZ(1, 0, 0)); // right side. ZX plane, Y = 100, normal pointing outside the cube

            // 2. Faces.
            BRepBuilderGeometryId faceId_Bottom = b.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), true);
            BRepBuilderGeometryId faceId_Top    = b.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false);
            BRepBuilderGeometryId faceId_Front  = b.AddFace(BRepBuilderSurfaceGeometry.Create(front, null), true);
            BRepBuilderGeometryId faceId_Back   = b.AddFace(BRepBuilderSurfaceGeometry.Create(back, null), false);
            BRepBuilderGeometryId faceId_Left   = b.AddFace(BRepBuilderSurfaceGeometry.Create(left, null), true);
            BRepBuilderGeometryId faceId_Right  = b.AddFace(BRepBuilderSurfaceGeometry.Create(right, null), false);

            // 3. Edges.

            // 3.a (define edge geometry)
            // walk around bottom face
            BRepBuilderEdgeGeometry edgeBottomFront = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 0), new XYZ(100, 100, 0));
            BRepBuilderEdgeGeometry edgeBottomRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 0), new XYZ(0, 100, 0));
            BRepBuilderEdgeGeometry edgeBottomBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 0), new XYZ(0, 0, 0));
            BRepBuilderEdgeGeometry edgeBottomLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 0), new XYZ(100, 0, 0));

            // now walk around top face
            BRepBuilderEdgeGeometry edgeTopFront = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 100), new XYZ(100, 100, 100));
            BRepBuilderEdgeGeometry edgeTopRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 100), new XYZ(0, 100, 100));
            BRepBuilderEdgeGeometry edgeTopBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 100), new XYZ(0, 0, 100));
            BRepBuilderEdgeGeometry edgeTopLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 100), new XYZ(100, 0, 100));

            // sides
            BRepBuilderEdgeGeometry edgeFrontRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 0), new XYZ(100, 100, 100));
            BRepBuilderEdgeGeometry edgeRightBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 0), new XYZ(0, 100, 100));
            BRepBuilderEdgeGeometry edgeBackLeft   = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 0), new XYZ(0, 0, 100));
            BRepBuilderEdgeGeometry edgeLeftFront  = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 0), new XYZ(100, 0, 100));

            // 3.b (define the edges themselves)
            BRepBuilderGeometryId edgeId_BottomFront = b.AddEdge(edgeBottomFront);
            BRepBuilderGeometryId edgeId_BottomRight = b.AddEdge(edgeBottomRight);
            BRepBuilderGeometryId edgeId_BottomBack  = b.AddEdge(edgeBottomBack);
            BRepBuilderGeometryId edgeId_BottomLeft  = b.AddEdge(edgeBottomLeft);
            BRepBuilderGeometryId edgeId_TopFront    = b.AddEdge(edgeTopFront);
            BRepBuilderGeometryId edgeId_TopRight    = b.AddEdge(edgeTopRight);
            BRepBuilderGeometryId edgeId_TopBack     = b.AddEdge(edgeTopBack);
            BRepBuilderGeometryId edgeId_TopLeft     = b.AddEdge(edgeTopLeft);
            BRepBuilderGeometryId edgeId_FrontRight  = b.AddEdge(edgeFrontRight);
            BRepBuilderGeometryId edgeId_RightBack   = b.AddEdge(edgeRightBack);
            BRepBuilderGeometryId edgeId_BackLeft    = b.AddEdge(edgeBackLeft);
            BRepBuilderGeometryId edgeId_LeftFront   = b.AddEdge(edgeLeftFront);

            // 4. Loops.
            BRepBuilderGeometryId loopId_Bottom = b.AddLoop(faceId_Bottom);
            BRepBuilderGeometryId loopId_Top    = b.AddLoop(faceId_Top);
            BRepBuilderGeometryId loopId_Front  = b.AddLoop(faceId_Front);
            BRepBuilderGeometryId loopId_Back   = b.AddLoop(faceId_Back);
            BRepBuilderGeometryId loopId_Right  = b.AddLoop(faceId_Right);
            BRepBuilderGeometryId loopId_Left   = b.AddLoop(faceId_Left);

            // 5. Co-edges.
            // Bottom face. All edges reversed
            b.AddCoEdge(loopId_Bottom, edgeId_BottomFront, true); // other direction in front loop
            b.AddCoEdge(loopId_Bottom, edgeId_BottomLeft, true);  // other direction in left loop
            b.AddCoEdge(loopId_Bottom, edgeId_BottomBack, true);  // other direction in back loop
            b.AddCoEdge(loopId_Bottom, edgeId_BottomRight, true); // other direction in right loop
            b.FinishLoop(loopId_Bottom);
            b.FinishFace(faceId_Bottom);

            // Top face. All edges NOT reversed.
            b.AddCoEdge(loopId_Top, edgeId_TopFront, false); // other direction in front loop.
            b.AddCoEdge(loopId_Top, edgeId_TopRight, false); // other direction in right loop
            b.AddCoEdge(loopId_Top, edgeId_TopBack, false);  // other direction in back loop
            b.AddCoEdge(loopId_Top, edgeId_TopLeft, false);  // other direction in left loop
            b.FinishLoop(loopId_Top);
            b.FinishFace(faceId_Top);

            // Front face.
            b.AddCoEdge(loopId_Front, edgeId_BottomFront, false); // other direction in bottom loop
            b.AddCoEdge(loopId_Front, edgeId_FrontRight, false);  // other direction in right loop
            b.AddCoEdge(loopId_Front, edgeId_TopFront, true);     // other direction in top loop.
            b.AddCoEdge(loopId_Front, edgeId_LeftFront, true);    // other direction in left loop.
            b.FinishLoop(loopId_Front);
            b.FinishFace(faceId_Front);

            // Back face
            b.AddCoEdge(loopId_Back, edgeId_BottomBack, false); // other direction in bottom loop
            b.AddCoEdge(loopId_Back, edgeId_BackLeft, false);   // other direction in left loop.
            b.AddCoEdge(loopId_Back, edgeId_TopBack, true);     // other direction in top loop
            b.AddCoEdge(loopId_Back, edgeId_RightBack, true);   // other direction in right loop.
            b.FinishLoop(loopId_Back);
            b.FinishFace(faceId_Back);

            // Right face
            b.AddCoEdge(loopId_Right, edgeId_BottomRight, false); // other direction in bottom loop
            b.AddCoEdge(loopId_Right, edgeId_RightBack, false);   // other direction in back loop
            b.AddCoEdge(loopId_Right, edgeId_TopRight, true);     // other direction in top loop
            b.AddCoEdge(loopId_Right, edgeId_FrontRight, true);   // other direction in front loop
            b.FinishLoop(loopId_Right);
            b.FinishFace(faceId_Right);

            // Left face
            b.AddCoEdge(loopId_Left, edgeId_BottomLeft, false); // other direction in bottom loop
            b.AddCoEdge(loopId_Left, edgeId_LeftFront, false);  // other direction in front loop
            b.AddCoEdge(loopId_Left, edgeId_TopLeft, true);     // other direction in top loop
            b.AddCoEdge(loopId_Left, edgeId_BackLeft, true);    // other direction in back loop
            b.FinishLoop(loopId_Left);
            b.FinishFace(faceId_Left);

            b.Finish();

            return(b);
        }
示例#10
0
        /// <summary>
        /// Create a cylinder to subtract from the cube.
        /// </summary>
        public BRepBuilder CreateBrepVoid()
        {
            // Naming convention for faces and edges: we
            // assume that x is to the left and pointing down,
            // y is horizontal and pointing to the right,
            // z is up.

            BRepBuilder b = new BRepBuilder(BRepType.Solid);

            // The surfaces of the four faces.
            Frame basis = new Frame(new XYZ(50, 0, 0), new XYZ(0, 1, 0), new XYZ(-1, 0, 0), new XYZ(0, 0, 1));
            CylindricalSurface cylSurf = CylindricalSurface.Create(basis, 40);
            Plane top1    = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 100)); // normal points outside the cylinder
            Plane bottom1 = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 0));   // normal points inside the cylinder

            // Add the four faces
            BRepBuilderGeometryId frontCylFaceId = b.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, null), false);
            BRepBuilderGeometryId backCylFaceId  = b.AddFace(BRepBuilderSurfaceGeometry.Create(cylSurf, null), false);
            BRepBuilderGeometryId topFaceId      = b.AddFace(BRepBuilderSurfaceGeometry.Create(top1, null), false);
            BRepBuilderGeometryId bottomFaceId   = b.AddFace(BRepBuilderSurfaceGeometry.Create(bottom1, null), true);

            // Geometry for the four semi-circular edges and two vertical linear edges
            BRepBuilderEdgeGeometry frontEdgeBottom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(10, 0, 0), new XYZ(90, 0, 0), new XYZ(50, 40, 0)));
            BRepBuilderEdgeGeometry backEdgeBottom  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(90, 0, 0), new XYZ(10, 0, 0), new XYZ(50, -40, 0)));

            BRepBuilderEdgeGeometry frontEdgeTop = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(10, 0, 100), new XYZ(90, 0, 100), new XYZ(50, 40, 100)));
            BRepBuilderEdgeGeometry backEdgeTop  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(10, 0, 100), new XYZ(90, 0, 100), new XYZ(50, -40, 100)));

            BRepBuilderEdgeGeometry linearEdgeFront = BRepBuilderEdgeGeometry.Create(new XYZ(90, 0, 0), new XYZ(90, 0, 100));
            BRepBuilderEdgeGeometry linearEdgeBack  = BRepBuilderEdgeGeometry.Create(new XYZ(10, 0, 0), new XYZ(10, 0, 100));

            // Add the six edges
            BRepBuilderGeometryId frontEdgeBottomId = b.AddEdge(frontEdgeBottom);
            BRepBuilderGeometryId frontEdgeTopId    = b.AddEdge(frontEdgeTop);
            BRepBuilderGeometryId linearEdgeFrontId = b.AddEdge(linearEdgeFront);
            BRepBuilderGeometryId linearEdgeBackId  = b.AddEdge(linearEdgeBack);
            BRepBuilderGeometryId backEdgeBottomId  = b.AddEdge(backEdgeBottom);
            BRepBuilderGeometryId backEdgeTopId     = b.AddEdge(backEdgeTop);

            // Loops of the four faces
            BRepBuilderGeometryId loopId_Top    = b.AddLoop(topFaceId);
            BRepBuilderGeometryId loopId_Bottom = b.AddLoop(bottomFaceId);
            BRepBuilderGeometryId loopId_Front  = b.AddLoop(frontCylFaceId);
            BRepBuilderGeometryId loopId_Back   = b.AddLoop(backCylFaceId);

            // Add coedges for the loop of the front face
            b.AddCoEdge(loopId_Front, linearEdgeBackId, false);
            b.AddCoEdge(loopId_Front, frontEdgeTopId, false);
            b.AddCoEdge(loopId_Front, linearEdgeFrontId, true);
            b.AddCoEdge(loopId_Front, frontEdgeBottomId, true);
            b.FinishLoop(loopId_Front);
            b.FinishFace(frontCylFaceId);

            // Add coedges for the loop of the back face
            b.AddCoEdge(loopId_Back, linearEdgeBackId, true);
            b.AddCoEdge(loopId_Back, backEdgeBottomId, true);
            b.AddCoEdge(loopId_Back, linearEdgeFrontId, false);
            b.AddCoEdge(loopId_Back, backEdgeTopId, true);
            b.FinishLoop(loopId_Back);
            b.FinishFace(backCylFaceId);

            // Add coedges for the loop of the top face
            b.AddCoEdge(loopId_Top, backEdgeTopId, false);
            b.AddCoEdge(loopId_Top, frontEdgeTopId, true);
            b.FinishLoop(loopId_Top);
            b.FinishFace(topFaceId);

            // Add coedges for the loop of the bottom face
            b.AddCoEdge(loopId_Bottom, frontEdgeBottomId, false);
            b.AddCoEdge(loopId_Bottom, backEdgeBottomId, false);
            b.FinishLoop(loopId_Bottom);
            b.FinishFace(bottomFaceId);

            b.Finish();

            return(b);
        }
示例#11
0
        private static GeometryObject ToRevitType(Autodesk.DesignScript.Geometry.Topology topology,
                                                  bool performHostUnitConversion,
                                                  BRepType type, ElementId materialId)
        {
            var faces       = topology.Faces.ToList();
            var brb         = new BRepBuilder(type);
            var edge2EdgeId = new Dictionary <Edge, BRepBuilderGeometryId>();

            //foreach face in solid/surface
            foreach (Face protoFace in faces)
            {
                using (var geom = protoFace.SurfaceGeometry())
                {
                    using (var ngeom = geom.ToNurbsSurface())
                    {
                        bool flipped = false;
                        // Check if the nurbs surface has flipped compared to the original surface
                        if (geom.NormalAtParameter(.5, .5).Dot(ngeom.NormalAtParameter(.5, .5)) < 0)
                        {
                            flipped = true;
                        }

                        // Create Revit nurbs surface
                        var bbface = BRepBuilderSurfaceGeometry.CreateNURBSSurface(ngeom.DegreeU, ngeom.DegreeV,
                                                                                   ngeom.UKnots(), ngeom.VKnots(), ngeom.ControlPoints().SelectMany(x => x.Select(y => y.ToXyz(performHostUnitConversion))).ToList(),
                                                                                   ngeom.Weights().SelectMany(x => x).ToList(),
                                                                                   false,
                                                                                   null);

                        // Add face
                        var faceId = brb.AddFace(bbface, flipped);

                        // Set material
                        if (materialId != null)
                        {
                            brb.SetFaceMaterialId(faceId, materialId);
                        }

                        // add loops and connected edges
                        foreach (var loop in protoFace.Loops)
                        {
                            var loopId = brb.AddLoop(faceId);

                            foreach (var coedge in loop.CoEdges)
                            {
                                var edge = coedge.Edge;
                                BRepBuilderGeometryId edgeId;
                                if (edge2EdgeId.ContainsKey(edge))
                                {
                                    edgeId = edge2EdgeId[edge];
                                }
                                else
                                {
                                    var curve = edge.CurveGeometry;
                                    // Revit is already projecting edges onto the surface after checking for loop consistency
                                    // and is quite forgiving even when we use the nurbs surface instead of
                                    // the original surface.
                                    //
                                    // But there are cases when edges ends up slightly outside one of the surfaces and Revit fails.
                                    //
                                    // This is something that we can be improve going forward.
                                    edgeId            = brb.AddEdge(BRepBuilderEdgeGeometry.Create(curve.ToRevitType(performHostUnitConversion)));
                                    edge2EdgeId[edge] = edgeId;
                                }
                                brb.AddCoEdge(loopId, edgeId, coedge.Reversed);
                            }

                            brb.FinishLoop(loopId);
                        }

                        brb.FinishFace(faceId);
                    }
                }
            }

            //clean up everything
            edge2EdgeId.ToList().ForEach(x => x.Key.Dispose());
            faces.ForEach(x => x.Dispose());

            // Get result
            var outcome   = brb.Finish();
            var converted = brb.GetResult();

            return(converted);
        }
示例#12
0
        /// <summary>
        /// 创建圆柱
        /// </summary>
        public static void CreateCylinder(Document doc, Material mat)
        {
            // Naming convention for faces and edges: we assume that x is to the left and pointing down, y is horizontal and pointing to the right, z is up
            BRepBuilder brepBuilder = new BRepBuilder(BRepType.Solid);

            // The surfaces of the four faces.
            Frame basis = new Frame(new XYZ(5, -10, 0), new XYZ(0, 1, 0), new XYZ(-1, 0, 0), new XYZ(0, 0, 1));
            // Note that we do not have to create two identical surfaces here. The same surface can be used for multiple faces,
            // since BRepBuilderSurfaceGeometry::Create() copies the input surface.
            // Thus, potentially we could have only one surface here,
            // but we must create at least two faces below to account for periodicity.
            CylindricalSurface frontCylSurf = CylindricalSurface.Create(basis, 5);
            CylindricalSurface backCylSurf  = CylindricalSurface.Create(basis, 5);
            Plane top    = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 100)); // normal points outside the cylinder
            Plane bottom = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 0));   // normal points inside the cylinder
                                                                                                // Note that the alternating of "inside/outside" matches the alternating of "true/false" in the next block that defines faces.
                                                                                                // There must be a correspondence to ensure that all faces are correctly oriented to point out of the solid.

            // Add the four faces
            BRepBuilderGeometryId frontCylFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(frontCylSurf, null), false);
            BRepBuilderGeometryId backCylFaceId  = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(backCylSurf, null), false);
            BRepBuilderGeometryId topFaceId      = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false);
            BRepBuilderGeometryId bottomFaceId   = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), true);

            brepBuilder.SetFaceMaterialId(frontCylFaceId, mat.Id);
            brepBuilder.SetFaceMaterialId(backCylFaceId, mat.Id);
            // Geometry for the four semi-circular edges and two vertical linear edges
            BRepBuilderEdgeGeometry frontEdgeBottom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -10, 0), new XYZ(10, -10, 0), new XYZ(5, -5, 0)));
            BRepBuilderEdgeGeometry backEdgeBottom  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(10, -10, 0), new XYZ(0, -10, 0), new XYZ(5, -15, 0)));

            BRepBuilderEdgeGeometry frontEdgeTop = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -10, 100), new XYZ(10, -10, 100), new XYZ(5, -5, 100)));
            BRepBuilderEdgeGeometry backEdgeTop  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(0, -10, 100), new XYZ(10, -10, 100), new XYZ(5, -15, 100)));

            BRepBuilderEdgeGeometry linearEdgeFront = BRepBuilderEdgeGeometry.Create(new XYZ(10, -10, 0), new XYZ(10, -10, 100));
            BRepBuilderEdgeGeometry linearEdgeBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, -10, 0), new XYZ(0, -10, 100));

            // Add the six edges
            BRepBuilderGeometryId frontEdgeBottomId = brepBuilder.AddEdge(frontEdgeBottom);
            BRepBuilderGeometryId frontEdgeTopId    = brepBuilder.AddEdge(frontEdgeTop);
            BRepBuilderGeometryId linearEdgeFrontId = brepBuilder.AddEdge(linearEdgeFront);
            BRepBuilderGeometryId linearEdgeBackId  = brepBuilder.AddEdge(linearEdgeBack);
            BRepBuilderGeometryId backEdgeBottomId  = brepBuilder.AddEdge(backEdgeBottom);
            BRepBuilderGeometryId backEdgeTopId     = brepBuilder.AddEdge(backEdgeTop);

            // Loops of the four faces
            BRepBuilderGeometryId loopId_Top    = brepBuilder.AddLoop(topFaceId);
            BRepBuilderGeometryId loopId_Bottom = brepBuilder.AddLoop(bottomFaceId);
            BRepBuilderGeometryId loopId_Front  = brepBuilder.AddLoop(frontCylFaceId);
            BRepBuilderGeometryId loopId_Back   = brepBuilder.AddLoop(backCylFaceId);

            // Add coedges for the loop of the front face
            brepBuilder.AddCoEdge(loopId_Front, linearEdgeBackId, false);
            brepBuilder.AddCoEdge(loopId_Front, frontEdgeTopId, false);
            brepBuilder.AddCoEdge(loopId_Front, linearEdgeFrontId, true);
            brepBuilder.AddCoEdge(loopId_Front, frontEdgeBottomId, true);
            brepBuilder.FinishLoop(loopId_Front);
            brepBuilder.FinishFace(frontCylFaceId);

            // Add coedges for the loop of the back face
            brepBuilder.AddCoEdge(loopId_Back, linearEdgeBackId, true);
            brepBuilder.AddCoEdge(loopId_Back, backEdgeBottomId, true);
            brepBuilder.AddCoEdge(loopId_Back, linearEdgeFrontId, false);
            brepBuilder.AddCoEdge(loopId_Back, backEdgeTopId, true);
            brepBuilder.FinishLoop(loopId_Back);
            brepBuilder.FinishFace(backCylFaceId);

            // Add coedges for the loop of the top face
            brepBuilder.AddCoEdge(loopId_Top, backEdgeTopId, false);
            brepBuilder.AddCoEdge(loopId_Top, frontEdgeTopId, true);
            brepBuilder.FinishLoop(loopId_Top);
            brepBuilder.FinishFace(topFaceId);

            // Add coedges for the loop of the bottom face
            brepBuilder.AddCoEdge(loopId_Bottom, frontEdgeBottomId, false);
            brepBuilder.AddCoEdge(loopId_Bottom, backEdgeBottomId, false);
            brepBuilder.FinishLoop(loopId_Bottom);
            brepBuilder.FinishFace(bottomFaceId);

            brepBuilder.Finish();

            createDirectShapeElementFromBrepBuilderObject(brepBuilder, "Full cylinder", doc);
        }
示例#13
0
        private BRepBuilder CreateNurbsSurface()
        {
            //Note that we are not creating a closed solid here. It is an open shell.
            BRepBuilder brepBuilder = new BRepBuilder(BRepType.OpenShell);

            // Create NURBS surface
            IList <double> knotsU = new List <double> {
                0, 0, 0, 0, 0, 1, 1, 1, 1, 1
            };
            IList <double> knotsV = new List <double> {
                0, 0, 0, 0, 0, 1, 1, 1, 1, 1
            };
            int degreeU = 4;
            int degreeV = 4;

            IList <XYZ> controlPoints = new List <XYZ>
            {
                new XYZ(0, 0, 0), new XYZ(0, 20, 0), new XYZ(0, 40, 0), new XYZ(0, 60, 0), new XYZ(0, 80, 0),
                new XYZ(20, 0, 100), new XYZ(20, 20, 200), new XYZ(20, 40, 300), new XYZ(20, 60, 200), new XYZ(20, 80, 100),
                new XYZ(40, 0, -100), new XYZ(40, 20, -250), new XYZ(40, 40, -300), new XYZ(40, 60, -250), new XYZ(40, 80, -100),
                new XYZ(60, 0, 100), new XYZ(60, 20, 200), new XYZ(60, 40, 300), new XYZ(60, 60, 200), new XYZ(60, 80, 100),
                new XYZ(80, 0, 0), new XYZ(80, 20, 0), new XYZ(80, 40, 0), new XYZ(80, 60, 0), new XYZ(80, 80, 0)
            };

            BRepBuilderSurfaceGeometry nurbsSurface = BRepBuilderSurfaceGeometry.CreateNURBSSurface(degreeU, degreeV, knotsU, knotsV, controlPoints, false /*bReverseOrientation*/, null /*pSurfaceEnvelope*/);

            // Create 4 NURBS curves defining the boundary of the NURBS surface that has just been created
            IList <double> weights = new List <double> {
                1, 1, 1, 1, 1
            };

            IList <XYZ> backEdgeControlPoints = new List <XYZ> {
                new XYZ(0, 0, 0), new XYZ(0, 20, 0), new XYZ(0, 40, 0), new XYZ(0, 60, 0), new XYZ(0, 80, 0)
            };
            Curve backNurbs = NurbSpline.CreateCurve(4, knotsU, backEdgeControlPoints, weights);
            BRepBuilderEdgeGeometry backEdge = BRepBuilderEdgeGeometry.Create(backNurbs);

            IList <XYZ> frontEdgeControlPoints = new List <XYZ> {
                new XYZ(80, 0, 0), new XYZ(80, 20, 0), new XYZ(80, 40, 0), new XYZ(80, 60, 0), new XYZ(80, 80, 0)
            };
            Curve frontNurbs = NurbSpline.CreateCurve(4, knotsU, frontEdgeControlPoints, weights);
            BRepBuilderEdgeGeometry frontEdge = BRepBuilderEdgeGeometry.Create(frontNurbs);

            IList <XYZ> leftEdgeControlPoints = new List <XYZ> {
                new XYZ(0, 0, 0), new XYZ(20, 0, 100), new XYZ(40, 0, -100), new XYZ(60, 0, 100), new XYZ(80, 0, 0)
            };
            Curve leftNurbs = NurbSpline.CreateCurve(4, knotsU, leftEdgeControlPoints, weights);
            BRepBuilderEdgeGeometry leftEdge = BRepBuilderEdgeGeometry.Create(leftNurbs);

            IList <XYZ> rightEdgeControlPoints = new List <XYZ> {
                new XYZ(0, 80, 0), new XYZ(20, 80, 100), new XYZ(40, 80, -100), new XYZ(60, 80, 100), new XYZ(80, 80, 0)
            };
            Curve rightNurbs = NurbSpline.CreateCurve(4, knotsU, rightEdgeControlPoints, weights);
            BRepBuilderEdgeGeometry rightEdge = BRepBuilderEdgeGeometry.Create(rightNurbs);

            // Add the geometries to the brepBuilder
            BRepBuilderGeometryId nurbSplineFaceId = brepBuilder.AddFace(nurbsSurface, false);
            BRepBuilderGeometryId loopId           = brepBuilder.AddLoop(nurbSplineFaceId);

            BRepBuilderGeometryId backEdgeId  = brepBuilder.AddEdge(backEdge);
            BRepBuilderGeometryId frontEdgeId = brepBuilder.AddEdge(frontEdge);
            BRepBuilderGeometryId leftEdgeId  = brepBuilder.AddEdge(leftEdge);
            BRepBuilderGeometryId rightEdgeId = brepBuilder.AddEdge(rightEdge);

            // Add each edge to the loop
            brepBuilder.AddCoEdge(loopId, backEdgeId, true);
            brepBuilder.AddCoEdge(loopId, leftEdgeId, false);
            brepBuilder.AddCoEdge(loopId, frontEdgeId, false);
            brepBuilder.AddCoEdge(loopId, rightEdgeId, true);
            brepBuilder.FinishLoop(loopId);
            brepBuilder.FinishFace(nurbSplineFaceId);

            brepBuilder.Finish();
            return(brepBuilder);
        }
示例#14
0
        private void CreateTruncatedCone()
        {
            BRepBuilder brepBuilder = new BRepBuilder(BRepType.Solid);
            Plane       bottom      = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, -1), new XYZ(0, 0, 0));
            Plane       top         = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 50));

            Frame basis = new Frame(new XYZ(0, 0, 100), new XYZ(0, 1, 0), new XYZ(1, 0, 0), new XYZ(0, 0, -1));

            // Note that we do not have to create two identical surfaces here. The same surface can be used for multiple faces,
            // since BRepBuilderSurfaceGeometry::Create() copies the input surface.
            // Thus, potentially we could have only one surface here,
            // but we must create at least two faces below to account for periodicity.
            ConicalSurface rightConicalSurface = ConicalSurface.Create(basis, Math.Atan(0.5));
            ConicalSurface leftConicalSurface  = ConicalSurface.Create(basis, Math.Atan(0.5));

            // Create 4 faces of the cone
            BRepBuilderGeometryId topFaceId       = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false);
            BRepBuilderGeometryId bottomFaceId    = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), false);
            BRepBuilderGeometryId rightSideFaceId = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(rightConicalSurface, null), false);
            BRepBuilderGeometryId leftSideFaceId  = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(leftConicalSurface, null), false);

            // Create 2 edges at the bottom of the cone
            BRepBuilderEdgeGeometry bottomRightEdgeGeom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(-50, 0, 0), new XYZ(50, 0, 0), new XYZ(0, 50, 0)));
            BRepBuilderEdgeGeometry bottomLeftEdgeGeom  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(50, 0, 0), new XYZ(-50, 0, 0), new XYZ(0, -50, 0)));

            // Create 2 edges at the top of the cone
            BRepBuilderEdgeGeometry topLeftEdgeGeom  = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(-25, 0, 50), new XYZ(25, 0, 50), new XYZ(0, -25, 50)));
            BRepBuilderEdgeGeometry topRightEdgeGeom = BRepBuilderEdgeGeometry.Create(Arc.Create(new XYZ(25, 0, 50), new XYZ(-25, 0, 50), new XYZ(0, 25, 50)));

            // Create 2 side edges of the cone
            BRepBuilderEdgeGeometry sideFrontEdgeGeom = BRepBuilderEdgeGeometry.Create(new XYZ(25, 0, 50), new XYZ(50, 0, 0));
            BRepBuilderEdgeGeometry sideBackEdgeGeom  = BRepBuilderEdgeGeometry.Create(new XYZ(-25, 0, 50), new XYZ(-50, 0, 0));

            BRepBuilderGeometryId bottomRightId   = brepBuilder.AddEdge(bottomRightEdgeGeom);
            BRepBuilderGeometryId bottomLeftId    = brepBuilder.AddEdge(bottomLeftEdgeGeom);
            BRepBuilderGeometryId topRightEdgeId  = brepBuilder.AddEdge(topRightEdgeGeom);
            BRepBuilderGeometryId topLeftEdgeId   = brepBuilder.AddEdge(topLeftEdgeGeom);
            BRepBuilderGeometryId sideFrontEdgeid = brepBuilder.AddEdge(sideFrontEdgeGeom);
            BRepBuilderGeometryId sideBackEdgeId  = brepBuilder.AddEdge(sideBackEdgeGeom);


            // Create bottom face
            BRepBuilderGeometryId bottomLoopId = brepBuilder.AddLoop(bottomFaceId);

            brepBuilder.AddCoEdge(bottomLoopId, bottomRightId, false);
            brepBuilder.AddCoEdge(bottomLoopId, bottomLeftId, false);
            brepBuilder.FinishLoop(bottomLoopId);
            brepBuilder.FinishFace(bottomFaceId);

            // Create top face
            BRepBuilderGeometryId topLoopId = brepBuilder.AddLoop(topFaceId);

            brepBuilder.AddCoEdge(topLoopId, topLeftEdgeId, false);
            brepBuilder.AddCoEdge(topLoopId, topRightEdgeId, false);
            brepBuilder.FinishLoop(topLoopId);
            brepBuilder.FinishFace(topFaceId);

            // Create right face
            BRepBuilderGeometryId rightLoopId = brepBuilder.AddLoop(rightSideFaceId);

            brepBuilder.AddCoEdge(rightLoopId, topRightEdgeId, true);
            brepBuilder.AddCoEdge(rightLoopId, sideFrontEdgeid, false);
            brepBuilder.AddCoEdge(rightLoopId, bottomRightId, true);
            brepBuilder.AddCoEdge(rightLoopId, sideBackEdgeId, true);
            brepBuilder.FinishLoop(rightLoopId);
            brepBuilder.FinishFace(rightSideFaceId);

            // Create left face
            BRepBuilderGeometryId leftLoopId = brepBuilder.AddLoop(leftSideFaceId);

            brepBuilder.AddCoEdge(leftLoopId, topLeftEdgeId, true);
            brepBuilder.AddCoEdge(leftLoopId, sideBackEdgeId, false);
            brepBuilder.AddCoEdge(leftLoopId, bottomLeftId, true);
            brepBuilder.AddCoEdge(leftLoopId, sideFrontEdgeid, true);
            brepBuilder.FinishLoop(leftLoopId);
            brepBuilder.FinishFace(leftSideFaceId);

            brepBuilder.Finish();
            createDirectShapeElementFromBrepBuilderObject(brepBuilder, "Cone surface");
        }
示例#15
0
        private BRepBuilder CreateCubeImpl()
        {
            // create a BRepBuilder; add faces to build a cube

            BRepBuilder brepBuilder = new BRepBuilder(BRepType.Solid);

            // a cube 100x100x100, from (0,0,0) to (100, 100, 100)

            // 1. Planes.
            // naming convention for faces and planes:
            // We are looking at this cube in an isometric view. X is down and to the left of us, Y is horizontal and points to the right, Z is up.
            // front and back faces are along the X axis, left and right are along the Y axis, top and bottom are along the Z axis.
            Plane bottom = Plane.CreateByOriginAndBasis(new XYZ(50, 50, 0), new XYZ(1, 0, 0), new XYZ(0, 1, 0));   // bottom. XY plane, Z = 0, normal pointing inside the cube.
            Plane top    = Plane.CreateByOriginAndBasis(new XYZ(50, 50, 100), new XYZ(1, 0, 0), new XYZ(0, 1, 0)); // top. XY plane, Z = 100, normal pointing outside the cube.
            Plane front  = Plane.CreateByOriginAndBasis(new XYZ(100, 50, 50), new XYZ(0, 0, 1), new XYZ(0, 1, 0)); // front side. ZY plane, X = 0, normal pointing inside the cube.
            Plane back   = Plane.CreateByOriginAndBasis(new XYZ(0, 50, 50), new XYZ(0, 0, 1), new XYZ(0, 1, 0));   // back side. ZY plane, X = 0, normal pointing outside the cube.
            Plane left   = Plane.CreateByOriginAndBasis(new XYZ(50, 0, 50), new XYZ(0, 0, 1), new XYZ(1, 0, 0));   // left side. ZX plane, Y = 0, normal pointing inside the cube
            Plane right  = Plane.CreateByOriginAndBasis(new XYZ(50, 100, 50), new XYZ(0, 0, 1), new XYZ(1, 0, 0)); // right side. ZX plane, Y = 100, normal pointing outside the cube
            //Note that the alternating of "inside/outside" matches the alternating of "true/false" in the next block that defines faces.
            //There must be a correspondence to ensure that all faces are correctly oriented to point out of the solid.
            // 2. Faces.
            BRepBuilderGeometryId faceId_Bottom = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(bottom, null), true);
            BRepBuilderGeometryId faceId_Top    = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(top, null), false);
            BRepBuilderGeometryId faceId_Front  = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(front, null), true);
            BRepBuilderGeometryId faceId_Back   = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(back, null), false);
            BRepBuilderGeometryId faceId_Left   = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(left, null), true);
            BRepBuilderGeometryId faceId_Right  = brepBuilder.AddFace(BRepBuilderSurfaceGeometry.Create(right, null), false);

            // 3. Edges.

            // 3.a (define edge geometry)
            // walk around bottom face
            BRepBuilderEdgeGeometry edgeBottomFront = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 0), new XYZ(100, 100, 0));
            BRepBuilderEdgeGeometry edgeBottomRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 0), new XYZ(0, 100, 0));
            BRepBuilderEdgeGeometry edgeBottomBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 0), new XYZ(0, 0, 0));
            BRepBuilderEdgeGeometry edgeBottomLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 0), new XYZ(100, 0, 0));

            // now walk around top face
            BRepBuilderEdgeGeometry edgeTopFront = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 100), new XYZ(100, 100, 100));
            BRepBuilderEdgeGeometry edgeTopRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 100), new XYZ(0, 100, 100));
            BRepBuilderEdgeGeometry edgeTopBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 100), new XYZ(0, 0, 100));
            BRepBuilderEdgeGeometry edgeTopLeft  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 100), new XYZ(100, 0, 100));

            // sides
            BRepBuilderEdgeGeometry edgeFrontRight = BRepBuilderEdgeGeometry.Create(new XYZ(100, 100, 0), new XYZ(100, 100, 100));
            BRepBuilderEdgeGeometry edgeRightBack  = BRepBuilderEdgeGeometry.Create(new XYZ(0, 100, 0), new XYZ(0, 100, 100));
            BRepBuilderEdgeGeometry edgeBackLeft   = BRepBuilderEdgeGeometry.Create(new XYZ(0, 0, 0), new XYZ(0, 0, 100));
            BRepBuilderEdgeGeometry edgeLeftFront  = BRepBuilderEdgeGeometry.Create(new XYZ(100, 0, 0), new XYZ(100, 0, 100));

            // 3.b (define the edges themselves)
            BRepBuilderGeometryId edgeId_BottomFront = brepBuilder.AddEdge(edgeBottomFront);
            BRepBuilderGeometryId edgeId_BottomRight = brepBuilder.AddEdge(edgeBottomRight);
            BRepBuilderGeometryId edgeId_BottomBack  = brepBuilder.AddEdge(edgeBottomBack);
            BRepBuilderGeometryId edgeId_BottomLeft  = brepBuilder.AddEdge(edgeBottomLeft);
            BRepBuilderGeometryId edgeId_TopFront    = brepBuilder.AddEdge(edgeTopFront);
            BRepBuilderGeometryId edgeId_TopRight    = brepBuilder.AddEdge(edgeTopRight);
            BRepBuilderGeometryId edgeId_TopBack     = brepBuilder.AddEdge(edgeTopBack);
            BRepBuilderGeometryId edgeId_TopLeft     = brepBuilder.AddEdge(edgeTopLeft);
            BRepBuilderGeometryId edgeId_FrontRight  = brepBuilder.AddEdge(edgeFrontRight);
            BRepBuilderGeometryId edgeId_RightBack   = brepBuilder.AddEdge(edgeRightBack);
            BRepBuilderGeometryId edgeId_BackLeft    = brepBuilder.AddEdge(edgeBackLeft);
            BRepBuilderGeometryId edgeId_LeftFront   = brepBuilder.AddEdge(edgeLeftFront);

            // 4. Loops.
            BRepBuilderGeometryId loopId_Bottom = brepBuilder.AddLoop(faceId_Bottom);
            BRepBuilderGeometryId loopId_Top    = brepBuilder.AddLoop(faceId_Top);
            BRepBuilderGeometryId loopId_Front  = brepBuilder.AddLoop(faceId_Front);
            BRepBuilderGeometryId loopId_Back   = brepBuilder.AddLoop(faceId_Back);
            BRepBuilderGeometryId loopId_Right  = brepBuilder.AddLoop(faceId_Right);
            BRepBuilderGeometryId loopId_Left   = brepBuilder.AddLoop(faceId_Left);

            // 5. Co-edges.
            // Bottom face. All edges reversed
            brepBuilder.AddCoEdge(loopId_Bottom, edgeId_BottomFront, true); // other direction in front loop
            brepBuilder.AddCoEdge(loopId_Bottom, edgeId_BottomLeft, true);  // other direction in left loop
            brepBuilder.AddCoEdge(loopId_Bottom, edgeId_BottomBack, true);  // other direction in back loop
            brepBuilder.AddCoEdge(loopId_Bottom, edgeId_BottomRight, true); // other direction in right loop
            brepBuilder.FinishLoop(loopId_Bottom);
            brepBuilder.FinishFace(faceId_Bottom);

            // Top face. All edges NOT reversed.
            brepBuilder.AddCoEdge(loopId_Top, edgeId_TopFront, false); // other direction in front loop.
            brepBuilder.AddCoEdge(loopId_Top, edgeId_TopRight, false); // other direction in right loop
            brepBuilder.AddCoEdge(loopId_Top, edgeId_TopBack, false);  // other direction in back loop
            brepBuilder.AddCoEdge(loopId_Top, edgeId_TopLeft, false);  // other direction in left loop
            brepBuilder.FinishLoop(loopId_Top);
            brepBuilder.FinishFace(faceId_Top);

            // Front face.
            brepBuilder.AddCoEdge(loopId_Front, edgeId_BottomFront, false); // other direction in bottom loop
            brepBuilder.AddCoEdge(loopId_Front, edgeId_FrontRight, false);  // other direction in right loop
            brepBuilder.AddCoEdge(loopId_Front, edgeId_TopFront, true);     // other direction in top loop.
            brepBuilder.AddCoEdge(loopId_Front, edgeId_LeftFront, true);    // other direction in left loop.
            brepBuilder.FinishLoop(loopId_Front);
            brepBuilder.FinishFace(faceId_Front);

            // Back face
            brepBuilder.AddCoEdge(loopId_Back, edgeId_BottomBack, false); // other direction in bottom loop
            brepBuilder.AddCoEdge(loopId_Back, edgeId_BackLeft, false);   // other direction in left loop.
            brepBuilder.AddCoEdge(loopId_Back, edgeId_TopBack, true);     // other direction in top loop
            brepBuilder.AddCoEdge(loopId_Back, edgeId_RightBack, true);   // other direction in right loop.
            brepBuilder.FinishLoop(loopId_Back);
            brepBuilder.FinishFace(faceId_Back);

            // Right face
            brepBuilder.AddCoEdge(loopId_Right, edgeId_BottomRight, false); // other direction in bottom loop
            brepBuilder.AddCoEdge(loopId_Right, edgeId_RightBack, false);   // other direction in back loop
            brepBuilder.AddCoEdge(loopId_Right, edgeId_TopRight, true);     // other direction in top loop
            brepBuilder.AddCoEdge(loopId_Right, edgeId_FrontRight, true);   // other direction in front loop
            brepBuilder.FinishLoop(loopId_Right);
            brepBuilder.FinishFace(faceId_Right);

            // Left face
            brepBuilder.AddCoEdge(loopId_Left, edgeId_BottomLeft, false); // other direction in bottom loop
            brepBuilder.AddCoEdge(loopId_Left, edgeId_LeftFront, false);  // other direction in front loop
            brepBuilder.AddCoEdge(loopId_Left, edgeId_TopLeft, true);     // other direction in top loop
            brepBuilder.AddCoEdge(loopId_Left, edgeId_BackLeft, true);    // other direction in back loop
            brepBuilder.FinishLoop(loopId_Left);
            brepBuilder.FinishFace(faceId_Left);

            brepBuilder.Finish();
            return(brepBuilder);
        }
示例#16
0
        /***************************************************/

        private static bool TryAddSurface(this BRepBuilder brep, NurbsSurface ns)
        {
            if (ns.IsClosed())
            {
                BH.Engine.Reflection.Compute.RecordError("Revit does not support closed or periodic nurbs surfaces, convert failed.");
                return(false);
            }

            try
            {
                List <int> uvCount = ns.UVCount(); // Align to Revit nurbs definition
                double[][] weights = new double[uvCount[0]][];
                XYZ[][]    points  = new XYZ[uvCount[0]][];

                List <double> uKnots = new List <double>(ns.UKnots);
                uKnots.Insert(0, uKnots.First());
                uKnots.Add(uKnots.Last());

                List <double> vKnots = new List <double>(ns.VKnots);
                vKnots.Insert(0, vKnots.First());
                vKnots.Add(vKnots.Last());

                for (int i = 0; i < uvCount[0]; i++)
                {
                    points[i]  = new XYZ[uvCount[1]];
                    weights[i] = new double[uvCount[1]];
                    for (int j = 0; j < uvCount[1]; j++)
                    {
                        points[i][j]  = ns.ControlPoints[j + (uvCount[1] * i)].ToRevit();
                        weights[i][j] = ns.Weights[j + (uvCount[1] * i)];
                    }
                }

                List <XYZ> pointList = new List <XYZ>();
                foreach (XYZ[] x in points)
                {
                    pointList.AddRange(x);
                }

                List <double> weightList = new List <double>();
                foreach (double[] x in weights)
                {
                    weightList.AddRange(x);
                }

                BRepBuilderSurfaceGeometry bbsg = BRepBuilderSurfaceGeometry.CreateNURBSSurface(ns.UDegree, ns.VDegree, uKnots, vKnots, pointList, weightList, false, null);
                BRepBuilderGeometryId      face = brep.AddFace(bbsg, false);

                foreach (SurfaceTrim trim in ns.OuterTrims)
                {
                    BRepBuilderGeometryId loop = brep.AddLoop(face);
                    foreach (ICurve sp in trim.Curve3d.ISubParts())
                    {
                        List <Curve> ccs = sp.IToRevitCurves();
                        foreach (Curve cc in ccs)
                        {
                            BRepBuilderGeometryId edge = brep.AddEdge(BRepBuilderEdgeGeometry.Create(cc));
                            brep.AddCoEdge(loop, edge, false);
                        }
                    }
                    brep.FinishLoop(loop);
                }

                foreach (SurfaceTrim trim in ns.InnerTrims)
                {
                    BRepBuilderGeometryId loop = brep.AddLoop(face);
                    foreach (ICurve sp in trim.Curve3d.ISubParts())
                    {
                        List <Curve> ccs = sp.IToRevitCurves();
                        foreach (Curve cc in ccs)
                        {
                            BRepBuilderGeometryId edge = brep.AddEdge(BRepBuilderEdgeGeometry.Create(cc));
                            brep.AddCoEdge(loop, edge, false);
                        }
                    }

                    brep.FinishLoop(loop);
                }

                brep.FinishFace(face);
            }
            catch
            {
                BH.Engine.Reflection.Compute.RecordError("An attempt to create a nurbs surface failed.");
                return(false);
            }

            return(true);
        }