예제 #1
0
        public static void House(Model model)
        {
            Region outer = Region.CreatePolygon(new Point3D[]
            {
                new Point3D(0, 0),
                new Point3D(460, 0),
                new Point3D(460, 100),
                new Point3D(600, 100),
                new Point3D(600, 400),
                new Point3D(0, 400)
            });

            // House's extruded outer profile
            Solid body = outer.ExtrudeAsSolid(400, 0);

            // Big room at origin
            Solid bigRoom = Solid.CreateBox(400, 340, 400);

            // Moves big room in place
            bigRoom.Translate(30, 30, 0);

            // Cuts the big room from the house's body
            Solid[] firstCut = Solid.Difference(body, bigRoom);

            // Small room
            Solid smallRoom = Solid.CreateBox(130, 240, 400);

            // Moves small room in place
            smallRoom.Translate(440, 130, 0);

            // Cuts the small room from the house's body
            Solid[] secondCut = Solid.Difference(firstCut[0], smallRoom);

            // Draws the main door profile on a vertical plane
            Plane pln = new Plane(new Point3D(100, 40, 0), Vector3D.AxisX, Vector3D.AxisZ);

            Line l1 = new Line(pln, 0, 180, 0, 0);
            Line l2 = new Line(pln, 0, 0, 120, 0);
            Line l3 = new Line(pln, 120, 0, 120, 180);
            Arc  a1 = new Arc(pln, new Point2D(60, 155), new Point2D(120, 180), new Point2D(0, 180));

            devDept.Eyeshot.Entities.Region reg = new devDept.Eyeshot.Entities.Region(new CompositeCurve(l1, l2, l3, a1));

            // Cuts the main door profile from the house's body
            secondCut[0].ExtrudeRemove(reg, 50, 1);

            // central horizontal beam
            Solid beam1 = Solid.CreateBox(680, 30, 40);

            // moves in place
            beam1.Translate(-40, 185, 360);

            // cut the house's body
            Solid[] thirdCut = Solid.Difference(secondCut[0], beam1);

            // same for other two horizontal beams
            Solid beam2 = Solid.CreateBox(680, 20, 40);

            beam2.Translate(-40, 0, 280);

            Solid[] fourthCut = Solid.Difference(thirdCut[0], beam2);

            Solid beam3 = Solid.CreateBox(680, 20, 40);

            beam3.Translate(-40, 380, 280);

            Solid[] fifthCut = Solid.Difference(fourthCut[0], beam3);

            // Intersection tool loop
            outer = Region.CreatePolygon(Plane.YZ, new Point2D[]
            {
                new Point2D(0, 0),
                new Point2D(400, 0),
                new Point2D(400, 300),
                new Point2D(200, 400),
                new Point2D(0, 300)
            });

            // Tool body
            Solid intersectionTool = outer.ExtrudeAsSolid(Vector3D.AxisX * 680, 0);

            // Moves the tool in place
            intersectionTool.Translate(-40, 0, 0);

            // Intersects the house's body with the tool
            Solid[] firstInters = Solid.Intersection(fifthCut[0], intersectionTool);

            // Intersects the horizontal beams with the tool
            Solid[] secondInters = Solid.Intersection(beam1, intersectionTool);
            Solid[] thirdInters  = Solid.Intersection(beam2, intersectionTool);
            Solid[] fourthInters = Solid.Intersection(beam3, intersectionTool);

            // Adds beams to the scene
            model.Entities.AddRange(secondInters, Color.SaddleBrown);
            model.Entities.AddRange(thirdInters, Color.SaddleBrown);
            model.Entities.AddRange(fourthInters, Color.SaddleBrown);

            // Basement sweep rail
            LinearPath rail = new LinearPath(new Point3D[]
            {
                new Point3D(220, 0),
                new Point3D(460, 0),
                new Point3D(460, 100),
                new Point3D(600, 100),
                new Point3D(600, 400),
                new Point3D(0, 400),
                new Point3D(0, 0),
                new Point3D(100, 0)
            });

            // Basement sweep section
            Region section = Region.CreatePolygon(new Point3D[]
            {
                new Point3D(220, 0, 0),
                new Point3D(220, -7.5, 0),
                new Point3D(220, 0, 75)
            });

            // Sweep solid
            Solid basement = section.SweepAsSolid(rail, 0);

            // Merges sweep with the house's body
            Solid[] firstUnion = Solid.Union(firstInters[0], basement);

            // Internal door
            Solid door = Solid.CreateBox(30, 80, 210);

            // Moves internal door in place
            door.Translate(420, 140, 0);

            // Cuts the internal door from the house's body
            Solid[] sixthCut = Solid.Difference(firstUnion[0], door);

            Solid beam10 = Solid.CreateBox(10, 120, 20);

            beam10.Translate(430, 120, 210);
            model.Entities.Add(beam10, Color.Gray);

            Solid[] seventhCut = Solid.Difference(sixthCut[0], beam10);

            // Window
            Solid window = Solid.CreateBox(90, 50, 140);

            // Moves window in place
            window.Translate(280, -10, 90);

            // Cuts the window from the house's body
            Solid[] eighthCut = Solid.Difference(seventhCut[0], window);

            Solid windowLedge = Solid.CreateBox(100, 35, 5);

            windowLedge.Translate(275, -5, 85);
            model.Entities.Add(windowLedge, Color.Gray);

            Solid[] sixthCut3 = Solid.Difference(eighthCut[0], windowLedge);

            sixthCut3[0].SmoothingAngle = Utility.DegToRad(1);

            model.Entities.AddRange(sixthCut3, Color.WhiteSmoke);


            // Oblique beam loop
            Region obliqueLoop = Region.CreatePolygon(Plane.YZ, new Point2D[]
            {
                new Point2D(200, 0),
                new Point2D(-60, -130),
                new Point2D(-60, -150),
                new Point2D(200, -20)
            });

            // Oblique beam
            Solid oblique = obliqueLoop.ExtrudeAsSolid(10, 0);

            // Moves in place
            oblique.Translate(-40, 0, 420);

            // A list of entities we need to mirror
            List <Entity> toBeMirrored = new List <Entity>();

            toBeMirrored.Add(oblique);

            // Copies and adds the oblique beam
            for (int i = 0; i < 7; i++)
            {
                Entity clone = (Entity)oblique.Clone();

                clone.Translate((((680 - 8 * 10) / 7.0) + 10) * (i + 1), 0, 0);

                toBeMirrored.Add(clone);
            }

            // Copies and mirrors
            int count = toBeMirrored.Count;

            Plane mirrorPlane = Plane.ZX;

            mirrorPlane.Origin.Y = 200;

            Mirror m = new Mirror(mirrorPlane);

            for (int i = 0; i < count; i++)
            {
                Entity clone = (Entity)toBeMirrored[i].Clone();

                clone.TransformBy(m);

                toBeMirrored.Add(clone);
            }

            // Adds all the array items to the scene
            model.Entities.AddRange(toBeMirrored, Color.SaddleBrown);
        }
예제 #2
0
        private static Solid getSolidFromIfcBooleanClippingResult(IfcBooleanClippingResult bcr)
        {
            Solid op1 = null, op2 = null;
            Solid mmm = null;

            Entity e;

            if (bcr.FirstOperand is IfcBooleanClippingResult)
            {
                op1 = getSolidFromIfcBooleanClippingResult((IfcBooleanClippingResult)bcr.FirstOperand);
            }
            else
            {
                e = getEntityFromIfcRepresentationItem((IfcRepresentationItem)bcr.FirstOperand);

                if (e != null)// && (e is Solid || e is Mesh))
                {
                    if (e is Mesh)
                    {
                        op1 = ((Mesh)e).ConvertToSolid();
                    }
                    else
                    {
                        op1 = (Solid)e;
                    }
                }
            }

            //m = getMeshFromIfcRepresentationItem((IfcRepresentationItem)bcr.SecondOperand);

            //if (m != null)
            //    op2 = m.ConvertToSolid();

            if (bcr.SecondOperand is IfcPolygonalBoundedHalfSpace)
            {
                IfcPolygonalBoundedHalfSpace polB = (IfcPolygonalBoundedHalfSpace)bcr.SecondOperand;

                IfcPlane baseSurface = (IfcPlane)polB.BaseSurface;

                Plane cutPln = Conversion.getPlaneFromPosition(baseSurface.Position);


                devDept.Eyeshot.Entities.Region r = new RectangularRegion(cutPln, 100, 100, true);
                mmm = r.ExtrudeAsSolid(cutPln.AxisZ * 0.1, 0.1);


                Plane boundaryPlane = Conversion.getPlaneFromPosition(polB.Position);

                Align3D align = new Align3D(Plane.XY, boundaryPlane);

                ICurve boundary = getICurveFromIfcCurve(polB.PolygonalBoundary);

                if (boundary != null)
                {
                    devDept.Eyeshot.Entities.Region region = new devDept.Eyeshot.Entities.Region(boundary);

                    region.TransformBy(align);

                    Vector3D extDir = boundaryPlane.AxisZ;

                    op2 = region.ExtrudeAsSolid(extDir * 20, 0.1); // 0.1 tolerance must be computed according to object size

                    if (!polB.AgreementFlag)
                    {
                        cutPln.Flip();
                    }

                    op2.CutBy(cutPln);
                }
            }
            else if (bcr.SecondOperand is IfcHalfSpaceSolid)
            {
                IfcHalfSpaceSolid hs = (IfcHalfSpaceSolid)bcr.SecondOperand;

                IfcPlane ip = (IfcPlane)hs.BaseSurface;

                Plane pln = Conversion.getPlaneFromPosition(ip.Position);

                if (!hs.AgreementFlag)
                {
                    pln.Flip();
                }

                if (op1 != null)
                {
                    op1.CutBy(pln);
                }
                return(op1);
            }

            if (op1 == null || op2 == null)
            {
                return(null);
            }

            //op1.TransformBy(trs);
            //op2.TransformBy(trs);

            //viewportLayout1.Entities.Add(op1, testLayer, Color.Red);
            //viewportLayout1.Entities.Add(op2, testLayer, Color.Blue);
            //return null;

            Solid[] result;

            double tolerance = 0.01;

            switch (bcr.Operator)
            {
            case IfcBooleanOperator.DIFFERENCE:
                result = Solid.Difference(op1, op2, tolerance);        //su dll nuova e' possibile inserire parametro di tolleranza
                break;

            case IfcBooleanOperator.UNION:
                result = Solid.Union(op1, op2, tolerance);
                break;

            case IfcBooleanOperator.INTERSECTION:
                result = Solid.Intersection(op1, op2, tolerance);
                break;

            default:
                return(null);
            }

            //WriteSTL ws = new WriteSTL(new Entity[] { op1, op2, mmm }, new Layer[] { new Layer("Default") }, new Dictionary<string, Block>(), @"c:\devdept\booleanError\gino" + count + ".stl", 0.01, true);
            //count++;
            //ws.DoWork();

            if (result != null)
            {
                return(result[0]);
            }
            else
            {
                WriteSTL ws = new WriteSTL(new Entity[] { op1, op2 }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\gino" + bcr.Index + ".stl", 0.01, true);
                count++;
                ws.DoWork();
                debug += "Error in boolean operation\n";
                return(op1);
            }
        }