SorcererXIII

So each set of polys in a Model with a common material becomes a ModelMeshPart once you load it into the game. What I can't figure out is how you determine which material got associated with which ModelMeshPart. There don't seem to be any public members of ModelMeshPart that tell you the name of that part, or any way to somehow implant your own "blind" data (to use Maya's terminology) and then read it back.

Here is why I want to do this: Say I've got a spaceship model, like in the Spacewar demo. I want the cockpit to have a separate material with completely different properties than the rest of the ship (textures, specular settings, etc.) The SpaceWar demo gets around this with its 2 reflection maps by hard-coding the index of the ModelMeshPart that uses it second, different map, then assigning the different map once the draw loop gets to that index. Aside from the fact that it's a patently terrible way of doing things, I don't want to use that method because it would require me to figure out what index the exporter assigned to each material . . . and I may very well end up with hundreds of Model objects to have to read through by hand just to get the index.

I also thought of simply skipping ModelMeshParts altogether and having the cockpit be a completely separate ModelMesh.

What is the real way to do this

Thanks,

Tom



Re: XNA Game Studio Express How to associate material info with a ModelMeshPart?

Shawn Hargreaves - MSFT

I would do this in the content pipeline, using a custom processor. You can easily assign a custom EffectMaterialContent to the Material property of the GeometryContent for your cockpit - that way you can set up all the textures, specular settings, etc, right there in the processor and not have to do anything special to the model when you load it at runtime.




Re: XNA Game Studio Express How to associate material info with a ModelMeshPart?

SorcererXIII

Ok, that sounds promising. I assume I can also associate an hlsl shader using this method as well





Re: XNA Game Studio Express How to associate material info with a ModelMeshPart?

Shawn Hargreaves - MSFT

Absolutely. This would be a good place to start:

http://creators.xna.com/Headlines/developmentaspx/archive/2007/02/22/Custom-Model-Effect-Sample.aspx






Re: XNA Game Studio Express How to associate material info with a ModelMeshPart?

SorcererXIII

Shawn,

You are the man! This seems to be able to do what I want.

Note: To anyone trying this method, the content pipeline seems not to allow run time debugging. But you can add statements like this -

context.Logger.LogWarning(null, input.Identity, "Name of the material: {0}\n", basicMaterial.Name);

- to output variable contents to the console. Here, the "basicMaterial.Name" was the thing that I was trying to get a hold of earlier - something to allow me to switch on the material and then work whatever necessary magic to get it to behave as I needed.

Thanks,

Tom