FindClosestVertex: retrieve vertex inside a Solid3D or Solid entity

In build 9.0.251 we added the following method of viewportLayout: 

public int FindClosestVertex(Point mousePos, double maxDistance, out HitVertex closestVertex)

public int FindClosestVertex(Point mousePos, double maxDistance, Type entType, out HitVertex closestVertex)

 

The "closestVertex" object contains both the Point3D vertex and the information to retrieve it from the Eyeshot entities.

The following derived class gets the vertex closest to the mouse and adds a Point entity on its position when clicking with the right mouse button.

It manages nested BlockReferences, standard Entities and the more complex Solid and Solid3D entities.

 

internal class MyViewportLayout : devDept.Eyeshot.ViewportLayout
    {
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (ActionMode == actionType.None && e.Button == MouseButtons.Right)
            {

                HitVertex hv;
                int entID = FindClosestVertex(e.Location, 10, out hv);

                Debug.WriteLine(entID);

                if (entID < 0)
                    return;

                if (hv.Parents != null)
                {
                    for (int i = 0; i < hv.Parents.Count; i++)
                    {
                        // Set as current all the parents, so I can use the BlockReference.AccumulatedParentsTransform to transform the vertex
                        Entities.SetCurrent(hv.Parents[i]);
                    }
                }

                Entity ent;
                if (Entities.CurrentBlockReference == null)
                {
                    ent = Entities[entID];
                }
                else
                {
                    // Get the Block entities
                    ent = Blocks[Entities.CurrentBlockReference.BlockName].Entities[hv.BlockEntityIndex];
                }

                Point3D pt;
                if (ent is Solid)
                {
                    var sol = (Solid) ent;

                    // Retrieve the vertex from the proper Solid portion
                    pt = sol.Portions[hv.FaceIndex].Vertices[hv.VertexIndex];
                }
                else if (ent is Solid3D)
                {
                    var sol = (Solid3D) ent;

                    // retrieve the vertex from the proper Solid3D face and parametric index
                    if (hv.ShellOrElementIndex == 0)
                    {
                        pt = sol.Faces[hv.FaceIndex].Parametric[hv.ParamSurfaceIndex].Vertices[hv.VertexIndex];
                    }
                    else
                        pt =
                            sol.Inners[hv.ShellOrElementIndex - 1][hv.FaceIndex].Parametric[hv.ParamSurfaceIndex]
                                .Vertices[
                                    hv.VertexIndex];

                }
                else
                {
                    pt = ent.Vertices[hv.VertexIndex];
                }


                if (Entities.CurrentBlockReference != null)
                {
                    // Transform the point by the accumulated BlockReference transformation to get the final world position
                    pt = Entities.CurrentBlockReference.AccumulatedParentsTransform*pt;
                }

                if (hv.Parents != null)
                    for (int i = 0; i < hv.Parents.Count; i++)
                    {
                        // Go back to the original parent
                        Entities.SetParentAsCurrent();
                    }

                if (pt != null)
                    Entities.Add(new devDept.Eyeshot.Entities.Point(pt, 10), 0, Color.Red);
            }
            base.OnMouseUp(e);
        }
Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Silvio Zimmer

    Perfect! Exactly what I was searching for.

    Thanks!

Please sign in to leave a comment.