Jump to content

How to swap the texture of decal material


photo

Recommended Posts

Hi, I am using the Unigine of version 2.6.

I create a decal projected and give it the decal material,  but I want to dynamic replace the texture of decal material.

I get the material and use the setTextureImage(),but the function return 0.

           Unigine::MaterialPtr matdecal = Unigine::Materials::get()->findMaterial("decal_base_0");
            if (matdecal)
            {
                int flag = matdecal->setTextureImage(1, img);
                matdecal->setTexturePath(1, path.toStdString().c_str());
            }

Does anyone know how to do?

Link to comment

zhengwenxin

Please make sure that texture slot 1 is the texture that you are really want to set.

If you want to change the albedo, first get the albedo texture slot from material:

Materials *materials = Materials::get();
MaterialPtr m = materials->findMaterial("decal_base_0");
int num = m->findTexture("albedo");
m->setTexturePath(num, new_texture);

Don't forget to check if num is a positive number, since -1 means that such texture slot is not found.

You can check how texture slots are named in .basemat file from core directory:

image.png

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...