2021-04-04 04:19:57 +08:00
|
|
|
import { defineComponent, watch } from 'vue';
|
2021-03-07 20:22:54 +08:00
|
|
|
import { PerspectiveCamera } from 'three';
|
2021-03-25 21:24:30 +08:00
|
|
|
import { bindProp } from '../tools';
|
2021-03-22 21:30:25 +08:00
|
|
|
import Camera from './Camera.js';
|
2020-09-14 22:57:11 +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: 'PerspectiveCamera',
|
2020-09-14 22:57:11 +08:00
|
|
|
inject: ['three'],
|
|
|
|
props: {
|
2020-10-08 05:38:39 +08:00
|
|
|
aspect: { type: Number, default: 1 },
|
|
|
|
far: { type: Number, default: 2000 },
|
|
|
|
fov: { type: Number, default: 50 },
|
|
|
|
near: { type: Number, default: 0.1 },
|
2021-03-07 18:45:25 +08:00
|
|
|
position: { type: Object, default: { x: 0, y: 0, z: 0 } },
|
|
|
|
lookAt: { type: Object, default: null },
|
2020-09-18 22:28:17 +08:00
|
|
|
},
|
2020-09-14 22:57:11 +08:00
|
|
|
created() {
|
2020-09-19 23:52:02 +08:00
|
|
|
this.camera = new PerspectiveCamera(this.fov, this.aspect, this.near, this.far);
|
2021-03-07 18:45:25 +08:00
|
|
|
bindProp(this, 'position', this.camera);
|
2020-09-19 23:52:02 +08:00
|
|
|
|
2021-03-05 16:10:20 +08:00
|
|
|
if (this.lookAt) this.camera.lookAt(this.lookAt.x, this.lookAt.y, this.lookAt.z);
|
|
|
|
watch(() => this.lookAt, (v) => { this.camera.lookAt(v.x, v.y, v.z); }, { deep: true });
|
|
|
|
|
2020-09-19 23:52:02 +08:00
|
|
|
['aspect', 'far', 'fov', 'near'].forEach(p => {
|
|
|
|
watch(() => this[p], () => {
|
|
|
|
this.camera[p] = this[p];
|
|
|
|
this.camera.updateProjectionMatrix();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-18 22:28:17 +08:00
|
|
|
this.three.camera = this.camera;
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
2021-03-07 22:14:34 +08:00
|
|
|
__hmrId: 'PerspectiveCamera',
|
2021-04-04 04:19:57 +08:00
|
|
|
});
|