1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/core/PerspectiveCamera.js

47 lines
963 B
JavaScript
Raw Normal View History

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-09-19 23:52:02 +08:00
aspect: {
type: Number,
default: 1,
},
far: {
type: Number,
default: 2000,
},
2020-09-14 22:57:11 +08:00
fov: {
type: Number,
default: 50,
},
2020-09-19 23:52:02 +08:00
near: {
type: Number,
default: 0.1,
},
2020-09-18 22:28:17 +08:00
position: {
type: [Object, Vector3],
default: { x: 0, y: 0, z: 0 },
},
},
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);
['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
},
render() {
return [];
},
2020-09-19 22:40:58 +08:00
__hmrId: 'PerspectiveCamera',
2020-09-14 22:57:11 +08:00
};