Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

c# - Load AR-model through button tap in Android

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.

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.

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.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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. Using Virtual Buttons (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.

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

You'll start with registering the buttons:

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;

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

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) and Elephant.enabled(true)

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. On-screen Buttons (OB)

  • If you want on-screen buttons, then just parent the button UI to the Camera and position in a particular corner of the screen or something.
  • Now if you function the button it will be within void Update() and you could use the scripting reference from Unity using the touch functions.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...