adding material to model in code

Dec 19, 2011 at 12:54 PM

I am a little confused on how to link a material to a model in code.  In the 4th video you add the ship.fbx, then you add the different maps, and then the .mat file just appears in the folder?  How do you create a new material and assign it to a model?  where did the .mat file in your video come from and how does the program know that the .mat is associated with the playership?  When I load the model in the editor it doesnt seem to have any problem with texturing it, but then i load it in code and it is blank.

thanks in advance,


Dec 19, 2011 at 2:56 PM

This is nothing IGF specific rather SunBurn related.

The .mat file doesn't just appear in the folder (I may have taken a quick shortcut in the video sorry). Actually, the ship.fbx file has already been compiled and processed by the SunBurn Model processor which generates this .mat file based on the Material I assigned to the ship in my modeler application.

When built, SunBurn content processor associates the .mat file with the .fbx file in the generated .xnb file.

In this case, I wanted to show you how you could edit a .mat file with the textures you want.

If it isn't clear, let me know and I'll try to clarify it ;)

Dec 19, 2011 at 2:59 PM
Edited Dec 19, 2011 at 3:01 PM

That's what I thought but wasn't sure, thanks for the reply.  I guess my question was is there any way to apply a material to a model through code instead of through modeler application?  Or is this more trouble than its worth?

One other question, is a .mat file always generated by SunBurn Model Processor when you upload a model? I can't seem to find one for the model i have complied/processed

thanks again

Dec 19, 2011 at 5:03 PM

You can apply a material by code simply setting the SceneObject.RenderableMeshes RenderableMesh instances' Effect property to the LightingEffect or DeferredObjectEffect of your choice.
Either by code or using ContentManager is up to you. If you need to change individual model materials during the game lifetime, I'd suggest you to create them by code. Otherwise, have it using the Content workflow as it saves a lot of time and debug sessions.

As for the .mat file, it always generate one when you set the Content Processor to the SunBurn Model processors and activate the "Apply Lighting" property which is "on" by default.
if you don't find it, make sure to look at the directory directly as the file isn't added to your content project in Visual Studio but it is still present in the directory using Explorer.