awv3
Version:
⚡ AWV3 embedded CAD
85 lines (73 loc) • 2.38 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _createClass from "@babel/runtime/helpers/createClass";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import * as THREE from 'three';
var CombinedCamera =
/*#__PURE__*/
function (_THREE$PerspectiveCam) {
_inheritsLoose(CombinedCamera, _THREE$PerspectiveCam);
function CombinedCamera(view, options) {
var _this;
if (options === void 0) {
options = {};
}
_this = _THREE$PerspectiveCam.call(this) || this;
options = _extends({
fov: 30,
aspect: 0,
near: 0.1,
far: 100000,
target: new THREE.Vector3(0, 0, 0),
position: new THREE.Vector3(0, 0, 1000),
up: new THREE.Vector3(0, 0, 1)
}, options);
_this.host = view;
_this.fov = options.fov;
_this.aspect = options.aspect;
_this.near = options.near;
_this.far = options.far;
_this.target = options.target;
_this.lookAt(_this.target);
_this.position.copy(options.position);
_this.up.copy(options.up);
_this.updateProjectionMatrix();
_this._orthographic = false;
_this._orthographicCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
return _this;
}
_createClass(CombinedCamera, [{
key: "display",
get: function get() {
if (this._orthographic) {
var halfTg = Math.tan(this.fov / 2 * THREE.Math.DEG2RAD);
var focusDistance = this.target.distanceTo(this.position);
var height = halfTg * focusDistance;
var camera = this._orthographicCamera;
camera.target = this.target;
camera.left = -height * this.aspect;
camera.right = height * this.aspect;
camera.top = height;
camera.bottom = -height;
camera.near = this.near;
camera.far = this.far;
camera.position.copy(this.position);
camera.up.copy(this.up);
camera.lookAt(this.target);
camera.updateProjectionMatrix();
camera.updateMatrixWorld(true);
return camera;
} else return this;
}
}, {
key: "orthographic",
get: function get() {
return this._orthographic;
},
set: function set(value) {
this._orthographic = value;
this.host.invalidate && this.host.invalidate();
}
}]);
return CombinedCamera;
}(THREE.PerspectiveCamera);
export { CombinedCamera as default };