How to convert a 3D object to ".glTF" (Blender 2.80 and later)¶
If you have an ".obj" file or another 3D format object and want to convert it to ".glTF", there is a way to do it with Blender.
About Blender's latest version
Blender 2.90 is the latest version of Blender, which is fantastic. However, if you prefer staying on Blender 2.79, go to this tutorial. You can also follow this tutorial if you are under Blender 2.80 or later.
1.1. If you don't have Blender, go and download the latest version (2.90, or later) on https://www.blender.org/download.
1.2. Open Blender. If you have a cube in the scene, select it by clicking on it and delete it by pressing "Delete" on your keyboard.
1.3. Then import your object by going to "File / Import" and choose ".obj" (or the format of your object). You should soon see your object in the viewport.
1.4. Select your object by clicking on it (it should be outlined in yellow).
1.5. Open the Shader Editor in the window below the viewport. To open the Shader Editor, you must first drag up the lower window.
1.6. Then click on the lowest-left button and choose "Shader Editor".
1.7. Normally, you should see your materials and textures already settled. In that case you can go straight to Section 3 "Export your object to ".glTF"". If that's not the case, then go to Section 2 "Set materials" below.
2.1. If you don't have any materials on your object, start by checking that "Use Nodes" is toggled.
2.2. To see your materials in real time, don't forget to activate the "Look Dev" mode that you can find on the top right-hand side of the viewport.
We noticed some troubles with Blender 2.80 rendering system. That is why sometimes the new rendering engine, Eevee, doesn't render right (totally dark objects, visual artefacts...). If that happens to you, try the button next to "Look Dev"(on the right), which is "Rendered". If that doesn't solve your problem, try to switch to Cycles engine in the render options. For more information about this, feel free to check that video by Blender Guru.
2.3. If you want to reset all your textures for some reason, or that you don't understand how Blender has interpreted your material, it might be best to make your material again from scratch. To do that, go to the "Material" panel.
2.4. In the "Material" panel, delete the current material (if there is any) by clicking on the "-".
2.5. Click on "New" to create another material.
2.6. In the Shader Editor, you should now see a "Principled BSDF" node connected to the "Material Output". This node is basically the most complete shader in Blender, which enables you to create all types of shaders from glass to metal to plastic to silk. But for now, it doesn't have an input for Ambient Occlusion. That's why we are going to need another special shader.
2.7. For now, let’s load all our textures and attach them to the "Principled BSDF shader. There are two ways to do that. The first way is simply to drag and drop your texture from your computer in the Shader Editor (one at a time).
2.8. The second way is to type "Shift + A" and choose "Search". Write "Image Texture" in the search bar, and click on "Image texture" in the list it provides.
2.9. Click on "Open" and load your first texture.
2.10. Navigate to your texture folder and choose the first one you want to connect, for instance the Base Color (or Diffuse, or Albedo).
2.11. You then have to connect your diffuse texture to the "Base Color" input of the "Principled BSDF" node.
2.12. For your Normal Map, don't forget to turn on the "Non-Color" mode.
2.13. Before connecting to the "Normal" input of the "Principled BSDF" shader, though, you have to use an intermediary node. Type "Shift + A", choose "Search", and then type "Normal Map". Import the corresponding node.
2.14. Connect your "Normal Map" to the "Color" input of the "Normal Map" node. Then connect the "Normal" output of the "Normal Map" node to the "Normal" input of the "Principled BSDF" shader.
2.15. Now, might have an ORM map, which is a map which contains a specific map in each channel: Ambient Occlusion in the red channel, Roughness in the green one, and Metallic in the blue one. The « .glTF » format is built to interpret these maps like this. So first, check that your map is in "Non-Color" mode, as we did for the Normal map.
2.16. Now, we need to separate each texture, in order to plug each channel into the right input. Type "Shift + A", choose "Search", and then type "Separate RGB". Import the corresponding node.
If you don't have an ORM
If your maps are separated, you can either combine them using this method, or connect them separately to the right inputs of the "Principled BSDF" shader.
If your maps are already separated, you don’t need the "Separate RGB" node : just connect the "Roughness" map to the "Roughness" input of the "Principled BSDF" shader, and the "Metallic" map to the "Metallic" input of the "Principled BSDF" shader.
Keep in mind that you can also have objects which have the Roughness and Metallic maps together in one map, and the Ambient Occlusion separated, or another configuration. In this case, you can use the "Separate RGB" node to separate the fused maps, and connect the separated map to the right output.
2.17. Connect the "Color" output of your texture to the "Image" input of the "Separate RGB" node. Then, connect the "G" output of the "Separate RGB" node to the "Roughness" input of the "Principled BSDF" shader, and the "B" output of the "Separate RGB" node to the "Metallic" input of the "Principled BSDF" shader.
You will certainly notice that we left one output out : the "R" output, which corresponds to the Ambient Occlusion information (or the Ambient Occlusion map itself if you don’t have an ORM). As said earlier, we have to connect this channel to another node, as the "Principled BSDF" shader does not have any input for that map. Here, we will follow the method showed right here. We need to create a custom node, named "GLTF Settings", which will be encoded inside the ".glb" / ".glTF" object, and be recognized as holding an Ambient Occlusion.
2.18. Type "Shift + A", and add any kind of node you want. This will only be a throwaway node, we will dispose of it later. For instance, choose "Search"; and type "Invert". Import the corresponding node.
2.19. Select the "Invert" node, and then type "Shift + A", go into "Group", and choose "Make Group". You can also hit "Ctrl + G". You are now inside the node group, as you can see with the green color.
2.20. Select the "Invert" node and hit "X", to discard it.
2.21. Hit "N", to toggle the options on the right part of the window, and go into "Node".
2.22. In there, you can see the inputs and outputs of your node group. But we don’t need an output. In the "Outputs" column, select the "Color" line (or whatever is in there), and hit the "X" icon besides "Name", under the columns. In the same manner, delete the "Color" input in the "Inputs" column. You should just have one input left.
2.23. Select the last input showing in the "Inputs" column (in this case the "Fac" input), and change its name for "Occlusion". Be extra careful of the spelling here : it needs to be spelled correctly so that the texture can be found and interpreted.
2.24. Exit the node group by hitting "Tab". You are now back in the Shader Editor, and your node group is almost ready to be connected to your Ambient Occlusion. In the first field of the node, change the name from "NodeGroup" to "GLTF Settings".
2.25. Connect your Ambient Occlusion map, or the "R" output of the "Separate RGB" node, to the "Occlusion" input of your newly created "GLTF Settings" node. Your Ambient Occlusion is now ready to be exported correctly ! Keep in mind, though, that this shader is invisible in Blender : it’s just not connected to the material. Blender is not going to use it in the preview window, but the exporter will find it.
At last, if you have an Emission texture, you can also connect it to your object, through two ways : either by connecting it to the "Principled BSDF" shader, or by connecting it to an "Emission" shader, which will then be added to your "Principled BSDF" shader. Here, we will show you the simplest way, which is the first solution. If you want to know more about the second, feel free to check this documentation.
2.26. Import your "Emission" texture, and connect it to the "Emission" input of the "Principled BSDF" shader.
Export your object to .glTF¶
3.1. You're all set! Now you just have to export your model in ".glTF". To do that, just click on your model in the 3D view, and go to "Files / Export" and choose ".glTF 2.0".
3.2. The export window will appear. On the right-hand side, you have some options for your export. In "Format", you can choose to pack all your files in a ".glb format" (glTF Binary), or export only the ".glTF object", or at last export the ".glTF object and all its textures". That's up to you! Don't forget to check the "Selected Objects" box just to be sure you don't end up with undesired items.
3.3. Once your choices are made, you just have to choose the folder in which you want to export your object, and click on "Export glTF 2.0" !
You have successuflly converted your object in ".glTF"!