|
@@ -1,142 +1,138 @@
|
|
|
export default class XCameraComponent {
|
|
|
- constructor(e, t, r) {
|
|
|
- E(this, "maincameraRotLimitObserver", null);
|
|
|
- E(this, "mainCamera");
|
|
|
- E(this, "cgCamera");
|
|
|
- E(this, "saveCameraPose");
|
|
|
- E(this, "_cameraPose");
|
|
|
- E(this, "scene");
|
|
|
- E(this, "canvas");
|
|
|
- E(this, "yuvInfo");
|
|
|
- E(this, "forceKeepVertical", !1);
|
|
|
- E(this, "initCamera", e=>{
|
|
|
- const {maxZ: t=1e4, minZ: r=.1, angularSensibility: n=2e3} = e;
|
|
|
- this.mainCamera = new BABYLON.FreeCamera("camera_main",new BABYLON.Vector3(0,0,1),this.scene),
|
|
|
- this.mainCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
|
|
|
- this.mainCamera.speed = .1,
|
|
|
- this.mainCamera.angularSensibility = n,
|
|
|
- this.mainCamera.setTarget(new BABYLON.Vector3(0,0,0)),
|
|
|
- this.mainCamera.minZ = r,
|
|
|
- this.mainCamera.fov = Math.PI * this.yuvInfo.fov / 180,
|
|
|
- this.mainCamera.maxZ = t,
|
|
|
- this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
- this.cgCamera = new BABYLON.FreeCamera("camera_temp",new BABYLON.Vector3(0,1e3,0),this.scene),
|
|
|
- this.cgCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
|
|
|
- this.cgCamera.speed = .1,
|
|
|
- this.cgCamera.setTarget(new BABYLON.Vector3(0,1010,0)),
|
|
|
- this.cgCamera.maxZ = t,
|
|
|
- this.cgCamera.minZ = r,
|
|
|
- this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
- this.cameraFovChange(this.yuvInfo)
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "cameraFovChange", e=>{
|
|
|
- this.yuvInfo = e;
|
|
|
- const t = e.width
|
|
|
- , r = e.height
|
|
|
- , n = this.canvas.width
|
|
|
- , o = this.canvas.height
|
|
|
- , a = e.fov;
|
|
|
- if (this.forceKeepVertical == !0) {
|
|
|
- const s = t / (2 * Math.tan(Math.PI * a / 360))
|
|
|
- , l = 2 * Math.atan(r / (2 * s));
|
|
|
- this.mainCamera.fov = l,
|
|
|
- this.cgCamera.fov = l,
|
|
|
- this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED,
|
|
|
- this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED
|
|
|
- } else if (this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
- this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
- n / o < t / r && this.mainCamera.fov) {
|
|
|
- const s = o
|
|
|
- , l = n
|
|
|
- , u = s * t / r / (2 * Math.tan(a * Math.PI / 360))
|
|
|
- , c = 2 * Math.atan(l / (2 * u));
|
|
|
- this.mainCamera.fov = c,
|
|
|
- this.cgCamera.fov = c
|
|
|
- } else
|
|
|
- this.mainCamera.fov = Math.PI * a / 180,
|
|
|
- this.cgCamera.fov = Math.PI * a / 180
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "setCameraPose", e=>{
|
|
|
- var n;
|
|
|
- const t = ue4Position2Xverse(e.position);
|
|
|
- let r = null;
|
|
|
- e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)),
|
|
|
- this._cameraPose = {
|
|
|
- position: t
|
|
|
- },
|
|
|
- r != null && (this._cameraPose.rotation = r),
|
|
|
- this.scene.activeCamera === this.mainCamera && !((n = this.mainCamera) != null && n.isDisposed()) && this._setCamPositionRotation(this.mainCamera, this._cameraPose)
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "_setCamPositionRotation", (e,t)=>{
|
|
|
- var r, n;
|
|
|
- t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()),
|
|
|
- t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone())
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "switchCamera", e=>{
|
|
|
- var t;
|
|
|
- (t = this.scene.activeCamera) == null || t.detachControl(this.canvas),
|
|
|
- this.scene.activeCamera = e
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "reCalXYZRot", (e,t)=>(e = e % (2 * Math.PI),
|
|
|
+ constructor(canvas, scene, r) {
|
|
|
+ this.maincameraRotLimitObserver = null
|
|
|
+ this.mainCamera
|
|
|
+ this.cgCamera
|
|
|
+ this.saveCameraPose
|
|
|
+ this._cameraPose
|
|
|
+ this.forceKeepVertical = !1
|
|
|
+
|
|
|
+ this.scene = scene,
|
|
|
+ this.canvas = canvas,
|
|
|
+ this.yuvInfo = r.yuvInfo,
|
|
|
+ r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical),
|
|
|
+ this.initCamera(r.cameraParam)
|
|
|
+ }
|
|
|
+
|
|
|
+ initCamera = cameraParam=>{
|
|
|
+ const {maxZ: t=1e4, minZ: r=.1, angularSensibility: n=2e3} = cameraParam;
|
|
|
+ this.mainCamera = new BABYLON.FreeCamera("camera_main",new BABYLON.Vector3(0,0,1),this.scene),
|
|
|
+ this.mainCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
|
|
|
+ this.mainCamera.speed = .1,
|
|
|
+ this.mainCamera.angularSensibility = n,
|
|
|
+ this.mainCamera.setTarget(new BABYLON.Vector3(0,0,0)),
|
|
|
+ this.mainCamera.minZ = r,
|
|
|
+ this.mainCamera.fov = Math.PI * this.yuvInfo.fov / 180,
|
|
|
+ this.mainCamera.maxZ = t,
|
|
|
+ this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
+ this.cgCamera = new BABYLON.FreeCamera("camera_temp",new BABYLON.Vector3(0,1e3,0),this.scene),
|
|
|
+ this.cgCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA,
|
|
|
+ this.cgCamera.speed = .1,
|
|
|
+ this.cgCamera.setTarget(new BABYLON.Vector3(0,1010,0)),
|
|
|
+ this.cgCamera.maxZ = t,
|
|
|
+ this.cgCamera.minZ = r,
|
|
|
+ this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
+ this.cameraFovChange(this.yuvInfo)
|
|
|
+ }
|
|
|
+ cameraFovChange = e=>{
|
|
|
+ this.yuvInfo = e;
|
|
|
+ const t = e.width
|
|
|
+ , r = e.height
|
|
|
+ , n = this.canvas.width
|
|
|
+ , o = this.canvas.height
|
|
|
+ , a = e.fov;
|
|
|
+ if (this.forceKeepVertical == !0) {
|
|
|
+ const s = t / (2 * Math.tan(Math.PI * a / 360))
|
|
|
+ , l = 2 * Math.atan(r / (2 * s));
|
|
|
+ this.mainCamera.fov = l,
|
|
|
+ this.cgCamera.fov = l,
|
|
|
+ this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED,
|
|
|
+ this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED
|
|
|
+ } else if (this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
+ this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED,
|
|
|
+ n / o < t / r && this.mainCamera.fov) {
|
|
|
+ const s = o
|
|
|
+ , l = n
|
|
|
+ , u = s * t / r / (2 * Math.tan(a * Math.PI / 360))
|
|
|
+ , c = 2 * Math.atan(l / (2 * u));
|
|
|
+ this.mainCamera.fov = c,
|
|
|
+ this.cgCamera.fov = c
|
|
|
+ } else
|
|
|
+ this.mainCamera.fov = Math.PI * a / 180,
|
|
|
+ this.cgCamera.fov = Math.PI * a / 180
|
|
|
+ }
|
|
|
+ setCameraPose = e=>{
|
|
|
+ var n;
|
|
|
+ const t = ue4Position2Xverse(e.position);
|
|
|
+ let r = null;
|
|
|
+ e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)),
|
|
|
+ this._cameraPose = {
|
|
|
+ position: t
|
|
|
+ },
|
|
|
+ r != null && (this._cameraPose.rotation = r),
|
|
|
+ this.scene.activeCamera === this.mainCamera && !((n = this.mainCamera) != null && n.isDisposed()) && this._setCamPositionRotation(this.mainCamera, this._cameraPose)
|
|
|
+ }
|
|
|
+ _setCamPositionRotation = (e,t)=>{
|
|
|
+ var r, n;
|
|
|
+ t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()),
|
|
|
+ t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone())
|
|
|
+ }
|
|
|
+ switchCamera = e=>{
|
|
|
+ var t;
|
|
|
+ (t = this.scene.activeCamera) == null || t.detachControl(this.canvas),
|
|
|
+ this.scene.activeCamera = e
|
|
|
+ }
|
|
|
+ reCalXYZRot = (e,t)=>(
|
|
|
+ e = e % (2 * Math.PI),
|
|
|
Math.abs(t - e) >= Math.PI && (e = e - 2 * Math.PI),
|
|
|
- e));
|
|
|
- E(this, "_moveCam", (e,t,r,n,o,a,s,l)=>{
|
|
|
- const u = (v,y,b)=>(v.x = this.reCalXYZRot(v.x, y.x),
|
|
|
- v.y = this.reCalXYZRot(v.y, y.y),
|
|
|
- v.z = this.reCalXYZRot(v.z, y.z),
|
|
|
- new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z))
|
|
|
- , c = function(v, y, b) {
|
|
|
- return new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z)
|
|
|
- }
|
|
|
- , h = new Animation("myAnimation1","position",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
|
|
|
- let f = []
|
|
|
- , d = t
|
|
|
- , _ = r;
|
|
|
- for (let v = 0; v < a; ++v)
|
|
|
- f.push({
|
|
|
- frame: v,
|
|
|
- value: c(d, _, v / a)
|
|
|
- });
|
|
|
+ e
|
|
|
+ )
|
|
|
+ _moveCam = (e,t,r,n,o,a,s,l)=>{
|
|
|
+ const u = (v,y,b)=>(v.x = this.reCalXYZRot(v.x, y.x),
|
|
|
+ v.y = this.reCalXYZRot(v.y, y.y),
|
|
|
+ v.z = this.reCalXYZRot(v.z, y.z),
|
|
|
+ new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z))
|
|
|
+ , c = function(v, y, b) {
|
|
|
+ return new BABYLON.Vector3((y.x - v.x) * b + v.x,(y.y - v.y) * b + v.y,(y.z - v.z) * b + v.z)
|
|
|
+ }
|
|
|
+ , h = new Animation("myAnimation1","position",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
|
|
|
+ let f = []
|
|
|
+ , d = t
|
|
|
+ , _ = r;
|
|
|
+ for (let v = 0; v < a; ++v)
|
|
|
f.push({
|
|
|
- frame: f.length,
|
|
|
- value: c(d, _, 1)
|
|
|
- }),
|
|
|
- h.setKeys(f);
|
|
|
- const g = new Animation("myAnimation2","rotation",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
|
|
|
- f = [],
|
|
|
- d = n,
|
|
|
- _ = o;
|
|
|
- for (let v = 0; v < a; ++v)
|
|
|
- f.push({
|
|
|
- frame: v,
|
|
|
- value: u(d, _, v / a)
|
|
|
- });
|
|
|
+ frame: v,
|
|
|
+ value: c(d, _, v / a)
|
|
|
+ });
|
|
|
+ f.push({
|
|
|
+ frame: f.length,
|
|
|
+ value: c(d, _, 1)
|
|
|
+ }),
|
|
|
+ h.setKeys(f);
|
|
|
+ const g = new Animation("myAnimation2","rotation",s,Animation.ANIMATIONTYPE_VECTOR3,Animation.ANIMATIONLOOPMODE_CONSTANT);
|
|
|
+ f = [],
|
|
|
+ d = n,
|
|
|
+ _ = o;
|
|
|
+ for (let v = 0; v < a; ++v)
|
|
|
f.push({
|
|
|
- frame: f.length,
|
|
|
- value: u(d, _, 1)
|
|
|
- }),
|
|
|
- g.setKeys(f),
|
|
|
- e.animations.push(g),
|
|
|
- e.animations.push(h);
|
|
|
- const m = this.scene.beginAnimation(e, 0, a, !1);
|
|
|
- m.onAnimationEnd = ()=>{
|
|
|
- l(),
|
|
|
- m.stop(),
|
|
|
- m.animationStarted = !1
|
|
|
- }
|
|
|
+ frame: v,
|
|
|
+ value: u(d, _, v / a)
|
|
|
+ });
|
|
|
+ f.push({
|
|
|
+ frame: f.length,
|
|
|
+ value: u(d, _, 1)
|
|
|
+ }),
|
|
|
+ g.setKeys(f),
|
|
|
+ e.animations.push(g),
|
|
|
+ e.animations.push(h);
|
|
|
+ const m = this.scene.beginAnimation(e, 0, a, !1);
|
|
|
+ m.onAnimationEnd = ()=>{
|
|
|
+ l(),
|
|
|
+ m.stop(),
|
|
|
+ m.animationStarted = !1
|
|
|
}
|
|
|
- );
|
|
|
- this.scene = t,
|
|
|
- this.canvas = e,
|
|
|
- this.yuvInfo = r.yuvInfo,
|
|
|
- r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical),
|
|
|
- this.initCamera(r.cameraParam)
|
|
|
}
|
|
|
+
|
|
|
get MainCamera() {
|
|
|
return this.mainCamera
|
|
|
}
|