前提・実現したいこと
unityでHTC Vive proのデュアルカメラから取得した一画面の映像のスクリーンを作成したい
発生している問題・エラーメッセージ
現在こちらのサイトを参考に、外付けカメラの映像を映し出すスクリーンの作成には成功したのですが、
右目の映像が上、左目の映像が下の縦二段組で表示されてしまいます。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class ViveCam : MonoBehaviour 6{ 7 [SerializeField] 8 private bool _undistorted = true; 9 10 [SerializeField] 11 private bool _cropped = true; 12 13 [SerializeField] 14 private bool _followTrakking = false; 15 16 [SerializeField] 17 private Transform _target; 18 19 [SerializeField] 20 private Material _material; 21 22 #region ### MonoBehaviour ### 23 private void OnEnable() 24 { 25 EnableSteamVRCamera(); 26 } 27 28 private void OnDisable() 29 { 30 DisableSteamVRCamera(); 31 } 32 33 private void Update() 34 { 35 UpdateCameraTexture(); 36 } 37 #endregion ### MonoBehaviour ### 38 39 private void UpdateCameraTexture() 40 { 41 var source = SteamVR_TrackedCamera.Source(_undistorted); 42 var texture = source.texture; 43 44 if (texture == null) 45 { 46 return; 47 } 48 49 _material.mainTexture = texture; 50 51 float aspect = (float)texture.width / texture.height; 52 53 if (_cropped) 54 { 55 var bounds = source.frameBounds; 56 _material.mainTextureOffset = new Vector2(bounds.uMin, bounds.vMin); 57 58 float du = bounds.uMax - bounds.uMin; 59 float dv = bounds.vMax - bounds.vMin; 60 61 _material.mainTextureScale = new Vector2(du, dv); 62 63 aspect *= Mathf.Abs(du / dv); 64 } 65 else 66 { 67 _material.mainTextureOffset = Vector2.zero; 68 _material.mainTextureScale = new Vector2(1f, -1f); 69 } 70 71 _target.localScale = new Vector3(1f, 1f / aspect, 1); 72 73 if (_followTrakking) 74 { 75 if (source.hasTracking) 76 { 77 var t = source.transform; 78 _target.localPosition = t.pos; 79 _target.localRotation = t.rot; 80 } 81 } 82 } 83 84 private void EnableSteamVRCamera() 85 { 86 var source = SteamVR_TrackedCamera.Source(_undistorted); 87 source.Acquire(); 88 89 // カメラが認識されていなかったらdisableにする 90 if (!source.hasCamera) 91 { 92 enabled = false; 93 } 94 } 95 96 private void DisableSteamVRCamera() 97 { 98 _material.mainTexture = null; 99 100 var source = SteamVR_TrackedCamera.Source(_undistorted); 101 source.Release(); 102 } 103}
試したこと
ViveSRのSDKが参考になるかと思い導入しましたが、SampleSceneが起動しないため(付属pdfファイル参照の上再起動etcも試しました)断念しました。
補足情報(FW/ツールのバージョンなど)
OS:Windows10
CPU:Intel i7-8700K
メモリ:16GB
GPU:GeForce GTX 1080
HTC VIVE pro
unity 2018.2.18f1
当方unity、HTC vive proともに初心者です。
よろしくお願いいたします。
あなたの回答
tips
プレビュー