- viewer = new Cesium.Viewer('cesiumContainer');
- var gravityScratch = new Cesium.Cartesian3();
- function applyGravity(p, dt) {
- // 计算每个粒子的向上向量(相对地心)
- var position = p.position;
- Cesium.Cartesian3.normalize(position, gravityScratch);
- Cesium.Cartesian3.multiplyByScalar(gravityScratch, viewModel.gravity * dt, gravityScratch);
- p.velocity = Cesium.Cartesian3.add(p.velocity, gravityScratch, p.velocity);
- }
- var entity = viewer.entities.add({
- // 加载飞机模型
- model : {
- uri : '../Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
- minimumPixelSize : 64
- },
- position : Cesium.Cartesian3.fromDegrees(-112.110693, 36.0994841, 1000.0)
- });
- viewer.trackedEntity = entity;
- function computeModelMatrix(entity, time) {
- var position = Cesium.Property.getValueOrUndefined(entity.position, time, new Cesium.Cartesian3());
- if (!Cesium.defined(position)) {
- return undefined;
- }
- var orientation = Cesium.Property.getValueOrUndefined(entity.orientation, time, new Cesium.Quaternion());
- if (!Cesium.defined(orientation)) {
- var 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;
- }
- function computeEmitterModelMatrix() {
- hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0, 0.0, 0.0, new Cesium.HeadingPitchRoll());
- var trs = new Cesium.TranslationRotationScale();
- trs.translation = Cesium.Cartesian3.fromElements(2.5, 4.0, 1.0, new Cesium.Cartesian3());
- trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr, new Cesium.Quaternion());
- return Cesium.Matrix4.fromTranslationRotationScale(trs, new Cesium.Matrix4());
- }
- var particleSystem = viewer.scene.primitives.add(new Cesium.ParticleSystem({
- // Particle appearance
- image : '../Apps/SampleData/fire.png',
- imageSize : new Cesium.Cartesian2(20, 20),
- startScale : 1.0,
- endScale : 4.0,
- // Particle behavior
- particleLife : 1.0,
- speed : 5.0,
- // Emitter parameters
- emitter : new Cesium.CircleEmitter(0.5),
- emissionRate : 5.0,
- emitterModelMatrix : computeEmitterModelMatrix(),
- // Particle system parameters
- modelMatrix : computeModelMatrix(entity, Cesium.JulianDate.now()),
- lifetime : 16.0,
- particleSystem : {
- image : '../Apps/SampleData/fire.png',
- emissionRate: 50.0,
- emitter: new Cesium.BoxEmitter(new Cesium.Cartesian3(10.0, 10.0, 10.0))
- },
- bursts : [
- new Cesium.ParticleBurst({time : 5.0, minimum : 300, maximum : 500}),
- new Cesium.ParticleBurst({time : 10.0, minimum : 50, maximum : 100}),
- new Cesium.ParticleBurst({time : 15.0, minimum : 200, maximum : 300})
- ],
- particleSystem : {
- lifetime: 5.0,
- loop: false
- },
- particleSystem : {
- minimumParticleLife: 5.0,
- maximumParticleLife: 10.0
- },
- particleSystem : {
- startColor: Cesium.Color.RED.withAlpha(0.7),
- endColor: Cesium.Color.YELLOW.withAlpha(0.3)
- },
- particleSystem : {
- minimumImageSize : new Cesium.Cartesian2(30.0, 30.0),
- maximumImageSize : new Cesium.Cartesian2(60.0, 60.0)
- },
- particleSystem : {
- startScale: 1.0,
- endScale: 4.0
- },
- particleSystem : {
- minimumSpeed: 5.0,
- maximumSpeed: 10.0
- },
- particleSystem: {
- forces: applyGravity
- },
- }));
Cesium基础知识-粒子应用-飞机冒火
于 2022-01-19 14:30:00 首次发布