Flat shade and custom render mesh provider

HI,

we have a custom render mesh provider in our plug-in but it seem to behave weirdly when the option flat shade is activated. The image below shows a side-by-side of the same mesh visualized through the custom render mesh provider and when the render mesh is extracted. Works correctly in Rhino 7

The issue does not appear on normal (i.e. not flat) shading. Is there some flags to use/set or something we are missing? The code that does the visualization is:


    public override RenderMeshes RenderMeshes(MeshType mt, ViewportInfo vp, RhinoDoc doc, Guid objectId, List<InstanceObject> ancestry, ref Flags flags, RenderMeshes previousPrimitives, PlugIn plugin, DisplayPipelineAttributes attrs)
    {
      var rhinoObject = doc.Objects.FindId(objectId);
      if (rhinoObject == null) {
        return null;
      }

      return ComputeMeshes(rhinoObject);
    }

    private ComputeMeshes(RhinoObject rhObj)
    {
     if (m_runtimeCache.TryGetValue(rhObj.Id, out uint runtimeid)) {
       if (runtimeid == rhObj.RuntimeSerialNumber && m_generatedMeshes.TryGetValue(rhObj.Id, out var cachedMeshes)) {
         return cachedMeshes;
       }
     }

     var meshes = BuildRenderMeshesFromObject(rhObj);
     var renderMeshes = new RenderMeshes(rhObj.Document, rhObj.Id, ThisId, m_internalHash);
     m_internalHash += 1;

     var material = rhObj.GetRenderMaterial(true);

     for (int i = 0; i < meshes.Length; ++i) {

       renderMeshes.AddInstance(new Instance {
         IsViewDependent = false,
         Material = material,
         Mesh = meshes[i],
         IsRequestingPlugInDependent = true,
       Transform = Transform.Identity
       });
     }

     m_generatedMeshes[rhObj.Id] = renderMeshes;
     m_runtimeCache[rhObj.Id] = rhObj.RuntimeSerialNumber;

     return renderMeshes;
    }

1 Like