get/setMaterial for single mesh buffer

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

get/setMaterial for single mesh buffer

Post by Acki »

Hi,
I worked a bit with mesh buffers and I realised that there are set methodes for the mesh buffer materials (setMaterialTexture, setMaterialFlag, setMaterialType) but there are no get methodes...

then I sound out that this could be maybe because with the set methodes you set the flag, type and texture for all mesh buffers the same...

I don't know why there are no get methodes and why you can't set type, flag and texture for a single buffer ???
so I implemented this for me... ;)

you don't need to recompile the engine, you just need to edit the ISceneNode.h file !!! :)

so open ISceneNode.h, find the public part and add this lines:

Code: Select all

class ISceneNode : public io::IAttributeExchangingObject
{
public:

// new functions start
  void setMaterialFlag(u32 idMBuffer, video::E_MATERIAL_FLAG flag, bool newvalue){
    if(idMBuffer < getMaterialCount()) getMaterial(idMBuffer).setFlag(flag, newvalue);
  }
  bool getMaterialFlag(u32 idMBuffer, video::E_MATERIAL_FLAG flag){
    if(idMBuffer < getMaterialCount()) return getMaterial(idMBuffer).getFlag(flag);
    return false;
  }

  void setMaterialTexture(u32 idMBuffer, u32 textureLayer, video::ITexture* texture){
    if(textureLayer >= video::MATERIAL_MAX_TEXTURES) return;
    if(idMBuffer < getMaterialCount()) getMaterial(idMBuffer).setTexture(textureLayer, texture);
  }
  video::ITexture* getMaterialTexture(u32 idMBuffer, u32 textureLayer){
    if(textureLayer >= video::MATERIAL_MAX_TEXTURES) return 0;
    if(idMBuffer < getMaterialCount()) return getMaterial(idMBuffer).getTexture(textureLayer);
    return 0;
  }

  void setMaterialType(u32 idMBuffer, video::E_MATERIAL_TYPE newType){
    if(idMBuffer < getMaterialCount()) getMaterial(idMBuffer).MaterialType = newType;
  }
  video::E_MATERIAL_TYPE getMaterialType(u32 idMBuffer){
    if(idMBuffer < getMaterialCount()) return getMaterial(idMBuffer).MaterialType;
    return video::EMT_SOLID;
  }
// new functions end
and now you can get and set the type, flags and textures of each mesh buffer separately !!! :)

this will also be a new extension, but because this is realy simple I thought to post this here in the code snippets forum, too ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post by Anteater »

Sweet this will be useful! Thanks!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It's because you have access to the single meshbuffer already, and filling interfaces with redundant methods can be counter productive.
BTW: Make your methods virtual, otherwise overwriting them in derived classes won't work properly.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

Now You can easy change public values this option without functions as Your functions eg.

Code: Select all

getMaterial(ID_NUMBER).TextureLayer[ID_TEX].Texture = ...
getMaterial(ID_NUMBER).MaterialType = ...
but Your functions are good and looks better and more useful than orginal functions for first mesh buffer :)
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply