Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

Clarification on meaning of tracking state for image tracking #639

Closed FantasyTianyu closed 4 years ago

FantasyTianyu commented 4 years ago

Describe the bug When tracking image move away from the camera,the trackImage's trackingState is not been TrackingState.None,and destroyOnRemoval doesn't work

To Reproduce Steps to reproduce the behavior:

  1. Open the track image
  2. Use phone to track the image, the image info will show on the image.
  3. close or remove the image out of phone's camera.
  4. the image info still stay on screen.

Expected behavior in the example , when listen to the trackedImagesChanged callback,if the trackImage.trackingState == TrackingState.None,means the trackImage no longer been tracked in the camera, the planeGo's active will be false , or we can set the destroyOnRemoval=true, the trackImage will also destroyed.

   // Disable the visual plane if it is not being tracked
        if (trackedImage.trackingState != TrackingState.None)
        {
            planeGo.SetActive(true);
            // The image extents is only valid when the image is being tracked
            trackedImage.transform.localScale = new Vector3(trackedImage.size.x, 1f, trackedImage.size.y);
            // Set the texture
            var material = planeGo.GetComponentInChildren<MeshRenderer>().material;
            material.mainTexture = (trackedImage.referenceImage.texture == null) ? defaultTexture : trackedImage.referenceImage.texture;
        }
        else
        {
            planeGo.SetActive(false);
        }

Actual behavior the trackImage.trackingState will never be TrackingState.None,and the destroyOnRemoval had been set to true,but it doesn't work.

   // Disable the visual plane if it is not being tracked
        if (trackedImage.trackingState != TrackingState.None)
        {
            planeGo.SetActive(true);
            // The image extents is only valid when the image is being tracked
            trackedImage.transform.localScale = new Vector3(trackedImage.size.x, 1f, trackedImage.size.y);
            // Set the texture
            var material = planeGo.GetComponentInChildren<MeshRenderer>().material;
            material.mainTexture = (trackedImage.referenceImage.texture == null) ? defaultTexture : trackedImage.referenceImage.texture;
        }
        else
        {
            planeGo.SetActive(false); // this will never be called
        }

Smartphone (please complete the following information):

tdmowrer commented 4 years ago

Sorry, I do not understand the bug you are describing.

When tracking image move away from the camera,the trackImage's trackingState is not been TrackingState.None

This sounds like the expected behavior to me.

and destroyOnRemoval doesn't work

In what way does it not work?

Steps to reproduce the behavior:

  1. Open the track image

What does that mean?

Expected behavior in the example...

Which example?

...when listen to the trackedImagesChanged callback,if the trackImage.trackingState == TrackingState.None,means the trackImage no longer been tracked in the camera, the planeGo's active will be false , or we can set the destroyOnRemoval=true, the trackImage will also destroyed.

I don't understand what the expected behavior is. Tracking state is a separate concept from removal. Further, the GameObject's active state is up to you; we have a sample that sets it in certain cases, but that is not a feature of the ARFoundation SDK.

Actual behavior the trackImage.trackingState will never be TrackingState.None...

This depends on the underlying AR framework, but that sounds about right. The tracking state is more a measure of whether the device is, well, tracking the image, not whether it was removed from view.

It's clear the result is not what you are expecting, but I do not see a bug here. Could you instead describe what you are trying to achieve?

FantasyTianyu commented 4 years ago

Sorry, I do not understand the bug you are describing.

Sorry,my English is not good,I try to explain it in detail. Please see this .cs file at line 95 in the UpdateInfo method ,when the trackedImage.trackingState != TrackingState.None ,the planeGo will be set to active true,otherwise the planeGo will be set to active false. but unnder what circumstances the trackedImage.trackingState will be none? I used the ARFoundation Sample's image from arfoundation-samples/Assets/Scenes/ImageTracking/Images/Rafflesia.jpg ,the image info is shown on the screen correctly,because the planeGo is set active to true, but when I removed the image out of the camera ,the image info still existence,because the code at line 95 seems never be called, even if I moved the iPhone's camera away from the image for a long time. I found that the trackImage.trackState will be TrackState.Limited So I think maybe it is a bug that the trackImage.trackState will never be TrackState.None.

This depends on the underlying AR framework, but that sounds about right. The tracking state is more a measure of whether the device is, well, tracking the image, not whether it was removed from view.

I've always thought that if the image is out of the camera,the tracking is lost, the TrackState will be TrackState.None.According to you, I may have misunderstood it.

tdmowrer commented 4 years ago

I've always thought that if the image is out of the camera,the tracking is lost, the TrackState will be TrackState.None

No, that is generally not how it works. There is an explanation at https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.0/manual/tracked-image-manager.html#tracking-state

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.