var viewer = new Cesium.Viewer('cesiumContainer');
//不透明的盒子,启用背面裁剪,深度检测,不需要混合
var appearance = new Cesium.PerInstanceColorAppearance({
translucent : false, //半透明
closed : true //闭合
});
//与上面的设置等价
var anotherAppearance = new Cesium.PerInstanceColorAppearance({
renderState : {
depthTest : {
enabled : true
},
cull : {
enabled : true,
face : Cesium.CullFace.BACK
}
}
});
var entityPlane = viewer.entities.add({
model : {
uri : 'http://localhost:8080/apps/SampleData/models/CesiumAir/Cesium_Air.gltf',
minimumPixelSize : 64
},
position : Cesium.Cartesian3.fromDegrees(-112.110693, 36.1, 1000.0)
});
viewer.trackedEntity =entityPlane;
//计算当前时间点飞机模型的位置矩阵
function computeModelMatrix(entity, time){
var position = Cesium.Property.getValueOrUndefined(entity.position, time, new Cesium.Cartesian3());
if( !Cesium.defined(position)){
return undefined;
}
//alert(position);
var orientation = Cesium.Property.getValueOrUndefined(entity.orientation, time, new Cesium.Quaternion());
var modelMatrix;
if(!Cesium.defined(orientation)){
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position,undefined, new Cesium.Matrix4());
}
else{
modelMatrix = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation, new Cesium.Matrix3()), position, new Cesium.Matrix4()) ;
}
return modelMatrix;
// return entity.computeModelMatrix(time, new Cesium.Matrix4());
}
//粒子放在飞机引擎上产生,平移矩阵
function computeEmitterModelMatrix(){
var hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0, 0.0, 0.0, new Cesium.HeadingPitchRoll());
var trs = new Cesium.TranslationRotationScale();
trs.translation = Cesium.Cartesian3.fromElements(0, 0, 0, new Cesium.Cartesian3());
trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr, new Cesium.Quaternion());
return Cesium.Matrix4.fromTranslationRotationScale(trs, new Cesium.Matrix4());
}
//加上重力
var gravityScratch = new Cesium.Cartesian3();
function applyGravity( p, dt ){
//计算每个粒子的向上向量
var position = p.position;
var positionA = Cesium.Cartesian3.normalize(position, new Cesium.Cartesian3());
Cesium.Cartesian3.multiplyByScalar(positionA, 5, positionA);
p.position = Cesium.Cartesian3.add(p.position,positionA, p.position);
}
//基本粒子系统
var particleSystem = viewer.scene.primitives.add(new Cesium.ParticleSystem({
//粒子图片
image : 'http://localhost:8080/apps/SampleData/fire.png',
//粒子大小
startScale : 1.0,
endScale : 4.0,
particleLife : 1.0,
//速度
speed : 5.0,
imageSize : new Cesium.Cartesian2(20.0,20.0),
emissionRate : 5.0,
rate : 5.0,
//颜色
startColor : Cesium.Color.RED.withAlpha(0.7),
endColor : Cesium.Color.YELLOW.withAlpha(0.3),
//粒子行为
//发射器参数
emitter : new Cesium.ConeEmitter(Cesium.Math.toRadians(30.0)),
//粒子系统的局部坐标系内变换粒子发射器
emitterModelMatrix : computeEmitterModelMatrix(),
//粒子系统参数
//粒子系统从模型坐标系转到世界坐标系
modelMatrix : computeModelMatrix(entityPlane, Cesium.JulianDate.now()),
lifetime : 16.0,
loop : false,
//重力加速度
forces : [applyGravity]
}));