您好,这是咱们iClient 3D for WebGL加载雨水粒子特效的代码
// rain
var rainParticleSize = scene.drawingBufferWidth / 80.0;
//降雨范围
var rainRadius = 4000.0;
var rainImageSize = new Cesium.Cartesian2(rainParticleSize, rainParticleSize * 3.0);
var rainGravityScratch = new Cesium.Cartesian3();
var rainUpdate = function (particle, dt) {
rainGravityScratch = Cesium.Cartesian3.normalize(particle.position, rainGravityScratch);
rainGravityScratch = Cesium.Cartesian3.multiplyByScalar(rainGravityScratch, -40, rainGravityScratch);
particle.position = Cesium.Cartesian3.add(particle.position, rainGravityScratch, particle.position);
var distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > rainRadius) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = rainSystem.endColor.alpha / (distance / rainRadius + 0.1);
}
};
var rainSystem = new Cesium.ParticleSystem({
modelMatrix: new Cesium.Matrix4.fromTranslation(scene.camera.position),
speed: -1.0,
lifetime: 10.0,
emitter: new Cesium.SphereEmitter(rainRadius),
startScale: 1.0,
endScale: 1.0,
image: './images/ParticleSystem/rain.png',
emissionRate: 3000.0,
startColor: new Cesium.Color(1, 1, 1, 0.8),
endColor: new Cesium.Color(1, 1, 1, 0.8),
imageSize: rainImageSize,
updateCallback: rainUpdate,
performance:false,
});
scene.primitives.add(rainSystem);
rainSystem.lodRangeScale=10000;
以及官网范例网址http://support.supermap.com.cn:8090/webgl/examples/webgl/editor.html#Particle%20System_rain。需要注意降雨范围的设置