viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

[Question] - Reinitialization of the entire AR system #67

Closed dittmarconsulting closed 7 years ago

dittmarconsulting commented 7 years ago

Hi @achuvm,

When the AR system is initialized the onTrackingInitialized method of the ViroARScene gets invoked once.

I'm wondering if that process can be repeated let's say with a reset button?

Thanks, Tom

achuvm commented 7 years ago

Hi @dittmarconsulting,

We don't currently have a way to "reset" AR, but it is something we may consider.

I am curious of what behavior you'd expect from a "reset" in AR though. Would the camera position simply go back to [0,0,0]? Would the planes that have been found be lost?

I'd also like to learn of the use cases you have for this feature to see if whether or not we can accomplish them with our existing API's.

Andy

dittmarconsulting commented 7 years ago

Hi Andy,

What I want to do is to is to re-init (find a new ground plane) using ARPlaneSelector.

What I do right now is to invoke the private function _onTrackingInitialized() of the ViroARScene, which works fine if the initial position is almost the same.

I have a REDUX props that decides when this function gets invoked in my version of the `ViroARScenes' component

componentDidUpdate() {
        // REDUX prop & function
        const { reinit, setSetReinit } = this.props
        if(reinit) {
            // re-init
            this.mainScene._onTrackingInitialized()
            // set the bool to false again (singleton)
            this.props.setSetReinit(false)
        }
    }

For some reason it remembers the initial position and it's hard to assign another plane somewhere else. I have tried to reset planeIsSelected and arPlaneSizes of the ViroARPlaneSelector but it seems it remembers the coordinates in another place?

achuvm commented 7 years ago

Hi @dittmarconsulting,

If you want to reset the ViroARPlaneSelector, there's a reset() function that you can call here:

http://docs.viromedia.com/docs/viroarplaneselector#methods

That'll show all the surfaces again and allow your users to select the next plane. I believe that's what you need.

As for _onTrackingInitialized() that's a function that's called when the underlying AR system (in this case, ARKit) has finished initializing and has started to track the camera position. It should only really callback when the user first opens your app.

Let me know if that solves your issue (or if I'm misunderstanding you).

Andy

dittmarconsulting commented 7 years ago

Hi Andy,

I tried reset() but all what it does it sets the selectedSurface props back to -1 so that the _getARPlanes function can push a new ViroARPlane to the array of arPlanes

reset() {
    this.setState({
      selectedSurface : -1
    });
  }

I have set _maxPlanes of the ViroARPlaneSelector to one. Hence it will only push 1 ViroARPlane to the array. Although it should reset the surfacePosition as well I'm not able to select a surface on another spot and it only work 2 or 3 times until it doesn't find a surface at all anymore without restarting the app.

I haven't been able to find the problem why that is.

Cheers, Tom

achuvm commented 7 years ago

Yeah, unfortunately that's a limitation of our existing APIs.

Essentially, the underlying system may find N number of planes, but there's no way for the developer to easily control which detected plane a ViroARPlane will attach to as we'll automatically assign ViroARPlane to whichever detected plane satisfies the minHeight/minWidth requirements.

One way you "could" do this is to simply add a bunch of ViroARPlanes and listen to their callbacks for when they are attached/updated/removed. With the callbacks you can determine the position of the planes and you can manually move your content to the ViroARPlane you want to use.

In our next update (~mid-November), we'll be exposing the full API that'll let the developer listen for found anchors without adding a Viro component. Then the developer can use an anchor ID to attach the a ViroARPlane to the underlying anchors.

Thanks,

dittmarconsulting commented 7 years ago

Thanks Andy,

I'm happy to wait for the next update.

I'm really excited about the lib. There is so much potential, especially since you have implemented ArKit.

Regarding the reset, I will try to reset the entire JS part of the app using this package. I hope that will reset the underlaying system as well.

Thanks again. Tom

dittmarconsulting commented 7 years ago

Hi @achuvm,

Just for the reference my approach with react-native-restart works perfectly.

I reset the entire JS project, which re-initiates the AR system as well. I get a new plane at any other location now.

fixed-term-tylernguyen commented 5 years ago

Is there a now proper way to handle resetting an ARScene where ARPlaneSelector will detect new planes (not just push next ones)?