禁止模型穿透,
viewer.scene.screenSpaceCameraController.enableCollisionDetection = false; //true 禁止 false 允许
设置相机高度属性
viewer.scene.screenSpaceCameraController.minimumZoomDistance = 0;//相机的高度的最小值
viewer.scene.screenSpaceCameraController.maximumZoomDistance = 1000; //相机高度的最大值
1.dataSources添加
let viewer = this.$viewer;
var dataSource = new Cesium.CustomDataSource();
dataSource.name = '资阳树'
viewer.dataSources.add(dataSource);
let url = './model/shu007.glb'
var position = Cesium.Cartesian3.fromDegrees(104.63533992721075, 30.13245463830626, 8.8);
//弧度的航向分量。
var heading = Cesium.Math.toRadians(135);
//弧度的螺距分量。
var pitch = 0;
//滚动分量(以弧度为单位)
var roll = 0;
//HeadingPitchRoll旋转表示为航向,俯仰和滚动。围绕Z轴。节距是绕负y轴的旋转。滚动是关于正x轴。
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
dataSource.entities.add({
name: url,
position: position,
orientation: orientation,
model: {
uri: url,
// minimumPixelSize: 128, //不管缩放如何,模型的最小最小像素大小。
// maximumScale: 20000, //模型的最大比例尺大小。 minimumPixelSize的上限。
scale: 0.4,
},
}
);
2.primitives添加集合
let shumodelCollection = new Cesium.PrimitiveCollection();
shumodelCollection.name = 'shumodel'
viewer.scene.primitives.add(shumodelCollection);
position = Cesium.Cartesian3.fromDegrees(104.63544395054346, 30.132476858922114, 8.8);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
shumodelCollection.add(
Cesium.Model.fromGltf({
url: url,
modelMatrix: modelMatrix,
show: true,
scale: 0.4,
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1.0, 1000.0)
// minimumPixelSize: 128,
// maximumScale: 20000,
// allowPicking: true,
// heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
})
)