GLTF/GLB格式数据格式解析,自制模型转换工具
GLTF是新的一种高效传输和加载3D场景和模型的格式。可以支持很多实现三维的引擎。
GLTF是由Khronos Group设计和规定的。
GLTF其实就是一个json文件,描述的就是3D场景数据的组成和构造。
GLTF最外层的属性有:
1.scenes,nodes,cameras,animations(这些属性描述的就是模型的基本结构)
2.mesh,textures,images,samplers(这些属性描述的模型的纹理信息,用于展示场景)
3.buffer,bufferViews,accessors(这些属性描述的是场景、模型的点的信息,点的位置,法线和纹理坐标值)
4.materials,techniques,programs,shaders(这些属性是场景/模型的材质信息,用于渲染3D模型)
5.skins(结合点的表面信息??没用过,给的都是空值)
说到这里,给大家看一个gltf的文件。
{
"accessors": {
"accessor_index0": {
"bufferView": "bufferView_index",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5123,
"count": 231432,
"type": "SCALAR"
},
"accessor_index1": {
"bufferView": "bufferView_index",
"byteOffset": 462864,
"byteStride": 0,
"componentType": 5123,
"count": 1020,
"type": "SCALAR"
},
"accessor_position": {
"bufferView": "bufferView_vertex",
"byteOffset": 0,
"byteStride": 12,
"componentType": 5126,
"count": 58900,
"max": [
308.304321,
159.551575,
145.747
],
"min": [
179.30542,
-72.13728,
71.62281
],
"type": "VEC3"
},
"accessor_normal": {
"bufferView": "bufferView_vertex",
"byteOffset": 706800,
"byteStride": 12,
"componentType": 5126,
"count": 58900,
"max": [
1.0,
1.0,
1.0
],
"min": [
1.0,
1.0,
1.0
],
"type": "VEC3"
},
"accessor_uv": {
"bufferView": "bufferView_vertex",
"byteOffset": 1413600,
"byteStride": 8,
"componentType": 5126,
"count": 58900,
"max": [
0.997774363,
0.8115263
],
"min": [
0.00197040662,
0.00195908546
],
"type": "VEC2"
}
},
"animations": {},
"asset": {
"generator": "infoearth",
"premultipliedAlpha": true,
"profile": {
"api": "webgl",
"version": "1.0.2"
},
"version": 1
},
"bufferViews": {
"bufferView_index": {
"buffer": "model_buffer",
"byteLength": 464904,
"byteOffset": 0,
"target": 34963
},
"bufferView_vertex": {
"buffer": "model_buffer",
"byteLength": 1884800,
"byteOffset": 464904,
"target": 34962
}
},
"buffers": {
"model_buffer": {
"byteLength": 2349704,
"type": "arraybuffer",
"uri": "Tile_+004_+004.bin"
}
},
"images": {
"texture0": {
"name": "texture0",
"uri": "Tile_+004_+004_0.jpg"
},
"texture1": {
"name": "texture1",
"uri": "notexture.png"
}
},
"materials": {
"material0": {
"name": "material0",
"technique": "technique0",
"values": {
"diffuse": "texture_texture0"
}
},
"material1": {
"name": "material1",
"technique": "technique0",
"values": {
"diffuse": "texture_texture1"
}
}
},
"meshes": {
"mesh_model": {
"name": "mesh_model",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_normal",
"POSITION": "accessor_position",
"TEXCOORD_0": "accessor_uv"
},
"indices": "accessor_index0",
"material": "material0",
"mode": 4
},
{
"attributes": {
"NORMAL": "accessor_normal",
"POSITION": "accessor_position",
"TEXCOORD_0": "accessor_uv"
},
"indices": "accessor_index1",
"material": "material1",
"mode": 4
}
]
}
},
"nodes": {
"node": {
"children": [],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
],
"meshes": [
"mesh_model"
],
"name": "node"
}
},
"programs": {
"program_0": {
"attributes": [
"a_normal",
"a_position",
"a_texcoord0"
],
"fragmentShader": "FS",
"vertexShader": "VS"
}
},
"samplers": {
"sampler_0": {
"magFilter": 9729,
"minFilter": 9729,
"wrapS": 10497,
"wrapT": 10497
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"node"
]
}
},
"shaders": {
"FS": {
"type": 35632,
"uri": "FS.glsl"
},
"VS": {
"type": 35633,
"uri": "VS.glsl"
}
},
"skins": {},
"techniques": {
"technique0": {
"attributes": {
"a_normal": "normal",
"a_position": "position",
"a_texcoord0": "texcoord0"
},
"parameters": {
"diffuse": {
"type": 35678
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"normal": {
"semantic": "NORMAL",
"type": 35665
},
"normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"texcoord0": {
"semantic": "TEXCOORD_0",
"type": 35664
}
},
"program": "program_0",
"states": {
"enable": [
2929,
2884
]
},
"uniforms": {
"u_diffuse": "diffuse",
"u_modelViewMatrix": "modelViewMatrix",
"u_normalMatrix": "normalMatrix",
"u_projectionMatrix": "projectionMatrix"
}
}
},
"textures": {
"texture_texture0": {
"format": 6408,
"internalFormat": 6408,
"sampler": "sampler_0",
"source": "texture0",
"target": 3553,
"type": 5121
},
"texture_texture1": {
"format": 6408,
"internalFormat": 6408,
"sampler": "sampler_0",
"source": "texture1",
"target": 3553,
"type": 5121
}
}
}
accessors属性里面存放的是点的信息。其中accessor_index0和accessor_index1存储的是点的索引,数据类型是scaler,bufferView属性对应的是存储点的值存储地,可在bufferView里面去找对应的id的buffer信息。byteOffset是当前索引值对应bufferView的偏移量,如果是索引,byteStride是0,如果是点的位置坐标,byteStride是3*4即12。count是数据的总个数,componentType是点存储的字节数,如果顶点的个数小于65535,及componentType用两个字节就可以,用5123,否则就四个字节用5126。对应的其他属性可以以此类推。
关于GLTF的其他属性的值就不一一介绍了,根据上面的例子可以大概看明白,不明白的也可以问我。
由于场景数据没有运动,所以没有给animations的值。
2. 分享目的仅供大家学习和交流,请不要用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性
GLB下载网 - GLB/GLTF模型与格式资源免费下载,支持在线浏览与转换 » GLTF/GLB格式数据格式解析,自制模型转换工具
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载要提取码
- 分享过期和重复下载怎么办
- 模型和平台不兼容怎么办