Table of Contents

Add mega tracking targets

This article introduces 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 Create and upload annotations using the Unity editor (mini-program development).

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

If you need to simulate and view the localization effect but don't have a usable Unity project, please refer to Simulated effect preview in the Mega usage guide.

Mega tracking targets

Mega's tracking targets are empty GameObjects containing the BlockController component, called blocks. In the scene, blocks are organized under an empty GameObject with the BlockRootController component, named MegaBlocks by default. All block objects under MegaBlocks represent the tracking targets in the current localization library.

alt text

During development, block models are often needed to assist in viewing and placing 3D content. These models can be loaded into the scene using tools for reference.

alt text

The model position aligns with the block tracking target, allowing direct placement of 3D content on the model.

Tip

Models are stored under tool nodes, exist only in editor mode, and will not be packaged into the final application.

Add tracking targets in the editor

This method requires configuring 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 use the menu EasyAR Mega > Tool > Block Viewer for Unity Developer (Edit Mode) to add the Block Viewer tool for Unity development.

alt text

Important

When developing Mega applications in 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.

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

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

alt text

Generate tracking targets - blocks

Select the EasyAR.Mega.BlockViewer (Dev) node, fill in your 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 in the tool panel.

alt text

Tip

Why is my MegaBlocks node empty?

Please check Is my localization library available?

At this point, block tracking targets have been generated. Each Block_-prefixed child node under the MegaBlocks node represents a block tracking target.

Load block models

Click Load selected blocks:

alt text

After loading is complete, blocks will be displayed in the Scene window.

alt text

Automatically add tracking targets upon successful localization

This method requires configuring BlockHolder.BlockRootSource to Internal or Mixed.

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

Tip

When automatically adding tracking targets upon successful localization, block models cannot be loaded; only block tracking targets can be added.

Add tracking targets via scripts

This method requires configuring BlockHolder.BlockRootSource to Internal or Mixed. In this case, if BlockHolder.BlockRoot does not exist, it will be created automatically. Alternatively, you can pre-specify the BlockHolder.BlockRoot GameObject in the editor when BlockHolder.BlockRootSource is set to External.

Note

If a block is not in the localization library, it cannot be localized even if added to the scene via script.

You can use the BlockHolder.Hold method to add a new block under the BlockHolder.BlockRoot node. This method is typically used with ema annotation files, where scripts read annotation information and add blocks.

For example, the following code snippet shows how to add blocks using information from annotation files:

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 via scripts at runtime, block models cannot be loaded; only block tracking targets can be added.

Next steps