2020-10-08 05:38:39 +08:00
|
|
|
import { OrthographicCamera, Vector3 } from 'three';
|
|
|
|
import { watch } from 'vue';
|
2021-03-07 02:22:01 +08:00
|
|
|
import { bindProp } from '../tools.js';
|
2020-10-08 05:38:39 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
inject: ['three'],
|
|
|
|
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 },
|
|
|
|
position: { type: [Object, Vector3], default: { x: 0, y: 0, z: 0 } },
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.camera = new OrthographicCamera(this.left, this.right, this.top, this.bottom, this.near, this.far);
|
2021-03-07 02:22:01 +08:00
|
|
|
bindProp(this, 'position', this.camera.position);
|
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];
|
|
|
|
this.camera.updateProjectionMatrix();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.three.camera = this.camera;
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
__hmrId: 'OrthographicCamera',
|
|
|
|
};
|