在垂直平面上添加对象始终在AR核心中旋转

Kev*_*kla 7 android kotlin arcore sceneform

在此输入图像描述我在sceneform AR Fragment中的垂直平面上添加了一个图像.但它总是被轮换.代码在水平面上工作正常.我在垂直平面上放置图像的代码如下.

arFragment.setOnTapArPlaneListener { hitResult: HitResult, 
                                         plane: Plane, 
                                   motionEvent: MotionEvent ->

    if(!isOnceTapedOnSurface) {
        val anchor = hitResult.createAnchor()
        val anchorNode = AnchorNode(anchor)
        anchorNode.setParent(arFragment.arSceneView.scene)

        andy = TransformableNode(arFragment.transformationSystem)

        if(plane.type == Plane.Type.VERTICAL) {
            val anchorUp = anchorNode.up
            andy.setLookDirection(Vector3.up(), anchorUp)
        }

        andy.setParent(anchorNode)
        andy.renderable = andyRenderable
        andy.select()

        // arFragment.arSceneView.planeRenderer.isVisible = false
        isOnceTapedOnSurface = true
    }
}
Run Code Online (Sandbox Code Playgroud)

ARG*_*Geo 1

要解决此问题,您需要设置public Pose getCenterPose(). 它返回检测到的平面中心的位姿,定义为具有原点。姿势的变换+Y轴将是平面外的法线点,+X+Z轴定向边界矩形的范围。

anchor = mySession.createAnchor(plane.getCenterPose())
Run Code Online (Sandbox Code Playgroud)

当其可追踪状态为 时TRACKING,该姿势与最新帧同步。当其可追踪状态为 时PAUSED,将返回身份姿态。

您的代码可能如下:

Anchor newAnchor;

for (Plane plane : mSession.getAllTrackables(Plane.class)) {

    if(plane.getType() == Plane.Type.VERTICAL && 
       plane.getTrackingState() == TrackingState.TRACKING) {
          newAnchor = plane.createAnchor(plane.getCenterPose());
          break;
    }
}
Run Code Online (Sandbox Code Playgroud)

Google ARCore 软件工程师还透露了一件事

Keep objects close to anchors

锚定对象时,请确保它们靠近您正在使用的锚点。避免将物体放置在距离锚点超过几米的地方,以防止由于 ARCore 更新世界空间坐标而导致意外的旋转运动。

如果您需要将对象放置在距离现有锚点几米远的地方,请创建一个更靠近此位置的新锚点,并将该对象附加到新锚点。