Hello there,
Rhino 8 is a sensation throughout, but I’m having an issue with the DrawMeshShaded in Rhino 8, which no more - draws a shaded mesh, not even in shaded display mode. I tried it both with framework 4.8, and .net 7.0 and on an Nvidia and an AMD GPU, didn’t make a difference.
Inside Tweener, its editing environment is based on a
public class AnimDisplayConduit3 : Rhino.Display.DisplayConduit
(is there anything better to get a DisplayMaterial from a bitmap)? This worked in Rhino 7, to draw a mesh, at least in the shaded mode (- which is why Tweener has to change modes to shaded for the editing environment, and to rendered after placing the mesh into the document to make the texture visible; is there a way I could avoid to set the viewports’ display modes altogether?), and is what makes Tweener run and fun. However, it broke in Rhino 8: the mesh is no more drawn in a shaded way by the PostDrawObjects method of the conduit! Instead, it just appears grey. Help appreciated.
I also have lots of other questions about the 7 → 8 migration, but that’s for another post.
Thanks in advance!
Mathias
Thank you for the answer, @dale. Yes, here you are. It took me quite some effort to boil down some minimal code that works in Rhino 7 but not in Rhino 8. (Code is not for performance, only to demonstrate the issue.) With the following code, the triangle is drawn with uv coordinates applied correctly in Rhino 7, but not in Rhino 8. The issue must be related to the way uv coordinates are applied in the rendering pipeline, so it should be reproducible with materials from doc.Materials as well, if you prefer.
public class SomeExampleConduit : Rhino.Display.DisplayConduit {
protected override void PostDrawObjects(Rhino.Display.DrawEventArgs e) {
base.PostDrawObjects(e);
Mesh cp = new Mesh();
cp.Vertices.Add(0, 0, 0);
cp.Vertices.Add(1, 0, 0);
cp.Vertices.Add(0, 1, 0);
cp.Faces.AddFace(new MeshFace(0, 1, 2));
cp.Normals.ComputeNormals();
cp.TextureCoordinates.Add(0, 0);
cp.TextureCoordinates.Add(1, 0);
cp.TextureCoordinates.Add(0, 1);
var iv = cp.IsValid; // returns true
var ma = new DisplayMaterial();
Bitmap bitmap = Properties.Resources._21; // just some image from the resources
var simtext = Rhino.Render.RenderTexture
.NewBitmapTexture(bitmap, Rhino.RhinoDoc.ActiveDoc)
.SimulatedTexture(Rhino.Render.RenderTexture.TextureGeneration.Allow)
.Texture();
ma.IsTwoSided = true;
ma.SetBitmapTexture(simtext, false);
ma.SetBitmapTexture(simtext, true);
// is drawn differently in Rhino 8. Why?
e.Display.DrawMeshShaded(cp, ma);
}
protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e) {
e.IncludeBoundingBox(new BoundingBox(new Point3d(0, 0, -1), new Point3d(1, 1, 1)));
}
}
}
Rhino 7 (don’t mind the violet curves):
Rhino 8:
Thanks for helping to find the cause, it really breaks Tweener. I don’t see an alternative to calling DrawMeshShaded and relying on the correct application of my uv coordinates.
M