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

wip: camera

This commit is contained in:
Kevin Levron 2021-04-19 01:53:25 +02:00
parent b073f738b2
commit f81c9a6996
3 changed files with 19 additions and 5 deletions

View File

@ -1,11 +1,20 @@
import { defineComponent } from 'vue' import { Camera } from 'three'
// import Object3D from '../core/Object3D' import { defineComponent, inject } from 'vue'
// import Object3D from './Object3D'
interface ThreeInterface {
camera?: Camera
}
export default defineComponent({ export default defineComponent({
// TODO: eventually extend Object3D, for now: error 'injection "scene" not found' // TODO: eventually extend Object3D
// because camera is a sibling of scene in Trois
// extends: Object3D, // extends: Object3D,
inject: ['three'], // inject: ['three'], // don't work with typescript, bug ?
setup() {
// this works in sub component ??
const three = inject('three') as ThreeInterface
return { three }
},
render() { render() {
return this.$slots.default ? this.$slots.default() : [] return this.$slots.default ? this.$slots.default() : []
}, },

View File

@ -6,6 +6,7 @@ import Camera from './Camera'
export default defineComponent({ export default defineComponent({
extends: Camera, extends: Camera,
name: 'OrthographicCamera', name: 'OrthographicCamera',
inject: ['three'],
props: { props: {
left: { type: Number, default: -1 }, left: { type: Number, default: -1 },
right: { type: Number, default: 1 }, right: { type: Number, default: 1 },
@ -23,7 +24,9 @@ export default defineComponent({
const watchProps = ['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom'] const watchProps = ['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom']
watchProps.forEach(p => { watchProps.forEach(p => {
// @ts-ignore
watch(() => props[p], (value) => { watch(() => props[p], (value) => {
// @ts-ignore
camera[p] = value camera[p] = value
camera.updateProjectionMatrix() camera.updateProjectionMatrix()
}) })

View File

@ -26,7 +26,9 @@ export default defineComponent({
const watchProps = ['aspect', 'far', 'fov', 'near'] const watchProps = ['aspect', 'far', 'fov', 'near']
watchProps.forEach(p => { watchProps.forEach(p => {
// @ts-ignore
watch(() => props[p], (value) => { watch(() => props[p], (value) => {
// @ts-ignore
camera[p] = value camera[p] = value
camera.updateProjectionMatrix() camera.updateProjectionMatrix()
}) })