Animated Model with many textures for armors

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
skizzy
Posts: 5
Joined: Wed Feb 07, 2018 8:49 pm

Animated Model with many textures for armors

Post by skizzy »

Hi, just starting in irrlicht and am trying to give a animated model the ability to have many different textures for different armor pieces obtained.
I want it to be one solid skeletal mesh with sections that are uv'ed and textured differently. I could grab the node and get a certain material id and assign it to a small texture, this is what I want.

What format would I use to accomplish this? Is this something irrlicht can do out of the box or do you have any ideas of what other libraries I made need to pull this off?

Thanks!
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated Model with many textures for armors

Post by CuteAlien »

You can always change materials for nodes with ISceneNode::getMaterial(id). That returns a refernce to the material used on a meshbuffer and you can change that.

But for changing uv's it's more tricky as those are part fo the vertices. In that case it's easier to swap the mesh itself. Meshes usually do not take up much memory (compared to textures), so having a new mesh per armor is often a good idea.

For animated meshes b3d tends to be a good format.
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
skizzy
Posts: 5
Joined: Wed Feb 07, 2018 8:49 pm

Re: Animated Model with many textures for armors

Post by skizzy »

Thanks i'll look into getMaterial. I don't need to change uv's I just want to use a uv per material id initially when I create the artwork.

The idea is to change a part of the animate model's textures as needed when they equip certain armors. getMaterial might work and i'll test that out when i get a chance.
skizzy
Posts: 5
Joined: Wed Feb 07, 2018 8:49 pm

Re: Animated Model with many textures for armors

Post by skizzy »

About the b3d format. Is there a recent b3d exporter for the newer Blender versions? I found some but it says < 2.5
skizzy
Posts: 5
Joined: Wed Feb 07, 2018 8:49 pm

Re: Animated Model with many textures for armors

Post by skizzy »

Sorry for replying so much..
Using the md2 format it only supports one uv/texture so that is out i guess but curious about this b3d format. Can I have many material id's on 1 animated model? Do i just do this in blender, i need a format that will allow me to use getMaterial on up to 7 ids on 1 animated model. Chest, Legs, Arms, Wrists, Head, Feet, Hands.

I'm working on the artwork now so sort of need to know what is possible.
I need the ability to change these based on server settings of the character when they load in and when they change armor pieces.

Oh and thanks for helping me!
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated Model with many textures for armors

Post by CuteAlien »

Ow, I just notice that SuperTuxKart no longer seems to have a b3d exporter :-( That was the one I always recommended *sigh*. I will try to search for it in the evening (unless someone else finds it by then which would be nice...). I hope it's still somewhere in their source-control and I think we should then copy it to some place where it's easier to find now.

Irrlicht's getMaterial function returns the material for a meshbuffer - it works independent of the format. You get as many materials as you have meshbuffers. Also the other way round - you have at least 1 meshbuffer per material (it's currently the only way to have several materials in a mesh). But - it's also possible to have several meshbuffers with the same material (like a model contains X chrome parts - those don't _have_ to be in the same meshbuffer). When exactly a meshbuffer is created depends on the format exporter and importer and maybe even on the way the model was created, so that's hard to generalize.
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
skizzy
Posts: 5
Joined: Wed Feb 07, 2018 8:49 pm

Re: Animated Model with many textures for armors

Post by skizzy »

Thanks for the advice but i'm not even sure what a meshbuffer is exactly in the context of a animated mesh with many materials/textures. Is each material/part of geometry I make in blender considered a meshbuffer in irrlicht? From what I understand a meshbuffer is just part of an entire mesh? I understand it's hard to generalize but lets say I am making the model in blender with multiple uv maps(Actually it seems the entire mesh uses one uv map but has many textures )/materials and exporting it with the b3d exporter.

Trying to learn the basics of the engine and having a hard time. Maybe I should start with learning a bit of OpenGL first?
Just for perspective I am a web developer/3D artist who is getting into game programming so this is all new to me.

