<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Rokid Air AR 眼鏡 && Cocos Creator XR 開發(fā)筆記

          共 5539字,需瀏覽 12分鐘

           ·

          2022-10-26 14:01

          9b1ef349297b8c71b4664959f33ae84a.webp

          開發(fā)前準(zhǔn)備

          硬件設(shè)備

          Rokid Air 眼鏡:

          https://air.rokid.com/

          支持進(jìn)入AR模式的 Android 手機(jī):

          https://air.rokid.com/userguide

          b9b57fcacc577956954341f8413e01a4.webp

          軟件

          Rokid Air App :

          在Rokid Air app 1.9.1版本上有部分不兼容問題,請確認(rèn)不要使用此版本的Rokid Air app進(jìn)行調(diào)試和發(fā)布,之前的版本和1.9.2或以后的版本將不受影響;

          直接從官網(wǎng)上下載,各大應(yīng)用市場可能更新有滯后。
          https://air.rokid.com/download
          55af6e7dcf8393176aae850feebfa247.webp

          Cocos Creator 3.6.1

          https://www.cocos.com/creator

          安裝配置安卓環(huán)境

          https://docs.cocos.com/creator/manual/zh/editor/publish/setup-native-development.html

          XR 插件:

          https://store.cocos.com/app/detail/4117

          投屏(可選

          adb tcpip + scrcpy

          Rokid AIR 投屏方案(Win):https://ivb750bbcz.feishu.cn/docs/doccniMDevcb6lgto0DzXPEn8Xe

          Rokid AIR 投屏方案(Mac):https://ivb750bbcz.feishu.cn/docs/doccndTeu2iDmQt7a2fSJqnpLvg


          Hello World

          新建VR模版

          8d300daa4b20fe9ce7680da45f54f658.webp

          打開?xr_main?場景,可以看到相機(jī)是掛在 XR HMD 這個節(jié)點(diǎn)下
          4e0b5b7a4cb98f5e827e1a06f8729673.webp

          場景空空,有點(diǎn)孤單,可以隨意添加一些3d物體,調(diào)節(jié)成你喜歡的角度和位置,確保在相機(jī)視野內(nèi)。

          baaeec399be95e3a56d42ef0557e57bc.webp

          構(gòu)建發(fā)布

          在菜單欄選擇?項(xiàng)目->構(gòu)建發(fā)布,發(fā)布平臺選擇?XR Rokid Air,第一次發(fā)布還需填上包名。首次構(gòu)建可能會慢點(diǎn),后面再構(gòu)建就會更快了。
          9b0f6cf863ceb3507405b294f3f1eec6.webp

          如果出現(xiàn)異常的話,一般來說是安卓環(huán)境相關(guān)配置有異常,可以查看構(gòu)建日志定位問題。
          855a14b64142385c435a5a545edc0cc1.webp

          打開?{當(dāng)面項(xiàng)目}/build/xr-rokid/publish/release?,將包安裝到手機(jī)上。
          9c0370e793a0c3dac9f3c0df525f8b43.webp

          效果預(yù)覽

          安裝應(yīng)用后,直接打開是這樣的
          f0e5bbe4704291a4940102ed1d281e2d.webp

          需要接上AR眼鏡,在 Rokid Air App 中進(jìn)入 AR 模式。

          1095604338c9d342f9b864a68aae84ef.webp

          在其應(yīng)用庫可以找到剛才安裝好的包。

          f8e28d485e21a00f17b5a6ad95cffef6.webp

          打開后,晃動腦袋,可以看到我們之前添加的物體
          52eb1e0af6a86d7616ecc70a2408483c.webp

          此時手機(jī)上顯示的是游戲手柄

          6442184234f04b705fc3f2a27a3c3d70.webp

          目前的資源包參考如下
          helloworld.zip?(24.2 KB)


          輸入事件

          手柄輸入事件

          為了更好的控制游戲,需要知道手機(jī)中的手柄事件。

          6442184234f04b705fc3f2a27a3c3d70.webp

          Cocos Creator 中的監(jiān)聽事件代碼如下:

              input.on(Input.EventType.GAMEPAD_INPUT, this._gamepadEvent, this);

          獲取手柄輸入?yún)?shù)如下

              private _gamepadEvent(event: EventGamepad) {
          const gamepad = event.gamepad;
          }

          gamepad 的成員可以在?cc.d.ts中看到。

          b7c7a4cb7c7ba30dcc892fc3bb6c0843.webp

          可以簡單寫個腳本,驗(yàn)證搖桿參數(shù)返回。

              import { _decorator, Component, input, Input, EventGamepad, Vec2, Label } from 'cc';
          const { ccclass, property } = _decorator;

          @ccclass('GamepadEventTest')
          export class GamepadEventTest extends Component {
          @property(Label)
          lb_leftStickValue: Label = null!

          @property(Label)
          lb_rightStickValue: Label = null!

          start() {
          input.on(Input.EventType.GAMEPAD_INPUT, this._gamepadEvent, this);
          }

          private _gamepadEvent(event: EventGamepad) {
          const gamepad = event.gamepad;
          const leftStickValue = gamepad.leftStick.getValue() as Vec2;
          this.lb_leftStickValue.string = `${leftStickValue.toString()}`;

          const rightStickValue = gamepad.rightStick.getValue() as Vec2;
          this.lb_rightStickValue.string = `${rightStickValue.toString()}`;
          }
          }

          并在場景中加入label節(jié)點(diǎn)驗(yàn)證輸出。

          b305b5dedc1d8b73db4f4e8a5d66fac3.webp

          重新打包后預(yù)覽效果,可以看出搖桿的輸出結(jié)果

          4f566a0fb58091446dfa9e0220c5b56d.webp

          資源包如下:

          helloworld-gamepad-event-test.zip?(194.1 KB)

          頭戴顯示器姿態(tài)輸入事件

          這個事件可以獲取到眼鏡的一些重要參數(shù),如旋轉(zhuǎn)角度,在定制眼鏡交互時可能會用到。

          813e112f471560de14623a13852459cd.webp

          Cocos Creator 中的監(jiān)聽事件代碼如下:

              input.on(Input.EventType.HMD_POSE_INPUT, this._dispatchEventHMDPose, this);

          獲取輸入?yún)?shù)如下

              private _dispatchEventHMDPose(eventHMD: EventHMD) {
          const hmdInputDevice = eventHMD.hmdInputDevice;
          }

          4ff6fdc95d586df2d11d463f62945dad.webp

          相關(guān)的邏輯可以參考插件中的代碼?extensions/xr-plugin/assets/xr/component/device/pose-tracker.ts

          c0501ee78bffb2d6a938d78ddeab9f5e.webp

          simple-shooting

          將現(xiàn)有的游戲移植到 Rokid Air 眼鏡,用的是?cocos-example-projects/simple-games/assets/simple-shooting 這個demo

          7bcc2422af642787349ad6f6650a157c.webp

          下載好工程后,找到主場景,導(dǎo)出資源包。

          6ce4c3b76dfd5c8ba6045b5c1a827ea8.webp

          這里已經(jīng)導(dǎo)出了資源包,如下所示:

          鏈接:?https://pan.baidu.com/s/1VRZyn3gAWF0Y6vsYdImFmg?pwd=6qce?提取碼: 6qce 復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機(jī)App,操作更方便哦

          再導(dǎo)入到helloworld 中03749cd16f65db808175cfe7f1cfd4ee.webp

          切換到shooting game 的場景中,找到主相機(jī),轉(zhuǎn)成?XR HMD

          238aabee8d8e96faa8b56b7de2dbcba7.webp

          構(gòu)建參數(shù)選擇當(dāng)前新的場景

          a3114f81c7288ef2bedb1d0040fd3f56.webp

          鏈接眼鏡,打開應(yīng)用后,效果如下圖所示:b06d020c32baf2db16b698dd59168e27.webp

          剩下的問題就是調(diào)整參數(shù),接入輸入事件,修改腳本assets/simple-shooting/scripts/ShootingPlayerController.ts?核心參考代碼如下:

                      //input.on(Input.EventType.GAMEPAD_INPUT, this._gamepadEvent, this);
          //input.on(Input.EventType.HMD_POSE_INPUT, this._dispatchEventHMDPose, this);

          private _dispatchEventHMDPose(eventHMD: EventHMD) {
          const hmdInputDevice = eventHMD.hmdInputDevice;

          const _quatPose:Quat = hmdInputDevice.headMiddleOrientation.getValue();
          _quatPose.getEulerAngles(tempVec3_a);

          const horizontalRot = this.node.getRotation();
          horizontalRot.getEulerAngles(tempVec3_b);
          tempVec3_b.y = tempVec3_a.y;
          this.node.setRotationFromEuler(tempVec3_b);

          if (-tempVec3_a.x > this.viewDownAngle && -tempVec3_a.x < this.viewUpAngle) {
          const verticalRot = this.verticalViewNode.getRotation();
          verticalRot.getEulerAngles(tempVec3_b);
          tempVec3_b.x = -tempVec3_a.x;
          this.verticalViewNode.setRotationFromEuler(tempVec3_b);
          }
          }

          aValue = false;
          bValue = false;
          private _gamepadEvent(event: EventGamepad) {
          const gamepad = event.gamepad;
          const leftStickValue = gamepad.leftStick.getValue() as Vec2;
          if(this._velocity.z !=leftStickValue.y && this._velocity.x!=-leftStickValue.x){
          this._velocity.z = leftStickValue.y;
          this._velocity.x = -leftStickValue.x;
          if(leftStickValue.lengthSqr()>0){
          this.changeToAnimState(PlayerAnimState.Running);
          }else{
          this.checkToIdle();
          }
          }

          if (gamepad.buttonSouth.getValue() === 1 && !this.aValue) {
          this.aValue = true;
          this.doAction(ActionType.Shoot,true)
          } else if (gamepad.buttonSouth.getValue() === 0) {
          this.aValue = false;
          }
          if (gamepad.buttonEast.getValue() === 1 && !this.bValue) {
          this.bValue = true;
          this.doAction(ActionType.ThrowGrenade,true)
          } else if (gamepad.buttonEast.getValue() === 0) {
          this.bValue = false;
          }
          }


          放上文章開頭接入的資源包供大家參考學(xué)習(xí)

          鏈接:?https://pan.baidu.com/s/1dpvvTppaPFyvGqRzsyWEIA?pwd=3q68?提取碼: 3q68 復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機(jī)App,操作更方便哦

          小結(jié)

          b視頻:?https://www.bilibili.com/video/BV1bt4y1u7CS/

          相關(guān)資源鏈接與討論見論壇:https://forum.cocos.org/t/topic/141564 ?(閱讀原文直達(dá))


          點(diǎn)擊 閱讀原文”跳轉(zhuǎn)至論壇討論

          “點(diǎn)贊“ ”在看”?鼓勵一下75c7626428d95f27c15d70749da28597.webp

          瀏覽 138
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欲色网站 | 无码囯无精品毛片大码 | 色天堂在线 | 操逼视频d3tt.s8 | 国产一级A片免费播放 |