Multiple material layers on my character

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Valipss
Posts: 2
Joined: Fri May 08, 2020 2:05 pm

Multiple material layers on my character

Post by Valipss »

Hi everybody,

I'm looking for some help to render multiple textures on characters. I've found some characters from the mario's universe in .obj with their textures in separate .png.
First, I animated them with 3ds max, then I exported them in .MD3 files thanks to the quake 3 3dsmax plugin.
But ... When I try to apply my textures on each layer as explained in the Irrlicht tutorial, it goes wrong.

expected : Image
got : Image

files : Image

idk why images are not loading for me, please right click and open in new tab ;) ty

here is my code, I created a Character class that takes a modelInfo struct and everything needed to create an animated mesh.

the modelInfos structure

Code: Select all

typedef struct modelInfos_s {
    std::string filename;
    std::vector<std::string> textures;
    std::pair<int, int> idleLoop;
    std::pair<int, int> movingLoop;
    std::pair<int, int> dyingLoop;
    std::pair<int, int> deadLoop;
    std::pair<int, int> victoryLoop;
    float size;
} modelInfos_t;
The structure sent to create a Waluigi character

Code: Select all

 { // MODELINFOS_T
            "resources/models/characters/waluigi/waluigi.MD3", // MODEL MD3
            {
                "resources/models/characters/waluigi/Tex_0001_0.png", // TEXTURES
                "resources/models/characters/waluigi/Tex_0002_0.png",
                "resources/models/characters/waluigi/Tex_0003_0.png",
                "resources/models/characters/waluigi/Tex_0004_1.png"
            },
            {0, 120}, // IDLE
            {121, 142}, // MOVING
            {143, 281}, // DYING
            {282, 353}, // DEAD
            {354, 604}, // VICTORY
            1 // SCALE SIZE
        }
}

Code: Select all

Character::Character(scene::ISceneManager *sManager, video::IVideoDriver *driver, modelInfos_t model, std::string name, int travelingTime, side orientation)
: _sManager(sManager), _driver(driver), _model(model), _name(name), _travelingTime(travelingTime), _orientation(orientation)
{
    _mesh = _sManager->addAnimatedMeshSceneNode(_sManager->getMesh(_model.filename.c_str()));
    _mesh->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_LIGHTING, false);
 
    for (std::size_t i = 0; i < _model.textures.size(); i++) { // for reach textures file (_model.textures is a vector containing every .png textures)
        video::ITexture *texture = _driver->getTexture(_model.textures[i].c_str());
        if (texture && _mesh) {
            _driver->removeTexture(texture);
            texture = _driver->getTexture(_model.textures[i].c_str());
            _mesh->setMaterialTexture(i, texture); // set the material texture on each layer
        }
    }
 
    setOrientation(orientation);
    setPosition(core::vector3df{0, 0, 0});
    setSize(_model.size);
    setAnimationSpeed(30);
    setState(Character::state::idle);
}
If someone knows how to help me, i'll be so grateful :)
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Multiple material layers on my character

Post by CuteAlien »

Welcome to the forum. Sorry, we started to prevent images in the first post for new users at some point because certain spammers filled our forums too much with delicate images. It will work for you from now on.

Without real model and textures it's a bit hard for me to investigate further. The code looks OK.
First test would be to count the meshbuffers of your model to see if it has the right amount of meshbuffers (should have on per material). Next would be printing out material-type of each one to see if there is maybe something strange with those (like the hat having another material-type which maybe causes troubles).

Tiny note: In most cases you don't need the removeTexture and second getTexture call. You only need that if you want to reload a texture which has changed in the meantime (and there are other ways to do that, but guess this doesn't matter for now).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Valipss
Posts: 2
Joined: Fri May 08, 2020 2:05 pm

Re: Multiple material layers on my character

Post by Valipss »

Hey thanks for your quick response,
I think I found the problem by displaying the number of materials for each of my characters.
Indeed, some have only one when they are supposed to have several.
Also, I was trying to apply multiple layers of textures, but what I needed to do is to set a texture to every material instead of set different layers on the first one.
I now use _mesh->getMaterial(i)->setTexture... and it seems be working for characters with more than one material.
I'll try to discover what happened during my animations in 3ds max

thanks again for the reply ;)
Post Reply