EN

# 四、接口说明

# 4.1 注视点渲染

注视点相关API,在Utils类中有如下两个方法:

  • 设置注视点等级
  /// <summary>
        /// 设置注释点渲染等级
        /// </summary>
        /// <param name="level">-1关闭,0-2分别是低中高三个等级</param>
        public static void SetFoveationLevel(int level)
        {
            NativeMethods.SetFoveationLevel(level);
        }
  • 设置注视点参数
 /// 设置注释点渲染参数
        /// </summary>
        /// <param name="foveationGainX">水平方向外围像素的缩减率,值越大缩减的越多</param>
        /// <param name="foveationGainY">竖直方向外围像素的缩减率</param>
        /// <param name="foveationArea">注视点周围分辨率不降范围,值越大,中心不缩减区域越大</param>
        /// <param name="foveationMinimum">默认最小像素密度</param>
        public static void SetFoveationParameters(float foveationGainX, float foveationGainY, float foveationArea, float foveationMinimum)
        {
            NativeMethods.SetFoveationParameters(foveationGainX, foveationGainY, foveationArea, foveationMinimum);
        }

# 4.2 Boundary APIs

# 4.2.1 UnityXR

UnityXR提供了以下接口:

  • 获取围栏点数据
UnityEngine.XR.InputDevices.GetDeviceAtXRNode(UnityEngine.XR.XRNode.Head).subsystem.TryGetBoundaryPoints(List<Vector3> boundaryPoints)
  • 围栏改变监听事件
UnityEngine.XR.InputDevices.GetDeviceAtXRNode(UnityEngine.XR.XRNode.Head).subsystem.boundaryChanged

# 4.2.2 QIYU

对于UnityXR未提供的接口,QiyuBoundary类开放了更多功能的接口,供开发者使用。

  • 获取围栏是否是自定义围栏
public static bool GetConfigured()
  • 测试围栏中的Node结果
public static BoundaryTestResult TestNode(Node node)
  • 测试围栏中的Point结果
public static QiyuBoundary.BoundaryTestResult TestPoint(Vector3 point)
  • 获取所有围栏点集
public static Vector3[] GetGeometry()
  • 获取围栏尺寸范围
public static Vector3 GetDimensions()
  • 获取围栏是否可见
public static bool GetVisible()
  • 设置围栏常驻显示(系统设置中的围栏开关会覆盖此接口)
public static void SetVisible(bool value)

# 4.3 设备

SDK提供设备信息接口,用于获取设备厂商、名称、唯一码等信息。开发者可使用UnityXR标准接口或奇遇接口GetDeviceInfo()。

