3d tiles的初始位置由tileset.json中root.transform的变换矩阵指定。该矩阵为建模坐标系原点转换到世界坐标系中的变换矩阵。
当3d tiles未指定根节点变换矩阵,通过以下两中方法可以指定模型初始位置
1、直接在tileset.json设置
假设已知3d tiles模型的建模坐标系的原点(0,0,0)在世界坐标系中的坐标(WGS84)。
const modelMat4=Cesium.Transforms.eastNorthUpToFixedFrame(origin);
然后将modelMat4的值添加到tileset.json中root.transform。
{
"asset": {
"version": "1.0"
},
"geometricError": 500,
"root": {
"transform": [
0.05602263155122217,
0.6403416087687968,
0.7660444431189781,
0,
-0.9961946980917457,
0.08715574274765825,
0,
0,
-0.06676517241775076,
-0.7631294127377697,
0.6427876096865391,
0,
-426427.5649314479,
-4874089.370505605,
4077985.572200376,
1
],
"geometricError": 0.2,
"refine": "REPLACE",
"content": {
},
"children": [
.....
.....
]
}
}
2、在程序代码中指定
//origin为模型坐标系原点的世界坐标
const modelMat4=Transforms.eastNorthUpToFixedFrame(origin);
const tileset=scene.primitives.add(new Cesium3DTileset({
url:url
}));
tileset.readyPromise.then(function(){//异步加载成功
tileset.modelMatrix=modelMat4;//指定根节点变换矩阵
viewer.camera.flyToBoundingSphere(tileset.boundingSphere);
})
tileset.json中的transform属性是一个4X4放射变换矩阵,以列主序存储,它将tile的局部坐标系变换到父tile的坐标系,或者可以说就是转换到tileset根节点的坐标系。
更广泛地说,3d tiles中的矩阵变换顺序为:
- glTF节点层次变换
- glTFY轴朝上变换到Z轴朝上
- 特定于tile格式的变换(.b3dm .bidm )
- Tile 变换矩阵
- 根节点变换矩阵
- Cesium3DTileset中设置的变换矩阵ModelMatrix