Jump to content

Material cloning for decals


photo

Recommended Posts

Hi guys,

I am new to unigine and this forum, sorry if I am duplicating topic.

 

I am working on selection decals ( selection ring around unit(s)/structure while they are selected ).

 

What I want is to create lots of decals from one base material with different ( random ) colors using "color_scale" parameter to distinguish each of them. I mean unit selection ring according to player color.

 

This is what I did till now but it's not working :

 

strMaterial is base material.

 

 

string strMaterialWithColor = format("%s, %.2f, %0.2f, %0.2f, %0.2f", strMaterial, vColorModifier.x, vColorModifier.y, vColorModifier.z, vColorModifier.w);
int idLibrary = engine.materials.findLibrary("world1.mat");
if(idLibrary == 0)
{
idLibrary = engine.materials.addWorldLibrary("world1.mat");
}

if(idLibrary == 0)
{
strMaterialWithColor = strMaterial;
}

if(idLibrary != 0 && engine.materials.findLibraryMaterial(idLibrary, strMaterialWithColor) == -1)
{
int idMaterial = engine.materials.cloneMaterial(strMaterial, "world1.mat", strMaterialWithColor);
Material mat = engine.materials.getMaterial("world1.mat", idMaterial);
mat.setParameter("color_scale", vColorModifier);
}
else
{
strMaterialWithColor = strMaterial;
}
DecalOrtho decal = new DecalOrtho(vPos.z + DECAL_PROJECTOR_OFFSET, 2, 2, strMaterialWithColor );

 

Please help me.

Link to comment

I fixed it.

 

This is my final code

 

 

string strMaterialWithColor = format("%s, %.2f, %0.2f, %0.2f, %0.2f", strMaterial, vColorModifier.x, vColorModifier.y, vColorModifier.z, vColorModifier.w);
if(engine.materials.findMaterial(strMaterialWithColor) == 0)
{
engine.materials.cloneMaterial(strMaterial, "materials/system.mat", strMaterialWithColor);
Material mat = engine.materials.findMaterial(strMaterialWithColor);
int idParam = mat.findParameter("color_scale");
mat.setParameter(idParam, vColorModifier);
}
DecalOrtho decal = new DecalOrtho(vPos.z + DECAL_PROJECTOR_OFFSET, 2, 2, strMaterialWithColor );

Link to comment
×
×
  • Create New...