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!?
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;
sn.Rebuild();
I tried different ways to force material inheritance, but it always shows strange results…
What is working is:
ISimNode sn = (ISimNode)component;
sn.HighlightMaterial = customMaterial;
sn.Rebuild();
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.
Hi, there. I have the same problem on assigning materials to the components using C# .net.
The colors can be assigned to the components but the colors shows not correctly. However, It shows the correct colors in the interface of “Tools - Material - assign”, if I change a little bit of the corresponding color in the interface of “Tools - Material - assign”, the color on the component can immediately show the correct color. I am wondering what the problem it is, is it a problem of render update? How to use code to solve this problem?
you did not what in this thread is recommendet! → Get some material from the library example “red”! → And copy everything to your customMaterial without the color then it should work…