在Android MetaIO项目中加载IGeometry时出错

时间:2014-05-31 18:31:02

标签: android metaio

    private IGeometry mItem;

    @Override
        protected void loadContents() {
            try {

                // TODO: Load desired tracking data for planar marker tracking
                boolean result = metaioSDK
                        .setTrackingConfiguration("ORIENTATION_FLOOR");
                MetaioDebug.log("Tracking data loaded: " + result);


                //
                //Load the item one
                mItem = loadItem("Project/Assets/chair.obj");
                mGestureHandler.addObject(mItem, 1);
                setVisibleItem(false);
             }catch (Exception e){}
        }

        public IGeometry loadItem(String objectPath){       
              IGeometry item = null;        
              try {             
                     // TODO: Load desired tracking data for planar marker tracking             
                     boolean result = metaioSDK     .setTrackingConfiguration("ORIENTATION_FLOOR");                        
                     MetaioDebug.log("Tracking data loaded: " + result);

                 // Load Object             
                     String filepath = AssetsManager.getAssetPath(
                        getApplicationContext(),
                        objectPath);            

                     item = metaioSDK.createGeometry(filepath);

                if (item != null) {
                    item.setScale(200f);
                    item.setTranslation(new Vector3d(0f, 0f, 0f));
                    item.setRotation(new Rotation((float) Math.PI / 2f, 0f,
                            0f));

                    //mGestureHandler.addObject(item, position);
                                } else
                    MetaioDebug.log(Log.ERROR, "Error loading geometry: "
                            + filepath);        }catch (Exception e){}
                    return item;    }



View.OnClickListener onClickColorTheme1(final Button but)  {
        return new View.OnClickListener() {
            public void onClick(View v) {

                        //mItem is a global variable
                mItem = loadItem("Project/Assets/newChair.obj");
            }
        };
    }

IGeometry被加载在被覆盖的“loadContent”内。 android metaIO项目中的方法。我想将另一个对象加载到' mItem'在点击事件之后。但它并没有加载newChair。这是调试时出现的错误:

  

错误:几何体只能在渲染线程中创建

尝试了很多方法来解决这个问题,但无法解决。其中一个是我尝试了以下内容,但不确定它是否正确,并且不知道该把它放在哪里

mSurfaceView.queueEvent(new Runnable(){
@Override
 public void run(){
         mItem = loadItem("Project/Assets/newChair.obj");
     }

} 

1 个答案:

答案 0 :(得分:3)

mSurfaceView.queueEvent是处理它的正确方法。您可以将其添加到loadItem方法:

public IGeometry loadItem(final String objectPath)
{   
  mSurfaceView.queueEvent(new Runnable()
  {
    @Override
    public void run()
    {
      // load the items here
    }
  }
}