Trouble with textures in Grasshopper Display.DrawMeshShaded()

I am developing a Grasshopper plugin and working to ensure its compatibility with Rhino 8. I create a mesh and add texture coordinates for each vertex in the mesh. I then create a DisplayMaterial, then using SetBitmapTexture to set the texture from a bitmap file. Then I am trying to use DisplayPipeline.DrawMeshShaded with the mesh and the display material to draw the mesh. The result is that the textured mesh has a single uniform color. If I change the bitmap file that the texture is set from, then the displayed color changes. I expect the mesh to have different colors, based on the texture coordinates. Additionally, if I bake the mesh with texture coordinates, then it is displayed correctly in a rendered viewport when a texture bitmap is specified.

The procedure described above worked without any problems in Grasshopper in Rhino 7. Any suggestions what the problem is? Is this an issue in the beta or how I am using it?

Here’s what Paul is talking about:

Attached is a minimal code example that duplicates the problem. Model and texture images are included in the archive.
~Michael (143.2 KB)

Hi @MichaelF, @Paul_Novak,

I believe a fix is in the works for Rhino 8.1.

In the mean time, this should fix the issue:

protected override void SolveInstance(IGH_DataAccess DA)
  if (DA.GetData(Inputs.mesh, ref mMesh) && DA.GetData(Inputs.bmp_path, ref mBmpPath))
    mDisplayMaterial.SetBitmapTexture(mBmpPath, true);
    BoundingBox bbox = mMesh.GetBoundingBox(false);
    foreach (var vertex in mMesh.Vertices)
      Point2f uv = new Point2f
        X = 0,
        Y = (vertex.X - (float)bbox.Min.X) / (float)bbox.Diagonal.X
    mMesh.SetSurfaceParametersFromTextureCoordinates(); // NEW!
    DA.SetData(Outputs.mesh, mMesh);

This API is on V8 only. So you’ll need to update the project NuGet package.

– Dale

Awesome! Thank you, Dale! We’ll give that a go.