Log in or register to post comments

Unity basics

May 4, 2013 - 4:16am #1

Hello.

I am working on unity and new to this platform.

I have the following questions. Can anyone please guide me with the answers or links to where I can find the solutions.

 

1. How to open the downloaded unity packages for sample apps and edit the C# parts of the code?

2. How to add virtual buttons on a imagetarget and set an function to be executed when it is pressed/touched?

3. How do I create 3D objects like the "TEAPOT"?

4. How to include animations to objects(Eg. the bowl moving around in the Multi-targets example?

 

Thank You.

My mail id is :

 

Unity basics

June 7, 2013 - 8:53am #23

Hello.

In the VirtualButtonEventHandler.cs, we have the declaration:

public Material[] m_TeapotMaterials;

This variable is used to set material for rred, green.. ....

Can I know what are the contents of the variable m_teapotMaterials & how does the color change actually take place on teapot due to these.

Unity basics

May 14, 2013 - 11:01am #22

.the console will display the message "OnButtonPressed" when i press the button . but the teapot does not change it color...........

 

mActiveMaterials.Add(m_TeapotMaterials[0]);

 

other than using the array, can i change the material directly by assign its name to the code?  i want to try the simplest code to detect whether the button is function or not  

Unity basics

May 13, 2013 - 11:03am #21

1. delete the default camera and add AR camera

Be sure that you are loading and activating the dataset in the Inspector

 

2. inser the image target from prefab, chose stone and chip

3. insert the teapot from model folder

Be sure that the teapot is a child of the target in the Hierarchy panel.

4. insert the virtual button form perfab folder and scale it

The VB needs to be a child of the target as well.

 

5. change the name oto "red" under the properties of "virtual button behaviour"

6. add component of "virtual button event handler " to image target.

The VB event handler script from the sample enables you to define materials to be assigned to the teapot on button events. You'll need to import these materials from the sample and select them as the elements of the Teapot Materials array. Also be sure that your VB event handler script is added to the parent ImageTarget instance.

7. run the playmode......

Unity basics

May 13, 2013 - 10:43am #20

Hello , i am still stuck with the issue....T_T   if you don't mind, can you please explain the procedure to make the virtual button work?

 

this is my procedure :

1. delete the default camera and add AR camera

2. inser the image target from prefab, chose stone and chip

3. insert the teapot from model folder

4. insert the virtual button form perfab folder and scale it

5. change the name oto "red" under the properties of "virtual button behaviour"

6. add component of "virtual button event handler " to image target.

7. run the playmode......

 

and the teapot does not change to red material .....>.<

 

did i miss out something during the procedure? 

Unity basics

May 9, 2013 - 11:36am #19

Hi, the code in the tutorial is really basic, and it is already explained step by step;

the assumption is that you have at least some basic understanding of Unity and C# programming; 

my best recommendation would be to tackle the Unity development first, and then to dig into Vuforia.

 

Unity basics

May 9, 2013 - 10:31am #18

Good eveninig Alessandro.

I am finding it difficult to digest the code and not understanding what part do I add to the OnButtonpressed function

Can you make it a little simpler for me.

My problem : I have an Imagetarget, a .3ds object and a virtual button.

Result I am expecting: On click of the virtual button I want  the 3ds object to be rendered on the screen.

PLease guide in a step by step manner of :

1. What all .cs(C#) files I should create and in which folder of the project?

2. What all inbuilt scripts should I update. (If update what is the code I should update)?

3. Is there is anything else I needed  to be done.!!

 

Pls help me out man. I am stuck at this stage from the past two days. Not able to continue with my project at all...

Unity basics

May 8, 2013 - 11:56pm #17

Hi, in the tutorial (article) I'm referring to the names of the classes are all specified;

in general, in C#, the name of a class (script) is also the name of the file + cs estension;

for instance, ImageTargetBehaviour would be => ImageTargetBehaviour.cs; note that in the Unity inspector view, these component names appear with blank spaces between main words, for instance:

MyCustomScript.cs would be shown as "My Custom Script"

Last note: OnButtonPressed (which I was mentioning) belongs to VirtualButtonEventHandler.

 

Unity basics

May 8, 2013 - 10:34pm #16

Can you please make it a little clear by specifying the .cs file name from which these code snippets you mentioned are taken from.

I am in the very begining stages of the Scripts.

 

Unity basics

May 8, 2013 - 11:22am #15

Hi, to achieve that you will need to add some code in the OnButtonPressed;

something similar is explained here (with code snippets) but you will need to adapt it to your specific case:

https://developer.vuforia.com/forum/faq/unity-how-can-i-dynamically-attach-my-3d-model-image-target

 

Unity basics

May 8, 2013 - 10:27am #14

I have 2 small images(just like red,green etc) of apple and A in my image targets.

On clicking the Virtual button A I should get the 3d object  of an A in the center of the Image target

when the virtual button apple is pressed I should get a 3d apple object

CAn you give me code snipets for this /links to where I can get these.

 

Note: I have already added the obj files of the A and Apple 3d objects

I have attached the screen shot  of whatever I have done..

AttachmentSize
Image icon upload.jpg188.42 KB

Unity basics

May 8, 2013 - 9:27am #13

Glad to help ;-)

Unity basics

May 8, 2013 - 9:18am #12

By the way Allasandro I wanna tell you that you have guided me very well.

From knowing nothing before a week to easily comfortable with the tool is all because of you.

 

Have some problems with the coding (like adding animations) but have the confidence that I can learn under your guidance.

 

By the way the colors problem is solved.

Unity basics

May 8, 2013 - 9:11am #11

Oh I found it. OK here's my plan with the app.

 

I have 2 small images(just like red,green etc) of apple and A in my image targets.

On clicking the Virtual button A I should get the 3d object  of an A in the center of the Image target

when the virtual button apple is pressed I should get a 3d apple object

CAn you give me code snipets for this /links to where I can get these.

 

Note: I have already added the obj files of the A and Apple 3d objects

I have attached the screen shot  of whatever I have done..

 

AttachmentSize
Image icon upload.jpg188.42 KB

Unity basics

May 8, 2013 - 7:19am #10

Hi, not sure to follow here; this is the interface definition (since it is an interface, the funtions are declared but not implemented):

 

public interface IVirtualButtonEventHandler
{
    /// <summary>
    /// Called when the virtual button has just been pressed.
    /// </summary>
    void OnButtonPressed(VirtualButtonBehaviour vb);

    /// <summary>
    /// Called when the virtual button has just been released.
    /// </summary>
    void OnButtonReleased(VirtualButtonBehaviour vb);
}

 

 
And this is the code extracted from the VirtualButtonEventHandler.cs (from the VB sample); here, as you can see, those functions are implemented:
/// <summary>
    /// Called when the virtual button has just been pressed:
    /// </summary>
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");

        if (!IsValid())
        {
            return;
        }

        // Add the material corresponding to this virtual button
        // to the active material list:
        switch (vb.VirtualButtonName)
        {
            case "red":
                mActiveMaterials.Add(m_TeapotMaterials[0]);
                break;

            case "blue":
                mActiveMaterials.Add(m_TeapotMaterials[1]);
                break;

            case "yellow":
                mActiveMaterials.Add(m_TeapotMaterials[2]);
                break;

            case "green":
                mActiveMaterials.Add(m_TeapotMaterials[3]);
                break;
        }

        // Apply the new material:
        if (mActiveMaterials.Count > 0)
            mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];
    }

 

 

