Multple UV textures for player model.

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Multple UV textures for player model.

by stu » Sat May 18, 2013 20:54

I wasn't really sure where to post this so moderators feel free to move.

It would be very helpful for some mods (especially some of my own) if the player model could support more than one UV texture. I know irrlicht can do this with node->setMaterialTexture() but I have no idea where to start looking in the minetest source code.

I do have some limited c++ experience and could perhaps implement this myself if someone could point me in then right direction.

Cheers!
Last edited by stu on Sat May 18, 2013 20:56, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Sun May 19, 2013 19:06

PilzAdam wrote:content_cao.cpp:554
GenericCAO is used for players and LuaEntities.

Thank you PilzAdam, that has been extremely helpful.

Am I right in thinking that this is where textures are applied to the player mesh?
Code: Select all
content_cao.cpp

1293:        if(m_animated_meshnode)
1294:        {
1295:            if(m_prop.visual == "mesh")
1296:            {
1297:                for (u32 i = 0; i < m_prop.textures.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
.
.
1311:                m_animated_meshnode->setMaterialTexture(i, texture);           

If so, it looks as if multiple textures should be already supported. However, if I supply more than one texture in the player object properties table, only the first one appears to be loaded.

Any ideas why that might be?

Is the player entity an animated meshnode or am I looking in the wrong place?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sun May 19, 2013 19:19

Code: Select all
m_animated_meshnode->getMaterialCount()

is 1, so only one texture can be applied.
Seems like only 1 texture per material is supported.
Last edited by PilzAdam on Sun May 19, 2013 19:20, edited 1 time in total.
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Sun May 19, 2013 20:55

PilzAdam wrote:
Code: Select all
m_animated_meshnode->getMaterialCount()

is 1, so only one texture can be applied.
Seems like only 1 texture per material is supported.

Well I guess that would make sense but looking at irrlicht ISceneNode::getMaterialCount(); it shoud infact return zero unless its overridden by the derived class. I can't find where this done in minetest besides farmesh.cpp

I guess this is not going to be as easy as I thought :(

Thank you again for your help.
Last edited by stu on Sun May 19, 2013 20:58, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sun May 19, 2013 21:00

stu wrote:
PilzAdam wrote:
Code: Select all
m_animated_meshnode->getMaterialCount()

is 1, so only one texture can be applied.
Seems like only 1 texture per material is supported.

Well I guess that would make sense but looking at irrlicht ISceneNode::getMaterialCount(); it shoud infact return zero unless its overridden by the derived class. I can't find where this done in minetest besides farmesh.cpp

I guess this is not going to be as easy as I thought :(

Thank you again for your help.

No problem, its always interesting to dig into a part of Minetest's code.
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Tue May 21, 2013 20:47

Ok well I think I am beginning to make some progress. It turns out that node->getMaterialCount() should do just exactly what it says; return the number of materials a model supplies. My model has 2 materials, therefore getMaterialCount returns 2.

I have proven this by applying the following to the irrlicht 'HelloWorld' example.
Code: Select all
        node->getMaterial(0).TextureLayer[0].Texture = driver->getTexture("wieldview_character.png");
        node->getMaterial(1).TextureLayer[0].Texture = driver->getTexture("armor.png");

        video::SMaterial& material_player = node->getMaterial(0);
        video::SMaterial& material_armor = node->getMaterial(1);

        material_player.setFlag(video::EMF_LIGHTING, false);
        material_armor.setFlag(video::EMF_LIGHTING, false);

        node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);

        printf("Material Count: %d \n", node->getMaterialCount());


This works fine in the example but for some reason only the first material is loaded when I use the same model in minetest.
My guess is that it has to do with how content.cao applies the material texture.

Notably this does NOT work when used with the example above.
Code: Select all
        node->setMaterialTexture( 0, driver->getTexture("wieldview_character.png") );
        node->setMaterialTexture( 1, driver->getTexture("armor.png") );
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue May 21, 2013 20:50

stu wrote:Ok well I think I am beginning to make some progress. It turns out that node->getMaterialCount() should do just exactly what it says; return the number of materials a model supplies. My model has 2 materials, therefore getMaterialCount returns 2.

I have proven this by applying the following to the irrlicht 'HelloWorld' example.
Code: Select all
        node->getMaterial(0).TextureLayer[0].Texture = driver->getTexture("wieldview_character.png");
        node->getMaterial(1).TextureLayer[0].Texture = driver->getTexture("armor.png");

        video::SMaterial& material_player = node->getMaterial(0);
        video::SMaterial& material_armor = node->getMaterial(1);

        material_player.setFlag(video::EMF_LIGHTING, false);
        material_armor.setFlag(video::EMF_LIGHTING, false);

        node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);

        printf("Material Count: %d \n", node->getMaterialCount());


This works fine in the example but for some reason only the first material is loaded when I use the same model in minetest.
My guess is that it has to do with how content.cao applies the material texture.

Notably this does NOT work when used with the example above.
Code: Select all
        node->setMaterialTexture( 0, driver->getTexture("wieldview_character.png") );
        node->setMaterialTexture( 1, driver->getTexture("armor.png") );

Interesting. Would be cool if you find a fix for the Minetest code and provide it as a patch.
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Tue May 21, 2013 21:26

Yay, I changed:
Code: Select all
 m_animated_meshnode->setMaterialTexture(i, texture);
To:
Code: Select all
 m_animated_meshnode->setMaterial(i).TextureLayer[0].Texture = texture;

Recompiled and it works! :D

Do you think that would be accepted as a pull request?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue May 21, 2013 21:28

stu wrote:Yay, I changed:
Code: Select all
 m_animated_meshnode->setMaterialTexture(i, texture);
To:
Code: Select all
 m_animated_meshnode->setMaterial(i).TextureLayer[0].Texture = texture;

Recompiled and it works! :D

Do you think that would be accepted as a pull request?

Definetly worth a try. Also add a short description how to test it (maybe a testmodel included).
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Tue May 21, 2013 21:38

Thanks, I will give it a shot. I would really love this to be included in 0.4.7, it would make my armor and weildview mods sooo much easier to implement and no more issues with conflicting texture resolutions.

Really speaking, I consider this to be a bug in minetest since the loop in updateTextures has clearly been desgined to cope with multiple materials/textures...it just does not work the way it is.
Last edited by stu on Tue May 21, 2013 21:39, edited 1 time in total.
 

User avatar
RealBadAngel
Member
 
Posts: 556
Joined: Wed Jul 18, 2012 16:30

by RealBadAngel » Wed May 22, 2013 02:42

I used multitextured objects already without problems.
if model comes with materials defined in it (like .x model for example) engine will load textures defined here, without even need to mention them in code.

Also sample objects loading from my skydome code:

scene::IAnimatedMesh *mesh;
mesh = mgr->getMesh("sky_sphere.x");
m_sky_sphere = mgr->addAnimatedMeshSceneNode(mesh, NULL);
mesh->drop();
mesh = mgr->getMesh("sky_dome.x");
m_sky_dome = mgr->addMeshSceneNode(mesh, NULL);
mesh->drop();
m_sky_sphere->animateJoints();
m_sky_sphere->setFrameLoop(1, 250);
m_sky_sphere->setAnimationSpeed(0);
m_sky_sphere->setPosition(v3f(0,0,0));
m_sky_sphere->setScale(v3f(1000,1000,1000));
u8 li = 255;
setMeshColor(m_sky_sphere->getMesh(), video::SColor(255,li,li,li));
m_sky_sphere->setMaterialFlag(video::EMF_LIGHTING, false);
m_sky_sphere->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
m_sky_sphere->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_sky_sphere->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
m_sky_sphere->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
m_sky_sphere->setMaterialFlag(video::EMF_ZBUFFER, false);

m_sky_dome->setPosition(v3f(0,400,0));
m_sky_dome->setScale(v3f(20,20,20));
m_sky_dome->setMaterialFlag(video::EMF_LIGHTING, false);
m_sky_dome->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
m_sky_dome->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_sky_dome->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
//m_sky_dome->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
//m_sky_dome->setMaterialFlag(video::EMF_ZBUFFER, false);
m_sky_dome->setMaterialTexture(0, mgr->getVideoDriver()->getTexture(getTexturePath("sky.png").c_str()));
m_sky_dome->setMaterialTexture(1, mgr->getVideoDriver()->getTexture(getTexturePath("glow.png").c_str()));
m_sky_dome->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
video::E_MATERIAL_TYPE sky_shader = m_client->getShaderSource()->getShader("test_shader_4").material;
m_sky_dome->setMaterialType(sky_shader);
m_sky_dome->setRotation (v3f(-90,0,0));
sky_sphere->setMaterialTexture(0, mgr->getVideoDriver()->getTexture(getTexturePath("sky.png").c_str()));
sky_sphere->setMaterialTexture(1, mgr->getVideoDriver()->getTexture(getTexturePath("glow.png").c_str()));
sky_sphere->setMaterialTexture(2, mgr->getVideoDriver()->getTexture(getTexturePath("stars.jpg").c_str()));
sky_sphere->setMaterialTexture(3, mgr->getVideoDriver()->getTexture(getTexturePath("moon.png").c_str()));
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Wed May 22, 2013 18:23

RealBadAngel wrote:I used multitextured objects already without problems.
if model comes with materials defined in it (like .x model for example) engine will load textures defined here, without even need to mention them in code.


I am aware that I can export textures with the model, however, it is currently only possible to update the first material dynamically through lua.

My suggested change should fix that also.

btw, there is a typo in the code I posted above, it should be:
Code: Select all
  // Set material flags and texture
  m_animated_meshnode->getMaterial(i).TextureLayer[0].Texture = texture;
 

User avatar
Jordach
Member
 
Posts: 4518
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Wed May 22, 2013 18:34

I was thinking something like this could make custom skins even further refined:

You could have one texture for eyes, hair, hats, clothes etc and no one will have a pron skin ever.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Wed May 22, 2013 19:45

Jordach wrote:I was thinking something like this could make custom skins even further refined:

You could have one texture for eyes, hair, hats, clothes etc and no one will have a pron skin ever.

Sure, there are lots of possibilities for this if it gets added.

Anyway I just made my very first pull request...and I mean like ever!

Hope I got it right.
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Wed May 22, 2013 22:28

stu wrote:
Jordach wrote:I was thinking something like this could make custom skins even further refined:

You could have one texture for eyes, hair, hats, clothes etc and no one will have a pron skin ever.

Sure, there are lots of possibilities for this if it gets added.

Anyway I just made my very first pull request...and I mean like ever!

Hope I got it right.
link
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

User avatar
Jordach
Member
 
Posts: 4518
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Thu May 23, 2013 04:45

jojoa1997 wrote:
stu wrote:
Jordach wrote:I was thinking something like this could make custom skins even further refined:

You could have one texture for eyes, hair, hats, clothes etc and no one will have a pron skin ever.

Sure, there are lots of possibilities for this if it gets added.

Anyway I just made my very first pull request...and I mean like ever!

Hope I got it right.
link
We never even did ANYTHING.

Next time Jojoa, try reading posts first. There are no links.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11
Location: Earth

by jojoa1997 » Thu May 23, 2013 09:44

You mean this
https://github.com/minetest/minetest/pull/733
I finally got time to search for it
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Thu May 23, 2013 23:52

I have put together a simple mod to demonstrate the problem.

Image

Download: https://www.dropbox.com/s/fesymfg9gklm6zi/chainbox.zip

You will need to look for chainbox:chainbox_node in creative,
this is a simple transparent entity placement node.

With the current version you should only see the outer chains.

With the patch applied you should also see the inner texture.

License is WTFPL btw, if anyone wants to use any of this in a real mod.
Last edited by stu on Fri May 24, 2013 00:01, edited 1 time in total.
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Sat May 25, 2013 19:57

Potential next-generation wieldview & armor mods if this patch is merged.
Fully compatible with HDX texture packs.
Image
Otherwise not possible!
Last edited by stu on Fri Jun 07, 2013 20:57, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Thu Jun 06, 2013 18:46

PilzAdam wrote:Merged, will be in 0.4.7

I read the logs and see this has now been reverted. I do think this was the right decision under the circumstances, I would hate to break a new release.

I think the problem here is how Pavel_S is applying materials to the model or maybe he has a broken exporter. The method I am using to apply textures to materials is perfectly valid, however, given the chance I would write it sightly differently.
Code: Select all
         // Set material flags and texture
         video::SMaterial& material = m_animated_meshnode->getMaterial(i);
         material.TextureLayer[0].Texture = texture;
         material.setFlag(video::EMF_LIGHTING, false);
         material.setFlag(video::EMF_BILINEAR_FILTER, false);

Looks much better.
Last edited by stu on Thu Jun 06, 2013 18:50, edited 1 time in total.
 

User avatar
stu
Member
 
Posts: 909
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

by stu » Tue Jun 11, 2013 21:37

It turns out that Pavel_S' helicopter model is in fact proof that my suggested fix does work. The exported directx file lists three materials, therefore minetest expects to see three textures in the entity property table. It only appears to work correctly at the moment because of the lacking multi-texture support in the engine. Pavel_S could make the model so that only one material is exported or he could even exploit the situation as it is.

For example, using my feature branch
Code: Select all
    visual = "mesh",
    mesh = "heli.x",
    textures = {"wool_red.png", "heli.png", "wool_blue.png"},

Image

Also, I found the irrlicht forum thread that helped me get this working.

http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=37046&p=215659

Pull request re-opened https://github.com/minetest/minetest/pull/767
Last edited by stu on Tue Jun 11, 2013 22:09, edited 1 time in total.
 

jin_xi
Member
 
Posts: 165
Joined: Mon Jul 02, 2012 18:19
 

User avatar
Inocudom
Member
 
Posts: 3020
Joined: Sat Sep 29, 2012 01:14
IRC: Inocudom
In-game: Inocudom

by Inocudom » Wed Jun 12, 2013 03:37

Here is to hoping that this feature will be in Minetest one day.
Recovering from the abomination I am. Clocking time for Garry's Mod I am too.
 

Next

Return to Feature Discussion



Who is online

Users browsing this forum: No registered users and 2 guests