public void SketchSelectionSensitivity()
        {
            var body = TestSketchGenerator.CreateRectangle(10, 10).Body;
            var ctx  = Context.Current;

            ctx.ViewportController.ZoomFitAll();

            Assert.Multiple(() =>
            {
                // Enhanced sensitivity for sketches
                ctx.ClickAt(350, 160);
                Assert.IsFalse(ctx.WorkspaceController.Selection.SelectedEntities.Contains(body), "1");
                ctx.ClickAt(350, 170);
                Assert.IsTrue(ctx.WorkspaceController.Selection.SelectedEntities.Contains(body), "2");

                // Restore original sensitivity when converted to solid
                Extrude.Create(body);
                ctx.WorkspaceController.Invalidate(forceRedraw: true);

                ctx.ClickAt(350, 160);
                Assert.IsFalse(ctx.WorkspaceController.Selection.SelectedEntities.Contains(body), "3");
                ctx.ClickAt(350, 170);
                Assert.IsTrue(ctx.WorkspaceController.Selection.SelectedEntities.Contains(body), "4");
                //AssertHelper.IsSameViewport(Path.Combine(_BasePath, "SketchSelectionSensitivity01"));
            });
        }
        public void test()
        {
            List <IVector3d> H_points = helvetica_H.ToList();
            List <IVector3d> e_points = helvetica_e.ToList();

            H_points = H_points.Distinct().ToList();
            e_points = e_points.Distinct().ToList();

            CSG HLetter = Extrude.points(Vector3d.xyz(0, 0, 10), H_points);
            CSG eLetter = Extrude.points(Vector3d.xyz(0, 0, 10), e_points);

            Console.Out.WriteLine("H number of polygons: " + HLetter.getPolygons().Count);
            Console.Out.WriteLine("e number of polygons: " + eLetter.getPolygons().Count);



            // CSG.setDefaultOptType(CSG.OptType.CSG_BOUND);


            CSG simpleUnionOfNonIntersectingBodies = eLetter.union(HLetter);

            int numPolysExpected = HLetter.getPolygons().Count + eLetter.getPolygons().Count;

            Console.Out.WriteLine("Both number of polygons: " + simpleUnionOfNonIntersectingBodies.getPolygons().Count);

            // assumption only valid if optimization is enabled! (see above)
            // assumption is wrong for CSG.setDefaultOptType(CSG.OptType.NONE);
            // assertTrue(numPolysExpected == simpleUnionOfNonIntersectingBodies.getPolygons().size());
        }
Example #3
0
        public void SolidIntersectsPlaneAtFaceReturningFaceLoop()
        {
            this.Name = nameof(SolidIntersectsPlaneAtFaceReturningFaceLoop);

            var r       = new Random();
            var profile = Polygon.Rectangle(5, 5);
            var extrude = new Extrude(profile, 5, Vector3.ZAxis, false);
            var plane   = new Plane(new Vector3(0, -2.5, 2.5), Vector3.YAxis.Negate());

            Assert.True(extrude.Solid.Intersects(plane, out List <Polygon> result));

            Assert.Single(result);
            var p = result[0];

            Assert.Equal(4, p.Vertices.Count);

            this.Model.AddElement(new Panel(p, r.NextMaterial()));

            var rep = new Representation(new List <SolidOperation>()
            {
                extrude
            });
            var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass);

            this.Model.AddElement(solidElement);
        }
Example #4
0
        public void Volume()
        {
            // A simple extrusion.
            var extrude = new Extrude(Polygon.Rectangle(1, 1), 1, Vector3.ZAxis, false);
            var mesh    = new Mesh();

            extrude.Solid.Tessellate(ref mesh);
            Assert.Equal(1.0, mesh.Volume(), 5);

            // A more complicated extrusion.
            var l        = Polygon.L(20, 10, 5);
            var lMesh    = new Mesh();
            var lExtrude = new Extrude(l, 5, Vector3.ZAxis, false);

            lExtrude.Solid.Tessellate(ref lMesh);
            Assert.Equal(l.Area() * 5, lMesh.Volume(), 5);

            // A boolean.
            var l1        = l.Offset(-1)[0].Reversed();
            var l1Mesh    = new Mesh();
            var l1Extrude = new Extrude(new Profile(l, l1), 5, Vector3.ZAxis, false);

            l1Extrude.Solid.Tessellate(ref l1Mesh);
            var a  = l.Area();
            var a1 = l1.Area();

            Assert.Equal((l.Area() + l1.Area()) * 5, l1Mesh.Volume(), 5);
        }
