Next (Animation) Previous (Objects)

Materials

###Create Material
Material creation is similar to the object creation, you can use both creators and addNode() approaches, when using addNode(), you need to add node under virtual node %MaterialLibrary, and you can also name the material and set some default primitives, the command looks like,

ctx('%MaterialLibrary').addNode('name', 'Material', {'Material':{"MaterialType":{"Primitive":value}}});

For Example: Create a Standard material,

ctx.exec("creators", "createStandardContext");

Create a Standard material “MyMaterial“,

ctx('%MaterialLibrary').addNode('MyMaterial', 'Material', {'Material':{"Standard":{}}});

###Rename Material
As mentioned in the “Create Material“, we can initialize the primitives of a material when creating it.
And we can also modify the value of primitive at any time. Different with an object, a material only has Name property and Material plug, to rename of a material use the command like,

ctx('OldName').set({"name":"NewName"});

For Example: Rename the material from “Standard“ to “MyMaterial“.

ctx('Standard').set({"name":"MyMaterial"});

###Set Primitives
All primitives of material are under the operators of the Material plug. Under this plug, all material has an operator named as their “MaterialType“, and you can add an operator named vray/BRDFLayered_item. To set the primitive value of operator “MaterialType“, use the command like,

ctx('name#Material[name=MaterialType]').set({"PrimitiveName":value});

For Example: set the diffuseColor of Standard material “MyMaterial“ to (0.5,0.5,0.5),

ctx('MyMaterial#Material[name=Standard]').set({"diffuseColor":{"r":0.5,"g":0.5,"b":0.5}});

###Apply Material
To apply a material to an object, return to Material plug of the desired object, set the operator reference to the name of the material which you want, the command looks like,

ctx('name#Material[name=Reference]').set({"reference":"MaterialName"});

For Example: Apply “MyMaterial“ to the object “MyBox“,

ctx('MyBox#Material[name=Reference]').set({"reference":"MyMaterial"});

###Plugs and Operators
MaterialType: Physical, Standard, MultiID, CubeMap, EnvironmentMap, Canvas.

Primitive: Please check Clara.io.


Next (Animation) Previous (Objects)