最近拿到了第一批VIVE追踪器设备,由于资料很少,官方给出的都是在Unity里面的使用,在Unreal中并没有说明任何使用方法,在摸索一阵子后,总算是能够在UE4里面运行起来了。
现在简单的说一下使用步骤:
申请到的设备,一套的话是一个追踪器以及一个dongle(插在usb上的,用来接收一个追踪器的数据)
1.拿到设备之后在USB接口上插上dongle
2.右键点击已存在的控制器图标中的一个,选择“配对控制器”,按住Vive跟踪器电源键2秒,松开进入配对模式
配对成功后,可以看到对应的设备图标
3.打开Unreal4工程文件
和原来直接套用控制器不一样,不能在MotionController里面选择已有的设备,需要自己在tick里面获取到设备的坐标数据,然后同步到控制器的StaticMesh上面去,从而实现跟踪器的跟踪效果。(实际上所有接的设备都是通过这样子来实现跟踪的,控制器和追踪器只是设备ID不一样而已)
同步蓝图实现如下,因为每台机器上设备编号会有所变动,所以先获取Tracked设备的所有编号,再对其中的设备进行相关Mesh绑定
4.注意:
每一个dongle只能够配对一个追踪器,如果要使用多个追踪器,那么要在电脑上插上多个dongle
在我的本机电脑上插上两个dongle之后,默认检索出来得设备为数组中的0和1
目前官方给出的说法是:
目前UE的引擎版本不支持直接识别tracker,也就是说通过添加motion controller的方式,是识别不到的,但是可以通过c++底层代码来获取
代码如下 :
/**
* Returns an array of the currently tracked device IDs
*
* @param DeviceType Which class of device (e.g.controller, tracking devices) to get Device Ids for
* @param OutTrackedDeviceIds (out) Array containingthe ID of each device that's currently tracked
*/
UFUNCTION(BlueprintPure, Category="SteamVR")
static void GetValidTrackedDeviceIds(ESteamVRTrackedDeviceType DeviceType, TArray<int32>& OutTrackedDeviceIds);
/**
* Gets the orientation and position (in device space) of the device withthe specified ID
*
* @param DeviceId Id of the device toget tracking info for
* @param OutPosition (out) Current position of the device
* @param OutOrientation (out) Current orientation of the device
* @return True if the specifieddevice id had a valid tracking pose this frame, false otherwise
*/
UFUNCTION(BlueprintPure, Category = "SteamVR")
static bool GetTrackedDevicePositionAndOrientation(int32DeviceId, FVector& OutPosition, FRotator& OutOrientation);
目前新设备也刚出,还有许多地方需要进行摸索,希望能对大家的开发有一定的帮助。
——Polaris_Aspire