Unity-Technologies / arfoundation-samples

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

[Bug]ARRaycastManager.Raycast(Ray) doesn’t work based on subsystem.Raycast #837

Closed tokageD closed 3 years ago

tokageD commented 3 years ago

About using ARRaycastManager.Raycast() in iOS. In case of using Ray (from Screen Pos direction to Camera) as the first argument, it doesn't work base on subsystem raycast (it means arkit raycast). Now it seems to work only based on ARFoundation's trackable raycast.

procedure

  1. Open Anchors Scene in Unity.
  2. Open AnchorCreator.cs in a script editor.
  3. Change Update Function as bellow (change 1, change 2).


    void Update()
    {
    if (Input.touchCount == 0)
        return;
    
    var touch = Input.GetTouch(0);
    if (touch.phase != TouchPhase.Began)
        return;
    
    // ######  Create Ray from screen pos ######                     .... change 1
    Ray ray = Camera.main.ScreenPointToRay(touch.position); 
    
    // Raycast against feature points
    const TrackableType trackableTypes =
        TrackableType.FeaturePoint;  
    
    // ###### Change first argument of Raycast ######            ....  change 2
    if (m_RaycastManager.Raycast(ray, s_Hits, trackableTypes))  
    {
        // Raycast hits are sorted by distance, so the first one will be the closest hit.
        var hit = s_Hits[0];
    
        // Create a new anchor
        var anchor = CreateAnchor(hit);
        if (anchor)
        {
            // Remember the anchor so we can remove it later.
            m_Anchors.Add(anchor);
        }
        else
        {
            Logger.Log("Error creating anchor");
        }
    }
    }
  4. Build and Run

Actual behavior I think it should work the same for both argument ( Vector2 , Ray ).

Smartphone (please complete the following information):

stale[bot] commented 3 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.

tdmowrer commented 3 years ago

ARKit doesn't support this interface, so the ARRaycastManager uses a fallback implementation provided by AR Foundation. However, it can only raycast against things it knows about. To make it aware of feature points, add an ARPointCloudManager to the ARSessionOrigin.

Most of the AR managers "turn on" features, e.g., the ARPlaneManager enables plane detection. However, ARKit always has feature points available internally, while AR Foundation is only aware of them if you "enable" them with the point cloud manager. This means that ARKit's native raycast method (using a screen point) can always use feature points, while AR Foundation can only use them if you enable the point cloud manager.

tokageD commented 3 years ago

Thank you for detail information. I understand it ! Could you add information to ARFoundation documentation ? It helps developers to understand.

stale[bot] commented 3 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.