Table of Contents

Add mega tracking target

This article explains how to add Mega's tracking targets and how to load environment models in the Unity editor to assist development.

Before you begin

Note

The following content and tools are only applicable to the process of developing Unity applications using EasyAR Mega.

If you are developing a mini-program, please refer to Creating and uploading annotations using the Unity editor (mini-program development).

If you only want to view the Mega mapping results, please refer to Previewing 3D textured mesh in the Mega user guide.

If you need to simulate and verify the localization effect but do not have a usable Unity project, please refer to Simulation effect preview in the Mega user guide.

Mega's tracking target

Mega's tracking target is an empty GameObject with the BlockController component, referred to as a block. In the scene, blocks are organized under an empty GameObject with the BlockRootController component, which is named MegaBlocks by default. All block GameObjects under MegaBlocks represent the tracking targets in the current localization library.

alt text

During development, it is often necessary to use block models to assist in viewing and placing 3D content. These models can be loaded into the scene using tools for easy reference.

alt text

The model's position is aligned with the block tracking target, allowing 3D content to be placed directly on the model.

Tip

The models are stored under the tool node and exist only in editor mode; they are not included in the final build.

Add tracking target in the editor

To use this method, configure BlockHolder.BlockRootSource to External (default) or Mixed.

alt text

Add Block Viewer for Unity Developer tool

Right-click on a blank area in the Hierarchy view, and select EasyAR Mega > Tool > Block Viewer for Unity Developer (Edit Mode) from the menu to add the Block Viewer tool for Unity development.

alt text

Important

When developing Mega applications with Unity, you must use the Block Viewer for Unity Developer tool. Other tools under the EasyAR Mega > Tool menu are not suitable for Unity application development.

Although the Annotation Tool has similar functionality, some features of this tool will be removed in future versions, so it is not recommended for use.

The annotation functionality of the Annotation Tool (only the annotations themselves) will soon be migrated to the EasyAR Developer Center webpage, while block mesh loading and model placement will remain unaffected.

After successfully adding the tool, a EasyAR.Mega.BlockViewer (Dev) node and a MegaBlocks node will appear in the scene hierarchy.

alt text

Generate tracking target —— block

Select the EasyAR.Mega.BlockViewer (Dev) node, fill in the EasyAR account information in the Inspector panel and log in;

alt text

Click the button on the right side of Mega Cloud Service;

alt text

Select the Mega localization service you want to use, and click OK.

alt text

After selecting the service, the block list in the current library will be displayed under the MegaBlocks node and shown on the tool panel.

alt text

Tip

Why is my MegaBlocks empty?

It is recommended to check Is my localization library ready to use?

At this point, the tracking target block has been generated. Each child node starting with Block_ under the MegaBlocks node represents a block tracking target.

Load block model

Click Load to select the Block:

alt text

After loading, the Block will be displayed in the Scene window.

alt text

Automatically add tracking targets upon successful localization

To use this method, you need to configure BlockHolder.BlockRootSource as Internal or Mixed.

In these two modes, if a new block is localized and there is no such block under the BlockHolder.BlockRoot node, this new block will be automatically added under the BlockHolder.BlockRoot node. If BlockHolder.BlockRoot does not exist, it will be automatically created.

Tip

When automatically adding tracking targets upon successful localization, the block model cannot be loaded, and only the block tracking target can be added.

Adding tracking targets in scripts

To use this method, you need to configure BlockHolder.BlockRootSource as Internal or Mixed. In this case, if BlockHolder.BlockRoot does not exist, it will be automatically created. Alternatively, you can also specify the BlockHolder.BlockRoot object in the editor in advance when BlockHolder.BlockRootSource is External.

Note

If the block is not in the localization library, it cannot be located even if it is added to the scene using scripts.

You can use the BlockHolder.Hold method to add a new block under the BlockHolder.BlockRoot node. This method is typically used when working with ema annotation files, where the script reads the annotation information and then adds the block.

For example, the following code snippet demonstrates how to add a block using the information from the annotation file:

foreach (var item in ema.blocks)
{
    var info = new BlockController.BlockInfo { ID = item.id.ToString(), Timestamp = item.timestamp };
    if (!item.keepTransform && item.location.OnSome)
    {
        blockHolder.Hold(info, item.location.Value);
    }
    else
    {
        blockHolder.Hold(info, item.transform.ToUnity());
    }
}
Tip

When adding tracking targets at runtime using scripts, the block model cannot be loaded, and only the block tracking target can be added.

Next steps