sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

AR Model Viewer sample in README is missing a statement

Open AlexDarigan opened this issue 1 year ago • 1 comments

I'm relatively new to this and had some trouble understanding why the models weren't loading, in the sample on the README the child nodes are never actually being added to the AR Scene.

The following

val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
val model = modelLoader.createModel("model.glb")
var frame by remember { mutableStateOf<Frame?>(null) }
val childNodes = rememberNodes()
ARScene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,
    modelLoader = modelLoader,
    onSessionUpdated = { session, updatedFrame ->
        frame = updatedFrame
    },
    onGestureListener = rememberOnGestureListener(
        onSingleTapConfirmed = { motionEvent, node ->
            val hitResults = frame?.hitTest(motionEvent.x, motionEvent.y)
            val anchor = hitResults?.firstOrNull {
                it.isValid(depthPoint = false, point = false)
            }?.createAnchorOrNull()

            if (anchor != null) {
                val anchorNode = AnchorNode(engine = engine, anchor = anchor)
                anchorNode.addChildNode(
                    ModelNode(modelInstance = modelLoader.createInstance(model)!!)
                )
                childNodes += anchorNode
            }
        }
    )
)

should be

val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
val model = modelLoader.createModel("model.glb")
var frame by remember { mutableStateOf<Frame?>(null) }
val childNodes = rememberNodes()
ARScene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,
    modelLoader = modelLoader,
    childNodes = childNodes, // change here
    onSessionUpdated = { session, updatedFrame ->
        frame = updatedFrame
    },
    onGestureListener = rememberOnGestureListener(
        onSingleTapConfirmed = { motionEvent, node ->
            val hitResults = frame?.hitTest(motionEvent.x, motionEvent.y)
            val anchor = hitResults?.firstOrNull {
                it.isValid(depthPoint = false, point = false)
            }?.createAnchorOrNull()

            if (anchor != null) {
                val anchorNode = AnchorNode(engine = engine, anchor = anchor)
                anchorNode.addChildNode(
                    ModelNode(modelInstance = modelLoader.createInstance(model)!!)
                )
                childNodes += anchorNode
            }
        }
    )
)

AlexDarigan avatar Jan 30 '24 17:01 AlexDarigan

Yeah facing the same issue. When i opened my logcat, following logs appeared: I I0000 00:00:1707233891.045692 17188 motion_analysis_calculator.cc:652] Analyzed frame 101 2024-02-06 21:08:11.076 17071-17071 native com.example.dna E E0000 00:00:1707233891.076925 17071 hit_test.cc:426] INTERNAL: No point hit. 2024-02-06 21:08:11.176 17071-17071 native com.example.dna E E0000 00:00:1707233891.176128 17071 hit_test.cc:426] INTERNAL: No point hit.

Razorquake avatar Feb 06 '24 15:02 Razorquake

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 07 '24 05:05 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

github-actions[bot] avatar May 15 '24 05:05 github-actions[bot]