2
$\begingroup$

I have tried "glTF Blender Exporter", "blendergltf" and "glTF 2" to try and export a Cycles model I made to .GLB format for Facebook upload, however nothing I tried worked.

Only "glTF Blender Exporter" seemed to add options in the "Export" menu, but even though I packed my textures, applied modifiers and followed the slim instructions given with it, I couldn't get it to export a model with the textures.

If anyone has made this work, I'd love to hear how they did it!

$\endgroup$
3
$\begingroup$

UPDATE: For Blender 2.80, see the Blender Manual 2.80 glTF/GLB documentation.

These instructions are for Blender 2.79x with the Khronos Blender Exporter:

https://github.com/KhronosGroup/glTF-Blender-Exporter

In addition to installing this plugin, you will also need a copy of the glTF2_Principled.blend file that ships with the plugin, for a custom node group it contains. Future versions of this plugin (glTF-Blender-IO for Blender 2.8) will not depend on these custom nodes, and use the Principled BSDF node instead, but it will target the same channels in the glTF output file.

First, select Cycles as the rendering engine. Then click File -> Append -> glTF2_Principled.blend -> NodeTree -> glTF Metallic Roughness. This imports a custom node group into your blend project, that the exporter will look for when exporting materials.

Create a new Cycles material, and turn on "Use Nodes". Then, select the newly appended node group, the "glTF Metallic Roughness" node, like this:

Blender glTF Metallic Roughness screenshot

The inputs on this node correspond almost exactly to the various channels available inside the glTF 2.0 format, and the glTF exporter will specifically look to see what's attached to this node when creating the glTF file.

Note that some are named "Factor" or "Strength". For example there is a "BaseColor" and also a "BaseColorFactor". In Blender, these are just node inputs and you can attach anything. But in glTF, the "BaseColor" is specifically a texturemap, that can be present or absent, and "BaseColorFactor" is a solid color (including alpha) that can either multiply against the BaseColor Texture, or be used in lieu of a BaseColor texture for cases where the base color is solid.

So keep that in mind when hooking up node inputs: Connect only texture images to the primary inputs, and set solid colors on the "factor" inputs.

glTF can also pack Occlusion (Red), Roughness (Green), and Metallic (Blue) values into a single image. Thus, a single image node can be connected to both the "MetallicRoughness" and "Occlusion" inputs, to allow that image to drive all three channels.

A tangent-space normal map can also be connected, and optionally an emissive map. If you connect an emissive map, be sure to change the EmissiveFactor to white, as that gets multiplied by the map. The default EmissiveFactor is black so that models don't emit light when the emissive map is missing.

A typical PBR wireup may look like this:

PBR texturemap wireup screenshot

With these textures wired up, you're ready to export a full PBR model to glTF format. If your target is Facebook, they currently have a size limit of 3 MB including textures, so keep it small! Using JPG images may help get under that limit. glTF supports both PNG and JPG image formats, but not arbitrary formats.

Use File -> Export -> GLTF. There are two choices, one will save a text-based glTF file with binary mesh and separate texture image files, the other will save a combined ".glb" with mesh and textures all rolled into a single binary file. Facebook wants the latter, the .glb file. You can save a tiny bit more space by un-checking "Export Tangents" from the export options. Facebook uses ThreeJS as its renderer, and the tangent vectors are easily recomputed on the client, so no need to clutter the export with them.

I hope this helps!

$\endgroup$
  • $\begingroup$ Way too complicated for such an old format. Facebook should use the more common WebGL format. $\endgroup$ – Brain Nov 22 '18 at 14:05
  • 2
    $\begingroup$ Granted it's more complicated than what's ideal. But consider that this format (glTF 2.0, dated from June 2017) is one of very few that will take a full set of PBR (Physically Based Rendering) texturemaps, and deliver them to a wide array of viewers, platforms, and engines. Few other formats from any age can share whole PBR materials across a wide ecosystem in this fashion. $\endgroup$ – emackey Nov 22 '18 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.