Alchemist0823 / three.quarks

Three.quarks is a general purpose particle system / VFX engine for three.js
https://quarks.art
480 stars 22 forks source link

Change the map doesn't work #53

Closed pbsmart closed 1 year ago

pbsmart commented 1 year ago
createParticleSystem = () => {
        this.batchSystem = new BatchedParticleRenderer();
        const texture = new TextureLoader().load("textures/star.png");
        texture.encoding = sRGBEncoding;
        const param = {
            shape: new DonutEmitter({
                radius: 2,
                angle: Math.PI / 4,
                arc: Math.PI,
            }),
            renderMode: RenderMode.BillBoard,
            worldSpace: false,
            renderOrder: 2,
            looping: true,
            duration: 5,
            emissionOverTime: new ConstantValue(100),
            startLife: new ConstantValue(5),
            startSize: new IntervalValue(10, 15),
            startSpeed: new ConstantValue(5),
            material: new MeshBasicMaterial({ transparent: true, color: 0xff0000, map: texture, blending: AdditiveBlending, depthTest: false }),
            onlyUsedByOther: false,
        };

        setTimeout(() => {
            const texture = new TextureLoader().load("textures/1.jpg");
            this.muzzle.texture = texture;
        }, 5000);

        this.muzzle = new ParticleSystem(param);

        this.muzzle.addBehavior(new SizeOverLife(new PiecewiseBezier([[new Bezier(.3, .5, .6, .3), 0]])));
        this.muzzle.addBehavior(new ColorOverLife(new ColorRange(new Vector4(0, 0, 0, 1), new Vector4(1, 1, 1, .3))));
        this.muzzle.emitter.name = 'muzzle1';
        this.batchSystem.addSystem(this.muzzle);

        this.muzzle.emitter.rotateX(-Math.PI / 2);
        this.scene.add(this.muzzle.emitter);
        this.scene.add(this.batchSystem);
    };

The above dynamic modify texture is not effective, Version is 0.10.2 ,Where I do wrong?

pbsmart commented 1 year ago

I found that after changing the texture, batch needs to call rebuildMaterial again

ParticleSystem.prototype.updateMaterial = function () {
    const po = this._renderer.systemToBatchIndex.get(this);
    if (po !== undefined) {
        this._renderer.batches[po].rebuildMaterial();
    } else {
        console.log(" no find batch" + this);
    }
};

This solved my problem,Hope to be helpful to those who encounter the same problems as others