Example #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);
        }
Example #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);
        }
Example #3
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));
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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");
        }
Example #8
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);
        }