let snowParticleSize = scene.drawingBufferWidth / 100.0;
let snowRadius = 100000.0;
let minimumSnowImageSize = new Cesium.Cartesian2(snowParticleSize, snowParticleSize);
let maximumSnowImageSize = new Cesium.Cartesian2(snowParticleSize * 2.0, snowParticleSize * 2.0);
let snowSystem;
let snowGravityScratch = new Cesium.Cartesian3();
function snowUpdate(particle, dt) {
console.log("update");
snowGravityScratch = Cesium.Cartesian3.normalize(particle.position, snowGravityScratch);
Cesium.Cartesian3.multiplyByScalar(snowGravityScratch, Cesium.Math.randomBetween(-30.0, -300.0), snowGravityScratch);
particle.velocity = Cesium.Cartesian3.add(particle.velocity, snowGravityScratch, particle.velocity);
let distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > snowRadius) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = snowSystem.endColor.alpha / (distance / snowRadius + 0.1);
}
}
snowSystem = new Cesium.ParticleSystem({
modelMatrix : new Cesium.Matrix4.fromTranslation(scene.camera.position),
minimumSpeed : -1.0,
maximumSpeed : 0.0,
lifetime : 15.0,
emitter : new Cesium.SphereEmitter(snowRadius),
startScale : 0.5,
endScale : 1.0,
image : './img/snowflake_particle.png',
emissionRate : 7000.0,
startColor : Cesium.Color.WHITE.withAlpha(0.0),
endColor : Cesium.Color.WHITE.withAlpha(1.0),
minimumImageSize : minimumSnowImageSize,
maximumImageSize : maximumSnowImageSize,
updateCallback : snowUpdate
});
scene.primitives.add(snowSystem);
这是Cesium一个示例的代码,核心代码这样的,测试运行可以看到snowSystem添加成功了,但是看不到效果,控制台看updateCallback里面的log也没有运行