How to export, process, load and draw textured model from Blender [Basic]

Not with the type of OBJ the Blender exports - if you open the .obj file in Notepad you’ll see it only contains data for vertices and UVs, but no texture references. So you would have to manually process, load and assign your textures.
Might be your OBJ files, that get exported by whichever program you’re using, are different. Take a look with notepad if they contain texture references.

1 Like

Blender’s default export format Collada (.dae) also works, but make sure to set the Importer to “Fbx Importer - Monogame” in the content pipeline tool. [See for details: https://github.com/MonoGame/MonoGame/issues/6179 ]
With the added benefit of:

  • The .dae file is human readable
  • The material Alpha will be correctly set
2 Likes

Did Blender not created the .MTL file for materials along with. OJB exported files ? that sad T_T But good to know Collada is supported in content pipeline out of the box.

Thanks dude ^_^y

You’re totally right, I’ve missed the .mtl since i never work with OBJ files :slight_smile:
I’ve tested it and it works great. Couple of things to note:

  • when exporting select “Strip path” option (so texture references only refer to file name and not relative/absolute path)
  • place .obj, .mtl and your textures in the same content folder, but only add the OBJ to the content pipeline.
  • as with .dae in the pipeline tool select the FBX Importer.
  • leave all rotation transform options at 0 (at least that was the case with blender exported .obj)
1 Like

Totally awesome bru! appreciated the info ^_^y

=
<[_] Downloading Blender…

It would be better if you make screenshot all blender window because panels on 2 and 3 pictures are different with panels in my blender 2.8 and blender 2.76.

Blender 2.80 will not work, since it uses nodes for material textures and does not export that information into the exported files (tested .fbx, .dae, .obj). That’s why i stated at the top that this is for blender 2.79 (and below).

Also i’m not sure how seeing the rest of the window would help you, since the rest is only the preview viewport and the timeline.

I managed to get Blender 2.80 models into Content Pipeline. Only difference was that I had to export texture painted onto the model (in Texture workspace) separately from the model itself. Did that with 3 models so far, after some fumbling with the export settings there was no problem (albeit I had transparency issues).

Sure, but there’s a lot of extra steps to get that texture displayed onto the model.
I’m guessing your workflow was something like this:

  1. Export model from Blender (to .fbx or similar)
        1a. Export the texture (since you said you made it with blender and didn’t use existing texture file)
  2. Add exported model to pipeline
  3. Add texture to pipeline
  4. Load model in game
  5. Load texture in game
  6. Assign texture to all the model’s mesh parts’ effects

Or did you manage to get the texture referenced and loaded on the model during pipeline processing?

The latter. Except for me having problem figuring out the correct path settings during export, my workflow haven’t changed between 2.79 and 2.8. So the workflow is basically

  1. Export model from Blender (to .fbx or similar)
    1a. Export the texture
  2. Add exported model to pipeline
  3. Copy texture to Content folder (without loading it in pipeline)
  4. Load model in game
  5. Set effect.TextureEnabled = true when setting mesh parts’ BasicEffect settings

It’s how I did it before, and it worked on a first try. Well, first time after Content Pipeline built it, because as I said, I didn’t know (and still don’t really know) which path settings are correct during export to .fbx X)
That and the transparency issue, but I didn’t know until reading this thread assimp has a bug so that I need to manually set effect.Alpha = 1.0f :wink:

I’ve watch video on YouTube and then I do model with texture. Also I want say that Blender 2.79 can work with nodes. And using nodes is easier for me because I need to cover sphere by texture and Blender generates a difficult and uncomfortable uv view for sphere.

Than I’d ask you two to show us how to do it with v2.80.
I’m doing it this way:

And exporting does not produce any reference to the texture, only material colors.
(Readable ones i check in notepad, binary like fbx i use debugger to see there’s no texture set to the mesh)
Example of .dae result: https://pastebin.com/A6xnkSJw

Here. I’ve made a video about it. It’s first video of this kind I’ve made, and I hope it’s at least… tolerable quality.

