viro icon indicating copy to clipboard operation
viro copied to clipboard

ViroPolyline: Indetermined path on ViroARImageMarker.onAnchorFound

Open rsc1975 opened this issue 3 years ago • 2 comments

Environment

  • Windows + Linux (WSL2)
  • Device: Android 10. Xiaomi Mi 9
  • ViroReact 2.20.2

Description

This is not a bug, just a question or request for help, I'm developing a PoC about a IPS (Indoor Positioning System), I want to show a "path" that joins 2 points in the real world using a ViroPolyline, However the polyline object is shown rotated (over the y-axis) depending on the camera initial orientation when the AR session is created. AFAIK there is no a way to reset the AR session in Android so I tried to "fix" the polyline rotation using the camera and image tracker rotation values, but I cannot find a rule or algorithm that works in all cases.

As an alternative approach, I wonder if I can reset the AR session (in Android) or create a new one using a second ViroARnavigationScene, that is, I would use the first one to locate the ImageTracker and a second one (if I can ensure the camera orientation in front of the image tracker) that will show the "path" to join the 2 points.

I've created a SO Issue (bounty 200) with more details about this case: https://stackoverflow.com/questions/66991820/viropolyline-indetermined-path-on-viroarimagemarker-onanchorfound

I'm not sure if this is the correct place for this question, but after the result with the SO question I'm a bit lost, any help is welcome.

rsc1975 avatar Apr 12 '21 09:04 rsc1975

Could we see an example of your code?

doranteseduardo avatar Apr 15 '21 22:04 doranteseduardo

@doranteseduardo In the S.O. there are more details, anyway the code is quite simple:

     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
          });
          }
        );
      }

The polyline orientation can be fixed only modifing the y-axis, the problem is that I cannot figure out a rule or algorith to do it.

rsc1975 avatar Apr 16 '21 06:04 rsc1975