Google ARCore - 获取Unity生成的平面的旋转值?

我有一个检测垂直表面的应用程序 . 现在,当检测到垂直表面时,ARCore会绘制出一个表面平面网格,以匹配垂直表面的透视 .

我想要做的是获得表面平面网格的旋转,因为如果我扫描一个表面(从左侧),我在墙上的实例化模型指向正确的方向 . 如果我从另一侧(从右侧)扫描表面并实例化模型,则模型上下颠倒180度 .

我的想法是检查旋转是什么以及它是否达到阈值然后在模型实例化之前将偏移量添加到模型中 .

if (touch.phase == TouchPhase.Began)
        {
            Debug.Log("Touch Began");
            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
            {
                if (CurrentNumberOfGameObjects < numberOfGameObjectsAllowed)
                {

                    Instructions.SetActive(true);
                    Debug.Log("Screen Touched");
                    Destroy(ARObject);
                    // 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)
                    {
                        Debug.Log("Hit at back of the current DetectedPlane");
                    }
                    else
                    {
                        ARObject = Instantiate(ARAndroidPrefab, hit.Pose.position, hit.Pose.rotation);// Instantiate Andy model at the hit pose.                                                                                 
                        ARObject.transform.Rotate(x_ModelRotation, k_ModelRotation, z_ModelRotation, Space.Self);// Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
                        demoscript.quad.transform.Rotate(x_ModelRotation, k_ModelRotation, z_ModelRotation, Space.Self);
                        //var anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        anchor = hit.Trackable.CreateAnchor(hit.Pose);
                        ARObject.transform.parent = anchor.transform;
                        CurrentNumberOfGameObjects = CurrentNumberOfGameObjects + 1;

                        // Hide Plane once ARObject is Instantiated 
                        foreach (GameObject Temp in DetectedPlaneGenerator.instance.PLANES) //RK
                        {
                            Temp.SetActive(false);
                        }
                    }
                }
            }
        }

这是实例化unity预制件的代码的一部分 .

x_ModelRotation is 0.0f;
 z_ModelRotation is 0.0f;

我已经尝试检查Pose的旋转并将calues输出到文本调试但是我总是为生成的平面获得0,0,0,0的值 .

关于如何获得垂直表面网格旋转的任何想法?

回答(0)