1

我正在使用 2020 版的 eyeshot。

有一个名为 CutBy 的函数,它通过表面切割网格,并且工作正常。

问题是浮出水面。例如,从实体或网格,如何创建曲面。

例如,我有一个与另一个实体相交的实体。我需要差异,但 Solid.Difference 方法只给出了切割实体的一部分。不幸的是,我需要另一部分。

我可以通过 Solid.Intersection 方法获得交叉点。我可以通过交叉点的表面切割实体,但我找不到如何获得实体的表面。

简而言之,问题是如何从实体中获取曲面或区域对象以调用 Solid.Cutby(surface.Plane) 方法。

这是我所做的:

        var template = sceneLeft.Entities[0] as Mesh;
        var piece = sceneLeft.Entities[1] as Mesh;

        var solidT = template.ConvertToSolid();
        var solidP = piece.ConvertToSolid();

        var diff1 = Solid.Difference(solidT, solidP);
        var diff2 = Solid.Difference(solidP, solidT);

        var intersection = Solid.Intersection(solidT, solidP);

        diff1[0].Color = System.Drawing.Color.LightGray;
        diff2[0].Color = System.Drawing.Color.LightGray;

        diff1[0].ColorMethod = colorMethodType.byEntity;
        diff2[0].ColorMethod = colorMethodType.byEntity;

        diff1[0].EntityData = "base";
        diff2[0].EntityData = "piece";

        sceneLeft.Entities.Clear();

      

        //sceneLeft.Entities.Add(diff1[0]);
        //sceneLeft.Entities.Add(piece);

        sceneLeft.Entities.Add(diff2[0]); //diff2 is returns only one solid and not the part that I need.
        //sceneLeft.Entities.Add(intersection[0]);

        //diff2[0].Scale(1.02, 1.02, 1.02);

        //var diff3 = Solid.Difference(intersection[0], solidT);

        //sceneLeft.Entities.Add(diff3[0]);

        sceneLeft.Entities.Regen();
        sceneLeft.Invalidate();

提前致谢。

4

1 回答 1

1

Solid.Difference 从两个的差中返回一个实体数组

        public static bool materialSubtraction(ref Mesh targetMesh, Mesh tool)
        {
            bool success = false;
            Solid targetSolid = targetMesh.ConvertToSolid();
            Solid toolSolid = tool.ConvertToSolid();
            Solid[] differenceSolid = Solid.Difference(targetSolid, toolSolid);
            if(differenceSolid != null)
            {
                targetMesh = differenceSolid[0].ConvertToMesh();
                success = true;
            }           
            return success;
        }

它将从 targetSolid 中删除 toolSolid。这可能会导致第一个实体的多个部分,因此返回是一个 Solid[]。这个数组是按大小排序的,最大的实体是第一个。如果您需要不同的作品:

differenceSolid[x]

其中 x 是您需要的部分。

为 CutBy 创建一个平面:最简单的方法是从实体对象中获取三个顶点并定义一个平面。从固体中抓住它是:

Point3D X1 = toolSolid.Portions[0].Vertices[1];

网格没有部分并且在此处有顶点:

Point3D X1 = targetMesh.Vertices[1];
        public static bool materialCutBy(ref Mesh targetMesh, Mesh tool)
        {           
            Solid toolSolid = tool.ConvertToSolid();

            Point3D X1 = targetMesh.Vertices[1];
            Point3D X2 = targetMesh.Vertices[2];
            Point3D X3 = targetMesh.Vertices[3];

            Plane P1 = new Plane(X1, X2, X3);

            var success = toolSolid.CutBy(P1);

            if(success == booleanFailureType.Success)
            {
                targetMesh = toolSolid.ConvertToMesh();
                return true;
            }
            else { return false; }          
        }
于 2021-03-02T19:13:16.080 回答