0

我正在使用 metaio sdk 6.0.2。我正在研究 metaio INSTANT_2D_GRAVITY 跟踪并且能够显示 3d 模型。我想在跟踪丢失时显示相同的 3d 模型。但我没有这样做。我尝试在MetaioSDKCallbackHandleronTrackingEvent中添加trackingValuesVector ,但没有成功。谁能告诉我哪里出错了?

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

加载 3d 模型:

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

1 回答 1

1

我看到您还尝试将模型设置为 COS 0。如果跟踪丢失,这实际上应该有效。

如果您没有看到模型,您将不得不使用比例值(即设置一个较低的值,如 0.01)和 Z 平移值。设置负 Z 值以将模型从相机剪裁平面移开。

于 2015-08-08T15:57:22.317 回答