Thanks @jeff,
to be clear - the CRM works ok in Rendered and Shaded. It just doesn’t show up in Wireframe. I guess this is not a bug, but a feature - there are no shaded objects to display, hence the pipeline skips all checks to registered CRMs.
In Wireframe, WillBuildCustomMeshes
is not called at all.
I believe to have read somewhere on the forum that GH uses a dual approach - CRMs in Rendered and Conduits in Wireframe/Shaded. Can’t find the reference now, though.
#if RHINO7
public class CustomMeshProvider : CustomRenderMeshProvider2
{
private static Mesh _customBox;
private static BoundingBox _boundingBox;
private RenderMaterial _material;
public override string Name => "CRM_Test";
public CustomMeshProvider()
{
InitializeCustomGeometry();
}
private void InitializeCustomGeometry()
{
var box = new Box(new Plane(Point3d.Origin, Vector3d.ZAxis), new Interval(-5, 5), new Interval(-5, 5), new Interval(-5, 5));
_customBox = Mesh.CreateFromBox(box, 1, 1, 1);
_boundingBox = _customBox.GetBoundingBox(false);
var material = new Material
{
DiffuseColor = System.Drawing.Color.Gray
};
_material = RenderMaterial.CreateBasicMaterial(material, RhinoDoc.ActiveDoc);
}
public static void ForceRedraw()
{
Random rnd = new Random();
var x = rnd.Next(3, 7);
var y = rnd.Next(3, 7);
var z = rnd.Next(3, 7);
var box = new Box(new Plane(Point3d.Origin, Vector3d.ZAxis), new Interval(-x, x), new Interval(-y, y), new Interval(-z, z));
_customBox = Mesh.CreateFromBox(box, 1, 1, 1);
_boundingBox = _customBox.GetBoundingBox(false);
CustomRenderMeshProvider2.DocumentBasedMeshesChanged(RhinoDoc.ActiveDoc);
}
public override bool BuildCustomMeshes(ViewportInfo vp, RhinoDoc doc, RenderPrimitiveList primitives, Guid requestingPlugIn, DisplayPipelineAttributes attrs)
{
bool addedContent = false;
if (primitives.RhinoObject == null)
{
primitives.Add(_customBox, _material);
BoundingBox(vp, null, doc, requestingPlugIn, attrs);
addedContent = true;
}
return addedContent;
}
public override bool WillBuildCustomMeshes(ViewportInfo vp, RhinoObject obj, RhinoDoc doc, Guid requestingPlugIn, DisplayPipelineAttributes attrs)
{
if (obj == null)// && attrs != null && attrs.EnglishName == "Rendered")
return true;
return false;
}
public override BoundingBox BoundingBox(ViewportInfo vp, RhinoObject obj, RhinoDoc doc, Guid requestingPlugIn, DisplayPipelineAttributes attrs)
{
var bbox = Rhino.Geometry.BoundingBox.Empty;
bbox.Union(_boundingBox);
return bbox;
}
}
#endif