首页 / 浏览问题 / WebGIS / 问题详情
粒子特效添加到场景但不显示
1EXP 2020年12月07日
var viewModelfire= {
    emissionRate: 200.0,
    gravity: 0.0,
    minimumParticleLife: 1.5,
    maximumParticleLife: 1.8,
    minimumSpeed: 7.0,
    maximumSpeed: 9.0,
    startScale: 3.0,
    endScale: 1.5,
    particleSize: 2,
    // windType: "undf",
    // windDirection: [{type:"west",canshu:new Cesium.Cartesian3(1 , 0 , 0),x:1.0,y:0,z:0},
    //     //x为正:向西; x为负:向东; y为正:向南向上; y为负:向北向下; z为正:向比向上; z为负:向南向下
    //     {type:"east",canshu:new Cesium.Cartesian3(-1,0,0),x:-1.0,y:0,z:0},
    //     {type:"south",canshu:new Cesium.Cartesian3(0,1,0),x:0,y:1.0,z:0},
    //     {type:"north",canshu:new Cesium.Cartesian3(0,-1,0),x:0,y:-1.0,z:0},
    //     {type:"undf",canshu:new Cesium.Cartesian3(0,0,0),x:0,y:0,z:0}]
};


function fire() {
    var pos1 = Cesium.Cartesian3.fromDegrees(120.26840620531044, 31.5737499999989,10);
    var entity = viewer.entities.add({
        position: pos1,
    });

    var particleSystem2 = viewer.scene.primitives.add(new Cesium.ParticleSystem({
        image: "image/fire4.png",
        startColor:new Cesium.Color(1,1,1,1),
        endColor:new Cesium.Color(0.5,0,0,0),
        // 粒子出生比例c
        startScale: viewModelfire.startScale,
        // 粒子结束比例
        endScale: viewModelfire.endScale,
        // 最小生命周期
        minimumParticleLife: viewModelfire.minimumParticleLife,
        // 最大生命周期
        maximumParticleLife: viewModelfire.maximumParticleLife,
        // 以米/秒为单位设置最小速度。
        minimumSpeed: viewModelfire.minimumSpeed,
        // 以米/秒为单位设置最大速度。
        maximumSpeed: viewModelfire.maximumSpeed,
        imageSize: new Cesium.Cartesian2(viewModelfire.particleSize, viewModelfire.particleSize),
        emissionRate: viewModelfire.emissionRate,
        // 粒子系统发射的时间 秒为单位
        lifetime: 6.0,
       //循环是否开启
        loop: true,
        // 系统粒子发射器
        emitter:new Cesium.ConeEmitter(Cesium.Math.toRadians(45.0)),
        sizeInMeters: true,
        // updateCallback:applyForce //设置作用力
    }));

    viewer.scene.preUpdate.addEventListener(function (scene, time) {
        particleSystem2.modelMatrix = computeModelMatrix(entity, time);
        particleSystem2.emitterModelMatrix = computeEmitterModelMatrix();
    });

    var emitterModelMatrix = new Cesium.Matrix4();
    var translation = new Cesium.Cartesian3();
    var rotation = new Cesium.Quaternion();
    var hpr = new Cesium.HeadingPitchRoll();
    var trs = new Cesium.TranslationRotationScale();

    //改变粒子系统的位置
    function computeEmitterModelMatrix() {
        hpr = Cesium.HeadingPitchRoll.fromDegrees(0.0,0.0,0.0, hpr);
        trs.translation = Cesium.Cartesian3.fromElements(0,0, 86, translation);
        trs.rotation = Cesium.Quaternion.fromHeadingPitchRoll(hpr, rotation);
        return Cesium.Matrix4.fromTranslationRotationScale(trs, emitterModelMatrix);
    }

1个回答

你好,你在代码中添加function computeModelMatrix(entity, time) {
            return entity.computeModelMatrix(time, new Cesium.Matrix4());
        }试试呢
1,225EXP 2020年12月07日
...