Android 无法在检测到操作时加载纹理

Android 无法在检测到操作时加载纹理,android,object,textures,augmented-reality,image,Android,Object,Textures,Augmented Reality,Image,所以我有一个应用程序,当它看到特定的图片时,它会设置一些动作。屏幕上应该会出现一张图片(它不会)。当你点击那张图片时,它会启动一个视频。 视频工作正常,我所要做的就是触摸屏幕,然后启动。 因为图片没有加载,所以我遗漏了一些东西。 我在Logcat中发现一个错误,如下所示: 08-29 10:15:44.102: E/libEGL(2314): call to OpenGL ES API with no current context (logged once per thread) 代码:

所以我有一个应用程序,当它看到特定的图片时,它会设置一些动作。屏幕上应该会出现一张图片(它不会)。当你点击那张图片时,它会启动一个视频。 视频工作正常,我所要做的就是触摸屏幕,然后启动。 因为图片没有加载,所以我遗漏了一些东西。 我在Logcat中发现一个错误,如下所示:

 08-29 10:15:44.102: E/libEGL(2314): call to OpenGL ES API with no current context (logged once per thread)
代码: 这是在我运行程序时实例化的: 该模型不是广告牌,因此它跳过该部分并继续加载纹理

private boolean mLoadGeometry(MetaioModel model, String assetsDirectoryPath) {
    // String modelName = model.name;
    // MetaioModel model = getModelForName(modelName);
    if (model != null) {
        LogService.log(TAG, "object : " + model.model);
        if (model.model == null) {
            if ((model.isBillboard != null) && model.isBillboard) {
                loadBillboard(entity.absolutePath + "/" + model.texture, model);
                LogService.log(TAG, "LoadBillboard : " + model.texture);
            } else {

                LogService.log(TAG, " model.geometryFile : " + model.file);
                if (model.file != null) {
                    String modelPath = assetsDirectoryPath + "/" + model.file /* + ".md2" */;
                    model.model = mMobileSDK.loadGeometry(modelPath);
                    LogService.log(TAG, "> Loaded model: " + modelPath);
                    if (model.model != null) {
                        LogService.log(TAG, "> model.texture: " + model.texture);
                        if ((model.texture != null) && !"".equals(model.texture)) {
                            LogService.log(TAG, "Setting texture = " + entity.absolutePath + "/" + model.texture);
                            model.model.setTexture(entity.absolutePath + "/" + model.texture);
                            LogService.log(TAG, "Texture set");

                        }
                        LogService.log(TAG, "[Loaded geometry] model.model = " + model.model);
                    } else {
                        LogService.log(TAG, "[Load geometry] object is null");
                    }
                } else {
                    LogService.log(TAG, "> model.geometryFile is NULL");
                }
            }
            boolean success = setModelProperties(model, assetsDirectoryPath);
            if (!success) {
                return false;
            }
        }
    }
    return true;
}
这就是
SetModelProperties
函数的外观:

