View are flaoting above plane in Sceneview form

203 Views Asked by At

I am using Sceneview to show AR characters. It is showing a few centimeters above the horizontal plane.

Here is Code for Sceneview and Anchor.

sceneView.apply {
    planeRenderer.isEnabled = true
    planeRenderer.planeRendererMode = PlaneRenderer.PlaneRendererMode.RENDER_ALL
    depthEnabled = true
    instantPlacementEnabled = false
    depthMode = Config.DepthMode.AUTOMATIC
    planeFindingMode = Config.PlaneFindingMode.HORIZONTAL
    lightEstimationMode = LightEstimationMode.ENVIRONMENTAL_HDR
}

cursorNode = CursorNode(context = requireContext(), lifecycle = lifecycle).apply {
    parent = sceneView
    maxHitTestPerSecond = 10
    isSmoothPoseEnable = true
    isSelectable = false
    onAnchorChanged = { node: ArNode, anchor: Anchor? ->
        if (!isLoading && node.isAnchored) {
            isLoading = true
            anchor?.let {
                anchorNode = it
                cursorNode.isVisible = false
                viewModelNode(it)
                newModelNode(it)
            }
        }
    }
}

When user clicked on button on screen anchor will be placed on Horizontal plane. Once anchor has been set up, view will be downloaded from firebase storage and placed on that node using method newModelNode(it).

private fun FragmentArExperienceBinding.newModelNode(anchor: Anchor) {
val model = arArrayList[currentPosition].ar[modelIndex]
ArModelNode(PlacementMode.DISABLED).apply {
    applyPoseRotation = false
    parent = cursorNode
    pose = anchor.pose
    position = Position(
        model.positionX.toFloat(),
        anchor.pose.position.y.plus(model.positionY.toFloat()),
        model.positionZ.toFloat()
    )
    val item = loadModelAsync(
        context = requireContext(),
        lifecycle = lifecycle,
        glbFileLocation = model.link,
        autoAnimate = false,
        scaleToUnits = model.scaleToUnit.toFloat(),
        centerOrigin = Position(
            model.positionX.toFloat(),
            anchor.pose.position.y.plus(model.positionY.toFloat()),
            model.positionZ.toFloat()
        ),
        onError = {
            Snackbar.make(binding.root, " ${it.message}", Snackbar.LENGTH_SHORT).show()
        }) {
        if (modelIndex < arArrayList[currentPosition].ar.size - 1) {
            modelIndex++
            newModelNode(anchor)
        } else {
            isLoading = false
        }
    }
    listOfNode.add(item)
    
}
}

In emulator it shows as below: Emulator Screenshot

In Real Device it looks like this

0

There are 0 best solutions below