[Original] ms3d models in irrlicht do not support resolution of multiple texture Problems

Source: Internet
Author: User

friends who have tested the ms3d model in irrlicht may find this phenomenon. If the ms3d model has only one texture, the model can be rendered normally, regardless of whether the texture file is placed in the same directory as the demo and the Program or by calling the setmaterialtexture () function, when the model has two or more textures, The pasters and executable programs can be correctly rendered only when they are automatically loaded in the same directory. setmaterialtexture (0 ,...), Setmaterialtexture (1 ,...) It seems that only the first texture works. A closer look at the engine's Code shows that this is not an accidental phenomenon. It is also a bug that the engine supports the ms3d model. Before talking about specific solutions, let's talk about the concept of group in the ms3d model. As the name suggests, "group" should be a collection of things with some common attributes. In ms3d, triangles in A group have the same texture file. When the engine loads ms3d model data, it has recorded the corresponding texture file name of the group, so the automatic texture will not go wrong. However, the setmaterialtexture function does not specify the group of textures at the specified time. Therefore, only one texture is displayed, as shown in the code, it traverses all groups, but uses setmaterialtexture (0 ,...) the specified texture.
Well, after knowing the cause, we can probably think of a solution. It specifies the group when setmaterialtexture is used. Yes. We provide two other setmaterialtexture functions for ms3d, namely:
void canimatedmeshscenenode: setms3dmaterialtexture (const C8 * groupname, s32 texturelayer, video: itexture * text)
{< br> If (texturelayer <0 | texturelayer> = video: material_max_textures)
return;

// obtain meshbuffer based on the group name
imesh * pmesh = mesh-> getmesh ();
for (s32 I = 0; I getmeshbuffercount (); I ++)
{< br> imeshbuffer * pmeshbuf = pmesh-> getmeshbuffer (I );
If (strcmp (pmeshbuf-> getgroupname (), groupname) = 0) {
IRR: Video :: smaterial & MAT = pmeshbuf-> getmaterial ();
mat. textures [texturelayer] = texture;
materials [I]. texture1 = texture;
break;
}< BR >}

}
Void canimatedmeshscenenode: setms3dmaterialtexture (s32 groupindex, s32 texturelayer, video: itexture * texture)
{
If (texturelayer <0 | texturelayer> = video: material_max_textures)
Return;

 
// Obtain meshbuffer based on the group name
Imesh * pmesh = mesh-> getmesh (0, 0 );

If (groupindex <0 | groupindex> pmesh-> getmeshbuffercount ())
Return;


Imeshbuffer * pmeshbuf = pmesh-> getmeshbuffer (groupindex );
// Yfxu
IRR: Video: smaterial & MAT = pmeshbuf-> getmaterial ();
Mat. Textures [texturelayer] = texture;
If (texturelayer = 0) mat. texture1 = texture;
Materials [groupindex]. texture1 = texture;

}
One is to set a texture based on the group name, and the other is to set a texture based on the group index.
It is worth noting that the engine also has a problem when retrieving group names for ms3d model data. The original code is as follows:
For (I = 0; I <numgroups; ++ I)
{
Groups. push_back (sgroup ());
Sgroup & GRP = groups. getlast ();
// Group name
GRP. Name = (const C8 *) PPT;
...

The file format of ms3d can be changed:
GRP. Name = (const C8 *) (PPT + 1 );
In order to get the group name correctly.
So far, the animation model rotation bug and the solution to the invalid frame problem have been added. Irrlicht's support for the ms3d model is basically perfect.

In the beauty, the body and hair are separated textures:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.