DamagedHelmet glTF 文件解析

145 阅读2分钟

DamagedHelmet 是一个经常用于 3D Hello world 测试的 gltf 模型,如下图所示:

image.png

glTF 数据结构

DamagedHelmet.json:

image.png

整个 gltf JSON 顶层被分为了 asset, scene, scenes, nodes, materials, meshes, textures, images, accessors, bufferViews, samplers, buffers 等字段,是这个 3D 模型的数据实体分类。

asset

image.png

gltf 资产元信息。

  • 指:由 blender 导出,版本为 2.0 的 gltf 文件。

scene

image.png

一个 glTF 文件中可能存储了多个场景。 scene 属性指示加载资产时应显示的默认场景。

  • "scene": 0:默认场景定义在 scenes[0] 处。
  • "nodes": [0]:场景树从 nodes[0] 开始。

nodes

image.png

  • "mesh": 0: 此 node 附加了一个 mesh,位于 meshes[0] 处。
  • "rotation": [...]: 此 node 的旋转量,用四元数 xyzw 表示。

meshes

image.png

  • "primitives": 基元数组,每个基元定义要渲染的几何体。
  • "attributes.POSITION": 0: 顶点位置数据的访问器索引,指向 accessors[0],必须是 VEC3 类型。
  • "attributes.NORMAL": 1: 顶点法线数据的访问器索引,指向 accessors[1],必须是 VEC3 类型。
  • "attributes.TEXCOORD_0": 2: UV 数据的访问器索引,指向 accessors[2],必须是 VEC2 类型。
  • "indices": 3: 顶点索引数据的访问器索引(不是顶点索引!!!),指向 accessors[3],必须是 SCALAR 类型。
  • "material": 0: 材质编号,指向 materials[0]

materials

image.png

  • emissiveFactor: 自发光通道强度
  • emissiveTexture.index:0: 自发光贴图索引,指向 textures[0]
  • normalTexture.index:1: 法线贴图索引,指向 textures[1]
  • occlusionTexture.index:2: 遮挡贴图索引,指向 textures[2]
  • pbrMetallicRoughness: PBR 金属流参数
    • baseColorTexture: 基础色贴图
    • metallicRoughnessTexture: 金属度贴图

textures

image.png

  • sampler: 纹理采样模式。
  • source: 指向的图片的索引,例如 source:0 -> images[0]

accessors

image.png

将类型化视图转换为包含原始二进制数据的缓冲区视图。

  • bufferView: bufferViews 索引
  • componentType: 访问器元件数据类型(这是一个枚举值)
  • type: 元素数据类型
  • count: 元素个数,例如 VEC3 的个数

componentType 枚举值

  • 5120 BYTE
  • 5121 UNSIGNED_BYTE
  • 5122 SHORT
  • 5123 UNSIGNED_SHORT
  • 5125 UNSIGNED_INT
  • 5126 FLOAT

type 枚举值

  • "SCALAR"
  • "VEC2"
  • "VEC3"
  • "VEC4"
  • "MAT2"
  • "MAT3"
  • "MAT4"

Texture sampler

用于过滤和包装模式的纹理采样器属性。

registry.khronos.org/glTF/specs/…

  • magFilter: 放大过滤器
    • 9728 NEAREST
    • 9729 LINEAR
  • minFilter: 缩小过滤器
    • 9728 NEAREST
    • 9729 LINEAR
    • 9984 NEAREST_MIPMAP_NEAREST
    • 9985 LINEAR_MIPMAP_NEAREST
    • 9986 NEAREST_MIPMAP_LINEAR
    • 9987 LINEAR_MIPMAP_LINEAR
  • wrapS: S (U) wrapping mode
    • 33071 CLAMP_TO_EDGE
    • 33648 MIRRORED_REPEAT
    • 10497 REPEAT
  • wrapT: T (V) wrapping mode
    • 33071 CLAMP_TO_EDGE
    • 33648 MIRRORED_REPEAT
    • 10497 REPEAT