Jump to content

Instance Materials


SpiderPig
 Share

Recommended Posts

I'm creating instances of a lot of vegetation.  When the player harvests a plant I wanted the material / texture to change to show it had been harvested.

Model* plant = Model::Load("plant.mdl");
Material* harvested = Material::Load("Harvested.mat");

Entity* instances[100];

//Load
for(int id=0;id<100;id++) {
	Instances[id] = plant->Instance();                  
}

//InGame
int closestIndex = 25;
if(window->keyHit(Key::E) == true){
	instance[closestIndex]->SetMaterial(harvested);
}

This is essentially what I'm doing except setting the material of one changes all the instances.

I can't use a copy because it can't be used in real-time.  As the player moves I create the foliage around them as required.

Link to comment
Share on other sites

I think what I'll end up doing is releasing the instance and creating a new instance of a harvested plant.

int closestIndex = 25;
if(window->keyHit(Key::E) == true){
	instance[closestIndex]->Release();
	instance[closestIndex] = harvestedPlant->Instance();
}

This means I could add different geometry in as well, like broken branches or something.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...