设备 奇遇3 奇遇Dream 奇遇Dream Pro 奇遇 MIX
厂商 Dreamagic Dreamagic Dreamagic Dreamagic
头显 QiyuHMD-3 QiyuHMD-Dream QiyuHMD-DreamPro QiyuHMD-MIX
左手柄 Qiyu Controller-Left-3 Qiyu Controller-Left-Dream Qiyu Controller-Left-Dream Qiyu Controller-Left-MIX
右手柄 Qiyu Controller-Right-3 Qiyu Controller-Right-Dream Qiyu Controller-Right-Dream Qiyu Controller-Right-MIX
  • XR.InputDevice(https://docs.unity.cn/cn/2020.3/ScriptReference/XR.InputDevice.html (opens new window)

  • Unity.XR.Qiyu.QiyuXRCore.GetDeviceInfo()

    返回如下结构:

    public struct QiyuDeviceInfo
            {
                public string Name_HMD;//头显名称
                public string Name_CtrL;//左手柄名称
                public string Name_CtrR;//右手柄名称
                public string Manufacturer;//厂商
                public string SN_HMD;//头显SN号
                public string SN_CtrL;//左手柄SN号(目前为空)
                public string SN_CtrR;//右手柄SN号(目前为空)
            };
    

注:以上内容可以参考Sample里的ButtonTest场景。

# 4.4 奇遇3Dof模式

 /// <summary>
        /// 设置3dof模式,1:3dof,0:6dof
        /// </summary>
        /// <returns></returns>
        public static void SetAppTrackingMode(int mode)
        {
            if (!QiyuPlatform.IsAndroid)
                return;

            QiyuXRCorePlugin.QVR_SetAppTrackingMode(mode);
        }

# 4.5 屏幕刷新率

屏幕刷新率代表VR设备屏幕每秒刷新次数。刷新率越高,可以支持应用实现更高的帧率、更稳定的追踪和更高的清晰度。奇遇设备上应用默认刷新率为72,即开发者在不设置或者修改刷新率时,应用以72Hz刷新屏幕。如果您想以更高刷新率运行应用,可通过下面的接口设置刷新率。需要注意的是,高刷新率要求应用每帧所消耗的时间更低,应用需确保运行期间的性能,稳定的维持高刷新率,否则可能无法通过奇遇商店的上线审核。奇遇各型号设备支持的刷新率情况如下:

设备型号 支持的刷新率
奇遇 MIX 72Hz、90Hz
奇遇 DreamPro 72Hz、90Hz
奇遇 Dream 72Hz
奇遇 3 72Hz
  • 设置屏幕刷新率(QiyuXRCore.TrySetDisplayRefreshRate)
///<summary>
///设置屏幕刷新率
///</summary>
///<paramname="refreshRate">刷新率</param>
///<returns></returns>
publicstaticboolTrySetDisplayRefreshRate(floatrefreshRate)
{
if(!QiyuPlatform.IsAndroid)
returnfalse;
returnQiyuXRCorePlugin.QVR_SetDisplayRefreshRate(refreshRate);
}
  • 获取屏幕刷新率(QiyuXRCore.TryGetDisplayRefreshRate)
///<summary>
///获取屏幕刷新率
///</summary>
///<paramname="refreshRate">返回值</param>
///<returns></returns>
publicstaticboolTryGetDisplayRefreshRate(outfloatrefreshRate)
{
if(!QiyuPlatform.IsAndroid)
{
refreshRate=72;
returntrue;
}
floatrate=0;
if(QiyuXRCorePlugin.QVR_GetDisplayRefreshRate(refrate))
{
refreshRate=rate;
returntrue;
}
else
{
refreshRate=rate;
returnfalse;
}
}
  • 获取可用刷新率列表(QiyuXRCore.TryGetAvailableDisplayRefreshRates)
///<summary>
///获取可用刷新率列表
///</summary>
///<paramname="refreshRates">返回列表</param>
///<returns></returns>
publicstaticboolTryGetAvailableDisplayRefreshRates(outfloat[]refreshRates)
{
if(!QiyuPlatform.IsAndroid)
{
refreshRates=newfloat[]{72,90};
returntrue;
}
intcount=0;
QiyuXRCorePlugin.QVR_GetAvailableDisplayRefreshRates(IntPtr.Zero,refcount);
if(count>0)
{
if(cachedRefreshRatesBuffer.GetCapacity()<count)
cachedRefreshRatesBuffer.Reset(count);
if(cachedRefreshRatesManagedBuffer.Length<count)
cachedRefreshRatesManagedBuffer=newfloat[count];
QiyuXRCorePlugin.QVR_GetAvailableDisplayRefreshRates(cachedRefreshRatesBuffer.GetPointer(),ref
count);
Marshal.Copy(cachedRefreshRatesBuffer.GetPointer(),cachedRefreshRatesManagedBuffer,
0,count);
refreshRates=newfloat[count];
for(inti=0;i<count;i++)
{
refreshRates[i]=cachedRefreshRatesManagedBuffer[i];
}
returntrue;
}
else
{
refreshRates=newfloat[0];
returnfalse;
}
}

# 4.6 Passthrough

  • 获取Passthrough 能力

    public static PassthroughCapabilities GetPassthroughCapabilities()
            {
                if (!QiyuPlatform.IsAndroid)
                    return PassthroughCapabilities.NotSupport;
    
                return (PassthroughCapabilities)QiyuXRCorePlugin.QVR_GetPassthroughCapabilities();
            }
    
            public enum PassthroughCapabilities : int
            {
                NotSupport = 0,//不支持passthrough
                Mono = 1,//支持黑白passthrough
                Color = 2//支持彩色passthrough
            }
    
  • 开启/关闭Passthrough背景

    public static void EnableSeeThrough(bool visible)
            {
                if (QiyuPlatform.IsAndroid)
                {
                    QiyuXRCorePlugin.QVR_EnableSeeThrough(visible);
                }
    }
    
  • 开启/关闭Passthrough背景回调函数的注册和反注册:

    public static void RegisterSeeThroughCallback(Action<int> callback)
            {
                if (seethrough_callback == null)
                {
                    seethrough_callback = callback;
                    if (QiyuPlatform.IsAndroid)
                    {
                        SeeThroughCallBack callback_delegate = OnSeeThroughChanged;
                        QiyuXRCorePlugin.QVR_SetSeeThroughCallback(Marshal.GetFunctionPointerForDelegate(callback_delegate));
                    }
                }
                else
                {
                    seethrough_callback += callback;
                    UnityEngine.Debug.Log("User RegisterSeeThroughCallback!");
                }
            }
    
            public static void UnRegisterSeeThroughCallback(Action<int> callback)
            {
                if (seethrough_callback != null)
                {
                    seethrough_callback -= callback;
                    UnityEngine.Debug.Log("User UnRegisterSeeThroughCallback!");
                }
            }
    
  • 调用示例:

            var deviceInfo = Unity.XR.Qiyu.QiyuXRCore.GetDeviceInfo();
            if (deviceInfo.Name_HMD != "QiyuHMD-3" && deviceInfo.Name_HMD != "QiyuHMD-Dream" && deviceInfo.Name_HMD != "QiyuHMD-Dream Pro")
            {
                //passthrough现阶段只支持MIX及以后新机型,需要排除老机型后开启,否则开启后是黑的。
                QiyuSeeThrough.EnableSeeThrough(true);
            }