鸟语天空
影创AR眼镜
post by:追风剑情 2020-10-15 17:45

影创科技-官方网站
影创科技-开放平台
影创科技-ActionOne文档
第二代影创眼镜系统(HONGHU,鸿鹄系统)升级包下载
第二代影创眼镜SDK下载
第二代影创眼镜在线文档
第二代影创眼镜在线文档(Tesseract_Module_Vuforia_Example)

Action One
分辨率 2560x960(8:3) 垂直刷新率: 75赫兹

1111.png

导入SDK

1111.png

遇到的坑

1、需要处理交互事件的UI组件需要添加BoxCollider

2、动态创建GameObject时,一定要重置新对象的scale和z坐标,否则新对象的这两个值会变得很大,导致无法在眼镜里看到创建出来的新对象

示例代码

GameObject go = Instantiate<GameObject>(templet);
go.transform.SetParent(xxx);
//注意: 一定要对缩放和z坐标进行重置,否则这两个值会变得很大,无法在影创眼镜里看到创建出来的对象。
go.transform.localScale = scale;//重置此值与templet的scale保持一致
go.transform.localRotation = Quaternion.identity;
RectTransform rt = go.GetComponent<RectTransform>();
Vector3 pos = rt.anchoredPosition3D;
pos.z = posZ;//重置此值与templet的z坐标保持一致
rt.anchoredPosition3D = pos;
go.SetActive(true);

3、影创SDK在Unity2017、Unity2019中才支持高通(Vuforia)插件

4、SDK3.0.1需要在Unity2019.2.3中运行才最稳定(影创官方推荐版本)

5、使用手柄时,需要在设置里开启蓝牙,长按手柄侧键复位

6、SDK3.0.1的UIButton脚本运行时会重置BoxCollider尺寸,建议修改他们的代码

void AddBoxCollider() {
	RectTransform rt = GetComponent<RectTransform>();
	BoxCollider boxCollider = GetComponent<BoxCollider>();
	if(rt) {
		//Fix: 仅对自动创建的BoxCollider设值
		if(boxCollider == null) {
			boxCollider = gameObject.AddComponent<BoxCollider>();
			boxCollider.size = new Vector3(rt.sizeDelta.x, rt.sizeDelta.y, 0);
		}
	}
}

7、UGUI的z坐标会影响深度,值越小越靠前(接近眼睛)

8、影创的交互系统,需要导入using SC.InputSystem;

9、ARCamera的Culling Mask必须勾上Default层才能将AR摄像头画面渲染到TargetTexture上
11111.png
要显示AR摄像头画面必须勾上Enable Video background
2222.png
如果不希望叠加模型渲染到AR场景中,让双目相机不渲染模型所在层即可。
33333.png
44444.png

Eye Left和Eye Right两个摄像机的Clipping Planes Far保持官方默认值1000,否则AR扫描时,Video Background与看到的实景比例不同。Far值大于1000,Video Background会被放大。

10. 在影创眼镜里当有其他程序占用过摄像头,则无法使用CameraDevice.Instance.Start()启动高通。解决方案是用ARCamera的GameObject的SetActive()方法来控制Vuforia的开启或停止。

11. 鼠标点击音效由AudioEffect脚本控制
11111.png
动态设置鼠标点击音效
AudioEffect.clickAudio = (AudioClip) Resources.Load("Sound/btnSound");


/// <summary>
/// 影创眼镜辅助类
/// </summary>
public sealed class ShadowCreatorHelper
{
    public const string ARCAMERA_PATH = "ShadowSystem/SvrCamera/Head/ARCamera";

    //[适配] 初始化
    public static void Initialize()
    {
        GameObject SDKSystem = Resources.Load<GameObject>("Prefabs/SDKSystem");
        //影创SDK_4.1.4已经移除了ShadowSystem
        GameObject ShadowSystem = Resources.Load<GameObject>("Prefabs/ShadowSystem");
        //影创SDK_3.0.1已经移除了ActionSystem
        GameObject ActionSystem = Resources.Load<GameObject>("Prefabs/ActionSystem");

        GameObject go = null;
        if (SDKSystem)
        {
            go = GameObject.Instantiate(ShadowSystem);
            go.name = "SDKSystem";
        }
        if (ShadowSystem)
        {
            go = GameObject.Instantiate(ShadowSystem);
            go.name = "ShadowSystem";
        }
        if (ActionSystem)
        {
            go = GameObject.Instantiate(ActionSystem);
            go.name = "ActionSystem";
        }

        if (go != null)
        {
            go.transform.localScale = Vector3.one;
            go.transform.position = Vector3.zero;
            go.transform.rotation = Quaternion.identity;
        }
    }

    //[适配] Root Canvas
    public static void ModifyRootCanvas(Canvas rootCanvas)
    {
        //适配Canvas
        rootCanvas.renderMode = RenderMode.WorldSpace;
        RectTransform rt = rootCanvas.GetComponent<RectTransform>();
        //z值调整界面远近
        rt.anchoredPosition3D = new Vector3(0, 0, 1.7f);
        //设置成开发分辨率
        rt.sizeDelta = new Vector2(1920, 1080);
        rt.pivot = new Vector2(0.5f, 0.5f);
        //rt.localScale = new Vector3(0.001f, 0.001f, 0.001f);
        rt.localScale = new Vector3(0.0005f, 0.0005f, 0.0005f);
    }

