Jump to content
  • Advertisement
Sign in to follow this  

XNA Model reseting BasicEffect matrix

This topic is 3025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I grab a model multiple times from the content manager it seems to return the exact same model including the same BasicEffect class. This means that if I take two copys from the content manager and alter BasicEffect settings both will be affected. I've managed to work around this by reseting any BasicEffect settings I want to use every frame from my own copies but in this rigid body animation tutorial you need to grab the original transform setting from the model and save the new ones to the model to render it correctly. So how am I suppose to create a new instance with a fresh world matrix.

Share this post


Link to post
Share on other sites
Advertisement
Um, that's how its meant to work. The ContentManager stops you from unnecessarily duplicating assets, and every frame you set the world matrix for each instance of your model, which is infinitely more efficient.

Share this post


Link to post
Share on other sites
Quote:
Original post by BLiTZWiNG
Um, that's how its meant to work. The ContentManager stops you from unnecessarily duplicating assets, and every frame you set the world matrix for each instance of your model, which is infinitely more efficient.


That makes sense for immutable assets like the mesh data but for the effects its a pain to manage.

Either way the problem is that for models that have multiple meshes or transformed meshes I need to set the world matrix to its intended position relative to its original transform and if I do that I overwrite its original transform.

Share this post


Link to post
Share on other sites
Here is the tank from the tutorial with its original transformations




And here it is with its world matrix forced and original ignored

Share this post


Link to post
Share on other sites
You can create a clone of any Effect if you want to maintain different state for multiple instances of the same Model.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
You can create a clone of any Effect if you want to maintain different state for multiple instances of the same Model.


I considered making a wrapper around the content manager that would save the original world matrices of all the meshes in the model but it seems like either their should be a easier way or its a bit of a design flaw.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
Quote:
Original post by MJP
You can create a clone of any Effect if you want to maintain different state for multiple instances of the same Model.


I considered making a wrapper around the content manager that would save the original world matrices of all the meshes in the model but it seems like either their should be a easier way or its a bit of a design flaw.


You have to be careful when you invoke the phrase "design flaw". What qualifications do you have to make this judgment? Given the rest of the industry does it the way we're telling you, is there a chance you could be wrong?

Share this post


Link to post
Share on other sites
Quote:
Original post by BLiTZWiNG
Quote:
Original post by Kaze
Quote:
Original post by MJP
You can create a clone of any Effect if you want to maintain different state for multiple instances of the same Model.


I considered making a wrapper around the content manager that would save the original world matrices of all the meshes in the model but it seems like either their should be a easier way or its a bit of a design flaw.


You have to be careful when you invoke the phrase "design flaw". What qualifications do you have to make this judgment? Given the rest of the industry does it the way we're telling you, is there a chance you could be wrong?


If theirs a trick I don't know about or a flaw in my logic tell me but it seems to me if I can't render a model without overwriting its configuration data thats a flaw. Why couldn't it have had some separation between the data in the model file and render option I want give it later.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
Quote:
Original post by MJP
You can create a clone of any Effect if you want to maintain different state for multiple instances of the same Model.


I considered making a wrapper around the content manager that would save the original world matrices of all the meshes in the model but it seems like either their should be a easier way or its a bit of a design flaw.


Effect's aren't really meant to hold per-instance state. The more common usage pattern is to have clones that hold per-model state (usually material data and other artist tweakables). Otherwise you'd need a clone for every single instance of every Model, and each Effect clone would contain the full state even for stuff that remains static. It makes more sense to just store your instance data in your own structures (since you probably have to do that anyway), that way you don't have memory wasted from having many copies of effect state everywhere.

It's really not that hard to do...

class ModelInstance
{
Model model;
Matrix worldMatrix;
// Any other per-instance parameters go here

void Draw()
{
foreach(ModelMesh mesh in model.ModelMeshes)
{
foreach(BasicEffect effect in mesh.Effects)
effect.World = worldMatrix;

// Do drawing stuff here
}
}
}


Then you can extend that to arbitrary effects and instance data, if you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
It's really not that hard to do...

class ModelInstance
{
Model model;
Matrix worldMatrix;
// Any other per-instance parameters go here

void Draw()
{
foreach(ModelMesh mesh in model.ModelMeshes)
{
foreach(BasicEffect effect in mesh.Effects)
effect.World = worldMatrix;

// Do drawing stuff here
}
}
}


Then you can extend that to arbitrary effects and instance data, if you want.


This is whats I was doing, the problem is that effect.World for each ModelMesh doesn't start off at Matrix.Identity;. It starts at whatever transform I assigned to it in the model editor.

EDIT:

class ModelInstance
{
Model model;
Matrix worldMatrix;
// Any other per-instance parameters go here

void Draw()
{
foreach(ModelMesh mesh in model.ModelMeshes)
{
foreach(BasicEffect effect in mesh.Effects)
effect.World = GetOriginalWorldMatrixFor(mesh) * worldMatrix;

// Do drawing stuff here
}
}
}




EDIT2:

thats wrong, the transforms are in the Model.Bones but its still the same problem, I cant modify them without overwriting the models original data.


[Edited by - Kaze on February 7, 2010 9:47:58 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!