2021-03-07 20:22:54 +08:00
|
|
|
import { PerspectiveCamera } from 'three';
|
2020-09-20 00:54:50 +08:00
|
|
|
import { watch } from 'vue';
|
2021-03-07 02:22:01 +08:00
|
|
|
import { bindProp } from '../tools.js';
|
2021-03-22 21:30:25 +08:00
|
|
|
import Camera from './Camera.js';
|
2020-09-14 22:57:11 +08:00
|
|
|
|
|
|
|
export default {
|
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',
|
2020-09-14 22:57:11 +08:00
|
|
|
};
|