2

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

Shvet
  • 1,159
  • 1
  • 18
  • 30
  • in simulator you have a clean enviroment. if you try with better enviroment would it work better? (i.e. better lightning, using it on non glossy surfaces, etc...) – A-_-S Mar 02 '23 at 10:06
  • @A-_-S I have tried it in real device too, I have uploaded Video of it at bottom. Also i found issue. Actually cursor is not being anchored on surface it detects. I have use HitTest for detecting Surface and anchor on it. but new issue is Surface detection is very bad. – Shvet Mar 02 '23 at 13:24

0 Answers0