Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I want to show a different object every time a target is scanned using vuforia SDK.
Currently, I'm able to show an object on the specific target.

What I have tried:

    public ImageTargetRendererObj(ImageTargets activity, SampleApplicationSession session) {
        mActivity = activity;
        vuforiaAppSession = session;
        //Instantiating a virtual world
        world = new World();
        world.setAmbientLight(100, 100, 100);
        // Set the ambient light source intensity. Negative: the entire scene will be darkened; positive: will illuminate everything.

        world.setClippingPlanes(2.0f, 3000.0f);

        sun = new Light(world);
        sun.setIntensity(250, 250, 250);

        // Set the color of the display
        if (!TextureManager.getInstance().containsTexture("texture")) {
            Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(
                    mActivity.getResources().getDrawable(R.drawable.a)), 64, 64));
            TextureManager.getInstance().addTexture("texture", texture);
        }
        FileUtils.copayAssetsToSdCard(activity.getAssets());
        try {
            tmp = Loader.loadOBJ(new FileInputStream(FileUtils.path+ "sphere.obj"),new FileInputStream(FileUtils.path+ "sphere.mtl"), 1);
//            tmp = Loader.loadOBJ(new FileInputStream(FileUtils.path+"DeadTree.obj"),new FileInputStream(FileUtils.path+"DeadTree.mtl"), 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if(tmp != null && tmp.length >= 1){
            cylinder = tmp[0];
        }
        cylinder.strip();
        cylinder.build();

        for (Object3D o3 : tmp) {

            o3.calcTextureWrapSpherical();

            if (null != o3.getMesh()) {
                //Color the model

                o3.setTexture("texture");

            }
            o3.strip();
            o3.build();
        }


// Transform (scale, rotate, translate) the object: Depends on your need.
// cylinder.scale(scale);
// cylinder[0].rotateX(90.0f);
// cylinder.rotateY(w); cylinder.rotateZ(w);
// cylinder.translate(x, y, z);
  

        Object3D[] hi = null;

        try {
            hi = Loader.load3DS(activity.getAssets().open("bounce.3DS"), 1);
        } catch (IOException e) {
            e.printStackTrace();
        }


        for (Object3D o3 : hi) {

            o3.calcTextureWrapSpherical();

            if (null != o3.getMesh()) {

                o3.setTexture("texture");

                if (o3.getAnimationSequence() != null) {
                    mesh = o3.getAnimationSequence().getKeyFrames();

                }

            }
            o3.strip();
            o3.build();
        }
        */


        world.addObjects(cylinder);
        // world.addObjects(hi);

        cam = world.getCamera();

        SimpleVector sv = new SimpleVector();
        sv.set(cylinder.getTransformedCenter());
        sv.y -= 100;
        sv.z -= 100;
        sun.setPosition(sv);

       /* sv = new SimpleVector();

        // sv.set(hi[0].getTransformedCenter());
        sv.y -= 5000;
        sv.z -= 5000;
        sv.rotateX(180);
        sun.setPosition(sv);*/

        // for older Android versions, which had massive problems with garbage collection
        MemoryHelper.compact();

    }
Posted
Updated 15-Aug-18 4:12am
v3

1 solution

If this is an Android application, try rendering each object in a separate fragment.

The guidelines on using fragments you can find it here:

Fragments  |  Android Developers[^] and Creating a Fragment  |  Android Developers[^]
 
Share this answer
 
Comments
Member 10960567 16-Aug-18 1:01am    
Thanks for the answer, but fragments doesn't solve the problem and I've updated vuforia configurations and updated the database settings that exported from vuforia developer console.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900