通过Android中的按钮点击加载AR模型 [英] Load AR-model through button tap in Android

查看:39
本文介绍了通过Android中的按钮点击加载AR模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Unity & 制作了一个基本的 AR 应用程序Vuforia 并将其导出到 Android,因此我可以在那里添加一些活动.当我使用应用程序中的 AR 相机扫描图像时,会弹出一个模型.没有什么新鲜事.

I have made a basic AR-app using Unity & Vuforia and exported it to Android, so I can add some activities there. When I scan the image with the AR-camera in the app, a model pops up. Nothing new there.

我想要实现的是,当用户在某个 Activity 中点击按钮时,假设按钮上的文本是大象",应用程序中的 AR 相机会打开,扫描图像并加载一个模型一头大象.

What I want to achieve, is that when a user taps a button in some activity, lets say the text on the button is "Elephant", the AR-camera in the app opens, scans the image and loads a model of an Elephant.

我的问题是:这可能吗?是否可以根据用户输入加载模型?如果这是可能的,搜索有关它的文档的最佳位置是什么?我已经在互联网上搜索过,但找不到任何具体的内容.我也是 Unity & 的新手Vuforia,所以我对这个程序了解不多.只有一些教程涵盖的内容.

My question is: is this possible? Is it possible to load a model depending on the user-input? And if this is possible, what would be the best place to search for some documentation about it? I've already searched on the internet, but can't find anything this specific. I'm also new to Unity & Vuforia, so I don't know that much about the program. Only the things some tutorials covered.

如果这个问题已经被问到/回答过,我很抱歉.

My apologies if this question has already been asked/answered.

提前致谢!

推荐答案

嗯,是的,这是可能的.为了让您的应用真正使用 AR 功能,您可以实施虚拟按钮技术.

Well, yes it is possible. And to make your app really use the AR feature you can implement the Virtual Button technique.

老实说,说到文档,高通是没用的.但由于您将 Unity 与 Vuforia 扩展一起使用,幸运的是大多数功能都包含在 Unity 文档中.

Honestly, when it comes to documentation, Qualcomm is useless. But since you use Unity with the Vuforia Extension, most features are luckily within the Unity Documentation.

我将通过两种方式解释您如何实现这一目标:

I'll explain how you can achieve this in two ways:

1.使用虚拟按钮 (VB)

首先,首先从 Assets>Qualcomm>Prefabs>Virtual Button 向场景中添加/删除 VB.确保 VB 是所用图像目标的子级.

First off, start by adding/dropping a VB onto the scene from Assets>Qualcomm>Prefabs>Virtual Button. Make sure the VB is a child of the Image Target used.

为定义您的 VB 需要做什么的图像目标创建一个新脚本.

Create a new script for the Image Target that defines what your VB needs to do.

您将从注册按钮开始:

void Start () {
        VirtualButtonBehaviour[] vbs = transform.GetComponentsInChildren<VirtualButtonBehaviour> ();

        for (int i=0; i < vbs.Length; ++i) {
            vbs[i].RegisterEventHandler(this);
        }

现在你可以开始使用按钮的功能了

And now you go ahead and start with the function of the button

public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

同样,如果您希望按钮在发布时执行某些操作:

Similarly if you want a button to do something on release:

public void OnButtonReleased(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

如果您希望按钮控制游戏对象,请继续将游戏对象声明为类中的公共变量,以便可以在检查器中访问它并进行相应的分配.

In case you want your button to control a Gameobject, then go ahead and declare the GameObject as a public variable in the class so that it can be accessed in the Inspector and assigned accordingly.

public GameObject human;

其中 GameObject 是变量类型,human 是我们引用的变量名

Where GameObject is the variable type and human is the variable name that we use for reference

再说一次,根据您想要获得的结果,有两种方法可以指定 callbuttonfunction() 可以做什么.

Now again, as per what you're trying to gain, there are two ways of assigning what the callbuttonfunction() can do.

  • Application.LoadLeve("Levelname")

这会加载一个新场景,其中新对象加载到同一图像目标上

This loads a new scene where the new object is loaded onto the same Image Target

  • Model.enabled(false)Elephant.enabled(true)

这只是禁用了当前模型并启用了 Elepant 模型.在课程开始时将这些设置为公共变量将使在 Inspect 元素中分配模型变得更加容易.

This simply disabled the current model and enabled the Elepant Model. Setting these to public variables at the start of your class will make it easier to assign the models within Inspect element.

2.屏幕按钮 (OB)

  • 如果您想要屏幕上的按钮,那么只需将按钮 UI 置于相机的父级,并将其放置在屏幕的特定角落或其他位置.
  • 现在,如果您运行按钮,它将位于 void Update() 内,您可以使用 Unity 使用触摸功能.

真的希望这能帮助你和其他所有患有高通绝对不支持.如果您需要更多说明,请联系我.

Really hope this helps you and everyone else who suffers from absolutely NO support from Qualcomm. Hit me up if you need more clarification.

这篇关于通过Android中的按钮点击加载AR模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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