Example #5
0
        public void Difference()
        {
            this.Name = "CSG_Difference";
            var profile = _profileFactory.GetProfileByType(HSSPipeProfileType.HSS10_000x0_188);

            var path = new Arc(Vector3.Origin, 5, 0, 270);
            var s1   = new Sweep(profile, path, 0, 0, 0, true);
            var csg  = s1.Solid.ToCsg();

            var s2 = new Extrude(new Circle(Vector3.Origin, 6).ToPolygon(20), 1, Vector3.ZAxis, false);

            csg = csg.Substract(s2.Solid.ToCsg());

            for (var i = 0.0; i < 1.0; i += 0.05)
            {
                var pt   = path.PointAt(i);
                var hole = new Extrude(new Circle(Vector3.Origin, 0.05).ToPolygon(), 3, Vector3.ZAxis, false);
                csg = csg.Substract(hole.Solid.ToCsg().Transform(new Transform(pt + new Vector3(0, 0, -2)).ToMatrix4x4()));
            }

            var result = new Mesh();

            csg.Tessellate(ref result);

            var me2 = new MeshElement(result);

            this.Model.AddElement(me2);
        }
Example #6
0
    void Cap_Triangles(Extrude Extrude)
    {
        if (Extrude.Shell)
        {
            for (int i = 0, c = 0; (i + 3) < Extrude.CapData.Vertices.Length && (c + 5) < Extrude.CapData.Triangles.Length; i = i + 2, c += 6)
            {
                Extrude.CapData.Triangles[c]     = i;
                Extrude.CapData.Triangles[c + 1] = i + 2;
                Extrude.CapData.Triangles[c + 2] = i + 1;

                Extrude.CapData.Triangles[c + 3] = i + 1;
                Extrude.CapData.Triangles[c + 4] = i + 2;
                Extrude.CapData.Triangles[c + 5] = i + 3;
            }
        }
        else
        {
            Extrude.CapVerticesIndices = new List <int>();
            for (int i = 0; i < Extrude.CapData.Vertices.Length; i++)
            {
                Extrude.CapVerticesIndices.Add(i);
            }
            EarCliping(Extrude, 0);
        }
    }
Example #7
0
        public void Csg()
        {
            this.Name = "Elements_Geometry_Csg";
            var s1  = new Extrude(Polygon.Rectangle(Vector3.Origin, new Vector3(30, 30)), 50, Vector3.ZAxis, false);
            var csg = s1.Solid.ToCsg();

            var s2 = new Extrude(Polygon.Rectangle(30, 30), 30, Vector3.ZAxis, false);

            csg = csg.Substract(s2.Solid.ToCsg());

            var s3 = new Sweep(Polygon.Rectangle(Vector3.Origin, new Vector3(5, 5)), new Line(new Vector3(0, 0, 45), new Vector3(30, 0, 45)), 0, 0, false);

            csg = csg.Union(s3.Solid.ToCsg());

            var poly = new Polygon(new List <Vector3>()
            {
                new Vector3(0, 0, 0), new Vector3(20, 50, 0), new Vector3(0, 50, 0)
            });
            var s4 = new Sweep(poly, new Line(new Vector3(0, 30, 0), new Vector3(30, 30, 0)), 0, 0, false);

            csg = csg.Substract(s4.Solid.ToCsg());

            var result = new Mesh();

            csg.Tessellate(ref result);
            this.Model.AddElement(new MeshElement(result, new Material("Mod", Colors.Red, 0.5, 0.5)));
        }
Example #8
0
    void Cap_Uvs(Extrude Extrude, int i)
    {
        var x = Extrude.CapData.Vertices[i].x;
        var z = Extrude.CapData.Vertices[i].z;

        Extrude.CapData.Uvs[i] = new Vector2(x, z);
    }
Example #9
0
    public void Body(Extrude Extrude, Branch branch)
    {
        var segments = branch.Vertices.Count;

        Extrude.BodyData.VertexNumber = (segments * (Extrude.Rings + 2));
        Extrude.BodyData.Vertices     = new Vector3[Extrude.BodyData.VertexNumber];
        Extrude.BodyData.Triangles    = new int[((segments - 1) * (Extrude.Rings + 1) * 6)];//+24

        Extrude.BodyData.Normals  = new Vector3[Extrude.BodyData.VertexNumber];
        Extrude.BodyData.Tangents = new Vector4[Extrude.BodyData.VertexNumber];
        Extrude.BodyData.Uvs      = new Vector2[Extrude.BodyData.VertexNumber];

        Body_Data(Extrude, branch);

        int u = 0;

        for (int n = 1; n < (Extrude.BodyData.Vertices.Length - segments); n++)
        {
            if (n % segments == 0)
            {
                continue;
            }
            u = Body_Triangles(Extrude, n, segments, u);
        }
        if (Extrude.CapHoles)
        {
            Cap(Extrude, branch);
        }
    }
Example #10
0
    void Body_Data(Extrude Extrude, Branch branch)
    {
        for (int n = 0, t = 0; n <= Extrude.Rings + 1; n++)
        {
            float u = 0;
            u = Mathf.InverseLerp(0, Extrude.Rings + 1, n);

            var curvature = Extrude.Curvature.Evaluate(u);

            for (int i = 0; i < branch.Vertices.Count; i++, t++)
            {
                // normals
                var normal = Vector3.Cross(branch.Tangents[i], branch.Normals[i]).normalized;
                Extrude.BodyData.Normals[t] = normal;
                // tangents
                Extrude.BodyData.Tangents[t] = branch.Tangents[i].normalized;

                //vertices
                var   vertex = Extrude.SplinePlus.SPData.SplinePlus.transform.InverseTransformPoint(branch.Vertices[i]);
                float heigth = (Extrude.Height * (n / (float)(Extrude.Rings + 1)));
                Extrude.BodyData.Vertices[t] = vertex + Vector3.up * heigth + normal * curvature * Extrude.CurvaturePower;
                //UV
                Body_Uvs(Extrude, branch, i, t, n);
            }
        }
    }
Example #11
0
        /// <summary>
        /// Update the representations.
        /// </summary>
        public override void UpdateRepresentations()
        {
            this.Representation.SolidOperations.Clear();
            var extrude = new Extrude(GetProfile(), this.Thickness, Vector3.ZAxis, false);

            this.Representation.SolidOperations.Add(extrude);
        }
Example #12
0
        public void StarShapedThing()
        {
            var s1 = new Extrude(Polygon.Star(10, 7, 10), 10, Vector3.ZAxis, false);
            var s2 = new Extrude(Polygon.Star(10, 7, 10).TransformedPolygon(new Transform(new Vector3(1, 1, -1))), 8, Vector3.ZAxis, false);

            _ = Solid.Difference(s1._solid, null, s2._solid, null);
        }
    private void OnEnable()
    {
        Extrude = target as Extrude;
        if (ExtrudeSplineBanner == null)
        {
            ExtrudeSplineBanner = new GUIContent((Texture2D)EditorGUIUtility.Load("Assets/ElseForty/Media/ExtrudeSplineBanner.png"));
        }

        if (Extrude.gameObject.GetComponent <MeshRenderer>() == null)
        {
            Extrude.gameObject.AddComponent <MeshRenderer>();
        }
        Extrude.MeshRenderer = Extrude.gameObject.GetComponent <MeshRenderer>();

        if (Extrude.gameObject.GetComponent <MeshFilter>() == null)
        {
            Extrude.gameObject.AddComponent <MeshFilter>();
        }
        Extrude.Mesh = Extrude.gameObject.GetComponent <MeshFilter>();

        if (Extrude.Material == null)
        {
            Extrude.Material = (Material)EditorGUIUtility.Load("Assets/ElseForty/Assets/Materials/Base.mat");
        }
        if (Extrude.SplinePlus == null)
        {
            Extrude.SplinePlus = Extrude.gameObject.GetComponent <SplinePlus>();
        }
        Extrude.SplinePlus.SPData.ObjectType = SPType.Extrude;
        Extrude.DrawMeshOnEachBranch();
    }
