1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| export function update3dtiles(tileSet: Cesium.Cesium3DTileset, options: any) { const { tx = 0, ty = 0, tz = 0, rx = 0, ry = 0, rz = 0, scale = 1,sx =1,sy =1,sz =1 } = options console.log(tx,ty,tz,rx,ry,rz,scale,'模型变换参数') const center = tileSet.boundingSphere.center
const m = Cesium.Transforms.eastNorthUpToFixedFrame(center)
const tempTranslation = new Cesium.Cartesian3(tx, ty, tz)
const offset = Cesium.Matrix4.multiplyByPoint( m, tempTranslation, new Cesium.Cartesian3(0, 0, 0) )
const translation = Cesium.Cartesian3.subtract( offset, center, new Cesium.Cartesian3() ) tileSet.modelMatrix = Cesium.Matrix4.multiply( Cesium.Matrix4.fromTranslation(translation), tileSet.modelMatrix, new Cesium.Matrix4() )
if (rx || ry || rz || scale) { const initialCenter = Cesium.Cartesian3.clone(tileSet.boundingSphere.center) const translationMatrix = Cesium.Matrix4.fromTranslation( Cesium.Cartesian3.negate( tileSet.boundingSphere.center, new Cesium.Cartesian3() ) )
const radiansX = Cesium.Math.toRadians(rx) const radiansY = Cesium.Math.toRadians(ry) const radiansZ = Cesium.Math.toRadians(rz)
const rotationX = Cesium.Matrix3.fromRotationX(radiansX) const rotationY = Cesium.Matrix3.fromRotationY(radiansY) const rotationZ = Cesium.Matrix3.fromRotationZ(radiansZ)
const combinedRotation = Cesium.Matrix3.multiply( rotationX, rotationY, new Cesium.Matrix3() ) Cesium.Matrix3.multiply(combinedRotation, rotationZ, combinedRotation)
const rotationMatrix4 = Cesium.Matrix4.fromRotation(combinedRotation)
let scaleTempParam = new Cesium.Cartesian3(scale, scale, scale) if(sx!=1 || sy!=1 || sz!=1){ scaleTempParam = new Cesium.Cartesian3(sx, sy, sz) } const scaleMatrix4 = Cesium.Matrix4.fromScale( scaleTempParam, new Cesium.Matrix4() )
const translationBack = Cesium.Matrix4.fromTranslation(initialCenter)
let tempMatrix = tileSet.modelMatrix tempMatrix = Cesium.Matrix4.multiply( translationMatrix, tempMatrix, new Cesium.Matrix4() ) tempMatrix = Cesium.Matrix4.multiply( rotationMatrix4, tempMatrix, new Cesium.Matrix4() ) tempMatrix = Cesium.Matrix4.multiply( scaleMatrix4, tempMatrix, new Cesium.Matrix4() ) tempMatrix = Cesium.Matrix4.multiply( translationBack, tempMatrix, new Cesium.Matrix4() ) tileSet.modelMatrix = tempMatrix }
return tileSet }
|