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:

  • Clearcoat, Clearcoat Roughness, Clearcoat Normal (uses KHR_materials_clearcoat)

  • Transmission (uses KHR_materials_transmission)

  • "Shadeless" materials (uses KHR_materials_unlit)

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

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

导入的材质

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

导入器支持金属/粗糙PBR(核心glTF),镜面/光泽度PBR (KHR_materials_pbrSpecularGlossiness) 和无阴影 (KHR_materials_unlit) 材质。

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能够存储烘焙的环境光遮蔽图。 目前没有任何节点安排导致Blender以与glTF中预期完全相同的方式使用这样的映射。 但是,如果导出器找到名为“glTF Settings`”的自定义节点组,并在该节点组上找到名为“Occlusion”的输入,它将查找附加在其上的图像纹理以用作遮蔽在glTF中映射。 该效果不需要在Blender中显示,因为Blender有其他方式显示环境光遮蔽,但此方法将允许导出器将遮挡图像写入glTF。 这对于实时glTF查看器非常有用,特别是在渲染时可能没有多余能力进行计算这些东西的平台上。

../../_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

Cycles渲染引擎有一个烘焙面板,可用于烘焙环境遮挡贴图。 生成的图像可以保存并直接连接到“glTF Setting”节点。

法线贴图

要在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.

Clearcoat

When the Clearcoat input on the Principled BSDF node has a non-zero 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.

Transmission

When the Transmission input on the Principled BSDF node has a non-zero 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.

双面/背面剔除

对于只能看到正面的材质,在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_lights_punctual

  • KHR_materials_unlit

  • KHR_texture_transform

  • KHR_materials_clearcoat

  • KHR_mesh_quantization

导出

  • KHR_draco_mesh_compression

  • KHR_lights_punctual

  • KHR_materials_clearcoat

  • KHR_materials_transmission

  • KHR_materials_unlit

  • 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 name-space, and may be used for any user-specific or application-specific purposes.

动画

当动画在导出时设置为针对特定对象时,glTF单个文件可包含多个动画。 为了确保包含动画,可以 (a) 使其成为对象的主动Action, (b) 创建单条NLA轨道,或 (c) 存储动作。

支持特性

仅支持某些类型的动画:

  • 关键帧(平移,旋转,缩放)

  • 形态键

  • 骨架/蒙皮

其他属性(如灯光或材质)的动画将被忽略。

NLA 片段动画 由一起播放的多个物体上的多个动作组成。要创建名称为"My Animation"的 NLA 片段动画,请将应播放每个物体的动作推到该物体的一个名为"My Animation" 的NLA 轨道上。

../../_images/addons_import-export_scene-gltf2_nla-strip-animation-example.png

将导出为名为"名称为 "My Animation"的动画,播放Cone上的ConeAction,以及Cube上 CubeAction。

NLA Strip animations will be exported if the Animation ‣ Group by NLA Track option is selected (on by default). All glTF animations are imported as NLA Strip animations.

如果禁用选项,将忽略 Blender NLA片段操作。将只考虑每个对象的活动操作,并合并到单个 glTF 动画中。

Note

In order to sample shape key animations controlled by drivers using bone transformations, they must be on a mesh object which 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文件中。

着色

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

Guess Original Bind Pose

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文件中,以便下次打开文件时调用它们。

包括

选定的物体

仅导出选定的物体。

自定义属性

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

相机

导出相机。

精确灯光

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

变换

Y 向上

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

几何数据(Geometry)

应用修改器

应用修改器(除骨架)到网格物体。

UV

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

法向

导出网格顶点法向。

切向

导出网格顶点切向。

顶点颜色

打出网格顶点颜色。

材质

导出材质。

图像

图像的输出格式. PNG是无损的,通常是首选,但由于文件较小,JPEG可能更适合Web应用。

压缩

使用Google Draco压缩网格。

压缩级别

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

量化位置

值越高,压缩率越高。

法向

值越高,压缩率越高。

纹理坐标

值越高,压缩率越高。

泛型

值越高,压缩率越高。

动画

使用当前帧

导出当前动画帧中的场景。

动画

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

限制回放范围

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

采样率

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

总是采样动画

应用采样对所有动画。

Group by NLA Track

是否导出 NLA 片段动画。

仅导出变形骨骼

仅导出变形骨骼(和层次结构所需的骨骼)

形态键

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

形态键法向

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

形态键切向

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

蒙皮

导出蒙皮(骨架)数据。

包含全部骨骼影响

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

贡献

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

Discussion and development of the glTF 2.0 format itself takes place on the Khronos Group glTF GitHub repository, and feedback there is welcome.