点击以选择带有Unity的ARCore中的特定平面

时间:2019-04-05 10:31:58

标签: unity3d arcore

我试图通过仅渲染单个平面而不是所有检测到的平面来对ARCore示例Andy放置应用程序进行修改。我想通过点击要渲染的平面来实现这一点。这是我尝试过的。

protected override void OnEndManipulation(TapGesture gesture)
{
    if (gesture.WasCancelled)
    {
        return;
    }

    // If gesture is targeting an existing object we are done.
    if (gesture.TargetObject != null)
    {
        return;
    }

    // Raycast against the location the player touched to search for planes.
    TrackableHit hit;
    TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinInfinity | TrackableHitFlags.PlaneWithinPolygon;

    if (Frame.Raycast(gesture.StartPosition.x, gesture.StartPosition.y, raycastFilter, out hit))
    {
        Debug.Log("Entered into hit if condition");
        // Use hit pose and camera pose to check if hittest is from the
        // back of the plane, if it is, no need to create the anchor.
        if ((hit.Trackable is DetectedPlane) &&
            Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                hit.Pose.rotation * Vector3.up) < 0)
        {
            //var andyObject = Instantiate(AndyPrefab, hit.Pose.position, hit.Pose.rotation);
            Debug.Log("Hit at back of the current DetectedPlane");
        }
        else
        {                
            if (PlaneFixed is false)
            {
                foreach (GameObject plane in DetectedPlaneGenerator.instance.PLANES) //RK
                {
                    // THE PROBLEM IS HERE! HOW TO GET CORRECT TYPECAST?
                    if (hit.Trackable is plane)
                    {
                        Debug.Log("Plane Selected");
                        PlaneFixed = true;
                        FixPositionButton.gameObject.SetActive(true);
                    }
                    else
                    {
                        plane.SetActive(false);
                    }
                }
            }
        }
    }
}

问题是我无法获得GameObject(PLANES-在DetectedPlaneGenerator.cs中创建)和DetectedPlane对象(使用PlaneWithinInfinity | PlaneWithinPolygon raycastfilters通过hit.Trackable返回)之间的正确匹配。

我还看到了尝试将“标签”关联到DetectedPlaneVisualizer(solution to this)的方法。但是,我看到这也可以使用GameObject处理飞机。如何匹配GameObject和Hit.Trackable(DetectedPlane对象)以识别刚刚点击的特定平面?

0 个答案:

没有答案