1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

pass ready events on all pass types

This commit is contained in:
Sander Moolin 2021-03-21 14:49:41 -04:00
parent 7887f2266a
commit d67805e6bd
11 changed files with 23 additions and 19 deletions

View File

@ -37,8 +37,7 @@ export default {
height: this.three.size.height, height: this.three.size.height,
}; };
const pass = new BokehPass(this.three.scene, this.three.camera, params); const pass = new BokehPass(this.three.scene, this.three.camera, params);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'BokehPass', __hmrId: 'BokehPass',
}; };

View File

@ -1,5 +1,6 @@
export default { export default {
inject: ['three', 'passes'], inject: ['three', 'passes'],
events: ['ready'],
beforeMount() { beforeMount() {
if (!this.passes) { if (!this.passes) {
console.error('Missing parent EffectComposer'); console.error('Missing parent EffectComposer');
@ -8,6 +9,13 @@ export default {
unmounted() { unmounted() {
if (this.pass.dispose) this.pass.dispose(); if (this.pass.dispose) this.pass.dispose();
}, },
methods: {
completePass(pass) {
this.passes.push(pass);
this.pass = pass;
this.$emit('ready', pass);
}
},
render() { render() {
return []; return [];
}, },

View File

@ -6,8 +6,7 @@ export default {
extends: EffectPass, extends: EffectPass,
mounted() { mounted() {
const pass = new ShaderPass(FXAAShader); const pass = new ShaderPass(FXAAShader);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
// resize will be called in three init // resize will be called in three init
this.three.onAfterResize(this.resize); this.three.onAfterResize(this.resize);

View File

@ -29,8 +29,7 @@ export default {
}, },
mounted() { mounted() {
const pass = new FilmPass(this.noiseIntensity, this.scanlinesIntensity, this.scanlinesCount, this.grayscale); const pass = new FilmPass(this.noiseIntensity, this.scanlinesIntensity, this.scanlinesCount, this.grayscale);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'FilmPass', __hmrId: 'FilmPass',
}; };

View File

@ -22,8 +22,7 @@ export default {
}); });
}); });
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'HalftonePass', __hmrId: 'HalftonePass',
}; };

View File

@ -11,8 +11,7 @@ export default {
console.error('Missing Camera'); console.error('Missing Camera');
} }
const pass = new RenderPass(this.three.scene, this.three.camera); const pass = new RenderPass(this.three.scene, this.three.camera);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'RenderPass', __hmrId: 'RenderPass',
}; };

View File

@ -6,8 +6,7 @@ export default {
mounted() { mounted() {
// three size is not set yet, but this pass will be resized by effect composer // three size is not set yet, but this pass will be resized by effect composer
const pass = new SMAAPass(this.three.size.width, this.three.size.height); const pass = new SMAAPass(this.three.size.width, this.three.size.height);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'SMAAPass', __hmrId: 'SMAAPass',
}; };

View File

@ -18,8 +18,7 @@ export default {
this.three.size.width, this.three.size.width,
this.three.size.height this.three.size.height
); );
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
for (let key of Object.keys(this.options)) { for (let key of Object.keys(this.options)) {
this.pass[key] = this.options[key]; this.pass[key] = this.options[key];

View File

@ -39,6 +39,9 @@ export default {
this.pass.setSize = (width, height) => { this.pass.setSize = (width, height) => {
uniforms.texSize.value.set(width, height); uniforms.texSize.value.set(width, height);
}; };
this.completePass(pass);
this.completePass(pass1);
}, },
methods: { methods: {
updateFocusLine() { updateFocusLine() {

View File

@ -17,8 +17,7 @@ export default {
mounted() { mounted() {
const size = new Vector2(this.three.size.width, this.three.size.height); const size = new Vector2(this.three.size.width, this.three.size.height);
const pass = new UnrealBloomPass(size, this.strength, this.radius, this.threshold); const pass = new UnrealBloomPass(size, this.strength, this.radius, this.threshold);
this.passes.push(pass); this.completePass(pass);
this.pass = pass;
}, },
__hmrId: 'UnrealBloomPass', __hmrId: 'UnrealBloomPass',
}; };

View File

@ -10,12 +10,13 @@ export default {
strength: { type: Number, default: 0.5 }, strength: { type: Number, default: 0.5 },
}, },
mounted() { mounted() {
this.pass = new ShaderPass(ZoomBlur); const pass = new ShaderPass(ZoomBlur);
this.passes.push(this.pass);
const uniforms = this.uniforms = this.pass.uniforms; const uniforms = this.uniforms = pass.uniforms;
bindProp(this, 'center', uniforms.center, 'value'); bindProp(this, 'center', uniforms.center, 'value');
bindProp(this, 'strength', uniforms.strength, 'value'); bindProp(this, 'strength', uniforms.strength, 'value');
this.completePass(pass);
}, },
__hmrId: 'ZoomBlurPass', __hmrId: 'ZoomBlurPass',
}; };