mNo edit summary Tags: Visual edit apiedit |
No edit summary Tags: Visual edit apiedit |
||
Line 15: | Line 15: | ||
boxObject->SetMaterial(mat2); |
boxObject->SetMaterial(mat2); |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
− | '''NOTE:''' Material::Clone() is returning a Urho3D::SharedPtr<Urho3D::Material>, you may want to either save this SharedPtr somewhere or the Material may get deleted and Urho may crash depending on how you use the Material. |
||
− | |||
You can use this to make every model unique by randomizing colors or color models in a team color. You can also pass custom parameters to control things like current weather or different (localized) lighting scenes. |
You can use this to make every model unique by randomizing colors or color models in a team color. You can also pass custom parameters to control things like current weather or different (localized) lighting scenes. |
||
Latest revision as of 03:51, 21 February 2016
Normally you assign materials like this:
StaticModel* boxObject=boxNode_->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
You can also load materials, copy them, and/or change parameters:
Material* mat1=cache->GetResource<Material>("Materials/Stone.xml");
Material* mat2=mat1->Clone(); // copy material
// change the ciffuse color
mat2->SetShaderParameter("MatDiffColor",Color(0.1,0.4,0.9));
boxObject->SetMaterial(mat2);
You can use this to make every model unique by randomizing colors or color models in a team color. You can also pass custom parameters to control things like current weather or different (localized) lighting scenes.
An example of 400 uniquely colored cubes: