Log in or register to post comments

Premade code resources?

April 18, 2011 - 7:40am #1

Essentially, I have 4 versions of this model that I want overlay. I want only one to be active at any given time, and that means making the rest invisible on start up until a button is invoke to reveal another one. When another button is occluded I want it to deactivate the previously selected model (regardless of which was active) to turn off and allow the selected one to turn on.

I've been comparing the structure of the sample application on virtual buttons with what is available on the Unity documentation pages and I now know it uses C# scripting, and I think I can generally edit at least a template that exists if it is structured to do what I'm hoping.

In my case, rather than than changing the material on button press, I'm trying to editthe example to something that changes the game object state to inactive and active by means of the user pressing virtual buttons. Most of the problems I've had are from my inexperience, so I do realize that I'm working with a significant handicap here, and I've searched for something specific to the qualcomm VB functionality but little is showing up in that regard.

Is there any resource that anyone can recommend with prebuilt templates that I can reference and is more specific to what's connected to QCAR's functionality?

Re: Premade code resources?

April 23, 2011 - 5:57pm #7

I removed it. I got the sample to work and I figured out somewhat how the script works in the example, so I'll experiment from here and see what I can do on my own for a bit. You've helped me quite a bit in the last few weeks and I'd like to thank you yet again for all of it.

As you said, playing around with unity answered some of my questions. So I'll slowly move into the model interaction once I more completely understand the sample code.

The reason I'd asked about it was because although I had sample I had to import it and not all the time did it have the pre configuration for me to look at. It finally did after another attempt to import the project

Re: Premade code resources?

April 21, 2011 - 7:06am #6

Try adding the ImageTargetEventHandler script to the target instead of to the teapot. This is how the sample is set up. Also, the ImageTargetEventHandler that comes with the VirtualButtons sample has an array to hold materials. You need to drag and drop the materials onto this array in the Inspector to set things up correctly. Please take a careful look at the sample project to see how things are set up there.

- Kim

p.s. This Youtube video needs to be removed. The beta license agreement states that videos including QCAR cannot be posted in the public space without prior permission from Qualcomm. Please send us private video links directly, to

. Thanks!

Re: Premade code resources?

April 21, 2011 - 6:44am #5

I've decided for the moment to try the sample app to see if I can get the texture changes to work first. It'll be a bit simpler and I think it highlights another issue with my work flow. I've actually tried putting that together in unity with the source files and while the 3D works the buttons don't seem to be. I think at this point rather than explain it it'll be better to show you what I'm doing. It may be easier for you to see where I'm going amiss:

http://www.youtube.com/watch?v=RSQoXaK7CBQ

While I'd still like to eventually do the model on/off commands i think I should've tried getting this to work first

I did try the code you posted but when I spoke to someone else he said I should have started by trying to get the original to work and then modify from there by tweaking it slightly. Sorry if it seems like I'm going a bit back and forth

Re: Premade code resources?

April 18, 2011 - 6:57pm #4

Oh, sorry my pseduo-code was a bit sloppy. I defined m_Models at the top and then referenced it as mModels later, just be use to use the same variable name :)

The point of the public array is to expose an array field in the Inspector view that you can drag models onto. You could also just create a separate public GameObject variable for each of your models, connect them in the Inspector, and reference them that way. It sounds like you just need to play around with Unity a little more. Practice exposing fields in the Inspector by adding public variables to your C# class, and dragging objects from your Hierarchy view to connect them. Then you can use them in the script.

- Kim

Re: Premade code resources?

April 18, 2011 - 3:40pm #3

Hey, so far the editor's not giving major fusses about the changes. It does however say that the mModel doesn't exist in the context. Reading around, it seems I haven't define anything for it, I gather this is where you were talking about modifying the unity configuration?

Re: Premade code resources?

April 18, 2011 - 8:14am #2

Use the ImageTargetEventHandler in the VirtualButtons sample as a starting point. In the OnVirtualButtonPress method, replace the button names in the switch statement with your own button names. Rather than switching the material, you could simply enable or disable your models. Instead of this:

public Material[] m_TeapotMaterials;
...
this.transform.FindChild("teapot").renderer.material = m_TeapotMaterials[1];

You could have this:

public GameObject[] m_Models;
...
mModels[0].active = true;

That allows you to create an array of model objects in the Inspector view.

Of course you'll need to update the rest of the file to meet your project's needs as well. The important point is that QCAR provides two simple callbacks, OnVirtualButtonPress and OnVirtualButtonRelease. The rest is up to you!

- Kim

Log in or register to post comments