Skip to content

Starting a new project

Philip Lamb edited this page Dec 5, 2024 · 7 revisions

Getting and installing the arunityX package

  1. If starting with a new Unity project, the "3D" template is most appropriate.
image
  1. The artoolkitX for Unity package is published on the OpenUPM package management system. Go to https://openupm.com/packages/org.artoolkitx.artoolkitx-unity/ and follow the instructions on that page on how to add the package to your Unity project using Unity's package manager.
  2. (Alternative to step 2). If you wish to modify artoolkitX for Unity, check out the master branch of the artoolkitX for Unity repository, and open the root of the checked-out repository as a Unity Project.

Add essential artoolkitX objects in the scene

  1. There are a handful of essential components you should add into your scene. The key component that results in loading of the ARX plugin is ARXController. Generally, this is most conveniently added to an empty GameObject in your scene. Once added, Unity will also add an ARXVideoConfig object.
  2. Locate the root object of your scene which is the "origin" for the part of your scene which you wish to manipulate via artoolkitX. Add an instance of the ARXOrigin component to this object.
  3. Add an instance of ARXCamera to the object containing the Unity Camera object, and make sure that this is a child object of the scene root (i.e. a child object of the ARXOrigin).

Add trackables and components to objects you want to move.

artoolkitX supports two common modes of building an AR scene:

  • GameObjects are considered "attached" to trackables, and moved around in the scene match the relative position of the trackables to the scene origin in the scene. This is the most common choice. In this choice, you will use ARXTrackedObject components in the scene, and an ARXCamera which will give artoolkitX control over the Unity camera.

  • As an alternative (and required in cases where some other system has control over the position and rotation of the Unity Camera) artoolkitX will not consider anything in the scene to be the "origin", and will move every object with an ARXTrackedObject script relative to the Camera. In this case you won't add an ARXOrigin to the scene. An ARXCamera is still required to be added to the Unity Camera so that artoolkitX can find it.

In either case, you will need to define what real-world objects should be tracked; so-called "trackables". artoolkitX offers a choice between 2D planar images, or square markers with a border. For square markers, the interior of the marker can be defined by a 2D barcode (of varying types) or simple images (with some restrictions).

To define the trackable at design time, simply add one or more ARXTrackable components. Usually, these are best kept grouped on the same GameObject as the ARXController. If you want to define trackables at runtime in code, take a look at the source for ARXTrackable.cs for the factory methods including ARXTrackable.Add2D(), ARXTrackable.AddSquareBarcode() and ARXTrackable.AddSquarePattern().

When adding each ARXTrackable, be sure to set it's "tag" value. This is a string which is used to link the ARXTrackable to the ARXTrackedObject in the scene.

If you want to move objects in the scene to match the trackable motion, next add an ARXTrackedObject to the root of the object in the scene, and set its tag to the tag of the ARXTrackable you want it to track. ARXTrackedObject causes the object's transform to be updated at runtime.