glTF 2.0

参考

类别

导入 - 导出

菜单

File ‣ 导入/导出 ‣ glTF 2.0 (.glb, .gltf)

用法

glTF™(GL传输格式)用于在 Web 和本机应用程序中传输和加载 3D 模型。glTF 减小了 3D 模型的大小以及解压缩和渲染这些模型所需的运行时处理。此格式通常用于网页上,并支持各种 3D 引擎,如 Unity3D、虚幻引擎 4 和Godot。

此导入器/导出器支持以下glTF2.0功能:

  • 网格

  • 材质(Principled BSDF)和无阴影(无光照)

  • 纹理

  • 相机

  • 精确光源(点光,聚光和定向光源)

  • Extensions (listed below)

  • Extras (custom properties)

  • 动画(关键帧,形态键及蒙皮)

网格

glTF的内部结构模拟了图形芯片在实时渲染时常用的内存缓冲区,这样资产可以交付到桌面、网页或移动终端,并以最少的处理进行迅速显示。 因此,当导出为glTF时,四边形和多边形会自动转换为三角形。 与Blender相比,不连续的UV和平面阴影边缘可能导致glTF中的顶点数适度增多,因为这样的顶点会被分开以导出。 同样,曲线和其他非网格数据不会保留,必须在导出之前转换为网格。

材质

glTF中的核心材质系统通过一下信息通道支持金属/粗糙 PBR 工作流:

  • 基础色

  • 金属度

  • 粗糙度

  • 烘焙的环境光遮蔽

  • Normal Map (tangent space, +Y up)

  • 发射

Some additional material properties or types of materials can be expressed using glTF extensions. The complete is can be found in _Extensions_ part of this documentation.

../../_images/addons_import-export_scene-gltf2_material-channels.jpg

glTF 2.0核心格式中可用的各种图像贴图的示例。这个 水瓶示例模型 一起显示了各种贴图切片样本。

导入的材质

glTF材质系统与Blender自己的材质不同。 导入glTF文件时,此插件将构造一组Blender节点,以尽可能接近地复制每个glTF材质。

The importer supports Metal/Rough PBR (core glTF), Spec/Gloss PBR (KHR_materials_pbrSpecularGlossiness) and some extension materials. The complete is can be found in _Extensions_ part of this documentation.

Tip

检查材质导入过程的结果,是查看可以导出到glTF的材质节点和设置类型的示例的好方法。

导出的材质

这个导出器支持金属/粗糙PBR(核心glTF)和无阴影 (KHR_materials_unlit) 材质。它将基于它在Blender材质中识别的节点构建glTF材质。 材质导出过程处理如下描述的设置。

Note

当材质中使用图像纹理时,glTF要求格式图像为PNG或JPEG。 此插件将自动转换其他格式的图像,从而增加导出时间。

基础色

通过在Principled BSDF节点上查找基础色输入来确定glTF基色。 如果输入未连接,则输入的默认颜色(未连接套接字旁边的颜色字段)将用作glTF材质的基色。

../../_images/addons_import-export_scene-gltf2_material-base-color-solid-green.png

可以在节点上直接指定纯色基础色。

如果发现图像纹理节点连接到基色输入,则该图像将用作glTF基础色。

../../_images/addons_import-export_scene-gltf2_material-base-color-image-hookup.png

图像用作glTF基础色。

金属度与粗糙度

这些值从Principled BSDF节点读取。 如果这两个输入都未连接,节点将显示滑块以控制它们各自的值在0.0和1.0之间,并且这些值将被复制到glTF中。

当使用图像时,glTF期望金属度的值在蓝色 (B) 通道中编码,粗糙度在同一图像的绿色 (G) 通道中编码。 如果图像以不遵循此约定的方式连接到Blender节点,则插件可能会尝试在导出期间使图像适应正确的形式(导出时间增加)。

在Blender节点树中,建议使用单独的RGB节点将通道与图像纹理节点分开,并将绿色 (G) 通道连接到粗糙度,将蓝色 (B) 通道连接到金属度。 glTF导出器会将此排列识别为与glTF标准匹配,这将允许它在导出期间把图像纹理简单地复制到glTF文件中。

此图像纹理节点应将其 颜色空间 设置为非颜色。

