Categories
Innovation projects technology

ARCore Unity Augmented images, Multiple images.

I’ve been playing with the Unity ARCore SDK for sometime now,
In the latest release they have added Augmented Images, which is awesome!

For some reason though the examples they released only framed a number of pictures.

That is that you could have multiple Images being tracked, but the example just added 4 objects to frame said tracked images.
The first thing Myself and a few others wanted to do was track multiple images with multiple objects.

For me I wanted 2 images to represent 2 different objects, or at least that’s what I started with.
Here is the thought process,

Have an image database, the index of the image in the database will match to the index of a list of prefabs that we will create.
When we scan the image, get it’s position in the database, create the object that matches the index in our list.

We just need a small modification to the

  • AugmentedImageVisualizer

And of course our image database.

I made an image database with the directions;

Create database file
In Project window, select your desired set of reference images (PNG or JPG), then right-click and select Create > GoogleARCore > AugmentedImageDatabase.

Next we need to modify the AugmentedImageVisualizer to add a list of prefabs that we want.
When the Image Visualiser is updated, check for the Image and update the position of the specific object.

public class AugmentedImageVisualizer : MonoBehaviour
{
    public AugmentedImage Image;
    public List<GameObject> prefabs;
    public void Update()
    {
        if (Image == null || Image.TrackingState != TrackingState.Tracking)
        {
            prefabs[Image.DatabaseIndex].SetActive(false);
            return;
        }
        float halfWidth = Image.ExtentX / 2;
        float halfHeight = Image.ExtentZ / 2;
        prefabs[Image.DatabaseIndex].transform.localPosition = Image.CenterPose.position;
        prefabs[Image.DatabaseIndex].transform.forward = Image.CenterPose.forward;
        prefabs[Image.DatabaseIndex].SetActive(true);

    }
}

After we have done this, match your prefabs with the image index in the inspector, like below, Element 0 I want to track to Image index 0.

1 reply on “ARCore Unity Augmented images, Multiple images.”

Leave a Reply

Your email address will not be published. Required fields are marked *