Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i need to import model from two separate files.

I have

  • dog.mesh
  • pet.material

dog.mesh contains vertices (converted to GeometryContent) and string "pet.material" (reference to .material file)

My MeshImporter that handles .mesh files returns NodeContent (one of children should be MaterialEffectContent)

Problem is, that in ContentImporter there is nothing to handle loading of additional assets.

Should pet.material be build by content pipeline in some way? To EffectMaterialContent for example. (Now i build it into MaterialDescription by MaterialImporter - contains string reference to .fx file)

The question is, can you even do things like this in xna? Split something that xna expects to be in one file (MeshContent) into two?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There are a few ways to bring in external files. In ContentImporter.Import you get a ContentImporterContext (MSDN) as a parameter. In ContentProcessor.Process you get a ContentProcessorContext (MSDN).

Both of these context objects have an AddDependency method. This signals to the content pipeline that your content importer/processor is bringing in another file. From that point you simply load yout pet.material file like you would any file (eg: using System.IO.File).

All this does is signal to the content pipeline that another file is being used in the build, and that subsequent changes to that file should (like the main file) cause the content that depend on that file to be rebuilt.

The remaining methods are only available in the content processor:

If pet.material is something that the content pipeline knows how to import and process, you can use BuildAndLoadAsset to load it through the content pipeline. The loaded content can then be embedded in your output content object.

If, however, your pet.material might be shared between multiple meshes at runtime, then you might want to use BuildAsset. The data structures you need to create are somewhat complicated (you need to use ExternalReference at build time), but then the pipeline will create a separate output XNB file for pet.material, and ContentManager will automatically load it for you when required, and share that instance around any meshes that need it.

share|improve this answer
    
In ContentImporter.Import you get ContentImporterContext (with no methods to build external references). I know i could solve this on ContentProcessor level, problem is that i really should not do this, because there is no reason for me not to use default model processor. –  Kikaimaru Aug 16 '11 at 5:34
    
@Kikaimaru Whoops. Fixed that error, and another one. In addition, you can still use the built-in ModelProcessor for the bulk of the work by extending your own content processor from it. See the documentation here. –  Andrew Russell Aug 16 '11 at 6:51
    
Yeah i understand that it can be "solved" that way, but as i understand difference between importers and processors, that is not a right way. I'm writing importer from ogres .mesh, and that should be it - importer, no additional processor should be nescessary to process things that are specific to that model format. And by the way, how should i add content that i want to load in importer as additional file? As item in content projection with build action content (and not compile)? –  Kikaimaru Aug 16 '11 at 7:14
    
When you use any of the three methods listed in my answer, you don't need to (and generally shouldn't) include the file in your content project. If you want to load something in the importer you have to do it the AddDependency anyway. But for your purposes the distinction between importer and processor does not really matter - simply do whatever works. –  Andrew Russell Aug 16 '11 at 12:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.