Example #14
0
        public void DifferenceWhichSplitsVolumeSucceeds()
        {
            this.Name = nameof(DifferenceWhichSplitsVolumeSucceeds);

            var s1      = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false);
            var s2      = new Extrude(Polygon.Rectangle(0.5, 4), 6, Vector3.ZAxis, false);
            var result1 = Solid.Difference(s1.Solid, new Transform(new Vector3(0, 0, -1)), s2.Solid, new Transform(new Vector3(0, 0, -3)));

            var s3 = new Extrude(Polygon.Rectangle(4, 0.5), 3, Vector3.ZAxis, false);

            result1 = Solid.Difference(result1, null, s3.Solid, new Transform(new Vector3(0, 0, -3.25)));

            var rep = new Representation(new List <SolidOperation>()
            {
                new ConstructedSolid(result1)
            });
            var solidElement = new GeometricElement(representation: rep);

            this.Model.AddElement(solidElement);

            this.Model.AddElements(DrawEdges(result1, null));
            Assert.Equal(20, result1.Faces.Count);
            Assert.Equal(32, result1.Vertices.Count);
            Assert.Equal(48, result1.Edges.Count);
        }
Example #15
0
        public void SolidIntersectsPlaneAtEdgeWithNoResult()
        {
            var profile = Polygon.Rectangle(5, 5);
            var extrude = new Extrude(profile, 5, Vector3.ZAxis, false);
            var plane   = new Plane(new Vector3(2.5, 2.5, 0.0), new Vector3(0.5, 0.5, 0.0));

            Assert.False(extrude.Solid.Intersects(plane, out List <Polygon> result));
        }
Example #16
0
        //--------------------------------------------------------------------------------------------------

        public static Extrude CreateExtrude(TestSketchGenerator.SketchType sketchType = TestSketchGenerator.SketchType.Circle)
        {
            var sketch = new Sketch();
            var body   = CreateBody(sketch);

            TestSketchGenerator.FillSketch(sketch, sketchType);

            return(Extrude.Create(body));
        }
Example #17
0
        static void MenuDoExtrude()
        {
            Extrude instance = EditorToolbarLoader.GetInstance <Extrude>();

            if (instance != null)
            {
                UnityEditor.ProBuilder.EditorUtility.ShowNotification(instance.DoAction().notification);
            }
        }
Example #18
0
        //--------------------------------------------------------------------------------------------------

        public static Extrude CreateExtrude(SketchType sketchType = SketchType.Circle)
        {
            var sketch = new Sketch();
            var body   = CreateBody(sketch);

            FillSketch(sketch, sketchType);

            return(Extrude.Create(body));
        }
Example #19
0
        public void CheckForEmptyResult()
        {
            var cyl     = TestGeomGenerator.CreateCylinder();
            var extrude = Extrude.Create(cyl.Body, cyl.GetSubshapeReference(SubshapeType.Face, 0));

            Assert.IsFalse(extrude.Make(Shape.MakeFlags.None));

            cyl.SegmentAngle = 160.0;
            Assert.IsTrue(extrude.Make(Shape.MakeFlags.None));
        }
