1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
This commit is contained in:
Kevin Levron 2021-04-21 16:07:03 +02:00
parent 7cdda981ef
commit 9288a3eedf
2 changed files with 10 additions and 6 deletions

View File

@ -1,21 +1,24 @@
import { Pass } from 'three/examples/jsm/postprocessing/Pass'
import { defineComponent, inject } from 'vue'
import { RendererInterface } from '../core/Renderer'
import { ThreeInterface } from '../core/useThree'
import { EffectComposerInterface } from './EffectComposer'
interface EffectSetupInterface {
renderer: RendererInterface
three: ThreeInterface
composer: EffectComposerInterface
pass?: Pass
}
export default defineComponent({
inject: ['three', 'composer'],
inject: ['renderer', 'three', 'composer'],
emits: ['ready'],
setup(): EffectSetupInterface {
const renderer = inject('renderer') as RendererInterface
const three = inject('three') as ThreeInterface
const composer = inject('composer') as EffectComposerInterface
return { three, composer }
return { renderer, three, composer }
},
created() {
if (!this.composer) {

View File

@ -2,7 +2,7 @@ import { defineComponent } from 'vue'
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js'
import { FXAAShader } from 'three/examples/jsm/shaders/FXAAShader.js'
import EffectPass from './EffectPass'
import { ThreeResizeEventInterface } from '../core/useThree'
import { SizeInterface } from '../core/useThree'
export default defineComponent({
extends: EffectPass,
@ -10,15 +10,16 @@ export default defineComponent({
const pass = new ShaderPass(FXAAShader)
// resize will be called in three init
this.three.onAfterResize(this.resize)
this.renderer.addListener('resize', this.resize)
this.initEffectPass(pass)
},
unmounted() {
this.three.offAfterResize(this.resize)
this.renderer.removeListener('resize', this.resize)
},
methods: {
resize({ size }: ThreeResizeEventInterface) {
resize({ size }: { size: SizeInterface }) {
console.log(size)
if (this.pass) {
const { resolution } = (this.pass as ShaderPass).material.uniforms
resolution.value.x = 1 / size.width