Log in or register to post comments

you can have multiple objects in a imagetarget?

August 26, 2011 - 2:40pm #18

Hello
My English is not very good and are new AR applications, and also am using a translator to put my concerns XD.

is possible to have the same imagetarget several 3D objects?
if possible as an object is created and destroyed another (or in the worst case hide) by a virtual button?

or Button on the screen!

for example, have one main area and pressing a button either on screen or a virtual button to change me by another object.

2 rotate an object placed on the same axis is possible? encuntra that functions to perform this action.

thanks in advance!!

GnnSLxndR

Re: you can have multiple objects in a imagetarget?

August 28, 2011 - 11:55am #17

Yes. Make each object a child of the image target. Add some virtual buttons to the image target. Give each button a different name. Then add a script like this to the image target:

using UnityEngine;

public class VirtualButtonSwapModel : MonoBehaviour,
                                      IVirtualButtonEventHandler
{
    // Set these in the Inspector view
    public GameObject model1;
    public GameObject model2;
    public GameObject model3;
    public GameObject model4;

    void Start()
    {
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }
        
        model1.active = true;
        model2.active = false;
        model3.active = false;
        model4.active = false;
    }

    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        switch (vb.VirtualButtonName)
        {
            case "red":
                model1.active = true;
                model2.active = false;
                model3.active = false;
                model4.active = false;
                break;

            case "blue":
                model1.active = false;
                model2.active = true;
                model3.active = false;
                model4.active = false;
                break;

            case "yellow":
                model1.active = false;
                model2.active = false;
                model3.active = true;
                model4.active = false;
                break;

            case "green":
                model1.active = false;
                model2.active = false;
                model3.active = false;
                model4.active = true;
                break;
        }
    }
    
    public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
    }
}

- Kim

Re: you can have multiple objects in a imagetarget?

August 28, 2011 - 1:16pm #16

thank you very much Kim.
When testing do you know if it was excited.

another question that comes to me, I realize the model in blender export them to. fbx besides it has a running animation in blender infinitely or time you want, but when exported to unity is performed only once.

blender is best explained in a sphere made ​​another turn around (360 °) and this operation is doubled to keep doing that you want.
in unity only makes a turn to be or do wrong?

I go back I say my English is poor use an interpreter to come to you XD
thanks

Re: you can have multiple objects in a imagetarget?

August 28, 2011 - 2:01pm #15
Quote:

When testing do you know if it was excited.

Sorry, I don't understand the question.

For looping animations, try setting the wrap mode: http://unity3d.com/support/documentation/ScriptReference/Animation-wrapMode.html

void Awake() {
    animation.wrapMode = WrapMode.Loop;
}

- Kim

Re: you can have multiple objects in a imagetarget?

August 28, 2011 - 5:30pm #14

hello kim.

testing the code for multiple objects. I have to assign it to the 3D object because it will take the value zero.

the way I'm trying to assign it this way, following the example:

modelo1 = transform.FindChild("3d object name").gameObject;

I'm right or is there another way?

thanks again

Re: you can have multiple objects in a imagetarget?

August 29, 2011 - 9:30pm #13

The other way is to drag objects onto the fields in the Inspector view. See the attached screenshot.

- Kim

Re: you can have multiple objects in a imagetarget?

September 5, 2011 - 12:37am #12

Hi, Is it possible to do this without the unity extension (as this is in the unity section), and is there a quick and easy way to use the regular menu to change the model? I have seen this done in the ARToolKit, where you could load different objects with 1 target, but I want to have about 3 detectable targets that have 2-3 models per marker that you can select from once it detects the relevant marker.

Re: you can have multiple objects in a imagetarget?

September 5, 2011 - 5:58pm #11

You can call a native function in response to an Android UI event using the JNI (Java Native Interface). There are plenty of examples in the sample applications, for instance look at the initApplicationNative method:

ImageTargets.java

private native void initApplicationNative(int width, int height);

ImageTargets.cpp

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative(
                            JNIEnv* env, jobject obj, jint width, jint height)
{
    ...
}

Then, in native you can have a global variable to keep track of which model to render. Use this variable in the renderFrame method to switch the model rendering logic. Take a look at the FrameMarkers sample for an example of switching the model (renderFrame in FrameMarkers.cpp).

- Kim

Re: you can have multiple objects in a imagetarget?

September 7, 2011 - 7:45am #10