private boolean setModelProperties(MetaioModel metaioModel, String assetsDirectoryPath) {
    LogService.log(TAG, "[MetaioModel] "+ metaioModel +"-----texture"+ metaioModel.texture);
    if (metaioModel == null) {
        return false;
    } else {
        IUnifeyeMobileGeometry object = metaioModel.model;
        if (object != null) {
            if (metaioModel.translate != null) {
                if (metaioModel.translate.length == 3) {
                    Vector3d vector3d = new Vector3d(metaioModel.translate[0], metaioModel.translate[1], metaioModel.translate[2]);
                    object.setMoveTranslation(vector3d);
                    LogService.log(TAG, "[Properties] translate set");
                } else {
                    LogService.log(TAG, "[ERROR] setModelProperties : translate ---> Vector is of wrong size !!!");
                }
            }
            if (metaioModel.scale != null) {
                if (metaioModel.scale.length == 3) {
                    Vector3d vector3d = new Vector3d(metaioModel.scale[0], metaioModel.scale[1], metaioModel.scale[2]);
                    object.setMoveScale(vector3d);
                    LogService.log(TAG, "[Properties] scale3 set");
                } else {
                    LogService.log(TAG, "[ERROR] setModelProperties : scale ---> Vector is of wrong size !!!");
                }
            }
            if (metaioModel.rotate != null) {
                if (metaioModel.rotate.length == 3) {
                    Vector3d vector3d = new Vector3d(metaioModel.rotate[0], metaioModel.rotate[1], metaioModel.rotate[2]);
                    object.setMoveRotation(vector3d);
                    LogService.log(TAG, "[Properties] rotate3 set");
                } else if (metaioModel.rotate.length == 4) {
                    Vector4d vector4d = new Vector4d(metaioModel.rotate[0], metaioModel.rotate[1], metaioModel.rotate[2], metaioModel.rotate[3]);
                    object.setMoveRotation(vector4d);
                    LogService.log(TAG, "[Properties] rotate4 set");
                } else {
                    LogService.log(TAG, "[ERROR] setModelProperties : rotate ---> Vector is of wrong size !!!");
                }
            }
            if (metaioModel.visible != null) {
                object.setVisible(metaioModel.visible);
                LogService.log(TAG, "[Properties] visibility set to : " + metaioModel.visible);
            }

            if (metaioModel.occlude != null) {
                object.setOcclusionMode(metaioModel.occlude);
                LogService.log(TAG, "[Properties] occlusion set to : " + metaioModel.occlude);
            }
            if (metaioModel.picking != null) {
                object.setPickingEnabled(metaioModel.picking);
                LogService.log(TAG, "[Properties] is pickable set to : " + metaioModel.picking);
            }

            if (metaioModel.xray != null) {
                object.setRenderAsXray(metaioModel.xray);
                LogService.log(TAG, "[Properties] xray set to : " + metaioModel.xray);
            }

            if (metaioModel.transparency != null) {
                int transparency = metaioModel.transparency;
                object.setTransparency((short) transparency);
                LogService.log(TAG, "[Properties] transparency set to : " + transparency);
            }

            if (metaioModel.texture != null) {
                object.setTexture(entity.absolutePath + "/" + metaioModel.texture);
                object.setVisible(true);

                LogService.log(TAG, "[Properties] Rendered set to : "+object.getIsRendered());
                LogService.log(TAG, "[Properties] Visibility set to : "+object.getIsVisible());
                LogService.log(TAG, "[Properties] texture set to : " + entity.absolutePath + "/" + metaioModel.texture);
            }
        }
    }
    return true;
}
该对象不为空,应输入比例和纹理。(it的LogCat状态):

更改可见性的setAction类:

