首页 > 解决方案 > ViroPolyline:ViroARImageMarker.onAnchorFound 上的不确定路径

问题描述

我正在尝试使用 ReactNative 和 ViroReact lib (v. 2.20.2) 为 IPS(室内定位系统)应用程序开发 PoC,我正在遵循这篇文章的“想法”:使用增强现实创建室内导航带有 VIROREACT 的系统

这是我的代码(相关部分):

      render() {
        return (
          <ViroARScene onTrackingUpdated={this._onInitialized} anchorDetectionTypes={"PlanesVertical"} 
          ref={(scene) => this._scene = scene}>
            <ViroAmbientLight color="#ffffff" />
            <ViroARImageMarker target={"arqo"} onAnchorFound={this._onAnchorFound} pauseUpdates={false}>
              <ViroSphere materials={["green"]}
                heightSegmentCount={20} widthSegmentCount={20} radius={.05}
                position={[0, 0, 0]}
                shadowCastingBitMask={0} />
            </ViroARImageMarker>        
            <ViroPolyline 
               position={this.state.origin} 
               points={this.state.path}            
               //rotation={this.state.rota}
               visible={this.state.found}
               thickness={0.08} materials={"blue"} />           
          </ViroARScene>
        );
      }
    
    
      _onAnchorFound(evt) {
        this._scene.getCameraOrientationAsync().then(
          (orientation) => {
            //console.log('orientation:', orientation.position);
          this.setState({
            origin: evt.position,
            rota: [0,0,0], // Tested with several combinatios of evt.rotation
            path: [[0,0,0],[0,-1,0], [-1, -1, 0], [-1, -1, 2.5], [-5.5, -1, 2.5], [-5.5, -1, .5],[-4.5, -1, .5], ],
            found: true
          });
          }
        );
      }

当 ImageMarker 找到锚点时,Polyline 显示的路径只有在应用程序初始化时相机处于特定方向时才能正常工作 ( ViroARScene.onTrackingUpdated)。换句话说,[[0,0,0],[0,-1,0],...当应用程序启动时,路径会根据相机方向出现在场景中完全不同的位置,我理解原因是 x/y/z 轴是相对于相机位置的那一刻ARScene 已初始化,但我找不到“重置”相机方向值的方法。

这是正确位置的折线:

正确的折线

如果我更改 ARScene 初始化的设备位置,这就是“错误的”折线:

错误的折线

似乎对于 iOS,有一种方法可以重置 ARScene,但不适用于 Android。我在 GitHub 上发现了这个问题,我尝试应用为 Android 提出的解决方案,但没有成功。

那么,在这种情况下(Android),正确的方法是什么?找到重置 ARScene 的方法?对整个折线应用某种旋转,让我总是在同一个地方显示它?

我已经测试了以前方法的几种组合,但都没有成功,欢迎提供任何帮助。

更新:我得到了一些额外的信息,我可以修复在旋转折线属性中改变 y 轴的路径,只有 y 轴值,但是我找不到让我自动计算 de fix 的模式 o 规则,我已经记录找到锚点时的相机和锚点旋转值,这些是值:

cam  rot: [-2.497048218334727, -63.859283946951926, -5.368946609829862] <- Camera rotation
evt  rot: [118.87363684327742, -88.53820541831203, -31.584297363756363] <- Anchor rotation
FIX: [0, -95, 0]
FIX: [0, 265, 0]

cam  rot: [-5.945959710252071, 20.48844502875367, 4.6278877334695805]
evt  rot: [88.5514013437885, -1.4750360204900235, -0.34028717480432263]
FIX: [0, 0, 0]

cam  rot: [170.70103030306413, 52.80923998316522, -178.81384703693524]
evt  rot: [-29.111365903050718, 89.33119038095052, -119.84312755444736]
FIX: [0, 95, 0]
FIX: [0, -265, 0]

cam  rot: [167.1699044644376, 7.111516124189114, 179.5554279958802]
evt  rot: [-84.62749864675119, 2.911754252849452, 176.83732689491694]
FIX: [0, 175, 0]
FIX: [0, -185, 0]

cam  rot: [15.589674554122324, -86.97010326790384, -27.120364052444707]
evt  rot: [-92.58756503002414, -65.74347359176998, -177.77821277384288]
FIX: [0, -120, 0]
FIX: [0, 240, 0]

cam  rot: [177.15412472900047, -21.647645951668018, -177.49628988566144]
evt  rot: [-89.2386276573185, 1.2896090844071653, -179.0481635066017]
FIX: [0, -180, 0]
FIX: [0, 185, 0]

cam rot: [-1.897906585662147, 66.01840236624133, 7.170484562388419]
evt rot: [90.14261002415887, 41.29178909900161, -2.2406920088771076]
FIX: [0, 45, 0]
FIX: [0, -325, 0]

cam  rot: [-26.443176409447332, 75.555791655302, -22.232962427686846]
evt  rot: [90.60874994444472, 49.162369758863626, -1.5288741328490028]
FIX: [0, 55, 0]
FIX: [0, -315, 0]

标签: react-nativeaugmented-realityviro-react

解决方案


推荐阅读