Search code examples
androidmetaio

Show 3dmodel after tracking lost metaio sdk


I am using metaio sdk 6.0.2. i am working on metaio INSTANT_2D_GRAVITY tracking and was able to display 3d model. I want to display same 3d model when tracking is lost.but I am failing to do so. I tried by adding trackingValuesVector in onTrackingEvent of MetaioSDKCallbackHandler with no success. can anyone tell me where am I going wrong?

private TrackingValues mTrackingValues;// declared globally
private IGeometry mModel;  // declared globally
private boolean mPreview=true;// declared globally

 // start INSTANT_2D_GRAVITY tracking
 public void onTakePicture(View v)
  {
    captureTrackingValues = true;
    metaioSDK.startInstantTracking("INSTANT_2D_GRAVITY", new File(""), mPreview);
    mPreview = !mPreview;
  }


 final class MetaioSDKCallbackHandler extends IMetaioSDKCallback
 {
    @Override
    public void onInstantTrackingEvent(final boolean success,final File filePath) {
        super.onInstantTrackingEvent(success, filePath);
        if(mSurfaceView != null)
        {
            mSurfaceView.queueEvent(new Runnable() {
                @Override
                public void run() {
                    if(success)
                    {
                        if(captureTrackingValues == true)
                        {
                            metaioSDK.setTrackingConfiguration(filePath);

                            Log.i("Tracking value success","good");
                        }
                    }
                    else
                    {
                        Log.i("Tracking value failure","bad");
                    }
                }
            });
        }
    }

    @Override
    public void onTrackingEvent(TrackingValuesVector trackingValuesVector) {
       super.onTrackingEvent(trackingValuesVector);
       if (!trackingValuesVector.isEmpty())
        {
           for(int i =0;i< trackingValuesVector.size();i++)
           {
             if(trackingValuesVector.get(i).isTrackingState() && mModel!=null)
              {
                  mTrackingValues = metaioSDK.getTrackingValues(i);
                  mModel.setCoordinateSystemID(trackingValuesVector.get(i).getCoordinateSystemID());
              }
              else {
                      if(mModel!= null && mTrackingValues != null) {
                         metaioSDK.setCosOffset(1, mTrackingValues);
                         //mChairModel.setCoordinateSystemID(0);
                          Log.e("TestAR","isTrackingState is null");
                      }
              }
           }
        }
       else{
              if(mModel!= null && mTrackingValues != null) {
                 metaioSDK.setCosOffset(1, mTrackingValues);
                 //mModel.setCoordinateSystemID(0);
                 Log.e("TestAR","trackingValuesVector is null");
              }
       }
    }
 }

loading 3d model:

private void loadModel()
{
  if (mSurfaceView != null) {
     mSurfaceView.queueEvent(new Runnable() {
            @Override
            public void run() {
                 File chairModel = AssetsManager.getAssetPathAsFile(getApplicationContext(),"chair.obj");
                 if (chairModel != null) {
                    mModel = metaioSDK.createGeometry(chairModel);
                    mModel.setScale(3f);
                    mModel.setTranslation(new Vector3d(0f,0f,-60f));
                    mGestureHandler.addObject(mModel, 1);
                    mModel.setRotation(new Rotation(0f, 0.5f, 0f));
                    mModel.setCoordinateSystemID(1);
                 }
            }
        });

  }
  else
  {
    Log.e("exception", "msurfaceview is null");
  }
}

Solution

  • I see that you also tried setting the model to COS 0. This should actually work, if the tracking is lost.

    If you do not see the model, you would have to play around with the scale value (i.e. set a low value like 0.01) and with the Z translation value. Set a negative Z value in order to move the model away from the camera clipping plane.