Top/Devel/OculusRift/HowToExecuteAppsForDK2MadeWithUnity

HowToExecuteAppsForDK2MadeWithUnityはてなブックマーク

日本語ページはこちら


EDIT2015.1.10: It's no longer necessary under Oculus SDK 0.4.4.


You may be irritated by Apps made with Unity + Oculus SDK 0.4.0.

Because it may crash if you run it without adding suitable Direct3D option.

  • If you use DK2 with [Direct HMD Access from Apps] mode, you should add "-force-d3d11".
  • If you use DK2 with [Extend Desktop to the HMD] mode, you should add "-force-d3d9".


But It's a bother.

So I wrote a script.

RunDemo Script: a script for executing *_DirectToRift.exe with suitable Direct3D argument.


Inside a script.

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

差分 一覧