../../_images/addons_import-export_scene-gltf2_material-metal-rough.png

金属度/粗糙度图像以与glTF标准一致的方式连接,允许在导出的glTF文件中逐字使用。

烘焙的环境光遮蔽

glTF is capable of storing a baked ambient occlusion map. Currently there is no arrangement of nodes that causes Blender to use such a map in exactly the same way as intended in glTF. However, if the exporter finds a custom node group by the name of glTF Material Output, and finds an input named Occlusion on that node group, it will look for an Image Texture attached there to use as the occlusion map in glTF. The effect need not be shown in Blender, as Blender has other ways of showing ambient occlusion, but this method will allow the exporter to write an occlusion image to the glTF. This can be useful to real-time glTF viewers, particularly on platforms where there may not be spare power for computing such things at render time.

../../_images/addons_import-export_scene-gltf2_material-occlusion-only.png

预先烘焙的环境光遮蔽贴图,连接到一个不渲染但将导出到glTF的节点。

Tip

创建自定义节点组的最简单方法是导入包含遮挡贴图的现有glTF模型,例如 水瓶 或其他现有的模型。也可以使用手动创建的自定义节点组。

glTF将遮蔽存储在红色 (R) 通道中,允许它选择与粗糙度和金属度通道共享相同的图像。

../../_images/addons_import-export_scene-gltf2_material-orm-hookup.png

这种节点组合模仿了glTF将遮蔽,粗糙度和金属值打包成单个图像的方式。

Tip

The Cycles render engine has a Bake panel that can be used to bake ambient occlusion maps. The resulting image can be saved and connected directly to the glTF Material Output node.

法线贴图

要在glTF中使用法线贴图,请将图像纹理节点的颜色输出连接到法线贴图节点的颜色输入,然后将法线贴图法线输出连接到Principled BSDF节点的法向输入。 此图像纹理节点应将其 色彩空间 属性设置为Non-Color。

法线贴图节点必须保留其切线空间的默认属性,因为这是glTF当前支持的唯一类型的法线贴图。 可以在此节点上调整法线贴图的强度。 导出器不直接导出这些节点,但会使用它们来定位正确的图像,并将强度设置复制到glTF中。

../../_images/addons_import-export_scene-gltf2_material-normal.png

导出器会找到连接的法线贴图并将其复制到glTF文件。

Tip

Cycles渲染引擎有一个烘焙面板,可用于从几乎任何其他法向量节点排列中烘焙切线空间法线贴图。 将Bake类型切换为Normal。 将此烘烤面板用于glTF时,请保留默认空间设置(空间:切向,R: +X, G: +Y, B: +Z)。 如上所述,可以保存生成的烘焙图像,并将其用于使用上述法线贴图节点的新材质,从而使其可以正确导出。

参见: Cycles渲染烘焙

发射

An Image Texture node can be connected to the Emission input on the Principled BSDF node to include an emissive map with the glTF material. Alternatively, the Image Texture node can be connected to an Emission shader node, and optionally combined with properties from a Principled BSDF node by way of an Add Shader node.

If the emissive map is alone in the material, it is best to set the Base Color default to black, and the Roughness default to 1.0. This minimizes the influence of the other channels if they are not needed.

../../_images/addons_import-export_scene-gltf2_material-emissive.png

This arrangement is supported for backwards compatibility. It is simpler to use the Principled BSDF node directly.

If any component of emissiveFactor is > 1.0, KHR_materials_emissive_strength extension will be used.

清漆

When the Clearcoat input on the Principled BSDF node has a nonzero default value or Image Texture node connected, the KHR_materials_clearcoat glTF extension will be included in the export. This extension will also include a value or Image Texture from the Clearcoat Roughness input if available.

If Image Textures are used, glTF requires that the clearcoat values be written to the red (R) channel, and Clearcoat Roughness to the green (G) channel. If monochrome images are connected, the exporter will remap them to these color channels.

The Clearcoat Normal input accepts the same kinds of inputs as the base Normal input, specifically a tangent-space normal map with +Y up, and a user-defined strength. This input can reuse the same normal map that the base material is using, or can be assigned its own normal map, or can be left disconnected for a smooth coating.

All Image Texture nodes used for clearcoat shading should have their Color Space set to Non-Color.