Unity basics

May 8, 2013 - 7:12am #9

Good evening Alex. I have opened the C# code of  VirtualButtonEventHandler and checked the IVirtualButtonEventHandler interface.

But i only found the call to Onbuttonpressed and Onbuttonreleased.

The functions are not defined there.

So, where can I find the definition for OnButtonPressed & onButtonReleased.

 

Unity basics

May 8, 2013 - 12:09am #8

Hi, 

concerning your question on how to change color of the model, this can be done in general by assigning different material to a model, and in the material you can then select the type of rendering (shader), such as Diffuse, Decal, etc... there you can also specify the specific base color and the textures.

However, this is a basic Unity subject, so I would recommend you search the Unity website on this matter:

http://docs.unity3d.com/Documentation/ScriptReference/Material.html

Concerning Virtual Buttons:

If you look at the sample, you can see the arrangement of virtual buttons attached under the ImageTarget "Wood".

The ImageTarget also has a component called VirtualButtonEventHandler (you can see it in the inspector view); this component is a C# class that implements the IVirtualButtonEventHandler interface; such interface, in particular has 2 methods:

OnButtonPressed

OnButtonReleased

Those methods are triggered whenever a virtual button is occluded or de-occluded; there, you can put your code to perform specific actions.

For the rest, my suggestion is to explore the sample code (scripts) and scene structure and trying to understand how things are interconnected (as that's on of the goal of our samples !, to teach you about Vuforia ;-)

 

I hope this helps.

 

Unity basics

May 7, 2013 - 8:35pm #7

Thanks very much. Found em and used.

I did not know that frame markers were transperent and we can customize them. This piece of information will greatly make my app better.

 

My next problem:

Color change:

> I have downloaded 3d objects as .obj, .3ds and .fbx formats.

> How do I change the color of these objects in unity. (I am working on an app with a 3d apple obj file,but the color of the apple is grey and I wanted to change it to red)

virtual button handler:

>In the demo apps of vuforia we have a virtual button app which changes the color of teapot as the buttons are pressed.

> How is it done actually? Where are the Button click listeners defined.

>In my project I want a 3d object to appear when a virtual button is pressed. How can I do it?

 

Unity basics

May 7, 2013 - 9:41am #6

Great to hear you made it work!

Now, for the Frame Marker textures, you will find them under your Unity sample project, in this folder:

\Assets\Editor\QCAR\FrameMarkerTextures\

the file is called frame-markers-transparent.zip, just unzip it and you'll find all the textures as PNG files;

note: they are transparent textures which inclue the Frame Marker borders; then you can combine them with some image of your choice to be placed (optionally) in the middle of the marker (as long as the binary encoding on the borders is well visible)

 

 

Unity basics

May 7, 2013 - 8:59am #5

PEace. It worked. Thanks for the help.

 

I have another problem.!!!

I have used around 20 frame markers in my program..

But i dont have image samples(i.e image targets) to print on after the first four(with id=0,id=1,id=2,id=3) given in their trial app.

 

Where can I find all others???

Unity basics

May 6, 2013 - 11:12pm #4

Hi, have you enabled in QCARBehaviour the"Load Data Set..." flag and enable "Activate" checkbox ?

Then, in your image target in the scene you also need to select the Dataset and the target (there are a few combo boxes in the inspector view);

note: these steps are described in the guide where I was pointing you to.

Then, when you aim your device to a printed target you should be able to see the teapot 3D model appearing on the targets.

 

Unity basics

May 6, 2013 - 9:01pm #3

Thanks.

But when I download the unity sample codes and open, only a blank screen with regular camera is opening.

How do I get to see the scene?

Please help.

Unity basics

May 5, 2013 - 10:39am #2

Hi,

have a look at this guide explaning how to use, compile and run our samples:

https://developer.vuforia.com/resources/dev-guide/step-2-compiling-simple-project

Also, have a look at the Virtual Buttons samples.

For Unity-related generic questions, your best bet is to study a bit of Unity basics before digging into Vuforia Unity extensions (and before posting questions in this Vuforia forum):

http://unity3d.com/learn/tutorials/modules

 

Log in or register to post comments