About Store Forum Documentation Contact



Post Reply 
Need help with mesh variations
Author Message
yvanvds Offline
Member

Post: #1
Need help with mesh variations
Hey Greg, it's been a while grin

I am trying to revive my old project now that I finally have more time. Hasn't been easy with six years of engine changes to go through. But I'm getting there.

What I am stuck with is mesh variations. The idea is that every player can pick his/her own color which will be applied to the player mesh. So making the materials in advance is not an option, and the old MaterialLock does not work anymore.

I understand that mesh variations are the way to go, but I cannot figure them out. I made an object to add variations to the mesh like this:

Code:
class charMaterials
{
private:
   Memx<Material> list;
   MeshPtr mesh;
  
public:
  
  
   int addVariation(C Color & color)
   {
      if(mesh == null) mesh = ObjectPtr(UID(3325270568, 1322544433, 1615607710, 3014310042))->mesh();  
      
      Material & last = list.New();
      last.reset();
      last.reflect(0.05);
      last.colorS(color);
      last.technique = MTECH_OPAQUE;
      last.validate();
      mesh->variations(list.elms()+1);
      REPA(mesh->parts)
      {
         mesh->parts[i].variations(list.elms()+1);
         mesh->parts[i].variation(list.elms(), &last);
      }
      
      // this is the index for this variation
      return list.elms();
   }
  
}

charMaterials CharMaterials;

And this will be called when the player or peer is created:

Code:
void setColor(Vec4 &color)
{
   color.w = 1.0;
   T.color = color;
   materialVariation = CharMaterials.addVariation(color);      
}

Then, during drawprepare I set my variation and draw the mesh:

Code:
Virtual UInt drawPrepare()
{
   UInt modes = super::drawPrepare();
   SetVariation(materialVariation);
   mesh->draw();
   SetVariation();
   return modes;
}

... but nothing happens. The player is drawn, but always with the original material. I did quit a bit of debugging. My addVariation code is executed, the index is returned and stored in materialVariation. But no avail. Am I doing this wrong?

Regards,
yvan
10-19-2022 04:53 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Need help with mesh variations
Oh hi Yvan!
It sure has been a while, hope you've been well. grin

If this was another engine, I would have done this color-per-player thing in a shader instead, as there is no difference in mesh whatsoever, only material.

I'm not sure how feasible it is to have a shader handle this in EE, but maybe that's the way to go?
10-20-2022 06:32 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #3
RE: Need help with mesh variations
Hi Tottel! Nice to see you're still active as well.

I skimmed over some posts in the forum, and it looks like I'll have to dive into the engine to add shaders. Nothing I cannot do, but I was trying to avoid that. Updates will be a lot more work if I have to compile them myself. Let's see if something else comes up before I take that route.

Thanks for the suggestion though.
10-20-2022 09:10 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Need help with mesh variations
Hi Yvan, nice to see you again.
Your codes look fine at first look, so it's probably some silly mistake. I'll try to look again.

Edit:
You're calling:
UInt modes = super::drawPrepare();
Not sure what class you're basing on, but if you call super drawPrepare then it might already draw the mesh with its default variation, try disable this call.
10-21-2022 03:25 AM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #5
RE: Need help with mesh variations
Indeed. That was it. The player class is a child of the character class, which inherits from Game::Chr. By looking at the engine source I found out that I could just set

Game::Chr.mesh_variation

instead and let the super class do the drawing. No idea why I did it manually 6 years ago, but there it is.

I have a few other questions but I'll make some other posts, instead of convoluting the topic of this thread.
10-21-2022 07:01 PM
Find all posts by this user Quote this message in a reply
Post Reply