primitives类型的实体(针对3DTileset)
//旋转
let mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(Number(this.form.x)));
let my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(Number(this.form.y)));
let mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(Number(this.form.z)));
let rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
let rotationY = Cesium.Matrix4.fromRotationTranslation(my);
let rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
//平移
//let position = Cesium.Cartesian3.fromDegrees(Number(this.form.left), Number(this.form.right), Number(this.form.up));
let cartesian = new Cesium.Cartesian3(this.model.position.x + Number(this.form.left), this.model.position.y + Number(this.form.right), this.model.position.z + Number(this.form.up))
//let m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
let m = Cesium.Transforms.eastNorthUpToFixedFrame(cartesian)
//旋转、平移矩阵相乘
Cesium.Matrix4.multiply(m, rotationX, m);
Cesium.Matrix4.multiply(m, rotationY, m);
Cesium.Matrix4.multiply(m, rotationZ, m);
console.log(this.model)
//赋值给tileset
this.model._root.transform = m;
其中关于平移的部分要注意,如果你输入的是经纬度,直接用注释里面的代码即可,如果你输入的多少米多少米,用我这部分即可。另外再注意一下,你点击获取的实体信息中是不存在这个"position"这个字段的,这个字段是我自己创建实体的时候添加上去的,这个尤其要注意
entity类型的实体(如glb)
let position = this.model.position._value
//旋转
let heading = Cesium.Math.toRadians(this.form.x)
let pitch = Cesium.Math.toRadians(this.form.y)
let roll = Cesium.Math.toRadians(this.form.z)
let hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll)
let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr)
this.model.orientation._value = orientation
//平移
let cartesian = new Cesium.Cartesian3(position.x + Number(this.form.left), position.y + Number(this.form.right), position.z + Number(this.form.up))
this.model.position._value = cartesian
//缩放
this.model.model.scale._value = this.form.scale
注意,这时候的model应该是点击地图要素获取的id不是上面那个primitive这两个要区分