cesium中对于 gltf1.0、2.0中某些扩展需要进行解析,解析的过程是将gltf1.0的格式转换成gltf2.0的格式。
对于解析过程中使用的某些扩展的解释:
{
"asset": {
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"nodes": [
{
"children": [
2,
1
],
"matrix": [
0.009999999776482582,
0.0,
0.0,
0.0,
0.0,
0.009999999776482582,
0.0,
0.0,
0.0,
0.0,
0.009999999776482582,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"matrix": [
-0.7289686799049377,
0.0,
-0.6845470666885376,
0.0,
-0.4252049028873444,
0.7836934328079224,
0.4527972936630249,
0.0,
0.5364750623703003,
0.6211478114128113,
-0.571287989616394,
0.0,
400.1130065917969,
463.2640075683594,
-431.0780334472656,
1.0
],
"camera": 0
},
{
"mesh": 0
}
],
"cameras": [
{
"perspective": {
"aspectRatio": 1.5,
"yfov": 0.6605925559997559,
"zfar": 10000.0,
"znear": 1.0
},
"type": "perspective"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2,
"TEXCOORD_0": 3,
"_CUSTOM_ATTRIBUTE": 4
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "LOD3spShape"
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"count": 12636,
"max": [
2398
],
"min": [
0
],
"type": "SCALAR"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"count": 2399,
"max": [
0.9995989799499512,
0.999580979347229,
0.9984359741210938
],
"min": [
-0.9990839958190918,
-1.0,
-0.9998319745063782
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 28788,
"componentType": 5126,
"count": 2399,
"max": [
96.17990112304688,
163.97000122070313,
53.92519760131836
],
"min": [
-69.29850006103516,
9.929369926452637,
-61.32819747924805
],
"type": "VEC3"
},
{
"bufferView": 2,
"byteOffset": 0,
"componentType": 5126,
"count": 2399,
"max": [
0.9833459854125976,
0.9800369739532472
],
"min": [
0.026409000158309938,
0.01996302604675293
],
"type": "VEC2"
},
{
"bufferView": 3,
"byteOffset": 0,
"componentType": 5125,
"count": 2399,
"type": "SCALAR"
}
],
"materials": [
{
"extensions": {
"KHR_techniques_webgl": {
"technique": 0,
"values" : {
"u_shininess": 10.0,
"u_light0Color": [
0.8,
0.8,
1.0
],
"u_ambient": [
0.1,
0.1,
0.1,
1.0
]
}
}
}
}
],
"textures": [
{
"sampler": 0,
"source": 0
}
],
"images": [
{
"uri": "DuckCM.png"
}
],
"extensions": {
"KHR_techniques_webgl": {
"programs": [
{
"fragmentShader": 0,
"vertexShader": 1
}
],
"shaders": [
{
"type": 35632,
"uri": "duck0FS.glsl"
},
{
"type": 35633,
"uri": "duck0VS.glsl"
}
],
"techniques": [
{
"program": 0,
"attributes": {
"a_normal": {
"semantic": "NORMAL"
},
"a_position": {
"semantic": "POSITION"
},
"a_texcoord0": {
"semantic": "TEXCOORD_0"
},
"a_custom": {
"semantic": "_CUSTOM_ATTRIBUTE"
}
},
"uniforms": {
"u_ambient": {
"type": 35666
},
"u_diffuse": {
"type": 35678,
"value": {
"index": 0
}
},
"u_shininess": {
"type": 5126
},
"u_light0Color": {
"type": 35665,
"value": [
1,
1,
1
]
},
"u_light0Transform": {
"semantic": "MODEL",
"node": 1,
"type": 35676
},
"u_modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"u_normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"u_projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
}
}
}
]
}
},
"extensionsRequired": [
"KHR_techniques_webgl"
],
"extensionsUsed": [
"KHR_techniques_webgl"
]
}
使用的扩展需要在 extensionsRequired、extensionsUsed中进行声明。
"materials": [
{
"extensions": {
"KHR_techniques_webgl": {
"technique": 0,
"values" : {
"u_shininess": 10.0,
"u_light0Color": [
0.8,
0.8,
1.0
],
"u_ambient": [
0.1,
0.1,
0.1,
1.0
]
}
}
}
}
],
上面的格式中某个mesh使用了材质扩展一些效果,使用了KHR_techniques_webgl扩展,这个扩展定义了technique是一个引用,真正的数据在"extensions":"KHR_techniques_webgl":"techniques":中。
而如果materials中的technique不是一个索引,是一个光照模型,就比较清楚materials中的扩展的values是什么了,technique可以是“lambert”、“phong”、“blinn”等光照模型,如果是“lambert”需要“u_ambint”,"u_light0Color"等信息。这些信息代表着模型本身的属性,如:环境光反射率、灯光的反射率、模型对灯光的反射强度等。
{
"extensions": {
"KHR_materials_common" : {
"lights" : {
"ambient_light_id": {
"ambient": {
"color": [
1.0,
1.0,
1.0
],
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"name": "user-defined name of ambient light",
"type": "ambient",
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"directional_light_id": {
"directional": {
"color": [
1.0,
1.0,
1.0
],
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"name": "user-defined name of directional light",
"type": "directional",
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"point_light_id": {
"name": "user-defined name of point light",
"point": {
"color": [
1.0,
1.0,
1.0
],
"constantAttenuation": 1.0,
"linearAttenuation": 0.5,
"quadraticAttenuation": 0.25,
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"type": "point",
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"spot_light_id": {
"name": "user-defined name of spot light",
"spot": {
"color": [
1.0,
1.0,
1.0
],
"constantAttenuation": 1.0,
"fallOffAngle": 40,
"fallOffExponent": 0.0,
"linearAttenuation": 0.5,
"quadraticAttenuation": 0.25,
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
},
"type": "spot",
"extensions" : {
"extension_name" : {
"extension specific" : "value"
}
},
"extras" : {
"Application specific" : "The extra object can contain any properties."
}
}
}
}
},
"nodes" : {
"light_node_id": {
"children": [],
"matrix": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ],
"name": "user-defined name of light node",
"extensions": {
"KHR_materials_common" : {
"light": "point_light_id"
}
}
}
},
"techniques" : {
"technique_id" : {
"name": "user-defined technique name",
"parameters": {
"lightTransform": {
"node": "directional_light_node_id",
"type": 35676
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"position": {
"semantic": "POSITION",
"type": 35665
},
},
"attributes": {
"a_position": "position"
},
"program": "program_id",
"uniforms": {
"u_lightTransformMatrix": "lightTransform"
},
}
}
}
对于“KHR_materials_common”这个扩展,设置了灯光的颜色属性。