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

How to use with Geospatial API

Open lincollincol opened this issue 2 years ago • 8 comments

Hey there! Thank you for this useful library which saves a lot of time when working with ARCore :)

I'm trying to create an android app that shows AR markers by specific location (LatLng). I'd like to create something like in this video (from README AR Geospatial API), but with simple ViewNode instead of ArModelNode.

I also can't place AR model at a specific location with a sample code from README. The model spawns just in front of the current camera position.

Here is my code:

val earth = binding.sceneView.arSession?.earth ?: return@launchWhenResumed
if (earth.trackingState == TrackingState.TRACKING) {
    val cameraGeospatialPose = earth.cameraGeospatialPose
    val earthAnchor = earth.createAnchor(49.844141, 24.024532, cameraGeospatialPose.altitude, 0f, 0f, 0f, 1f)
    val arModelNode = ArModelNode(
        context = this@MainActivity,
        lifecycle = lifecycle,
        modelFileLocation = "https://sceneview.github.io/assets/models/Gumball.glb"
    )
    arModelNode.anchor = earthAnchor
    binding.sceneView.addChild(arModelNode)
}

I would be grateful for your help!

lincollincol avatar Aug 08 '22 11:08 lincollincol

I also attached a file with the desired result

lincollincol avatar Aug 08 '22 11:08 lincollincol

Hi. The code you posted looks fine to me. Did you figure out the problem? Does setting editableTransforms on arModelNode to EditableTransform.ALL help?

SeyedAlirezaFatemi avatar Aug 09 '22 11:08 SeyedAlirezaFatemi

It looks like EditableTransform doesn't exist in io.github.sceneview:arsceneview:0.8.0

image

lincollincol avatar Aug 09 '22 12:08 lincollincol

I guess the editableTransforms is not important. I think it's a problem with 0.8.0. You can downgrade to 0.7.0 for now until the problems are fixed.

SeyedAlirezaFatemi avatar Aug 09 '22 13:08 SeyedAlirezaFatemi

I have the same problem. It seems that the position of the arModelNode is not updated, after assigning the anchor, when isSmoothPoseEnable is true

Oromere avatar Aug 09 '22 13:08 Oromere

@SeyedAlirezaFatemi You are right, downgrading to 0.7.0 helped me to fix it. I also added implementation 'com.google.ar:core:1.32.0' to enable Geospatial API. More here: #109

Thank you for your help and hope that it will be fixed in the next version :)

lincollincol avatar Aug 09 '22 14:08 lincollincol

@lincollincol Does earth.trackingState become TrackingState.TRACKING? Always different.

binding.arSceneView.apply {
    geospatialEnabled = true

    onArSessionFailed = { _: Exception ->
    
    }
    onArSessionCreated = { arSession ->
        val earth = arSession.earth
        if (earth != null && earth.trackingState == TrackingState.TRACKING) {
            val altitude = earth.cameraGeospatialPose.altitude - 1
            val rotation = Rotation(0f, 0f, 0f)
            val latitude = earth.cameraGeospatialPose.latitude + 0.0004
            val longitude = earth.cameraGeospatialPose.longitude + 0.0004
            earthAnchor = earth.createAnchor(latitude, longitude, altitude, rotation.toFloatArray())

            val arModelNode = ArModelNode(
                context = this@GeoSpatialActivity,
                lifecycle = lifecycle,
                modelFileLocation = "https://sceneview.github.io/assets/models/Gumball.glb"
            )

            arModelNode.anchor = earthAnchor
            binding.arSceneView.addChild(arModelNode)
        }
    }
}

yhishi avatar Aug 26 '22 15:08 yhishi

I solved ↑. In onArSessionCreated, the trackingState was still PAUSED. When a button is clicked, it is TRACKING.

yhishi avatar Aug 28 '22 05:08 yhishi

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 Nov 27 '22 05:11 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 Dec 05 '22 05:12 github-actions[bot]