Top/Devel/OculusRift/Unity製DK2用アプリの起動方法

Unity製DK2用アプリの起動方法はてなブックマーク

If you want to see this page in English, goto to another page.


2015.1.10追記:Oculus SDK 0.4.4以降では下記は不要です。逆にジャダーを発生させますので、利用は推奨しません。


Unity + Oculus SDK 0.4.0でOculus Rift DK2用アプリを製作した場合、2014.08.05現在、
[Rift Display Mode]によって、"*_DirectToRift.exe"の起動オプションを次のように変える必要がある場合があるらしい。(変えない場合、アプリがクラッシュする。)


  • [Rift Display Mode]が[Direct HMD Access from Apps]の場合、起動オプションとして"-force-d3d11"を指定して起動する必要がある。
  • [Rift Display Mode]が[Extend Desktop to the HMD]の場合、起動オプションとして"-force-d3d9"を指定して起動する必要がある。


しかし、これはとても面倒。

ということで、起動スクリプトを書きました。

RunDemoスクリプト: [Rift Display Mode]を検知して"*_DirectToRift.exe"に最適な引数をつけて起動するスクリプト

こちらからダウンロードしていただけます。 "*_DirectToRift.exe"があるディレクトリに置いて、実行してください。


パブリックドメインにいたしますので、再配布や改変もご自由に。

中身はこんな感じ。

RunDemo.vbs
Option Explicit
 
' RunDemo script
'  a script for executing *_DirectToRift.exe with suitable Direct3D argument.
'  This is free and unencumbered script released into the public domain.
'
' date:   2014/08/05
' author: https://twitter.com/cubic9com
' site:   http://cubic9.com/Devel/OculusRift/HowToExecuteAppsForDK2MadeWithUnity/
 
Function IsExtendMode()
    Dim objWMIService
    Dim colItems
    Dim objItem
 
    Set objWMIService = GetObject("winmgmts:\\.\root\WMI")
    Set colItems = objWMIService.ExecQuery( _
        "Select UserFriendlyName, UserFriendlyNameLength From WmiMonitorID" _
    )
 
    For Each objItem in colItems
        If objItem.UserFriendlyNameLength > 0 then
            If BytesToString(objItem.UserFriendlyName) = "Rift DK2" Then
                IsExtendMode = True
            End If
        End If
    Next
End Function
 
Function BytesToString(ByVal bytes)
    Dim str, n
 
    str = ""
    For n = 0 To UBound(bytes)
        If CInt(bytes(n)) = 0 Then
            Exit For
        Else
            str = str & Chr(bytes(n))
        End If
    Next
 
    BytesToString = str
End Function
 
Function GetDirectToRift()
    Dim objFSO
    Dim objFolder
    Dim objFile
 
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(".")
    For Each objFile In objFolder.Files
        If InStrRev(objFile.Name, "_DirectToRift.exe") <> 0 Then
            GetDirectToRift = objFile.Name
        End If
    Next
End Function
 
Dim objShell
 
Set objShell = WScript.CreateObject("WScript.Shell")
If IsExtendMode() = True Then
    objShell.Run(GetDirectToRift() & " -force-d3d9")
Else
    objShell.Run(GetDirectToRift() & " -force-d3d11")
End If

Amazon

差分 一覧