[Bug] MeshTopologyEdge index incorrect after rotation of a mesh


(Menno Deij - van Rijswijk) #1

When testing a command that relies on the mesh topology indices, I found that after a mesh is rotated that the topology indices are incorrect. Clicking on a mesh edge will in fact give access to a completely different mesh edge.

This is on Rhino 5SR4.

To reproduce this bug, use the command below:

  1. Create a mesh on any surface.
  2. run the command below and select a mesh edge. it will be “reproduced” as a red line in the document.
  3. now rotate the mesh by 90 degrees (the exact angle probably does not matter).
  4. run the command again and select the same mesh edge (which is now rotated). Another mesh edge will be “reproduced” as a red line.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    GetObject go = new GetObject();
    go.SetCommandPrompt("Select mesh edge");
    go.AcceptNothing(true);
    go.GeometryFilter = ObjectType.MeshEdge;

    while (true)
    {
        doc.Objects.UnselectAll(true);
        GetResult res = go.Get();
        if (res == GetResult.Cancel)
            return Result.Cancel;

        if (res == GetResult.Object)
        {
            ObjRef aRef = go.Object(0);
            if (null != aRef)
            {
                if (aRef.GeometryComponentIndex.ComponentIndexType == ComponentIndexType.MeshTopologyEdge)
                {
                    RhinoObject meshObject = doc.Objects.Find(aRef.ObjectId);
                    Mesh mesh = meshObject.Geometry as Mesh;

                    if (null == mesh)
                        continue;

                    Line edge = mesh.TopologyEdges.EdgeLine(aRef.GeometryComponentIndex.Index);

                    doc.Objects.AddLine(edge,
                                        new ObjectAttributes
                                            {
                                                ColorSource = ObjectColorSource.ColorFromObject,
                                                ObjectColor = Color.Red
                                            });
                    return Result.Success;
                }
            }
        }
    }
}

(Menno Deij - van Rijswijk) #2

See also http://youtu.be/sz7K1MBuOB0


(Steve Baer) #3

Yes, the topology indices may change if the mesh is transformed. I believe that when the topology is calculated, it currently does so by sorting vertex locations. As the vertex locations change, so does the sort order and the topology edge indices change. I’m not sure what we can do about this for V5.


(Menno Deij - van Rijswijk) #4

Is there another way to finding the coordinates of the vertices in the mesh edge that a user clicked? Because that is all I’m after - in a reliable way that works after transformation.