Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:singlecolorbackfaces [2015/09/14] (current)
Line 1: Line 1:
 +====== Setting Backface Colors in Advanced Display Settings ======
 +> **Developer:​** //​[[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to modify advanced display settings.//
 +
 +===== Question =====
 +I am trying to set the backface settings for the Shaded advanced display mode to single color. In other words:
 +
 +{{:​developer:​backfacesettings.jpg|}}
 +
 +Any help here would be appreciated.
 +
 +===== Answer ===== 
 +Setting advanced display settings can be difficult primarily due to the number of display attributes (variables). For what you are looking to do, here is an example that you can reference.
 +
 +===== Example =====
 +
 +==== C# ====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  // The name of the display mode attributes to change
 +  string attr_name = "​Shaded";​
 +  OnColor cyan = new OnColor(0, 255, 255);
 +  int gloss = 30;
 +  int transparancy = 10;
 +
 +
 +  // Get a list of all display mode attributes
 +  MDisplayAttrsMgrList attrs_list = new MDisplayAttrsMgrList();​
 +  int attrs_count = MRhinoDisplayAttrsMgr.GetDisplayAttrsList(ref attrs_list);​
 +  if (0 == attrs_count)
 +    return IRhinoCommand.result.failure;​
 +
 +  // Find the display mode attribute
 +  int attr_index = -1;
 +  for( int i = 0; i < attrs_count;​ i++ )
 +  {
 +    if (null != attrs_list[i].m_pAttrs)
 +    {
 +      if (attr_name.Equals(attrs_list[i].m_pAttrs.EnglishName(),​ StringComparison.OrdinalIgnoreCase))
 +      {
 +        attr_index = i;
 +        break;
 +      }
 +    }
 +  }
 +
 +  if (-1 == attr_index)
 +    return IRhinoCommand.result.failure;​
 +
 +  // Get the display mode attribute
 +  MDisplayAttrsMgrListDesc desc = attrs_list[attr_index];​
 +  if (null == desc || null == desc.m_pAttrs)
 +    return IRhinoCommand.result.failure;​
 +
 +  // Modify backface settings
 +  desc.m_pAttrs.m_bCullBackfaces = false;
 +  desc.m_pAttrs.m_bUseObjectBFMaterial = false;
 +  desc.m_pAttrs.m_pMaterial.m_bUseBackMaterial = true;
 +  desc.m_pAttrs.m_pMaterial.m_BackMaterial.m_bOverrideObjectColor = true;
 +  desc.m_pAttrs.m_pMaterial.m_BackMaterial.m_diffuse = new OnColor(0, 255, 255); // Cyan in this example
 +  desc.m_pAttrs.m_pMaterial.m_BackMaterial.m_shine = Math.Ceiling(gloss/​100.0) * OnMaterial.MaxShine();​
 +  desc.m_pAttrs.m_pMaterial.m_BackMaterial.m_transparency = (transparancy / 100.0f) + (transparancy > 0 ? 0.001 : 0);
 +  desc.m_pAttrs.m_pMaterial.m_bBackIsCustom = false;
 +
 +  // Use the display attributes manager to update the display mode.
 +  MRhinoDisplayAttrsMgr.UpdateAttributes(desc);​
 +
 +  // Force the document to regenerate.
 +  context.m_doc.Regen();​
 +
 +  return IRhinoCommand.result.cancel;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer dotnet}}
 +
  
developer/singlecolorbackfaces.txt ยท Last modified: 2015/09/14 (external edit)