Hello.
How are you Kim?
drag objects onto the fields in the Inspector view (post # 6), can manipulate the object but not the stage.

the way I did was:

/ Get handle to the teapot object
mTeapot = GameObject.Find("teapot");
mprueba = GameObject.Find("H2O");

mTeapot.SetActiveRecursively(false);
mprueba.SetActiveRecursively(true);
...

public void OnButtonPressed(VirtualButtonBehaviour vb)
{
switch (vb.VirtualButtonName)
{
case "red":
mTeapot.SetActiveRecursively(true);
mprueba.SetActiveRecursively(false);
break;

...

now:
using the virtual button to change the object, the object is not displayed.
to display the object on the screen, you must remove the phone. of the target image

My question is, no way to update the screen without removing the phone. of the target image?

forgive my English

thanks

Re: you can have multiple objects in a imagetarget?

September 8, 2011 - 11:35am #9
Quote:

using the virtual button to change the object, the object is not displayed.

I'm not sure what you mean. I tried the code you posted and it seems to work fine. I used the teapot and a simple cube object, and was able to swap the models by pressing the virtual buttons. I didn't have to look away from the target for it to work.

Make sure you have a TrackableEventHandler attached to your image target, like in the sample applications.

- Kim

Re: you can have multiple objects in a imagetarget?

September 8, 2011 - 11:07pm #8

hi!! kim

video test

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

can you update the screen without removing the phone?.

thanks

Re: you can have multiple objects in a imagetarget?

September 10, 2011 - 7:33am #7

Do you see similar problems with the regular VirtualButtons sample?

It looks like you're losing tracking. Try printing out the target, tracking typically works better off printed media compared to tracking off a computer screen.

- Kim

Re: you can have multiple objects in a imagetarget?

September 10, 2011 - 2:30pm #6

Thanks Kim!

I will test with a sheet of printing

question.

at runtime can be placed enable or disable the virtual buttons?

Re: you can have multiple objects in a imagetarget?

September 12, 2011 - 2:21pm #5

Yes, you can enable or disable a virtual button by enabling or disabling the VirtualButtonBehaviour component. For example, if you wanted to disable all the virtual buttons in your scene you could use this:

foreach (VirtualButtonBehaviour vbb in FindObjectsOfType(typeof(VirtualButtonBehaviour)))
{
    print("disabling virtual button named " + vbb.VirtualButtonName);
    vbb.enabled = false;
}

- Kim

Re: you can have multiple objects in a imagetarget?

January 10, 2013 - 7:34pm #4

hi all.

i try to add sript in post #2, and it's work.

my question :

how to make one virtual button can show and hide one object? if i press red button in first time, the object will appear, and if i press another button, another object will appear without hiding an object in red button. and then, if i press red button again, the object in red button will hide without hiding an another object.

so what can i do for this situation?

thx.

If you look at

January 11, 2013 - 3:30am #3

If you look at the VirtualButtonEventHandler script then you should be able to customise the section of code below to get the desired behaviour.

    /// Called when the virtual button has just been pressed:

    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];

    }

 

 

 

However, you will need to find the Virtual Button itself so you can enable and disable it.  Check the VirtualButton.cs script for the exact methods to use here.

HTH

N

 

 

 

 

you can have multiple objects in a imagetarget?

September 8, 2014 - 5:40am #2

ksiva wrote:

Yes. Make each object a child of the image target. Add some virtual buttons to the image target. Give each button a different name. Then add a script like this to the image target:

using UnityEngine; public class VirtualButtonSwapModel : MonoBehaviour, IVirtualButtonEventHandler { // Set these in the Inspector view public GameObject model1; public GameObject model2; public GameObject model3; public GameObject model4; void Start() { VirtualButtonBehaviour[] vbs = GetComponentsInChildren(); for (int i = 0; i < vbs.Length; ++i) { vbs[i].RegisterEventHandler(this); } model1.active = true; model2.active = false; model3.active = false; model4.active = false; } public void OnButtonPressed(VirtualButtonBehaviour vb) { switch (vb.VirtualButtonName) { case "red": model1.active = true; model2.active = false; model3.active = false; model4.active = false; break; case "blue": model1.active = false; model2.active = true; model3.active = false; model4.active = false; break; case "yellow": model1.active = false; model2.active = false; model3.active = true; model4.active = false; break; case "green": model1.active = false; model2.active = false; model3.active = false; model4.active = true; break; } } public void OnButtonReleased(VirtualButtonBehaviour vb) { } }

- Kim

how to make this case but using Gui button in unity?

you can have multiple objects in a imagetarget?

May 8, 2016 - 11:23am #1

Hi, 

How I can accompish this feature on regular GUI buttons ?

I need to hide all 3d objects linked to ImageTarget and then make visible each one of them using GUI buttons ...

Please help me out.

Thanks

Bart

 

Log in or register to post comments