If you build the following code against RhinoCommon 6.24.20079.23341 it should work as expected in Rhino 6.24.20079.23341 but fail (i.e. will return null for the texture when it should not) when run in WIP 7.0.20091.15085. However, if you build against RhinoCommon 7.0.20091.15085 it will work as expected in V7.
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
{
foreach (var rm in doc.RenderMaterials)
{
var tex = rm.GetTextureFromUsage(Rhino.Render.RenderMaterial.StandardChildSlots.Diffuse);
if (tex != null)
Rhino.RhinoApp.WriteLine("{0} texture: {1}", rm.Name, tex.Name);
else
Rhino.RhinoApp.WriteLine("{0} has no diffuse texture.");
}
return Rhino.Commands.Result.Success;
}
Thanks Andy, it would be great if this can just work, to prevent the need for a separate V7-specific package.
That said, in looking for a workaround, I have found that while I am able to get a reference to the RenderTexture using e.g. rm.FindChild("bitmap-texture"), the issue appears to be more general, with RenderMaterial.TextureChildSlotName (and some others like GetTextureOnFromUsage) also failing.
So while it seems that for what I need at the moment, I’ll be able to work around this whether or not you fix it, I don’t yet know if that will remain the case.
Seems this workaround will not work for getting the bump texture from e.g. a metal material (the reason I need a RenderTexture, as opposed to using a Texture from a simulation, is that I need RenderTexture.GetProjectionMode).