如何在vuforia android或unity中每次使用不同的目标跟踪或渲染一个又一个对象? [英] How do I track or render one after another object using different targets every time in vuforia android or unity?

查看:83
本文介绍了如何在vuforia android或unity中每次使用不同的目标跟踪或渲染一个又一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每次使用vuforia SDK扫描目标时都显示不同的对象。

目前,我可以在特定目标上显示一个对象。



我尝试过:



 public ImageTargetRendererObj(ImageTargets活动,SampleApplicationSession会话){
mActivity = activity;
vuforiaAppSession = session;
//实例化虚拟世界
world = new World();
world.setAmbientLight(100,100,100);
//设置环境光源强度。否定:整个场景会变暗;积极的:将照亮一切。

world.setClippingPlanes(2.0f,3000.0f);

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

//设置显示的颜色
if(!TextureManager.getInstance()。containsTexture(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()){
//为模型着色

o3.setTexture(texture);

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


//变换(缩放,旋转,平移)对象:取决于您的需要。
// cylinder.scale(scale);
// cylinder [0] .rotateX(90.0f);
// cylinder.rotateY(w); cylinder.rotateZ(W);
// cylinder.translate(x,y,z);


Object3D [] hi = null;

尝试{
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); * /

//适用于较旧的Android版本,垃圾收集存在大量问题
MemoryHelper.compact();

}

解决方案

如果这是一个Android应用程序,请尝试在单独的片段中呈现每个对象。



使用片段的指南,你可以在这里找到:



片段  |  Android开发者 [ ^ ]和创建片段  |  Android开发者 [ ^ ]

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();

    }

解决方案

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[^]


这篇关于如何在vuforia android或unity中每次使用不同的目标跟踪或渲染一个又一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