    //[适配] 移除主摄像机
    public static void RemoveMainCamera()
    {
        GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
        if (mainCamera)
            mainCamera.SetActive(false);
        GameObject.Destroy(mainCamera);
    }

    //[适配] 设置AR摄像机
    public static void SvrMonoOverlay(Canvas canvas)
    {
        Camera overlayCamera = SvrManager.Instance.monoOverlay;
        canvas.worldCamera = overlayCamera;
        overlayCamera.enabled = true;
        overlayCamera.gameObject.SetActive(true);
    }

    // 获取ARCamera
    public static Camera GetARCamera()
    {
        GameObject go = GameObject.Find(ARCAMERA_PATH);
        if (go == null)
            return null;
        Camera camera = go.GetComponent<Camera>();
        return camera;
    }

    //启动高通扫描
    public static void StartVuforia()
    {
        if (VuforiaRuntime.Instance.InitializationState == VuforiaRuntime.InitState.NOT_INITIALIZED)
            VuforiaRuntime.Instance.InitVuforia();

        if (!Application.HasUserAuthorization(UserAuthorization.WebCam))
            Application.RequestUserAuthorization(UserAuthorization.WebCam);

        CameraDevice.Instance.Start();
        GameObject ARCamera = GameObject.Find(ARCAMERA_PATH);
        if (ARCamera)
            ARCamera.SetActive(true);
    }

    //停止高通扫描
    public static void StopVuforia()
    {
        GameObject ARCamera = GameObject.Find(ARCAMERA_PATH);
        if (ARCamera)
            ARCamera.SetActive(false);
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 跟随头显姿态
/// 影创HUD信息显示
/// </summary>
public class SC_FollowHeadPose : MonoBehaviour
{
    private Transform cacheTransform;
    private bool firstSet = true;
    private float lastRotY = 0;

    private void Awake()
    {
        cacheTransform = transform;
    }

    private void LateUpdate()
    {
        if (SvrManager.Instance == null)
            return;
        //SvrManager.Instance.headPose: 左右摆头姿态
        //SvrManager.Instance.head.transform: 获取头显姿态变换
        
        float y = SvrManager.Instance.head.localEulerAngles.y;
        if (firstSet)
        {
            firstSet = false;
            cacheTransform.RotateAround(SvrManager.Instance.head.position, Vector3.up, y);
            lastRotY = y;
        }
        else
        {
            if (Mathf.Abs(y - lastRotY) >= 0.01f)
            {
                cacheTransform.RotateAround(SvrManager.Instance.head.position, Vector3.up, y - lastRotY);
                lastRotY = y;
            }
        }
    }
}

------------------------------------------ 第二代 影创眼镜(鸿鹄系统) -------------------------------------

鸿鹄系统(HONGHU)、视场角52度、单眼分辨率1920*1080、摄像头800万主摄+双6DoF空间定位摄像头。眼镜参数

1、系统升级步骤:

1、将待升级设备连接到PC端,确保PC已经连接上待升级设备。
2、将从官网下载来的升级包先进行解压,后得到一个update.zip压缩包,将该压缩包拷贝至设备的根目录下。
3、在设备上依次打开设置->系统->系统更新,然后点击右上角的三个点中的隐藏menu,并选择本地升级(local update)后,页面会跳转到升级界面。

按电源键10秒以上强制开机/关机

注意:运行时ARCamera会自动设置到SDKSystem/SlamCamera/Head/ARCamera位置。

SDK自带的字体资源 SDK/Common/StandardAssets/Font

获取头显对象: Transform head = GSXRManager.Instance.head;

2、拖动窗口时,让UI始终面向玩家
所需组件:BoxCollider + NearInterationGrabbable.cs + ManipulationHandler.cs + UIDragLookAtPlayer.cs
因为需要让UI的负Z轴方向面向玩家,所以不能直接用transform.LookAt()

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 让UI面向玩家
/// </summary>
[DisallowMultipleComponent]
public class UIDragLookAtPlayer : PointerHandler
{
    public Transform head;
    public Transform target;

    private void Start()
    {
        BackLookAt();
    }

    public override void OnDrag(PointerEventData eventData)
    {
        BackLookAt();
    }

    //让UI的背面(Z轴负方向)面向玩家
    private void BackLookAt()
    {
        Vector3 headPos = head.position;
        Vector3 targetPos = target.position;

        Vector3 targetForward = target.forward;
        targetForward = -targetForward;

        Vector3 fromDirection = targetForward;
        Vector3 toDirection = headPos - targetPos;
        //让UI只绕Y轴旋转
        fromDirection.y = 0;
        toDirection.y = 0;

        Quaternion qua = Quaternion.FromToRotation(fromDirection, toDirection);
        target.Rotate(qua.eulerAngles, Space.World);
    }
}


3、给UI添加缩放/旋转边框
所需组件:BoxCollider + BoundingBox.cs
111111.png
Active Handler: 设置支持的功能, None相当于关闭该功能。
1111.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容