1 Like

Thank you for the video, I followed your instructions and it worked :slight_smile: (note about quality: the text on some of the controls is blurry so sometimes it’s hard to see)

Afterward I found out the problem with my textures - I needed to include the Principled BSDF shader node, than the model got exported correctly with texture reference.

Everyone in this thread is awesome. I spent a few hours tonight banging my head against this (after following the instructions from a 4-year-old GamesFromScratch video) and the solution was sitting in here all along.

I have rigged animated models loading from blender 2.79b thru assimp.net nuget directly into monogame. I still need to work out minor bugs and redo the model class i made im not sure how ill deal with textures either yet but its damn cool.

(i say minor bugs because most of the models i tested pretty much work even in the rough state this is in now. I have this running in a single project primarily just two classes so far the reader and the model. The only dependency is downloading the nuget assimp.net package.)

Will post up a example project soon as i get something presentable.

Has anyone been able to get this working while having assets outside of the Content directory? My setup is as follows:

Model file: C:\winterborn\solari\assets\models\temp\TestWorld.fbx
Texture file: C:\winterborn\solari\assets\models\temp\grass.png
Content file: C:\winterborn\solari\code\solari\Content\Content.mgcb

Following the steps from the above posts results in the following locations for the xnb files:

C:\winterborn\solari\code\solari\Content\bin\Windows\Content\TestWorld.xnb
C:\winterborn\solari\code\solari\Content\assets\models\temp\grass_0.xnb

The texture references in the FBX file look to just be “grass.png” as I’m stripping away the path, but the MGCB seems to be taking the “assets\models\temp” part of the path and using it when building the grass texture, which is referenced in the TestWorld FBX. Is there a way to just have MGCB keep the model and texture together throughout the build and copy process?

For reference, the snippet where I’m including the FBX file in Content.mgcb:

begin …/…/…/assets/models/temp/TestWorld.fbx
/importer:FbxImporter
/processor:ModelProcessor
/processorParam:ColorKeyColor=0,0,0,0
/processorParam:ColorKeyEnabled=True
/processorParam:DefaultEffect=BasicEffect
/processorParam:GenerateMipmaps=True
/processorParam:GenerateTangentFrames=False
/processorParam:PremultiplyTextureAlpha=True
/processorParam:PremultiplyVertexColors=True
/processorParam:ResizeTexturesToPowerOfTwo=False
/processorParam:RotationX=0
/processorParam:RotationY=0
/processorParam:RotationZ=0
/processorParam:Scale=1
/processorParam:SwapWindingOrder=False
/processorParam:TextureFormat=Compressed
/build:…/…/…/assets/models/temp/TestWorld.fbx;TestWorld.fbx

I got disillusioned trying to load models thru monogame and wrote my own loader and model classes using the nuget open assimp importer directly which can load blender 2.79 generated fbx files directly.
I purposely separately loaded the textures though then attach them to the model when i load the fbx.
I was getting that renaming on the xnb’s as well when i tried to do it thru monogame and other problems also like missing data that i needed.

seen here

Thanks @willmotil I’ll take a look at the linked post. May end up doing the same depending on level of effort. I feel like I’ve been fighting with the asset pipeline a lot on this process. I will let you know if I end up going that route!

Yep or take a look at nkasts pretty sure he was working on his for a lot longer and its probably in a real usable condition.

Mine is just a testing version it works but its filled with notes and extra testing and debuging stuff, i haven’t picked it back up yet cause i just haven’t had the time.
Plus there is a nasty little problem to solve when exporting blender models that i haven’t figured out a solution for how to detect yet. Basically blender can export two different kinds of animations that affect the way scaling works on the other in a negative manner im sure the blender files flag it in the ,blend files while assimp doesn’t know to detect it or blender doesn’t write the difference to a fbx. Got no response for the issue on the assimp forum.
So when i pick it back up ill try to deal with it and clean that up but you might be able to use it as a reference.