Example #20
0
        /// <summary>
        /// 创建单边偏置的拉伸
        /// </summary>
        /// <param name="features"></param>
        /// <param name="curves"></param>
        /// <param name="extrudeDirection"></param>
        /// <param name="startDistance"></param>
        /// <param name="endDistance"></param>
        /// <param name="bodyStyle"></param>
        /// <param name="offsetValue"></param>
        /// <returns></returns>
        public static Extrude CreateExtrude(this FeatureCollection features, IBaseCurve[] curves, Vector3d extrudeDirection, double startDistance, double endDistance, NXOpen.GeometricUtilities.FeatureOptions.BodyStyle bodyStyle, double offsetValue)
        {
            NXOpen.Features.ExtrudeBuilder extrudeBuilder = features.CreateExtrudeBuilder(null);

            Section section1 = WorkPart.Sections.CreateSection(0.0095, 0.01, 0.5);

            extrudeBuilder.Section = section1;

            extrudeBuilder.AllowSelfIntersectingSection(true);

            extrudeBuilder.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

            extrudeBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.SingleOffset;

            extrudeBuilder.Offset.EndOffset.Value = offsetValue;

            extrudeBuilder.Draft.DraftOption = NXOpen.GeometricUtilities.SimpleDraft.SimpleDraftType.NoDraft;

            extrudeBuilder.FeatureOptions.BodyType = bodyStyle;

            section1.DistanceTolerance = 0.01;

            section1.ChainingTolerance = 0.0095;

            section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

            extrudeBuilder.Direction = WorkPart.Directions.CreateDirection(new Point3d(0.0, 0.0, 0.0), extrudeDirection, NXOpen.SmartObject.UpdateOption.WithinModeling);

#if NX12
            CurveDumbRule curveDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#else
            CurveDumbRule curveDumbRule = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#endif
            section1.AllowSelfIntersection(true);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1] {
                curveDumbRule
            };

            section1.AddToSection(rules1, (NXObject)curves[0], null, null, new Point3d(0, 0, 0), NXOpen.Section.Mode.Create, false);

            extrudeBuilder.Limits.StartExtend.TrimType = NXOpen.GeometricUtilities.Extend.ExtendType.Value;

            extrudeBuilder.Limits.EndExtend.TrimType = NXOpen.GeometricUtilities.Extend.ExtendType.Value;

            extrudeBuilder.Limits.EndExtend.Value.RightHandSide = endDistance.ToString();

            extrudeBuilder.Limits.StartExtend.Value.RightHandSide = startDistance.ToString();

            extrudeBuilder.ParentFeatureInternal = false;

            Extrude extrude = (Extrude)extrudeBuilder.CommitFeature();
            extrudeBuilder.Destroy();
            return(extrude);
        }
    // Use this for initialization
    void Start()
    {
        Mesh mesh = new Mesh();

        CatmullRomSpline spline = new CatmullRomSpline();

        Vector3[]    pos = new Vector3[points.Count];
        Quaternion[] rot = new Quaternion[points.Count];

        for (int i = 0; i < points.Count; i++)
        {
            pos[i] = points[i].transform.position;
            rot[i] = points[i].transform.rotation;
        }

        Vector3 tangent;

        for (int i = 0; i < points.Count; i++)
        {
            tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.forward);

            if (tangent.magnitude == 0)
            {
                tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.up);
            }
            points[i].transform.rotation = Quaternion.Euler(tangent);
        }

        OrientedPoint[] oPoints = new OrientedPoint[(int)(1 / resolution)];
        for (float i = 0f; i < 1.0f; i += resolution)
        {
            if (i != 0f || i != 1f)
            {
                oPoints[(int)i * 10].position = spline.GetPoint(i, pos);
                tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.forward);

                if (tangent.magnitude == 0)
                {
                    tangent = Vector3.Cross(spline.GetTangent(i, pos), Vector3.up);
                }
                oPoints[(int)i * 10].rotation = Quaternion.Euler(tangent);
            }
        }

        Vector2[] verts   = { new Vector2(0, 0), new Vector2(1, 0) };
        Vector2[] normals = { new Vector2(0, 1), new Vector2(0, 1) };
        int[]     lines   = { 0, 1 };

        Shape shape = new Shape(verts, normals, lines);

        Extrude extrusao = new Extrude(ref mesh, shape, oPoints);

        this.GetComponent <MeshFilter>().sharedMesh = mesh;
    }
        //--------------------------------------------------------------------------------------------------

        public CreateExtrudeTool(Extrude extrudeToChange)
        {
            _ExtrudeToChange = extrudeToChange;
            Debug.Assert(_ExtrudeToChange != null);
            _TargetBody = _ExtrudeToChange.Body;
            Debug.Assert(_TargetBody != null);
            _TargetShape = _ExtrudeToChange.Operands[0] as Shape;
            Debug.Assert(_TargetShape != null);

            _Mode = ToolMode.ReselectFace;
        }
