Assign Material via .Net during Runtime


I successfully assign a Material to a component during simulation but the different color of the material won’t appear!? If I assign the material afterwards manually everything is fine…

But what should I do that this working just by code!?

I’m using IMaterial, Color, ISimNode.

Thx & Regards

So you are assigning material to root node of component? If a feature has a material assigned to it already, the component material won’t override it. What you can do is force material inheritance.

Color color = new VisualComponents.Create3D.Color((byte)red, (byte)green, (byte)blue, (byte)alpha); //Create the color
customMaterial.Color = color; //Set the color over RGBA
customMaterial.Ambient = color; //Set the Ambient over RGBA
customMaterial.Specular = color; //Set the Specular over RGBA
customMaterial.Emissive = color; //Set the Emissive over RGBA
customMaterial.Opacity = (byte)alpha; //Set Transparency becauseAlphaValue works not well...
customMaterial.ForceUpdate(); //Update Material

ISimNode sn = (ISimNode)component;
sn.MaterialInheritance = MaterialInheritance.ForceInheritNode;
sn.Material = customMaterial;

I tried different ways to force material inheritance, but it always shows strange results… :frowning:

What is working is:

ISimNode sn = (ISimNode)component;
sn.HighlightMaterial = customMaterial;

but AlphaValue is not working at all…

Can you tell me how to Update/Render the whole component correctly that the result is shown immediately?


Sounds like you should do render because changing material does require render update. You can try contacting support or others can help. I won’t be able to test until later today.

_RenderService.RequestRender(); does the trick! :slight_smile:

Thx & Regards

1 Like