Help us understand the problem. What is going on with this article?

Vive Stereo Rendering Toolkit(MirrorExample)をUnity2019+SteamVR Plugin2.3.2で動かすまで

More than 1 year has passed since last update.

最初に

VRChat等で見かけるリアルな鏡が含まれているアセットですが、最新の環境で動かすのにひと手間必要だったのでメモしておきます。Vive Stereo Rendering Toolkitのアップデートは2018年1月から行われておらず、Unity 2019で使用する為には数か所変更が必要になります。その為か分かりませんが、エディタからの再生テストにおいて稀にエラーを吐きます。現時点では、ビルド環境において実行中のエラーは確認しておりません。

開発環境

Oculus Rift CV1
Unity 2019.1.9f1 Personal

使用アセット

Vive Stereo Rendering Toolkit
https://assetstore.unity.com/packages/tools/particles-effects/vive-stereo-rendering-toolkit-71255
SteamVR Plugin
https://assetstore.unity.com/packages/tools/integration/steamvr-plugin-32647

手順

空のプロジェクトを作成、上記アセットを導入。
1. StereoRendering>Examples>2.Mirror>MirrorExampleを開く。
2. 以下、二つのスクリプトに対して、一部をコメントアウト・追記する。

DeviceType.cs
//43~68行を以下の通りにコメントアウト

        public static IDeviceParamFactory InitParamFactory(HmdType hmdType)
        {
// #if (VIVE_STEREO_STEAMVR)
//             if (hmdType == HmdType.SteamVR)
//             {
                return new SteamVRParamFactory();
//             }
// #endif

// #if (VIVE_STEREO_OVR)
//             if (hmdType == HmdType.OVR)
//             {
//                 return new OVRParamFactory();
//             }
// #endif

// #if (UNITY_ANDROID && VIVE_STEREO_WAVEVR)
//             if (hmdType == HmdType.WaveVR)
//             {
//                 return new WaveVRParamFactory();
//             }
// #endif

//             Debug.LogError("Cannot get suitable projection parameter for current HMD.");
//             return null;
        }
SteamVRParamFactory.cs
//2行目 追記 using Valve.VR;
//ディレクティブをコメントアウト

//========= Copyright 2016-2017, HTC Corporation. All rights reserved. ===========
using UnityEngine;
using Valve.VR;

namespace HTC.UnityPlugin.StereoRendering
{
// #if (VIVE_STEREO_STEAMVR)
    public class SteamVRParamFactory : IDeviceParamFactory
    {
        public int GetRenderWidth()
        {
            return (int)SteamVR.instance.sceneWidth;
        }

        public int GetRenderHeight()
        {
            return (int)SteamVR.instance.sceneHeight;
        }

        public Vector3 GetEyeSeperation(int eye)
        {
            var eyePos = SteamVR.instance.eyes[eye].pos;
            eyePos.z = 0.0f;
            return eyePos;
        }

        public Quaternion GetEyeLocalRotation(int eye)
        {
            return SteamVR.instance.eyes[eye].rot;
        }

        public Matrix4x4 GetProjectionMatrix(int eye, float nearPlane, float farPlane)
        {
            return HMDMatrix4x4ToMatrix4x4(SteamVR.instance.hmd.GetProjectionMatrix((Valve.VR.EVREye)eye, nearPlane, farPlane));
        }

        // transform a SteamVR matrix format to Unity matrix format
        private Matrix4x4 HMDMatrix4x4ToMatrix4x4(Valve.VR.HmdMatrix44_t hmdMatrix)
        {
            Matrix4x4 m = Matrix4x4.identity;

            m[0, 0] = hmdMatrix.m0;
            m[0, 1] = hmdMatrix.m1;
            m[0, 2] = hmdMatrix.m2;
            m[0, 3] = hmdMatrix.m3;

            m[1, 0] = hmdMatrix.m4;
            m[1, 1] = hmdMatrix.m5;
            m[1, 2] = hmdMatrix.m6;
            m[1, 3] = hmdMatrix.m7;

            m[2, 0] = hmdMatrix.m8;
            m[2, 1] = hmdMatrix.m9;
            m[2, 2] = hmdMatrix.m10;
            m[2, 3] = hmdMatrix.m11;

            m[3, 0] = hmdMatrix.m12;
            m[3, 1] = hmdMatrix.m13;
            m[3, 2] = hmdMatrix.m14;
            m[3, 3] = hmdMatrix.m15;

            return m;
        }
    }
// #endif
}

動作確認

こんな感じに動きます。プロジェクトに組み込む場合は、サンプルのパラメータを参考にして設置しましょう。
mirrorimage.gif

参考リンク

Vive Stereo Rendering Toolkit
https://github.com/ViveSoftware/ViveStereoRenderingToolkit
Vive Stereo Rendering Prototypes -- License
https://github.com/ViveSoftware/ViveStereoRenderingToolkit/blob/master/license.md

Sesleria
Unity(VR開発)に興味があります。 BOOTHでOculus RiftやOculus Questアプリとか配布しています。 https://sesleria.booth.pm/
https://sesleria.hatenadiary.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした