Added object on vertical plane always rotated in ARCore

久未见 提交于 2019-12-08 18:52:31

问题


I am adding an image on vertical plane in Sceneform ARFragment. But it always get rotated. The code is working fine on horizontal plane. My code for placing images on vertical Plane is as follow:

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
    }
}

回答1:


To fix this issue you need to set public Pose getCenterPose(). It returns the pose of the center of the detected plane, defined to have the origin. The pose's transformed +Y axis will be point normal out of the plane, with the +X and +Z axes orienting the extents of the bounding rectangle.

anchor = mySession.createAnchor(plane.getCenterPose())

When the its trackable state is TRACKING, this pose is synced with the latest frame. When its trackable state is PAUSED, an identity pose will be returned.

Your code could be the following:

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;
    }
}

One more thing from Google ARCore software engineers:

Keep objects close to anchors.

When anchoring objects, make sure that they are close to the anchor you are using. Avoid placing objects farther than a few meters from the anchor to prevent unexpected rotational movement due to ARCore's updates to world space coordinates.

If you need to place an object more than a few meters away from an existing anchor, create a new anchor closer to this position and attach the object to the new anchor.

Hope this helps.



来源:https://stackoverflow.com/questions/54106499/added-object-on-vertical-plane-always-rotated-in-arcore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!