let that = this; let longitude = this.config.position.longitude; let latitude = this.config.position.latitude; let height = this.config.position.height; let heading = 0; if(this.config.position.heading!=null) heading = this.config.position.heading; this.model.readyPromise.then(function (argument) { // 如果tileset自带世界矩阵,那么计算放置的经纬度和heading let mat0 = Cesium.Matrix4.fromArray(that.model._root.transform); // 原来的矩阵的逆 that.orginMatrixInverse = Cesium.Matrix4.inverse(mat0, new Cesium.Matrix4()); // 模型的位置坐标(三维笛卡尔坐标)。Cartesian3 let position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height); // 模型的位置矩阵(WGS84 Matrix4)。 let mat = Cesium.Transforms.eastNorthUpToFixedFrame(position); // Heading(航向)是负z轴的旋转。Pitch(俯仰)是负y轴的旋转。Roll(滚动)是正x轴的旋转 // 根据heading, 创建一个围绕z轴的旋转矩阵Matrix3。 // 从 旋转矩阵Matrix3 转换成 旋转矩阵Matrix4。 let rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(heading))); // 计算模型的 位置矩阵(WGS84 Matrix4) 和 旋转矩阵Matrix4 的乘积,并存储到模型的位置矩阵。 Cesium.Matrix4.multiply(mat, rotationX, mat); // 把新构造的模型矩阵(既可以表示位置,也能表示旋转)赋值给该模型的model._root.transform(转换)。 that.model._root.transform = mat; // 至此,完成了模型的位置及heading的变更。 }); function locateNode(e, t) { /* 定位模型的最后一级节点。 * e, 节点id。 * t, 节点包容球[x,y,z,radius], * 其中x,y,z,代表包容球的球心坐标,单位:米。 * radius,包容球的半径。*/ console.log("e:", e); // e: 8aa8055c543c4c4a8272bf04d8d671a5 console.log("t:", t); // t: (4) [-2254678.64016919, 4416402.06381591, 3998110.43911067, 0.13197181397185, remove: ƒ, insert: ƒ] if (!(t[3] <= 0)) { let i = workModel.tileset; let o = workModel.orginMatrixInverse; let r = new Cesium.Cartesian3(t[0], t[1], t[2]); if (o && i._root.transform) { let a = Cesium.Matrix4.multiply(i._root.transform, o, new Cesium.Matrix4); r = Cesium.Matrix4.multiplyByPoint(a, r, new Cesium.Cartesian3) } let n = new Cesium.BoundingSphere(r, t[3]); viewer.camera.flyToBoundingSphere(n, {duration: .5}); i.style = new Cesium.Cesium3DTileStyle({color: {conditions: [["${id} ==='" + e + "'", "rgb(255, 255, 255)"], ["true", "rgba(255, 200, 200,0.2)"]]}}) } }
cesium 模型位置编辑、旋转、节点定位.txt
于 2019-08-01 08:57:33 首次发布