so, I've got a *.FBX model displaying, how do I set it to use my material in code
by Ezra · in Torque X 3D · 10/18/2009 (6:49 am) · 4 replies
This seems like a really simple thing, but I can't seem to find information on it anywhere. I've loaded an FBX model through code, it displays on-screen using the model color from when I exported it.
I have a simple shader which I'd like to apply to the model in code also, how do I do this? I've gotten as far as creating a new material class which is based off GenericMaterial and it has the EffectFilename set to my *.fx file.
The next step isn't clear, is there a command where I can do something like this?
myModel.material = mymaterial
..basically something the same as TX2D when applying a material to a T2DStaticSprite
I have a simple shader which I'd like to apply to the model in code also, how do I do this? I've gotten as far as creating a new material class which is based off GenericMaterial and it has the EffectFilename set to my *.fx file.
The next step isn't clear, is there a command where I can do something like this?
myModel.material = mymaterial
..basically something the same as TX2D when applying a material to a T2DStaticSprite
About the author
#2
The Materials are bound to the file path, so you can create a Material in XML that will apply to a Model Code. This means if you add:
<YourMaterial type="GarageGames.Torque.Materials.LightingMaterial" name="YourModelsMaterial">
<NameMapping>dataYourModelYourModelsDTS</NameMapping>
<TextureFilename>dataYourModelDiffuseTexture</TextureFilename>
<NormalMapFilename>dataYourModelNormalMap</NormalMapFilename>
<LightingMode>PerPixel</LightingMode>
</YourMaterial >
to the XML, when you load your object via code it will lookup the correct material to apply.
Edit: The Naming is not important, but the NameMapping parameter is how you link it to your object.
11/08/2009 (10:55 pm)
I'm not sure of a way to apply a Material in code, but I do have a sort of solution.The Materials are bound to the file path, so you can create a Material in XML that will apply to a Model Code. This means if you add:
<YourMaterial type="GarageGames.Torque.Materials.LightingMaterial" name="YourModelsMaterial">
<NameMapping>dataYourModelYourModelsDTS</NameMapping>
<TextureFilename>dataYourModelDiffuseTexture</TextureFilename>
<NormalMapFilename>dataYourModelNormalMap</NormalMapFilename>
<LightingMode>PerPixel</LightingMode>
</YourMaterial >
to the XML, when you load your object via code it will lookup the correct material to apply.
Edit: The Naming is not important, but the NameMapping parameter is how you link it to your object.
#3
<NameMapping>dataYourModelYourModelsDTS</NameMapping>
Have you tried this with T3DXNARenderComponent (i.e. an .fbx model)?
11/09/2009 (5:18 pm)
I was playing with this idea...in your XML:<NameMapping>dataYourModelYourModelsDTS</NameMapping>
Have you tried this with T3DXNARenderComponent (i.e. an .fbx model)?
#4
Looking at the Material Manager now, you could also, if you really want to avoid the XML call MaterialManager.add(name, material). Where the name is the File to map it to (I wish you could just assign it to a model by name).
Essentially from what I'm seeing once it's in the library, correctly mapped (watch for the correct slashes) creating that model automatically assigns the Material.
11/09/2009 (7:50 pm)
Ah, I've not, but when I went looking into the code, it went to the same MaterialManager as the DTS files. (Line 236 of T3DXNARenderComponent).Looking at the Material Manager now, you could also, if you really want to avoid the XML call MaterialManager.add(name, material). Where the name is the File to map it to (I wish you could just assign it to a model by name).
Essentially from what I'm seeing once it's in the library, correctly mapped (watch for the correct slashes) creating that model automatically assigns the Material.
Torque Owner Eric Ewen