2021-04-16 09:19:50 +08:00
|
|
|
import { defineComponent, watch } from 'vue'
|
|
|
|
import { OrthographicCamera } from 'three'
|
|
|
|
import { bindProp } from '../tools'
|
|
|
|
import Camera from './Camera'
|
2020-10-08 05:38:39 +08:00
|
|
|
|
2021-04-04 04:19:57 +08:00
|
|
|
export default defineComponent({
|
2021-03-22 21:30:25 +08:00
|
|
|
extends: Camera,
|
2021-03-07 20:22:54 +08:00
|
|
|
name: 'OrthographicCamera',
|
2020-10-08 05:38:39 +08:00
|
|
|
props: {
|
|
|
|
left: { type: Number, default: -1 },
|
|
|
|
right: { type: Number, default: 1 },
|
|
|
|
top: { type: Number, default: 1 },
|
|
|
|
bottom: { type: Number, default: -1 },
|
|
|
|
near: { type: Number, default: 0.1 },
|
|
|
|
far: { type: Number, default: 2000 },
|
|
|
|
zoom: { type: Number, default: 1 },
|
2021-04-16 09:19:50 +08:00
|
|
|
position: { type: Object, default: () => ({ x: 0, y: 0, z: 0 }) },
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
const camera = new OrthographicCamera(props.left, props.right, props.top, props.bottom, props.near, props.far)
|
|
|
|
return {
|
|
|
|
camera,
|
|
|
|
}
|
2020-10-08 05:38:39 +08:00
|
|
|
},
|
|
|
|
created() {
|
2021-03-07 18:45:25 +08:00
|
|
|
bindProp(this, 'position', this.camera);
|
2020-10-08 05:38:39 +08:00
|
|
|
|
|
|
|
['left', 'right', 'top', 'bottom', 'near', 'far', 'zoom'].forEach(p => {
|
|
|
|
watch(() => this[p], () => {
|
|
|
|
this.camera[p] = this[p];
|
2021-04-16 09:19:50 +08:00
|
|
|
this.camera.updateProjectionMatrix()
|
|
|
|
})
|
|
|
|
})
|
2020-10-08 05:38:39 +08:00
|
|
|
|
2021-04-16 09:19:50 +08:00
|
|
|
this.three.camera = this.camera
|
2020-10-08 05:38:39 +08:00
|
|
|
},
|
2021-03-07 22:14:34 +08:00
|
|
|
__hmrId: 'OrthographicCamera',
|
2021-04-16 09:19:50 +08:00
|
|
|
})
|