Log in or register to post comments

Scaling downloaded imageTarget. "itSize"

December 22, 2011 - 5:38am #7

Hi,
I load and activate downloaded markers from web. It comes with a problem.
Accordingly i cant see "imagetargets" in project and i cant calibrate objects.

I want to know how can i equalise Image's ratio to Plane's ratio or sizes?

i found "itSize" varible in dataset.cs script.

myPlane.transform.localScale = itSize.transform.localScale;

How can i reach "itSize" from another Script ?

Re: Scaling downloaded imageTarget. "itSize"

December 22, 2011 - 8:18pm #6

Once you have an ImageTarget in the scene you can scale it down using the Inspector view. Note this is a uniform scale. If you want to know the aspect ratio of the target you can use the ImageTargetBehaviour.AspectRatio property.

- Kim

Re: Scaling downloaded imageTarget. "itSize"

December 30, 2011 - 2:15pm #5

How can i use AspectRatio? it isnt giving me float result.

public bool markerDedected;

void Update () {
		
if(markerDedected){

ImageTargetBehaviour ITB=GetComponent<ImageTargetBehaviour>();

Debug.Log(ITB.AspectRatio.ToString());

Debug.Log(ITB.mAspectRatio.ToString());

		
	}
}

Re: Scaling downloaded imageTarget. "itSize"

December 30, 2011 - 4:07pm #4

Hmm, it should... I created the following script:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour
{
    void Update ()
    {
        ImageTargetBehaviour ITB=GetComponent<ImageTargetBehaviour>();
        Debug.Log(ITB.AspectRatio.ToString());
    }
}

And attached it to the ImageTargetChips object in the ImageTargets sample. The log prints 0.7 each frame. What are you seeing in the log?

- Kim

Re: Scaling downloaded imageTarget. "itSize"

December 30, 2011 - 5:20pm #3

My project doesnt include ".dat" and ".xml" files in Unity. Script download them at runtime on device. Than i can't test this command in Unity, so i added "if(markerDedected)" command.

So when tracking found app crushes. If I delete "if(markerDedected)" command app crushes directly.

how can i use that with downloaded markers?

Re: Scaling downloaded imageTarget. "itSize"

January 2, 2012 - 7:47am #2

Okay, now I understand. It looks like you've found a bug, the AspectRatio property isn't initialized for trackables created at runtime. We'll fix this for the next release.

In the meanwhile, you can fix it on your end by editing the following scripts:

ImageTargetBehaviour.cs - comment out the Application.isEditor check in AspectRatio.set

    public float AspectRatio
    {
        get
        {
            return mAspectRatio;
        }

        set
        {
            /*
            if (!Application.isEditor)
            {
                Debug.LogError("ImageTargetBehaviour: 'AspectRatio' must " +
                    "not be set at run-time.");
                return;
            }
            */

            mAspectRatio = value;
        }
    }

DataSet.cs - set the AspectRatio

    private ImageTargetBehaviour CreateImageTarget(int id,
                                                   string itName,
                                                   Vector2 itSize)
    {
        ...

        newITB.CorrectScale();
        newITB.AspectRatio = itSize[1] / itSize[0];

        return newITB;
    }

- Kim

Re: Scaling downloaded imageTarget. "itSize"

January 2, 2012 - 8:36am #1

Thank you so so so much Kim.

Log in or register to post comments