The only reason I'm stuck at this point is that I want to make sure I am making my artwork correctly for the engine. Having parts of the mesh's texture change on demand is key to my design.
Oh and thanks for looking for the b3d exporter. I couldn't find it but if you do please let me know. I appreciate it very much.

UPDATE! I got it working and found a download to the bs3d exporter at http://www.rtsoft.com/forums/showthread ... ort-script. It's for 2.6 but just tested it on 2.7.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Animated Model with many textures for armors

Post by CuteAlien »

2.6 and 2.7 should be compatible (only time they broke python script compatiblitly in Blender so far was between 2.4 and 2.5 to my knowledge).

Meshbuffer is an Irrlicht thing (thought other engines often have the same or something similar). Basically it can be any kind of split of your mesh. But in most cases it means 1 material = 1 meshbuffer. So if you have 2 different textures on your model (for example one for head and one for body) then you will also get 2 meshbuffers. So there is never a problem changing textures independent of the format.
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
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: Animated Model with many textures for armors

Post by LunaRebirth »

So I ran across something similar a while ago.
I wanted a character to be able to switch out gloves, helmets, shoulder pads, etc.

If you're only wanting to switch the texture image and not the model, then this is probably unnecessary for you.

First I created the player model with bones so that I could animate the character.
Then, I created separate models for armor (shoulder pads, helmet, etc) also with bones. The bones that correlate with the player have the same name in .b3d, so that they can match up.
(For example, if the player's head bone is named "01.head", the helmet model needs a bone named "01.head" where the helmet is connected to that bone)

Next, I added this code that runs on the player model:

Code: Select all

// attach the child (the helmet) to the mesh (the player)
void Mesh::addChild(Mesh* child) {
    if (std::find(this->children.begin(), this->children.end(), child) != this->children->end() ||
        !this->mesh ||
        !child->mesh)
        return;
 
    this->mesh->addChild(child->mesh);
    this->children.push_back(child);
}
 
// animate the bones of the child (the helmet) to the bones of the mesh (the player)
void Mesh::runChildAnimation() {
    // this->mesh is an IAnimatedMeshSceneNode*, the player model
    if (!this->mesh)
        return;
 
    // the child in this case is the helmet
    for (int x = 0; x < this->children.size(); x++) {
        Mesh* m = this->children[x];
        if (!m)
            continue;
 
        // allow the helmet mesh to be animated Via code
        m->mesh->setJointMode(EJUOR_CONTROL);
        for (int i = 0; i < this->b->getJointCount(); i++) {
            // the player's bone (for all bones)
            IBoneSceneNode* thisB = this->mesh->getJointNode(i);
            if (!thisB)
                continue;
            std::string name = thisB->getName();
 
            // the helmet's bone, if the bone name matches the player's bone name
            IBoneSceneNode* mB = m->mesh->getJointNode((char*)name.c_str());
            if (!mB)
                continue;
 
            // move the helment's "head" bone to the same position/rotation as the player's head bone
            mB->setPosition(thisB->getPosition());
            mB->setRotation(thisB->getRotation());
        }
    }
}
In theory, it would be a lot easier if you could make a bone a child of another bone.
Looks like it's supported in Irrlicht, but my program crashes every time I try -- so this was my alternative.

But again, this is for attaching a whole different mesh to another mesh, which may or may not be what you want.
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Animated Model with many textures for armors

Post by Arclamp »

In Blender, if you select an object, then enter edit mode.
Next you selected some faces and applied a material, then selected other faces and applied a material from another slot.
Those material slots and their order correlate to how they are loaded in Irrlicht.

Most of the importers load in materials, but not always textures. If your node has 3 materials and the textures hadn't been loaded then you could set them like so:

Code: Select all

 
    node->getMaterial(0).setTexture(0, driver->getTexture("media/textures.png"));
    node->getMaterial(1).setTexture(0, driver->getTexture("media/wall.jpg"));
    node->getMaterial(2).setTexture(0, driver->getTexture("media/detailmap3.jpg"));
 
You can use the ISceneNode to find out how many and get the materials using getMaterialCount() and getMaterial(i), etc...
Post Reply