注:1.96以上版本的源码发生了较大变更,以下内容不一定适用
1、modelMatrix
作为模型在世界坐标系下的矩阵,该矩阵决定着模型的全局(旋转、平移、缩放)形态。这里的矩阵数据格式和3d tiles的矩阵有稍稍的不同。
2、 _boundingSphere
定位中常用的boundingSphere为何他的center这么小呢?
这里的boundingSphere.center是当前模型局部坐标系下的位置,求其在世界坐标系下的位置,可以利用:
let center = Cesium.Matrix4.multiplyByPoint(
model.modelMatrix,
model.boundingSphere.center,
new Cesium.Cartesian3()
);
1.95以上版本的包围盒已经转换成ECEF坐标系可以直接使用
3、gltf模型的gltf属性:
在模型的gltf节点下存储着.gltf模型最原始的数据格式,包括网格(meshs)、材质(material)、动画( animations)、 动画数据来源(samplers)、节点(nodes)、节点之间的关系等等。
特别的是,nodes下面有children属性的即表示父节点。我们可以打开blender,对照在blender中查看他们对应的关系如下:
4、模型间节点的矩阵转换关系:
在_runtime.nodeByName中,储存着节点相关的信息。
[]computedMatrix
该矩阵的含义:当前节点在世界坐标系下的矩阵,该矩阵是实时更新的,节点的变化会影响着当前矩阵的变化;
它是怎么计算来的呢?
const nodeMatrix = Matrix4.multiplyTransformation(
computedModelMatrix,
transformToRoot,
n.computedMatrix
);
1、其中computedModelMatrix是根节点的变换矩阵;
2、transformToRoot是子节点到父节点的变换;
如果子节点没有变换的情况下,transformToRoot子节点的矩阵由原始节点的matrix组成,即由translation、rotation、scale构成, 否则则根据node.matrix获取
Matrix4.fromTranslationQuaternionRotationScale(
node.translation,
node.rotation,
node.scale,
result
);
我们对节点的操作主要是去变换transformToRoot这个矩阵。
cesium内部会根据矩阵的关系:
Matrix4.multiplyTransformation(
transformToRoot,
child.transformToRoot,
child.transformToRoot
);
使得父节点的变换带动子节点的变换