Example #23
0
        public void SolidFace()
        {
            var shape = TestGeomGenerator.CreateImprint();

            Assume.That(shape != null);

            var subshapeRef = shape.GetSubshapeReference(SubshapeType.Face, 7);
            var extrude     = Extrude.Create(shape.Body, subshapeRef);

            AssertHelper.IsMade(extrude);
            AssertHelper.IsSameModel(extrude, Path.Combine(_BasePath, "SolidFace"));
        }
    void ObjectManagment()
    {
        myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        bool doHit = Physics.Raycast(myRay, out hit, 500f);

        Debug.DrawRay(myRay.origin, myRay.direction * 10, Color.yellow);

        if (doHit)
        {
            if (hit.collider.tag == "Selector" && Input.GetKeyDown(KeyCode.Space))
            {
                if (hit.collider.gameObject.GetComponent <Renderer>().material.color == Color.blue)
                {
                    hit.collider.gameObject.GetComponent <Renderer>().material.color = Color.red;
                }
                else
                {
                    hit.collider.gameObject.GetComponent <Renderer>().material.color = Color.blue;
                }
            }
            if (hit.collider.name == "Snowball")
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    if (hit.collider.transform.childCount < 1)
                    {
                        GetSelect(hit.collider.gameObject);
                    }
                    else
                    {
                        Deselect(hit.collider.gameObject);
                    }
                }
                if (Input.GetButtonDown("Fire1"))
                {
                    MoveRotate.Moving(hit.collider.gameObject, CurrAxis, reverse);
                }
                if (Input.GetButtonDown("Fire3"))
                {
                    MoveRotate.Rotate(hit.collider.gameObject, RotateDegreesPerSecond, clockwise);
                }
                if (Input.GetKeyDown(KeyCode.E))
                {
                    if (hit.collider.transform.childCount > 1)
                    {
                        Deselect(hit.collider.gameObject);
                    }
                    Extrude.MakeExtrusion(hit.collider.gameObject, hit);
                }
            }
        }
    }
        private static WallPanel CreateSimpleWallPanel(Line wallLine, double thickness, double height, Material mat)
        {
            var wallProfile   = new Profile(Polygon.Rectangle(Vector3.Origin, new Vector3(wallLine.Length(), height)));
            var d             = wallLine.Direction();
            var z             = d.Cross(Vector3.ZAxis);
            var wallTransform = new Transform(wallLine.Start, d, z);
            var extrude       = new Extrude(wallProfile, thickness, Vector3.ZAxis, false);
            var geomRep       = new Representation(new[] { extrude });

            var identifier = $"{Math.Round(wallLine.Length(), 2)} x {Math.Round(height, 2)}";
            var wallpanel  = new WallPanel(identifier, wallProfile, true, thickness, wallTransform, mat, geomRep, false, Guid.NewGuid(), "");

            return(wallpanel);
        }
Example #26
0
    int Body_Triangles(Extrude Extrude, int n, int Segments, int u)
    {
        Extrude.BodyData.Triangles[u]     = n;
        Extrude.BodyData.Triangles[u + 1] = n - 1 + Segments;
        Extrude.BodyData.Triangles[u + 2] = n - 1;
        u += 3;

        Extrude.BodyData.Triangles[u]     = n;
        Extrude.BodyData.Triangles[u + 1] = n + Segments;
        Extrude.BodyData.Triangles[u + 2] = n - 1 + Segments;

        u += 3;
        return(u);
    }
