Combining Multiple Area Targets¶
Multiple Area Targets from individual scans can be placed in the Unity Editor to create a seamless tracking experience of multiple connected spaces.
It is possible to scan multiple rooms and areas separately and fit them together later to cover a single AR experience over a larger area. However, the Area Targets might drift away from one another at runtime, leaving a gap or incorrect poses of the individual Area Targets.
Incorrect poses of the Area Targets can be seen when only one of multiple Area Targets is in view. The one in view (EXTENDED_TRACKED) will have a correct pose, while the others have no means of adjusting theirs since they are not directly tracked (LIMITED).
The solution is, therefore, to constrain the Area Targets to one another and provide each with a common pose, as if one were tracking the combination of targets as one connected space.
NOTE: To add navigation to this type of setup with multiple Area Targets, you can use Unity's BuildNavMesh method.
Location Prior¶
If you have use cases where you hit the limit of Area Target databases that can be activated simultaneously, location prior allows you to activate many more databases at the "cost" of requiring you to provide an external position value. You can use this mechanism by setting the Requires External Position to TRUE for each Area Target. See the Area Targets in Unity to enable the location prior for an Area Target.
With the external position enabled, Vuforia Engine will manage the loading of data from the multiple activated Area Targets and load at runtime the most appropriate ones based on the proximity and overlap of each other. See the Location Prior for details.
Note that whenever you have multiple active Area Targets in a scene, they must all have the same Requires External Position setting. Dissimilar settings will fail to load some Area Targets.
Setup Unity Project¶
To follow this guide, ensure that the latest supported Unity version and Vuforia Engine SDK are correctly set up. For a guide to setting up the Vuforia Engine and importing databases, please see our Unity Guide.
- Import two or more Area Targets that can be fitted together as they are in reality.
Scene Composition¶
Below is an illustrative example of how three Area Targets were positioned together to form an apartment. Perform the same operation with your Area Targets using the Rotation and Positioning tool in the Unity scene.
TIP: Use the alignment option when generating an Area Target in the Vuforia Creator App or from an Area Target Capture to create multiple Area Targets with the same origin. Aligned Aea Targets will appear in the Unity scene correctly positioned to their position and physical arrangement (provided they are scans of the same connected environment).
- Position your Area Targets according to the physical environment.
-
Create an Empty GameObject and name it MultiArea.
- Set the position of the MultiArea to (0, 0, 0).
-
Drop the Area Targets as a child of MultiArea in the Hierarchy.
-
Add augmentations normally: As children of the Area Targets.
MultiArea¶
To fix the Area Targets together, we need to work with the poses of the targets, ranking them to track only the most reliable pose, which is most likely the area users are situated in at that given time. The below script does the following:
- Saves the relative pose of each Area Target at the start of runtime.
- At each frame, it queries the Vuforia State list for active targets to check their tracking status, EXTENDED_TRACKED or LIMITED.
- Based on the returned tracking status, it ranks and selects the most reliable target pose.
- If two or more targets are ranked equally, any of them will be used; they will usually be consistent with one another.
- The script then returns the reliable target's pose to the MultiArea pose and updates its pose, and consequently, all the Area Targets and child GameObjects.
Add the script to the MultiArea GameObject.¶
- Create a new script with the name
MultiArea.cs
. - Open the empty script and copy the below code snippet.
- Save the file.
- Select the MultiArea GameObject and press Add Component in the Inspector.
- Select the
MultiArea.cs
script. - Enable Simulator mode in Play Mode or build to your device to test the experience.
MultiArea.cs | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
Keeping the Area Targets static in the Unity World¶
The above approach assumes that the World Center Mode is set to DEVICE and that the ARCamera moves according to the Device Tracking. Therefore, the Area Targets are not guaranteed to remain static in the Unity world since the World Center Mode - DEVICE implies that the target poses of the Area Targets get updated with regard to the AR Camera.
However, if the application requires a perfectly static behavior (i.e., a position not changing) of the Area Targets themselves. In that case, it is possible to enforce such behavior by adding the following code: