1

I am using the version 2020 of eyeshot.

There is a function called CutBy which cuts a mesh by a surface and it works fine.

The problem is getting the surface. For exemple, from a solid or a mesh, how to create a surface.

For exemple, I have a solid which intersects another solid. I need the difference but the Solid.Difference method gives only one part of the cut solid. Unfortunately I need the other part.

I can get the intersection via the Solid.Intersection method. I can cut the solid by the intersection's surface but I couldn't find how to get a surface of a solid.

Briefly, the question is how to get a surface or a region object from a solid to call the Solid.Cutby(surface.Plane) method.

Here is what I did :

        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();

Thanks in advance.

Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32
  • I believe the diff is an array of the differences as there may be more than one solid generated by the difference. I also believe that the array is sorted by size, with the largest piece being diff[0], the second largest would be diff[1]. So on – Daniel Lord Mar 02 '21 at 14:20
  • I am also confused by your question. As you gave no dimensionality to your two meshes I picture them as two spheres. A surface/ region of one sphere is a piece of the sphere aka: a hemisphere. A plane can be drawn tangentially to any point on the surface, or through the center of mass of your sphere and would give you many different things. Does your cutting mesh have a very flat planar side that you wish to cut by? – Daniel Lord Mar 02 '21 at 15:00

1 Answers1

1

Solid.Difference returns an array of solids from the difference of two

        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;
        }

It will remove the toolSolid from the targetSolid. This could result in multiple pieces of the first solid therefore the return is a Solid[]. This array is sorted by size, with the largest solid of the solid difference being first. If you need a different piece:

differenceSolid[x]

where x is the piece you need.

To Create a planar surface to CutBy: The easiest way to do this is to grab three vertices from the solid object and define a plane. to grab this from a solid it is:

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

Meshes don't have portions and have vertices here:

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; }          
        }
Daniel Lord
  • 754
  • 5
  • 18