../../_images/addons_import-export_scene-gltf2_material-clearcoat.png

An example of a complex clearcoat application that will export correctly to glTF. A much simpler, smooth coating can be applied from just the Principled BSDF node alone.

光泽

When the Velvet BSDF node is used in addition to Principled BSDF node, the KHR_materials_sheen glTF extension will be included in the export. The Sheen Color will be exported from Color socket of Vevlet node. Sheen Roughness will be exported from Sigma socket.

If a Sheen Rougness Texture is used, glTF requires the values be written to the alpha (A) channel.

../../_images/addons_import-export_scene-gltf2_material-sheen.png

Tip

Velvet BSDF node is only available on Cycles render engine. You may have to temporary switch to Cycles to add this node, and get back to Eevee.

Note

Because the node tree is adding 2 Shaders (Principled and Sheen), the resulting shader is not fully energy conservative. You may find some difference between Blender render, and glTF render. Sheen models are not fully compatible between Blender and glTF. This trick about adding Velvet Shader is the most accurate approximation (better that using Sheen Principled sockets).

镜面反射

When the Specular or Specular Tint input of Principled BSDF node have a non default value or Image Texture node connected, the KHR_materials_specular glTF extension will be included in the export.

Note

Specular models are not fully compatible between Blender and glTF. By default, Blender data are converted to glTF at export, with a possible loss of information. Some conversion are also performed at import, will a possible loss of information too.

At import, a custom node group is created, to store original Specular data, not converted.

../../_images/addons_import-export_scene-gltf2_material_specular-custom-node.png

At export, by default, Specular data are converted from Principled BSDF node.

You can export original Specular data, enabling the option at export. If enabled, Principled Specular data are ignored, only data from custom node are used.

../../_images/addons_import-export_scene-gltf2_material_specular-export-option.png

Tip

If you enable Shader Editor Add-ons in preferences, you will be able to add this custom node group from Menu: Add > Output > glTF Material Output

传递采样

When the Transmission input on the Principled BSDF node has a nonzero default value or Image Texture node connected, the KHR_materials_transmission glTF extension will be included in the export. When a texture is used, glTF stores the values in the red (R) channel. The Color Space should be set to Non-Color.

Transmission is different from alpha blending, because transmission allows full-strength specular reflections. In glTF, alpha blending is intended to represent physical materials that are partially missing from the specified geometry, such as medical gauze wrap. Transmission is intended to represent physical materials that are solid but allow non-specularly-reflected light to transmit through the material, like glass.

glTF does not offer a separate "Transmission Roughness", but the material's base roughness can be used to blur the transmission, like frosted glass.

Tip

Typically the alpha blend mode of a transmissive material should remain "Opaque", the default setting, unless the material only partially covers the specified geometry.

Note

In real-time engines where transmission is supported, various technical limitations in the engine may determine which parts of the scene are visible through the transmissive surface. In particular, transmissive materials may not be visible behind other transmissive materials. These limitations affect physically-based transmission, but not alpha-blended non-transmissive materials.

Warning

Transmission is complex for real-time rendering engines to implement, and support for the KHR_materials_transmission glTF extension is not yet widespread.

IOR

At import, there are two different situation:

  • if KHR_materials_ior is not set, IOR value of Principled BSDF node is set to 1.5, that is the glTF default value of IOR.

  • If set, the KHR_materials_ior is used to set the IOR value of Principled BSDF.

At export, IOR is included in the export only if one of these extensions are also used:

  • KHR_materials_transmission

  • KHR_materials_volume

  • KHR_materials_specular

IOR of 1.5 are not included in the export, because this is the default glTF IOR value.

体积光渲染

Volume can be exported using a Volume Absorption node, linked to Volume socket of Output node. Data will be exported using the KHR_materials_volume extension.

  • For volume to be exported, some transmission must be set on Principled BSDF node.

  • Color of Volume Absorption node is used as glTF attenuation color. No texture is allowed for this property.

  • Density of Volume Absorption node is used as inverse of glTF attenuation distance.

  • Thickess can be plugged into the Thickess socket of custom group node glTF Material Output.

  • If a texture is used for thickness, it must be plugged on (G) Green channel of the image.

../../_images/addons_import-export_scene-gltf2_material-volume.png

glTF Variants

Note

For a full Variants experience, you have to enable UI in Add-on preferences

There are two location to manage glTF Variants in Blender

  • In 3D View, on glTF Variants tab

  • For advanced settings, in Mesh Material Properties (see Advanced glTF Variant checks)

The main concept to understand for using Variants, is that each material slot will be used as equivalent of a glTF primitive.

glTF Variants switching

After importing a glTF file including KHR_materials_variants extension, all variants can be displayed.

../../_images/addons_import-export_scene-gltf2_material_variants-switch.png

You can switch Variant, by selecting the variant you want to display, then clicking on Display Variant.

You can switch to default materials (when no Variant are used), by clicking on Reset to default.

glTF Variants creation

You can add a new Variant by clicking the + at right of the Variant list. Then you can change the name by double-clicking.

After changing Materials in Material Slots, you can assign current materials to the active Variant using Assign to Variant.

You can also set default materials using Assign as Original. These materials will be exported as default material in glTF. This are materials that will be displayed by any viewer that don't manage KHR_materials_variants extension.

Advanced glTF Variant checks

If you want to check primitive by primitive, what are Variants used, you can go to Mesh Material Properties.

../../_images/addons_import-export_scene-gltf2_material_variants-detail.png

The glTF Material Variants tab refers to the active material Slot and Material used by this slot. You can see every Variants that are using this material for the given Slot/Primitive.

You can also assign material to Variants from this tab, but recommandation is to perform it from 3D View tab.

双面/背面剔除

对于只能看到正面的材质,在Eevee材质的 设置 面板中打开 背面剔除 。 使用其他引擎(Cycles,Workbench)时,您可以暂时切换到Eevee以配置此设置,然后切换回来。

Leave this box unchecked for double-sided materials.

../../_images/addons_import-export_scene-gltf2_material-backface-culling.png

此设置反转控制glTF Double Sided 标志。

混合模式

基础色输入可以选择性地提供alpha值。 glTF如何处理这些值取决于所选的混合模式。

选择Eevee渲染引擎后,每种材质在材质设置面板上都有混合模式。 使用此设置可定义如何在glTF中处理基础色通道的Alpha值。 glTF支持三种设置:

不透明

忽略Alpha值(默认值)。

Alpha混合

较低的alpha值会导致与背景对象混合。

Alpha钳制

低于“剪切阈值”设置的Alpha值将导致部分材质根本不会被渲染。 其他一切都呈现为不透明。

../../_images/addons_import-export_scene-gltf2_material-alpha-blend.png

选择Eevee引擎后,材质的混合模式可配置。

Note

请注意,实时引擎渲染透明度(或 Alpha混合 模式)很复杂,并且在导出后可能会以意想不到的方式运行。 尽量使用 Alpha剪切(Alpha Clip) 模式,或者将 不透明 多边形放在仅有 Alpha混合 多边形的单层后面。

UV 映射

通过将UV贴图节点和映射节点连接到任何图像纹理节点,可以控制UV贴图选择和转换。

映射节点中的设置使用名为 KHR_texture_transform 的glTF扩展名导出。 顶部有一个映射类型选择器。推荐使用 导出。也支持 纹理矢量 。 支持的偏移量是:

  • 位置 - X和Y

  • 旋转 - 仅限Z

  • 缩放 - X和Y

对于 纹理 类型,缩放 X和Y必须相等(均匀缩放)。

../../_images/addons_import-export_scene-gltf2_material-mapping.png

刻意选择的UV贴图。

Tip

这些节点是可选的。 并非所有glTF阅读器都支持多个UV贴图或纹理变换。

因子

任何图像纹理节点可以选择性地乘以恒定颜色或标量。 它们将被写为glTF文件中的因子,这些数字是与指定图像纹理相乘的数字。并不常见。

例子

如果需要,单一材质可以同时使用所有上述节点。 此图显示了一次性应用上述多个选项时的典型节点结构:

../../_images/addons_import-export_scene-gltf2_material-principled.png

具有发光纹理的Principled BSDF材质。

Exporting a Shadeless (Unlit) Material

To export an unlit material, mix in a camera ray, and avoid using the Principled BSDF node.

../../_images/addons_import-export_scene-gltf2_material-unlit.png

One of several similar node arrangements that will export KHR_materials_unlit and render shadeless in Blender.

