3
\$\begingroup\$

I'm trying to retrieve the names of the texture files (or their locations) on a mesh.

I realize that the texture file name information is not preserved when the model is loaded.

I've been doing tons of searching and some experimenting but I've been met with no luck. I've gathered that I need to extended the content pipeline and store the file location in somewhere like ModelMeshPart.Tag.

My problem is, even when I'm trying to make my own custom processor, I still can't figure out where the texture file name is. :(

Any thoughts? Thanks!

UPDATE:

Okay, so I found something kind of promising. NodeContent.Identity.SourceFilename, only that returns the location of my .X model. When I go down the node tree he is always null. Then there's the ContentItem.Name property. It seems to have names of my mesh, but not my actual texture file names. :(

\$\endgroup\$
3
  • \$\begingroup\$ Mind if I ask why you're doing this? (I.e. why you need the name of the texture file.) \$\endgroup\$
    – Olhovsky
    Commented Jun 2, 2011 at 17:23
  • \$\begingroup\$ I'm converting an old .NET 1.1 app that used MDX to XNA. In that app, the texture represents a part on a vehicle. When the user clicks the texture (or the part on the vehicle), it uses the texture's name to figure out what part it is. And based off the texture name, it loads more information on the part. I'm not sure of a better way to do this, so I was just trying to do the same in XNA. Better ideas are especially welcomed. :) \$\endgroup\$ Commented Jun 2, 2011 at 17:31
  • 2
    \$\begingroup\$ @townsean: A better way of doing it would be changing it to not use the texture name as part of the program state. You should never use strings for passing around state. \$\endgroup\$ Commented Jul 3, 2011 at 6:32

1 Answer 1

3
\$\begingroup\$

Alright, I think I figured it out. Maybe not the best solution (so I would still appreciate other answers ;) )

public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
    ModelContent model = base.Process(input, context);
    foreach(ModelMeshContent modelMesh in model.Meshes)
    {
        foreach(ModelMeshPartContent meshPart in modelMesh.MeshParts)
        {
            MaterialContent materialContent = meshPart.Material;

            foreach(var texture in materialContent.Textures)
            {
                if(texture.Value != null)
                    meshPart.Tag = texture.Value.Filename;
            }
        }
    }
    return model;
}

The Tag property of my ModelMeshPart the file points to the .xnb file in the output directory.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1 for preventing Community ♦ from bumping this question again. \$\endgroup\$ Commented Dec 29, 2011 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .