About Store Forum Documentation Contact



Post Reply 
Setting material user_type with custom ENUM
Author Message
cat555 Offline
Member

Post: #1
Setting material user_type with custom ENUM
Hi, i'm trying to set material user_type with custom ENUM. I do this on application start, so i can use it on update methods.

Here's example:
Code:
void InitMaterials()
{
   // MATERIALS USER_TYPE
   MaterialPtr mtrGrass = UID(4132778014, 827999197, 656095536, 393076638);
   mtrGrass->user_type = GROUND_GRASS;
   mtrGrass->user_type_name = "ground_grass";
   mtrGrass->validate();
   // /MATERIALS USER_TYPE
}

Then, in update methods, i try do get user_type for those materials, but can't get my values, just default ones!

What's the correct way to persist changes in material user_type, so it can be accessed anywhere in the application?

Thanks!
04-22-2015 10:29 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #2
RE: Setting material user_type with custom ENUM
you have to set manually the user_type, user type is int.

so GROUND_GRASS is null because not valid.

if you set user_type = 1; it will stay 1 as usertype

i believe its how this work ! wink (i made it works this way in my project)
(This post was last modified: 04-23-2015 01:14 AM by RedcrowProd.)
04-23-2015 12:56 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #3
RE: Setting material user_type with custom ENUM
(04-23-2015 12:56 AM)RedcrowProd Wrote:  you have to set manually the user_type, user type is int.

so GROUND_GRASS is null because not valid.

if you set user_type = 1; it will stay 1 as usertype

i believe its how this work ! wink (i made it works this way in my project)

Hi @RedCrowProd, thanks for your reply!

In fact GROUND_GRASS is also int, and it has a value assign to it. To overcome this problem, i'm now calling InitMaterials() in the update method... but i would like to call it just once at the start of the application...

How are you doing it in your project? You are also using MaterialPtr to do it right? Also, you are setting this only once at the start of application and it's working fine? Can you share some piece of code so i can see if any difference comaring with what i am doing here?

Thanks!
04-23-2015 01:49 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #4
RE: Setting material user_type with custom ENUM
hey so yeah i've tried it again and didnt found any special issue with it

my code:

Code:
bool InitGame()
{

   matsinittest.materialtest();
}

class Matsinit
{
   MaterialPtr materialtesting;
void materialtest()
{  
   materialtesting =UID(3515322458, 1078918197, 468396461, 4069332970);
   materialtesting->user_type = 5;
   materialtesting->user_type_name = "test";
   materialtesting->validate();
   Gui.msgBox(S, S+ materialtesting->user_type);
   Gui.msgBox(S, S+ materialtesting->user_type_name);
}
}
Matsinit matsinittest;

anywhere in the update:
      if(Kb.bp(KB_O))
   {
      Gui.msgBox(S, S+ matsinittest.materialtesting->user_type);
      Gui.msgBox(S, S+ matsinittest.materialtesting->user_type_name);
   }

mhhh let me know if i do something that is wrong in C++
but this way is working =p and easy to switch to a list + REPA to avoid any crazy sized script wink
(This post was last modified: 04-24-2015 01:10 AM by RedcrowProd.)
04-24-2015 12:49 AM
Find all posts by this user Quote this message in a reply
cat555 Offline
Member

Post: #5
RE: Setting material user_type with custom ENUM
Hi, thanks! I see what you're doing, but that way i manage to get it working also...

But that's not what i need... i'm getting the material in the terrain/ground objects (just under the actor), and by having a reference to that material, i then need to access user_type values, that are set in application start. Something like this:

Code:
((GroundObj*)hit.obj).mesh->parts[triangle_id].material()->user_type;
(This post was last modified: 04-24-2015 10:05 AM by cat555.)
04-24-2015 10:05 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #6
RE: Setting material user_type with custom ENUM
then, isnt hmmaterial what youre looking for ?
04-24-2015 06:20 PM
Find all posts by this user Quote this message in a reply
Post Reply