2020-09-18 22:28:17 +08:00
|
|
|
import { PerspectiveCamera, Vector3 } from 'three';
|
2020-09-20 00:54:50 +08:00
|
|
|
import { watch } from 'vue';
|
2020-09-19 23:52:02 +08:00
|
|
|
import useBindProp from '../use/useBindProp.js';
|
2020-09-14 22:57:11 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
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 },
|
|
|
|
position: { type: [Object, Vector3], default: { x: 0, y: 0, z: 0 } },
|
2021-03-05 16:10:20 +08:00
|
|
|
lookAt: { type: [Object, Vector3], 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);
|
|
|
|
useBindProp(this, 'position', this.camera.position);
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-05 16:10:20 +08:00
|
|
|
// this.camera.updateProjectionMatrix();
|
2020-09-18 22:28:17 +08:00
|
|
|
this.three.camera = this.camera;
|
2020-09-14 22:57:11 +08:00
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return [];
|
|
|
|
},
|
2020-09-19 22:40:58 +08:00
|
|
|
__hmrId: 'PerspectiveCamera',
|
2020-09-14 22:57:11 +08:00
|
|
|
};
|