documentation

Setting an Init-Pose
Level: Basic
SettingAnInitPose-1_banner.jpg

The init pose defines the initial viewpoint from which the physical object should be detected and from where tracking starts. You can either define the init pose in the tracking configuration, or set it from inside Unity.

SimpleModelTrackerExample_changeInitPose.png

In Unity, the initPose can be defined by using the prefab VLInitCamera. Drop the Prefab on the stage and position it until you get the desired init detection position. VisionLib will use its translation and rotation and calculate the init pose from it.

With the VLInitCamera selected, make sure the flag overwrite on load is disabled — otherwise, the settings of the tracking configuration will be used, overwriting the pose defined in Unity with the VLInitCamera.

In order to find an appropriate init position, we recommend to add the 3D file to your scene (it is not needed during runtime in general, but helps during positioning the init camera). So, drop the 3D file used for tracking into the Hierarchy panel to display it. Then select the VLInitCamera and position it as desired. Like in the picture above, the Camera Preview window reveals your current pose.

SimpleModelTrackerExample_tracking_1.png

Once done, press Play in Unity and run your scene. If you didn't disable it or manage visibility in your source code, the 3D model you dropped into the scene will show up during runtime. Similar to the image above, your model will be displayed from the init pose's viewpoint. Once tracking snaps in, it will appear superimposed like all other scene content. Again, if you prefer not showing it, disable it or manage appearance event-wise in a script.

Avoid errors from mismatches between 3D model for tracking and rendering

Please note that the changes you make to the 3D model you use for visualization in the Unity editor — such as transforming the position, scale or rotate the model — won't necessarily affect the tracking model as well, which is stored in another place.

VisionLib will always load the model 'as is' from its original file source and ignore changes you made in Unity, unless those are stored in the 3D model file that is used for tracking, too.

For instance, if you've dropped your 3D model into the Unity scene, changed its scale and rotation, and then aligned the VLInitCamera according to this model, tracking won't eventually work! That's because VisionLib uses the non-transformed original file and won't be aware of those changes, and hence the init pose you have chosen won't make much sense compared to the original 3D file VisionLib will use for tracking.

If you are not sure whether this applies in your case, use the VLDebugImage prefab. If your init pose is set appropriately, you will see the 3D model from its init pose render as 'jagged lines' in the VLDebugImage's view. If they do not exist although your init camera has a useful viewpoint at the 3D model in Unity, the coordinate systems might eventually not match, or the VisionLib couldn't load the 3D file for tracking at all.

Init Pose Priority

Even if it's declared in a tracking configuration, VisionLib will overwrite a declared init pose at runtime when the VLInitCamera prefab is present in a scene. But if the prefab's flag overwrite on load is enabled, the tracking configuration init pose declaration will always overwrite the manually positioned VLInitCamera in Unity.

Retrieving the init pose declaration in Unity

You can put the init pose plain-text into the tracking configuration and store it there instead of using the VLInitCamera prefab in your scene. To get the init pose declaration you can either use Unity, or VisionLib's companion app visLab, which also allows to set and store init pose and other tracking metrics in the tracking configuration directly from within the tool.

SimpleModelTrackerExample_InitPoseDump2.jpg

To get the init pose in Unity, first bring your VLInitCamera into position and copy the JSON-formatted string from the prefab's ìnitPose field in the Inspector; this init pose description (t and q) stores the VlInitCameracomponent values. Copy and paste it in your tracking configuration.

To use the init pose stored in the tracking configuration in Unity, either enable the Overwrite On Load flag of the VLInitCameraprefab, or disable or remove the prefab entirely from your Hierarchy.

Legacy init pose

In older versions of VisionLib one could not use the exact same model for tracking and displaying in Unity. One either had to use models stored in different (right-handed vs. left-handed) coordinate systems or rotate the displayed content 180 degree around the y-axis. If your code depends on this behaviour, you can use the flip model manually flag in the VLWorkerBehaviour to keep the old behaviour. This will lead to a deprecated warning.