private void setActions(ArrayList<Action> actions, String directory) {
    if ((actions != null) && (actions.size() > 0)) {
        for (int i = 0; i < actions.size(); i++) {
            String type = actions.get(i).type;
            Action action = actions.get(i);
            LogService.log(TAG, "==> action Type : " + type);

            if ("saveScreenshot".equalsIgnoreCase(type)) {
                LogService.log(TAG, "==> saveScreenshot");
                captureScreenShot(entity.absolutePath + "/Screenshots/screenshot.jpg");
            }
 else if ("setTexture".equalsIgnoreCase(type)) {
                LogService.log(TAG, "==> setTexture");
                String modelName = action.model;
                if ((modelName != null) && (modelName.length() > 0)) {
                    LogService.log(TAG, "InSetTEXTURE======Inainte de Texture set: " + action.file);
                    String texture = action.file;
                    if (texture.length() > 0) {
                        String texturePath = entity.absolutePath + "/" + texture;
                        MetaioModel metaioModel = getModelForName(modelName);
                        IUnifeyeMobileGeometry object = metaioModel.model;
                        if (object != null) {
                            object.setTexture(texturePath);
                            // flag = !flag;
                            // System.out.println("flag = " + flag);
                            // object.setTexture("changed.jpg", null, true);

                            // object.setTexture(entity.absolutePath + "/" + model.texture);
                            // if (flag) {
                            // } else {
                            // object.setTexture(entity.absolutePath + "/normal.png" /* + model.texture */);
                            // }

                            LogService.log(TAG, "InSetTEXTURE======Texture set: " + texturePath);
                        } else {
                            LogService.log(TAG, "ERROR: object is null!");
                        }
                    }
                }
            }
当检测到标记并应将纹理设置为可见时,进行LogCat:

08-28 12:17:01.926: I/AugmentedRealityActivity(5910): >> Marker detected..
08-28 12:17:01.926: I/System.out(5910): >> cosName patch1
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Action size in action!=null  ----1/mnt/sdcard/Android/data/com.cardemotion.mobile/files/VWSEEMORE/TEMP/movie_texture
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): ==> action Type : setVisible
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): ==> setVisible
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Got 1 models
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Returning model : movie
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): ==> modelName: movie setVisible : true
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Devine Visible==> modelName: movie true  object is object: com.metaio.unifeye.ndk.IUnifeyeMobileGeometry@4af880texturecom.metaio.unifeye.ndk.IUnifeyeMobileGeometry@4af880
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): modelName unde sunt acuma= movie
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Model name : movie
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Got 1 models
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): Returning model : movie
08-28 12:17:01.926: I/AugmentedRealityActivity(5910): model.texture : 'start.png' 
08-28 12:17:01.926: I/System.out(5910): model.texture : 'start.png' 
08-28 12:17:01.926: I/System.out(5910): Pose set : 1
和检测代码:

 @Override
        public void onTrackingEvent(PoseVector poses) {
         for (int i = 0; i < poses.size(); i++) {
            Pose pose = poses.get(i);
            if (pose.isDetected()) {
                ArrayList<MetaioEvent> items = entity.events;
                for (int k = 0; k < items.size(); k++) {
                    MetaioEvent item = items.get(k);
                    Event event = item.event;
                    String type = event.type;
                    String cosName = pose.getCosName() != null ? pose.getCosName().toLowerCase() : "NULL";
                    String cosNameFromFile = event.cosName != null ? event.cosName.toLowerCase() : "NULL";

                    if ("markerDetected".equals(type)) {
                        LogService.log(TAG, ">> Marker detected..");
                        if (!"".equals(cosName) && !"".equals(cosNameFromFile) && cosName.equals(cosNameFromFile)) {
                            System.out.println(">> cosName " + cosName);
                            ArrayList<Action> actions = item.actions;
                            if ((actions != null) && (actions.size() > 0)) {
                                LogService.log(TAG, "Action size in action!=null  ----"+actions.size() + "" + entity.absolutePath );
                                setActions(actions, entity.absolutePath);
                                for (Action action : actions) {
                                    if ((action != null) && (action.type != null)) {
                                        String modelName = action.model;
                                        LogService.log(TAG, "modelName unde sunt acuma= " + modelName);
                                        if ((modelName != null) && (modelName.length() > 0)) {
                                            LogService.log(TAG, "Model name : " + modelName);
                                            MetaioModel model = getModelForName(modelName);
                                            LogService.log(TAG, "model.texture : '" + model.texture + "' ");
                                            System.out.println("model.texture : '" + model.texture + "' ");

                                            IUnifeyeMobileGeometry object = model.model;
                                            String cosName2 = action.cosName;

                                            if ((object != null)) {
                                                if ("camera".equals(cosName2)) {
                                                    object.setCos(0);
                                                    System.out.println("Pose set 0 ");
                                                } else {
                                                    object.setCos(pose.getCosID());
                                                    System.out.println("Pose set : " + pose.getCosID());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (pose.isLost()) {
                for (MetaioEvent item : entity.events) {
                    Event event = item.event;
                    String type = event.type;
                    String cosName = pose.getCosName() != null ? pose.getCosName().toLowerCase() : "NULL";
                    String cosNameFromFile = event.cosName != null ? event.cosName.toLowerCase() : "NULL";

                    if ("markerLost".equals(type)) {
                        LogService.log(TAG, ">> Marker lost..");
                        if (!"".equals(cosNameFromFile) && !"".equals(cosName) && cosName.equals(cosNameFromFile)) {
                            ArrayList<Action> actions = item.actions;
                            if ((actions != null) && (actions.size() > 0)) {
                                setActions(actions, "");
                            }
                        }
                    }
                }
            }
        }
    }
@覆盖
公开无效onTrackingEvent(PoseVector姿势){
对于(int i=0;i>检测到标记..”);
如果(!“”.equals(cosName)和&&!“”.equals(cosNameFromFile)和&cosName.equals(cosNameFromFile)){
System.out.println(“>>cosName”+cosName);
ArrayList actions=item.actions;
如果((actions!=null)&&(actions.size()>0)){
LogService.log(标记“Action size in Action!=null----”+actions.size()+“”+entity.absolutePath);
setActions(actions,entity.absolutePath);
for(操作:操作){
if((action!=null)&&(action.type!=null)){
字符串modelName=action.model;
LogService.log(标记“modelName unde sunt acuma=“+modelName”);
如果((modelName!=null)&&(modelName.length()>0)){
LogService.log(标签,“型号名称:”+modelName);
MetaioModel模型=getModelForName(modelName);
LogService.log(标记“model.texture:”“+model.texture+””);
System.out.println(“model.texture:”“+model.texture+””);
IUnifeyeMobileGeometry对象=model.model;
字符串cosName2=action.cosName;
如果((对象!=null)){
如果(“摄影机”。等于(cosName2)){
setCos(0);
System.out.println(“姿势集0”);
}否则{
object.setCos(pose.getCosID());
System.out.println(“姿势集:+Pose.getCosID());
}
}
}
}
}
}
}
}
}
}else if(pose.isLost()){
对于(MetaioEvent项:entity.events){
事件=item.Event;
字符串类型=event.type;
字符串cosName=pose.getCosName()!=null?pose.getCosName().toLowerCase():“null”;
字符串cosNameFromFile=event.cosName!=null?event.cosName.toLowerCase():“null”;
if(“markerLost”.equals(类型)){
LogService.log(标记“>>标记丢失…”);
如果(!“”.equals(cosNameFromFile)和(!“”.equals(cosName)和&cosName.equals(cosNameFromFile)){
ArrayList actions=item.actions;
如果((actions!=null)&&(actions.size()>0)){
设置动作(动作“”);
}
}
}
}
}
}
}

它位于错误的线程中,因此我执行了以下操作:

if (object != null) {
                            mUnifeyeSurfaceView.queueEvent(new Runnable() {
                                @Override
                                public void run() {
                                    object.setTexture(texturePath);
                                }
                            });


                            LogService.log(TAG, "Texture set: " + texturePath);
                        } else {
                            LogService.log(TAG, "ERROR: object is null!");
                        }
 @Override
        public void onTrackingEvent(PoseVector poses) {
         for (int i = 0; i < poses.size(); i++) {
            Pose pose = poses.get(i);
            if (pose.isDetected()) {
                ArrayList<MetaioEvent> items = entity.events;
                for (int k = 0; k < items.size(); k++) {
                    MetaioEvent item = items.get(k);
                    Event event = item.event;
                    String type = event.type;
                    String cosName = pose.getCosName() != null ? pose.getCosName().toLowerCase() : "NULL";
                    String cosNameFromFile = event.cosName != null ? event.cosName.toLowerCase() : "NULL";

                    if ("markerDetected".equals(type)) {
                        LogService.log(TAG, ">> Marker detected..");
                        if (!"".equals(cosName) && !"".equals(cosNameFromFile) && cosName.equals(cosNameFromFile)) {
                            System.out.println(">> cosName " + cosName);
                            ArrayList<Action> actions = item.actions;
                            if ((actions != null) && (actions.size() > 0)) {
                                LogService.log(TAG, "Action size in action!=null  ----"+actions.size() + "" + entity.absolutePath );
                                setActions(actions, entity.absolutePath);
                                for (Action action : actions) {
                                    if ((action != null) && (action.type != null)) {
                                        String modelName = action.model;
                                        LogService.log(TAG, "modelName unde sunt acuma= " + modelName);
                                        if ((modelName != null) && (modelName.length() > 0)) {
                                            LogService.log(TAG, "Model name : " + modelName);
                                            MetaioModel model = getModelForName(modelName);
                                            LogService.log(TAG, "model.texture : '" + model.texture + "' ");
                                            System.out.println("model.texture : '" + model.texture + "' ");

                                            IUnifeyeMobileGeometry object = model.model;
                                            String cosName2 = action.cosName;

                                            if ((object != null)) {
                                                if ("camera".equals(cosName2)) {
                                                    object.setCos(0);
                                                    System.out.println("Pose set 0 ");
                                                } else {
                                                    object.setCos(pose.getCosID());
                                                    System.out.println("Pose set : " + pose.getCosID());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (pose.isLost()) {
                for (MetaioEvent item : entity.events) {
                    Event event = item.event;
                    String type = event.type;
                    String cosName = pose.getCosName() != null ? pose.getCosName().toLowerCase() : "NULL";
                    String cosNameFromFile = event.cosName != null ? event.cosName.toLowerCase() : "NULL";

                    if ("markerLost".equals(type)) {
                        LogService.log(TAG, ">> Marker lost..");
                        if (!"".equals(cosNameFromFile) && !"".equals(cosName) && cosName.equals(cosNameFromFile)) {
                            ArrayList<Action> actions = item.actions;
                            if ((actions != null) && (actions.size() > 0)) {
                                setActions(actions, "");
                            }
                        }
                    }
                }
            }
        }
    }
if (object != null) {
                            mUnifeyeSurfaceView.queueEvent(new Runnable() {
                                @Override
                                public void run() {
                                    object.setTexture(texturePath);
                                }
                            });


                            LogService.log(TAG, "Texture set: " + texturePath);
                        } else {
                            LogService.log(TAG, "ERROR: object is null!");
                        }