Space Tracker
Related documentations |
---|
MAXSCAN |
The Object Fusion Tracker loads the map file and renders a 3D object on it.
After target recognition and initial poses are acquired through the MAXST SDK, use Nreal SLAM for tracking.
Tracker, on the other hand, tracks through the Nreal SLAM, which allows the target to deviate from the camera frame or keep the feature point at least without tracking, due to the nature of learning the environment in which the current target lies.
Make Space Tracker Scene
Set Map
Add / Replace Map
Start / Stop Tracker
Use Tracking Information
Make Space Tracker Scene
Install MAXST AR SDK For Unity, MAXSTARSDK_FOR_NRSDK, and NRSDKForUnity_Release.
Create a new scene.
Delete the Main Camera that exists by default, then go to Assets > NRSDK > Prefabs > NRCameraRig, NRInput, Assets > MaxstAR > Prefabs > SpaceTrackable to your scene.
※ In the Project window, you need to add the license key to Assets > Resources > MaxstAR > Configuration.
Create an empty object and add 'Assets > MaxstARSamples > Scripts > spaceTrackerSample' as a component.
Place the files generated by MAXSCAN in Assets > StreamingAssets > MaxstAR, then drag the map file into SpaceTrackable's Inspector to set up the map file and 3D file. Press the Load button to load the 3D spatial model from the 3D file into Unity.
※ If the map file is not placed under the StreamingAssets folder, the map file is not recognized.
※ If you have run texturing in MAXSCAN, you will need to have the texture file and the mtl file in the same folder as the obj file to load a normal 3D spatial model.After loading the 3D space model, in Scene View and Game View, you can see the space scanned by MAXSCAN on top of the scanned space.
Occlusion Culling is selected by default in the SpaceModel's Inspector. By enabling Occlusion Culling, you can handle objects behind the space being obscured.
※ SpaceModel
When you load a 3D file into SpaceTrackable, a SpaceModel is automatically created under SpaceTrackable.
Occlusion Culling: Objects that are behind a space can be hidden. By using mesh information to determine the order in which objects are visible, we effectively implement occlusion culling.
Places the virtual object under SpaceTrackable in the Hierarchy View. In the Maxst SDK, maxst_cube is placed under by default.
Use the 3D spatial model to place virtual content in the appropriate locations.
Set Map
By callingaddTrackerData() to register the map file and callingloadTrackerData(), Space can be tracked. To set a map, refer to the following code.
>SpaceTrackerSampleForNreal.cs
private void AddTrackerData()
{
foreach (var trackable in spaceTrackablesMap)
{
if (trackable.Value.TrackerDataFileName.Length == 0)
{
continue;
}
if (trackable.Value.StorageType == StorageType.AbsolutePath)
{
TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName);
}
else
{
if (Application.platform == RuntimePlatform.Android)
{
TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName, true);
}
else
{
TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + trackable.Value.TrackerDataFileName);
}
}
}
TrackerManager.GetInstance().LoadTrackerData();
}
Add / Replace Map
- Use MAXSCAN to create maps and 3D file.
- Copy the transferred files to the desired path.
- Set up a map.
- If you have a previously registered map file, you can call TrackerManager.GetInstance().RemoveTrackerData() and then call AddTrackerData() and LoadTrackerData().
- Call trackableBehaviour.LoadObj() to load the 3D spatial model.
Start / Stop Tracker
TrackerManager.getInstance().isFusionSupported()
This function checks whether or not your device supports Fusion. Return value is bool type. If true, it supports the device in use. If it is false, it does not support the device.
TrackerManager.getInstance().GetFusionTrackingState();
Pass the tracking status of the current Fusion.
The return value is an int of -1, which means that tracking isn't working properly, and 1 means that it's working properly.
After loading the map, refer to the following code to start / stop the tracker.
>SpaceTrackerSampleForNreal.cs
void Start()
{
...
CameraDevice.GetInstance().SetARCoreTexture();
TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_SPACE);
TrackerManager.GetInstance().AddTrackerData("SpaceTarget/map_20230420.mmap", true);
TrackerManager.GetInstance().LoadTrackerData();
...
}
void OnApplicationPause(bool pause)
{
...
TrackerManager.GetInstance().StopTracker();
...
}
void OnDestroy()
{
TrackerManager.GetInstance().StopTracker();
TrackerManager.GetInstance().DestroyTracker();
...
}
Use Tracking Information
To use the Tracking information, refer to the following code.
>SpaceTrackerSampleForNreal.cs
void Update()
{
...
TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
TrackingResult trackingResult = state.GetTrackingResult();
for (int i = 0; i < trackingResult.GetCount(); i++)
{
Trackable trackable = trackingResult.GetTrackable(i);
spaceTrackablesMap[trackable.GetName()].OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetNRealPose());
}
}