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

View File

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