glTF学习笔记(3)——glTF Tutorials/Example: A Minimal glTF File

https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_003_MinimalGltfFile.md

Table of Contents

示例文件及注释:

The scene and nodes structure

The meshes

The buffer, bufferView, and accessor concepts

Buffers

Buffer views

Accessors

The asset description

效果图:

效果(视频):


示例文件及注释:

{
  "scenes" : [
    {
      "nodes" : [ 0 ]
    }
  ],
  
  "nodes" : [
    {
      "mesh" : 0
    }
  ],
  
  "meshes" : [
    {
      "primitives" : [ {
        "attributes" : {
          "POSITION" : 1
        },
        "indices" : 0
      } ]
    }
  ],

  "buffers" : [
    {
      "uri" : "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=",
      "byteLength" : 44
    }
  ],
  "bufferViews" : [
    {
      "buffer" : 0,
      "byteOffset" : 0,
      "byteLength" : 6,
      "target" : 34963
    },
    {
      "buffer" : 0,
      "byteOffset" : 8,
      "byteLength" : 36,
      "target" : 34962
    }
  ],
  "accessors" : [
    {
      "bufferView" : 0,
      "byteOffset" : 0,
      "componentType" : 5123,
      "count" : 3,
      "type" : "SCALAR",
      "max" : [ 2 ],
      "min" : [ 0 ]
    },
    {
      "bufferView" : 1,
      "byteOffset" : 0,
      "componentType" : 5126,
      "count" : 3,
      "type" : "VEC3",
      "max" : [ 1.0, 1.0, 0.0 ],
      "min" : [ 0.0, 0.0, 0.0 ]
    }
  ],
  
  "asset" : {
    "version" : "2.0"
  }
}

The scene and nodes structure

scene是存储在glTF中的场景描述的入口。在解析glTF JSON文件时,场景结构的遍历将从此处开始。每个场景都包含了一个叫nodes的数组,这个数据的内容是node对象的索引。这些nodes是场景图层次结构(scene graph hierarchy)的根结点。

这里的例子由一个场景组成,它只引用了一个node,该node的索引是0。这个node,又指向唯一的mesh,这个mesh的索引是0。

  "scenes" : [
    {
      "nodes" : [ 0 ]
    }
  ],
  
  "nodes" : [
    {
      "mesh" : 0
    }
  ],

The meshes

一个mesh表示出现在场景中的一个实际几何对象。mesh本身通常不具有任何属性(properties),只包括一个mesh.primitive对象的数据,这些mesh.primitive是构建更大的模型的组成部分。每个mesh primitive都包含对mesh所组成的几何数据的描述。

这个例子由一个mesh组成,只有一个mesh.primitive对象。mesh.primitive有一个属性(attributes)数组,用于存储mesh的几何特性的顶点(vertices)属性。在这个例子里,只有POSITION属性,描述顶点(vertices)的位置。mesh.primitive还描述了一个索引的几何信息,由索引属性来表示。默认情况下,假定其描述了一系列的三角形,因此,三个连续的索引就是一个三角形的顶点的索引。

mesh primitive的实际的几何数据由attribute和indices说明,它们都指向accessor对象。

"meshes" : [
    {
      "primitives" : [ {
        "attributes" : {
          "POSITION" : 1
        },
        "indices" : 0
      } ]
    }
  ],

The buffer, bufferView, and accessor concepts

buffer、bufferView、accessor提供了组成mesh primitive的集合数据。更多更详细的介绍详见“ Buffers, BufferViews, and Accessors ”部分。

Buffers

buffer定义了没有原始含义的原始、非结构化数据块。它包括了一个uri,它可以指向包含该数据的外部数据,也可以是直接在JSON文件中编码的二进制数据的data URI。

在这个例子中,用了第二种方式。

  "buffers" : [
    {
      "uri" : "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=",
      "byteLength" : 44
    }
  ],

这里的数据只包括三角形的索引和顶点位置数据。为了可以在mesh primitive中使用这些数据,还需要关于这些数据的结构信息。关于结构的数据存储在bufferView和accessor兑现中。

Buffer views

bufferView描述了整个原始缓冲区数据的“一块”或者“一片”(其实也就是一部分)。在这个例子中,有两个bufferView,它们引用了同一个buffer。第一个bufferView引用了包含索引数据的buffer部分,它的byteOffset是0,byteLength是6。第二个bufferView引用buffer中包含顶点位置的数据,它的byteOffset为8,byteLength为36,延伸到整个缓冲区的末尾。

  "bufferViews" : [
    {
      "buffer" : 0,
      "byteOffset" : 0,
      "byteLength" : 6,
      "target" : 34963
    },
    {
      "buffer" : 0,
      "byteOffset" : 8,
      "byteLength" : 36,
      "target" : 34962
    }
  ],

Accessors

构造数据的第二步是完成accessor对象。它们定义了如何利用提供的关于数据类型和布局的信息来解析bufferView的数据。在这个例子中,有两个accessor对象。

第一个accessor描述了几何数据的索引。它引用索引为0的bufferView,包括buufer中关于indices的原始数据。另外,它指定元素的数量(count)和类型(type),和componentType。在这种情况下,有3个标量元素(scalar elements),其组件类型由代表无符号short类型的常量给出。

第二个accessor描述顶点位置。 它通过带有索引1的bufferView包含对缓冲区数据相关部分的引用,其计数,类型和componentType属性表示3D向量包含三个元素,每个元素都具有浮点分量。

  "accessors" : [
    {
      "bufferView" : 0,
      "byteOffset" : 0,
      "componentType" : 5123,
      "count" : 3,
      "type" : "SCALAR",
      "max" : [ 2 ],
      "min" : [ 0 ]
    },
    {
      "bufferView" : 1,
      "byteOffset" : 0,
      "componentType" : 5126,
      "count" : 3,
      "type" : "VEC3",
      "max" : [ 1.0, 1.0, 0.0 ],
      "min" : [ 0.0, 0.0, 0.0 ]
    }
  ],

像上面提到的,一个mesh.primitive可以利用索引,引用这些accessor。

  "meshes" : [
    {
      "primitives" : [ {
        "attributes" : {
          "POSITION" : 1
        },
        "indices" : 0
      } ]
    }
  ],

当要渲染mesh.primitive时,渲染器可以解析底层的bufferViews和buffers,并将buffer中需要的部分以及有关数据类型和布局的信息发送给渲染器。

The asset description

In glTF 1.0, this property is still optional, but in subsequent glTF versions, the JSON file is required to contain an asset property that contains the version number. The example here says that the asset complies to glTF version 2.0:

  "asset" : {
    "version" : "2.0"
  }

The asset property may contain additional metadata that is described in the asset specification.

效果图:

Imagee 1: A single triangle. 

效果(视频):

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值