Example #27
0
        public void SolidIntersectsWithPlane()
        {
            this.Name = nameof(SolidIntersectsWithPlane);
            var n       = 4;
            var outer   = Polygon.Ngon(n, 2);
            var inner   = Polygon.Ngon(n, 1.75).Reversed();
            var profile = new Profile(outer, new[] { inner });
            var sweep   = new Extrude(profile, 5, Vector3.ZAxis, false);

            var plane1 = new Plane(new Vector3(0, 0, 1), new Vector3(0.5, 0.5, 0.5));
            var plane2 = new Plane(new Vector3(0, 0, 2), new Vector3(0.1, 0, 1));
            var plane3 = new Plane(new Vector3(0, 0, 5), Vector3.ZAxis);

            Plane[] planes = new Plane[] { plane1, plane2, plane3 };
            var     r      = new Random();

            foreach (var plane in planes)
            {
                if (sweep.Solid.Intersects(plane, out List <Polygon> result))
                {
                    if (result.Count > 1)
                    {
                        Assert.Equal(2, result.Count);
                        var cutProfile = new Profile(result[0], result.Skip(1).ToArray());
                        var lam        = new Lamina(cutProfile, false);
                        var cutRep     = new Representation(new List <SolidOperation>()
                        {
                            lam
                        });
                        this.Model.AddElement(new GeometricElement(representation: cutRep, material: r.NextMaterial()));
                    }
                    else
                    {
                        Assert.Single(result);
                        this.Model.AddElement(new Panel(result[0], r.NextMaterial()));
                    }
                }
            }

            var rep = new Representation(new List <SolidOperation>()
            {
                sweep
            });
            var solidElement = new GeometricElement(representation: rep, material: BuiltInMaterials.Mass);

            this.Model.AddElement(solidElement);
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face = TopoDS.Face(selectAction.SelectedSubshape);
                selectAction.Stop();
                Stop();
                finished = true;
                var faceRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), face);
                if (faceRef == null)
                {
                    Messages.Error("A subshape reference could not be produced for this face.");
                    return;
                }

                if (_Mode == ToolMode.CreateNew)
                {
                    // Create new
                    var extrude = Extrude.Create(_TargetBody, faceRef);
                    if (extrude != null)
                    {
                        InteractiveContext.Current.UndoHandler.Commit();
                        InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                    }
                }
                else if (_Mode == ToolMode.ReselectFace)
                {
                    // Reselected face
                    _ExtrudeToChange.Face = faceRef;
                    _ExtrudeToChange.Invalidate();
                    InteractiveContext.Current.UndoHandler.Commit();
                }
            }

            if (!finished)
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
Example #29
0
        public void CoplanarSolidFacesUnionCorrectly()
        {
            this.Name = nameof(CoplanarSolidFacesUnionCorrectly);

            var s1     = new Extrude(Polygon.Rectangle(2, 2), 2, Vector3.ZAxis, false);
            var s2     = new Extrude(Polygon.Rectangle(2, 2).TransformedPolygon(new Transform(new Vector3(1, 1))), 2, Vector3.ZAxis, false);
            var result = Solid.Union(s1._solid, null, s2._solid, null);

            var rep = new Representation(new List <SolidOperation>()
            {
                new ConstructedSolid(result)
            });
            var solidElement = new GeometricElement(representation: rep);

            this.Model.AddElement(solidElement);
            this.Model.AddElements(DrawEdges(result, null));

            Assert.Equal(10, result.Faces.Count);

            var t       = new Transform(new Vector3(5, 0));
            var result1 = Solid.Difference(s1._solid, t, s2._solid, t);
            var rep1    = new Representation(new List <SolidOperation>()
            {
                new ConstructedSolid(result1)
            });
            var solidElement1 = new GeometricElement(representation: rep1);

            this.Model.AddElement(solidElement1);
            this.Model.AddElements(DrawEdges(result1, null));

            Assert.Equal(8, result1.Faces.Count);

            var t1      = new Transform(new Vector3(10, 0));
            var result2 = Solid.Intersection(s1._solid, t1, s2._solid, t1);
            var rep2    = new Representation(new List <SolidOperation>()
            {
                new ConstructedSolid(result2)
            });
            var solidElement2 = new GeometricElement(representation: rep2);

            this.Model.AddElement(solidElement2);
            this.Model.AddElements(DrawEdges(result2, null));

            Assert.Equal(6, result2.Faces.Count);
        }
Example #30
0
        public void Union()
        {
            this.Name = "CSG_Union";
            var s1  = new Extrude(Polygon.Rectangle(1, 1), 1, Vector3.ZAxis, false);
            var csg = s1.Solid.ToCsg();

            var s2 = new Extrude(Polygon.L(1.0, 2.0, 0.5), 1, Vector3.ZAxis, false);

            csg = csg.Union(s2.Solid.ToCsg());

            var result = new Mesh();

            csg.Tessellate(ref result);

            var me = new MeshElement(result);

            this.Model.AddElement(me);
        }