扩展(名)

使用glTF扩展可以使用附加信息扩展核心glTF 2.0格式。 这允许文件格式保存在最初发布时非通用的细节。 并非所有的glTF阅读器都支持所有扩展,但有些是相当常见的。

某些Blender功能只能通过这些扩展名导出到glTF。 此附加组件直接支持以 glTF 2.0 扩展

导入

  • KHR_materials_pbrSpecularGlossiness

  • KHR_materials_clearcoat

  • KHR_materials_transmission

  • KHR_materials_unlit

  • KHR_materials_emissive_strength

  • KHR_materials_volume

  • KHR_materials_sheen

  • KHR_materials_specular

  • KHR_materials_ior

  • KHR_materials_variants

  • KHR_lights_punctual

  • KHR_texture_transform

  • KHR_mesh_quantization

导出

  • KHR_draco_mesh_compression

  • KHR_lights_punctual

  • KHR_materials_clearcoat

  • KHR_materials_transmission

  • KHR_materials_unlit

  • KHR_materials_emissive_strength

  • KHR_materials_volume

  • KHR_materials_sheen

  • KHR_materials_specular

  • KHR_materials_ior

  • KHR_materials_variants

  • KHR_texture_transform

Third-party glTF Extensions

It is possible for Python developers to add Blender support for additional glTF extensions by writing their own third-party add-on, without modifying this glTF add-on. For more information, see the example on GitHub and if needed, register an extension prefix.

自定义属性

Custom properties are always imported, and will be exported from most objects if the Include ‣ Custom Properties option is selected before export. These are stored in the extras field on the corresponding object in the glTF file.

Unlike glTF extensions, custom properties (extras) have no defined namespace, and may be used for any user-specific or application-specific purposes.

动画

A glTF animation changes the transforms of objects or pose bones, or the values of shape keys. One animation can affect multiple objects, and there can be multiple animations in a glTF file.

导入

Imported models are set up so that the first animation in the file is playing automatically. Scrub the Timeline to see it play.

When the file contains multiple animations, the rest will be organized using the Nonlinear Animation editor. Each animation becomes an action stashed to an NLA track. The track name is the name of the glTF animation. To make the animation within that track visible, click Solo (star icon) next to the track you want to play.

../../_images/addons_import-export_scene-gltf2_animation-solo-track.png

This is the fox sample model showing its "Run" animation.

If an animation affects multiple objects, it will be broken up into multiple parts. The part of the animation that affects one object becomes an action stashed on that object. Use the track names to tell which actions are part of the same animation. To play the whole animation, you need to enable Solo (star icon) for all its tracks.

Note

There is currently no way to see the non-animated pose of a model that had animations.

导出

You can export animations by creating actions. How glTF animations are made from actions is controlled by the Animation ‣ Group by NLA Track export option.

Group by NLA Track on (default)

An action will be exported if it is the active action on an object, or it is stashed to an NLA track (e.g. with the Stash or Push Down buttons in the Action Editor). Actions which are not associated with an object in one of these ways are not exported. If you have multiple actions you want to export, make sure they are stashed!

A glTF animation can have a name, which is the action name by default. You can override it by renaming its NLA track from NLATrack/[Action Stash] to the name you want to use. For example, the Fig. fox model will export with three animations, "Survey", "Walk", and "Run". If you rename two tracks on two different objects to the same name, they will become part of the same glTF animation and will play together.

The importer organizes actions so they will be exported correctly with this mode.

Group by NLA Track off

In this mode, the NLA organization is not used, and only one animation is exported using the active actions on all objects.

Note

For both modes, remember only certain types of animation are supported:

  • Object transform (location, rotation, scale)

  • Pose bones

  • Shape key values

Animation of other properties, like physics, lights, or materials, will be ignored.

Note

In order to sample shape key animations controlled by drivers using bone transformations, they must be on a mesh object that is a direct child of the bones' armature.

文件格式变体

glTF规范确定了数据存储的不同方式。 导入器可处理所有存储方式。 导出器将要求用户选择以下几种形式之一:

glTF二进制(.glb)

这将生成一个“.glb”文件,其中所有网格数据,图像纹理和相关信息都打包到一个二进制文件中。

Tip

使用单个文件可以轻松地将模型共享或复制到其他系统和服务。

glTF分离式(.gltf + .bin + textures)

这将生成一个基于JSON文本的描述整体结构的 .gltf 文件,一个包含网格和矢量数据的``.bin``文件,以及引用在 .gltf 文件中的多个可选的 .png.jpg 文件。

Tip

拥有各种单独的文件使用户在导出完成后,返回与编辑任何JSON或图像变得更加容易。

Note

请注意,共享此格式是需要将所有这些单独的文件作为一个群组共享。

glTF嵌入式 (.gltf)

这将生成一个基于JSON文本的``.gltf``文件,其中所有网格数据和图像数据都在文件中进行编码(使用Base64)。 如果资产必须通过纯文本连接共享,则此格式很有用。

Warning

这是可用格式中效率最低的,仅在需要时使用。

属性

导入

打包图像

打包所有图像到blend文件中。

着色

如何在导入期间计算法线。

猜测原始绑定姿态

Determines the pose for bones (and consequently, skinned meshes) in Edit Mode. When on, attempts to guess the pose that was used to compute the inverse bind matrices.

Bone Direction

Changes the heuristic the importer uses to decide where to place bone tips. Note that the Fortune setting may cause inaccuracies in models that use non-uniform scaling. Otherwise this is purely aesthetic.

导出

格式

参见: 文件格式变体

纹理

用于放置纹理文件的文件夹。相对于 .gltf 文件。

版权符号

该模型的法律权利和条件。

记住导出设置

将导出设置存储在blend文件中,以便下次打开文件时调用它们。

包括

选定的物体

仅导出选定的物体。

可见物体

Export visible objects only.

Renderable Objects

Export renderable objects only.

活动的集合

Export objects from active collection only.

Active Scene

Export active scene only.

自定义属性

将自定义属性导出为glTF附加信息。

相机

导出相机。

精确灯光

导出定向光、点光和聚光。 使用 KHR_lights_punctual glTF扩展名。

变换

Y 向上

使用glTF约定导出,+Y向上。

几何数据(Geometry)

应用修改器

Export objects using the evaluated mesh, meaning the resulting mesh after all Modifiers have been calculated.

UV

导出网格UV(纹理坐标)。

法向

导出网格顶点法向。

切向

导出网格顶点切向。

顶点颜色

Export Color Attributes with meshes.

松散边

Export loose edges as lines, using the material from the first material slot.

松散点

Export loose points as glTF points, using the material from the first material slot.

材质

Export full materials, only placeholders (all primitives but without materials), or does not export materials. (In that last case, primitive are merged, lossing material slot information).

图像

Output format for images. PNG is lossless and generally preferred, but JPEG might be preferable for web applications due to the smaller file size. If None is chosen, materials are exported without textures.

压缩

使用Google Draco压缩网格。

压缩级别

压缩越高,编码和解码速度越慢。

量化位置

值越高,压缩率越高。

法向

值越高,压缩率越高。

纹理坐标

值越高,压缩率越高。

颜色

值越高,压缩率越高。

泛型

值越高,压缩率越高。

动画

使用当前帧

Export the scene in the current animation frame. For rigs, when off, rest pose is used as default pose for joints in glTF file. When on, the current frame is used as default pose for joints in glTF file.

动画

导出活动的动作和NLA轨道为glTF动画。

限制回放范围

将动画剪辑到所选的播放范围。

采样率

评估动画值的频率(以帧为单位)。

总是采样动画

应用采样对所有动画。

按NLA轨道分组

是否导出 NLA 片段动画。

Optimize Animation Size

Reduce exported file-size by removing duplicate keyframes.

仅导出变形骨骼

Export deformation bones only.

形态键

导出形态键(形变目标)。

形态键法向

使用形状键(形变目标)导出顶点法线。

形态键切向

使用形状键(变形目标)导出顶点切线。

蒙皮

导出蒙皮(骨架)数据。

包含全部骨骼影响

Allow more than 4 joint vertex influences. Models may appear incorrectly in many viewers.

贡献

该导入器/导出器是通过 glTF-Blender-IO repository 开发的,您可以在其中提交错误报告,提交功能请求或提供代码。

关于glTF 2.0格式的讨论和开发,参见 glTF GitHub repository ,欢迎提供反馈。