Ejemplo n.º 1
0
        /// <summary>
        /// Initialize a new loop for the current face
        /// </summary>
        public void InitializeNewLoop()
        {
            if (m_BrepBuilder == null)
            {
                throw new InvalidOperationException("StartCollectingFaceSet has not been called");
            }
            if (m_CurrentBrepBuilderFace == null)
            {
                throw new InvalidOperationException("StartCollectingFaceForBrepBuilder has not been called");
            }

            if (m_CurrentBrepBuilderLoop != null)
            {
                // We could allow several active faces, with each face having a loop being actively constructed, but the current
                // design, with a single m_CurrentBrepBuilderFace and a single m_CurrentBrepBuilderLoop, apparently imposes the
                // stricter requirement that faces are constructed one at a time, and for each face, its loops are constructed
                // one at a time.
                throw new InvalidOperationException("InitializeNewLoop has already been called - only one loop may be active at a time.");
            }

            m_CurrentBrepBuilderLoop = m_BrepBuilder.AddLoop(m_CurrentBrepBuilderFace);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finish constructing a loop for the current face.
        /// </summary>
        /// <param name="isValid">We are finishing a valid loop if true.</param>
        public void StopConstructingLoop(bool isValid)
        {
            if (m_BrepBuilder == null)
            {
                throw new InvalidOperationException("StartCollectingFaceSet has not been called");
            }
            if (m_CurrentBrepBuilderFace == null)
            {
                throw new InvalidOperationException("StartCollectingFaceForBrepBuilder has not been called");
            }

            if (m_CurrentBrepBuilderLoop == null)
            {
                throw new InvalidOperationException("InitializeNewLoop has not been called");
            }

            if (isValid)
            {
                m_BrepBuilder.FinishLoop(m_CurrentBrepBuilderLoop);
            }

            m_CurrentBrepBuilderLoop = null;
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add the oriented edge to the current loop
        /// </summary>
        /// <param name="id">the id of the edge, corresponding to the StepID of the IfcOrientedEdge</param>
        /// <param name="curve">the curve, which represents the geometry of the edge</param>
        /// <param name="startPoint">the start point of the curve</param>
        /// <param name="endPoint">the end point of the curve</param>
        /// <param name="orientation">the orientation of the edge</param>
        /// <returns>true if the edge is successfully added to the boundary</returns>
        public bool AddOrientedEdgeToTheBoundary(int id, Curve curve, XYZ startPoint, XYZ endPoint, bool orientation)
        {
            if (m_CurrentBrepBuilderLoop == null)
            {
                throw new InvalidOperationException("StartCollectingLoopForBrepBuilder hasn't been called");
            }

            BRepBuilderGeometryId edgeId = null;

            if (m_EdgeIdToBrepId.ContainsKey(id) && m_EdgeIdToBrepId[id] != null)
            {
                edgeId = m_EdgeIdToBrepId[id];
            }
            else
            {
                //TODO: create an utility function MakeBound(Curve, XYZ, XYZ) and factor out this code
                BRepBuilderEdgeGeometry edge = null;
                if (curve is Line)
                {
                    edge = BRepBuilderEdgeGeometry.Create(startPoint, endPoint);
                }
                else if (curve is Arc)
                {
                    Arc arc = curve as Arc;

                    // The curve we receive is an unbound arc, so we have to bound it by the startPoint and the endPoint
                    IntersectionResult start = arc.Project(startPoint);
                    IntersectionResult end   = arc.Project(endPoint);

                    double startParameter = start.Parameter;
                    double endParameter   = end.Parameter;

                    if (endParameter < startParameter)
                    {
                        endParameter += Math.PI * 2;
                    }

                    arc.MakeBound(startParameter, endParameter);

                    edge = BRepBuilderEdgeGeometry.Create(arc);
                }
                else if (curve is Ellipse)
                {
                    Ellipse ellipse = curve as Ellipse;

                    IntersectionResult start = ellipse.Project(startPoint);
                    IntersectionResult end   = ellipse.Project(endPoint);

                    double startParameter = start.Parameter;
                    double endParameter   = end.Parameter;

                    if (endParameter < startParameter)
                    {
                        endParameter += Math.PI * 2;
                    }

                    ellipse.MakeBound(startParameter, endParameter);
                    edge = BRepBuilderEdgeGeometry.Create(ellipse);
                }
                else if (curve is NurbSpline)
                {
                    NurbSpline nurbs = curve as NurbSpline;

                    // Bound the NurbSpline based on the start and end points.
                    // As mentioned above, there should be a function to bound
                    // a curve based on two 3D points and it should be used here
                    // instead of duplicating manual code.
                    IntersectionResult start          = nurbs.Project(startPoint);
                    IntersectionResult end            = nurbs.Project(endPoint);
                    double             startParameter = start.Parameter;
                    double             endParameter   = end.Parameter;
                    if (endParameter < startParameter)
                    {
                        Importer.TheLog.LogError(id, "Inverted start/end parameters for NurbSpline.", false /*throwError*/);
                        return(false);
                    }
                    else
                    {
                        nurbs.MakeBound(startParameter, endParameter);
                    }

                    edge = BRepBuilderEdgeGeometry.Create(nurbs);
                }
                else
                {
                    Importer.TheLog.LogError(id, "Unsupported edge curve type: " + curve.GetType().ToString(), false);
                    return(false);
                }

                edgeId = m_BrepBuilder.AddEdge(edge);
                m_EdgeIdToBrepId.Add(id, edgeId);
            }
            try
            {
                m_BrepBuilder.AddCoEdge(m_CurrentBrepBuilderLoop, edgeId, !orientation);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }