Reputation: 397
I'm trying to use Blender to make a simple playing card with a texture on either side for the face and back and load it in to Monogame. The model itself is fine and shows on the emulator when run but I can't seem to get the textures included though.
The textures on the card seem to render ok in Blender. The materials are set to 'shadeless' so they shouldn't be affected by light levels correct?
I've tried using the different version settings and various different path modes from 'copy' to 'strip path' when exporting the file.
The content manager has the output directory set to the main content folder so there shouldn't be a referencing problem with the textures I hope.
All the textures themselves are in the same folder.
The content is all loaded manually in to Visual Studio.
Here's the code I'm using to draw the card showing the different light settings I've played around with.
private void DrawCard(Model m, Vector3 v, CardFacing c, PlayerFacing p)
{
foreach (var mesh in m.Meshes)
{
foreach (var effect1 in mesh.Effects)
{
var effect = (BasicEffect)effect1;
effect.TextureEnabled = true;
effect.EnableDefaultLighting();
//effect.PreferPerPixelLighting = true;
//effect.AmbientLightColor = Color.White.ToVector3();
effect.DiffuseColor = Color.White.ToVector3();
//effect.EmissiveColor = Color.White.ToVector3() * 2f;
//effect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(0, 0, 1));
effect.Alpha = 1;
effect.VertexColorEnabled = false;
Matrix mCardFacing = new Matrix();
switch(c)
{
case CardFacing.Down:
mCardFacing = Matrix.CreateRotationY((float)(Math.PI / 180) * 180) * Matrix.CreateRotationX((float)(Math.PI / 180) * 90) * Matrix.CreateTranslation(new Vector3(0, 0, 0));
break;
case CardFacing.Up:
mCardFacing = Matrix.CreateRotationZ((float)(Math.PI / 180) * 180) * Matrix.CreateRotationX((float)(Math.PI / 180) * 90) * Matrix.CreateTranslation(new Vector3(0, 0, 0));
break;
case CardFacing.Hand:
mCardFacing = Matrix.CreateRotationX((float)(Math.PI / 180) * -20);
break;
}
Matrix mPlayerFacing = new Matrix();
switch (p)
{
case PlayerFacing.North:
mPlayerFacing = Matrix.CreateRotationZ((float)(Math.PI / 180) * 0);
break;
case PlayerFacing.East:
mPlayerFacing = Matrix.CreateRotationZ((float)(Math.PI / 180) * 90);
break;
case PlayerFacing.South:
mPlayerFacing = Matrix.CreateRotationZ((float)(Math.PI / 180) * 180);
break;
case PlayerFacing.West:
mPlayerFacing = Matrix.CreateRotationZ((float)(Math.PI / 180) * 270);
break;
}
effect.World = mCardFacing * Matrix.CreateTranslation(v) * mPlayerFacing;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
Any ideas? Thanks.
Upvotes: 0
Views: 1047
Reputation: 1317
Probably you have forgotten to include embedded resources into .FBX. Please, change on your export settings Path Mode to Copy and enable the button right next to it. Refer to this tutorial: https://www.youtube.com/watch?v=kEP34CbPWUo
EDIT:
That didn't work for me, as Monogame content build tool was always failing to build content with error:
*/Content/Wall2.fbx: error: The source file '*/Content/*0' does not exist!
Then I just exported .FBX without embedded textures but added texture picture manually to Content.mgcb and switched TextureFormat to 'NoChange'
And that has worked out just fine!
P.S. I would suggest moving this question to https://gamedev.stackexchange.com/
Upvotes: 0
Reputation: 789
A 3d model usually doesn't contain the texture itself. An FBX file stores where each vertex is, how they are connected and which part of the texture is at any single point.
It does not store the texture itself. Therefore, you need to load the texture separately the way you load any other texture (you need a Texture2D, even though this is a 3d model).
Then, you can assign your texture to the effect:
effect.Texture = cardTexture;
I believe that this should render the effect correctly.
This means that you can also easily swap out the texture of your model on the fly, without having to change the model itself. If you model is just a 2d quad, if might also be simpler to just generate it in code, but your current setup isn't wrong either.
Upvotes: 1