Render PlugIn


#1

Hello,

I’m trying to create a Render Plugin with RhinoCommon and I’m having some issues. I don’t know if I’m doing it in a proper way. Could you help me?
I made you a project with a little exemple of what I’m trying to do. My idea is the next:

  • Add a new kind of material. “NewMaterial:RenderMaterial”. And view this new material when I try to add a material. I’m able to create the new material class and register it in the plugin but I’m not able to create the persistent new material. What I’m missing? The RenderContent.Create(… never works with my custom RenderMaterial.

  • Add a new Render Content: I’can’t inherit from Render Content ( Cannot acces to the internal constructor)

You can see this errors in the attached project.

Could you give some instructions of how I have to deal with the render plugins?

Thanks,

Guille
RenderPlugIn.zip (14.4 KB)


(Dale Fugier) #2

@JohnM, is this something you can help with?


#3

Hello Dale,

I’m trying to create my own materials type, but RhinoCommon doesn’t allow me to add the new materials to the persistent list. The RenderContent.Create function always return me null.

        protected override LoadReturnCode OnLoad(ref string errorMessage)
    {
        //Register the new render contents. My own material type
        RenderContent.RegisterContent(this);

        //Create a persistent material and add it to the internal rdk lists
        var persistetContnt = RenderContent.Create(MyOwnMaterial.MyOwnMaterial_Id, null, "", RenderContent.ShowContentChooserFlags.None,null);
        if(persistetContnt != null)
            RenderContent.AddPersistentRenderContent(persistetContnt);

        return base.OnLoad(ref errorMessage);
    }
    
    protected override bool AllowChooseContent(RenderContent content)
    {
        if (content.TypeName == "MyCustomMaterial")
        {

        }
        return base.AllowChooseContent(content);
    }

MyOwnMaterial inherits from RenderMaterial.

[Guid("2194e475-834a-4650-b6b6-0c1f696373e0")]
public class MyOwnMaterial : Rhino.Render.RenderMaterial
{
    /// <summary>
    /// Guid to identify the RenderContent
    /// </summary>
    public static Guid Guid = new Guid("2194e475-834a-4650-b6b6-0c1f696373e0");

    public override string TypeName
    {
        get { return "MyOwnMaterial"; }
    }

    public override string TypeDescription
    {
        get { return "MyOwnMaterial"; }
    }

    protected override void OnAddUserInterfaceSections()
    {
        base.OnAddUserInterfaceSections();
    }
}

Another problem I have is that I cannot directly inherit from Render Content. The compiler says “no access to the internal constructor ‘RenderContent’”.

public abstract class NewRenderContent : RenderContent {}

Could you give some help?

Thank you,


(Andrew le Bihan) #4

Are you using Rhino 5 SR7? This is the first build that supports this stuff properly.

You can’t inherit from RenderContent - it has to be RenderMaterial, RenderEnvironment or RenderTexture.


(Andrew le Bihan) #5

Try something like this:

[System.Runtime.InteropServices.Guid(“ABE4059B-9BD7-451C-91B2-67C2F188860A”)]
public class CustomMaterial : RenderMaterial
{
public override string TypeName { get { return “CSharp Custom Material”; } }
public override string TypeDescription { get { return “My first custom .NET material”; } }

public CustomMaterial()
{
  //ModifyRenderContentStyles(RenderContentStyles.None, RenderContentStyles.TextureSummary);
  Fields.Add("bool", false, "Yes/No");
  Fields.AddTextured("color", Rhino.Display.Color4f.White, "Color");

  //Non visible fields to store texture on-ness and amount
  Field field = Fields.Add("color-texture-on", true);
  BindParameterToField("color", "texture-on", field, ChangeContexts.UI);

  field = Fields.Add("color-texture-amount", 100.0);
  BindParameterToField("color", "texture-amount", field, ChangeContexts.UI);
}

protected override void OnAddUserInterfaceSections()
{
  AddAutomaticUserInterfaceSection("Parameters", 0);
}

public override void SimulateMaterial(ref Rhino.DocObjects.Material simulatedMaterial, bool forDataOnly)
{
  base.SimulateMaterial(ref simulatedMaterial, forDataOnly);

  Rhino.Display.Color4f color;
  if( Fields.TryGetValue("color", out color) )
    simulatedMaterial.DiffuseColor = color.AsSystemColor();
}

//public override IntPtr GetShader(Guid renderEngineId, IntPtr privateData)
//{
//  if (!IsCompatible(renderEngineId))
//    return IntPtr.Zero;

//  return IntPtr.Zero;
//}


//BoolField m_bool = new BoolField("bool", "Yes/No", false);
//ColorField m_color = new ColorField("color", "Color", Rhino.Display.Color4f.White);

}


#6

Thank you Andy, now its working!