google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

(Large) Objects sticking to corner of screen #215

Closed Jahmale closed 6 years ago

Jahmale commented 6 years ago

I've been having an 'issue' where the objects are sticking to the side of screen when trying to walk around them. It's rather noticeable for larger objects. I will add a small clip to visualise the problem.

sceneform-stickygif

I've anchored the objects in the following way:

    val anchorNode = AnchorNode(anchor)
    val baseNode = Node()
    val gateNode = Node()
    val gateVisual = GatewayObject(context, this)

    anchorNode.setParent(sceneView.scene)
    gateNode.setParent(baseNode)
    gateNode.localPosition = Vector3(0f,0f,-2f)

    gateVisual.setParent(gateNode)
    gateVisual.localPosition = Vector3(0f, 0.25f, 0f)
    gateVisual.localScale = Vector3(0.5f, 0.7f, 0.5f)

I've tried sticking the gatevisual directly to the node, with no success either. Can I do something to 'fix' this?

malik-at-work commented 6 years ago

The object appears to be placed correctly and it appears to track correctly. This particular video demonstrates an issue with occlusion. Sceneform does not allow the camera stream to appear in front of any rendered object. The ability to do have objects like the plant occlude rendered objects would be a major feature.

The only thing you can do for now is to compose your scene so that your rendered objects are not behind real objects. This is a fundamental limitation of the technology at the moment.

claywilkinson commented 6 years ago

Are you trying to anchor the gateVisual ? It looks like a typo in the code. The scene graph from the code is anchor -> scene gateNode -> baseNode gateVisual -> gateNode (so there must be other code in there somewhere, since gateVisual is visible in the scene, but is not attached to the scene?)

Is your anchor created from a hittest on a trackable?

Did you try

anchorNode.setParent(sceneView.scene)
gateVisual.setParent(anchorNode)
gateVisual.localPosition = Vector3(0f, 0.25f, 0f)
 gateVisual.localScale = Vector3(0.5f, 0.7f, 0.5f)

Objects following the camera or "floating" around usually is caused by not being anchored to a Trackable.

Jahmale commented 6 years ago

Yes, I am trying to anchor the gatvisual. As you suggested @claywilkinson I have tried directly anchoring the gatevisual to the anchornode, however I get the same effect. I also use a trackable to plant the anchor yes.

Jahmale commented 6 years ago

sceneform-stickygif-2

@malik-at-work I adjusted the scene to just display a simple facedown wall to display this 'problem' As you can see, even when doing a complete 180 myself, the object still slightly sticks into my field of view. It seems rather strange that this is normal behaviour. I also added the updated code for the example:

    val anchorNode = AnchorNode(anchor)
    val baseNode = Node()
    val gateNode = Node()
    val gateVisual = Node()
    gateVisual.renderable = getRenderable(RenderableHolder.RENDERABLE_TITLE.WALL)

    anchorNode.setParent(sceneView.scene)
    gateNode.setParent(baseNode)
    gateNode.localPosition = Vector3(0f,0f,-2f)

    gateVisual.setParent(gateNode)
    gateVisual.localScale = Vector3(0.5f, 0.7f, 0.5f)

    gateVisual.localPosition = Vector3(0f, - gateVisual.size().y/2f, 0f)
    gateVisual.localRotation = Quaternion(Vector3.left(), 90f)

    anchorNode.addChild(baseNode)
malik-at-work commented 6 years ago

Ok, this video doesn't match the issue I was describing. Can you check anchor.getTrackingState() as you are rotating around? Is it reporting TRACKING or has it flipped to something else?

Jahmale commented 6 years ago

it stays on TRACKING @malik-at-work I added the code as to how I create the anchor for the object, perhaps there is an issue there, but I applied the same logic as with the solarsystem example.

private fun placeScene(placementTap: MotionEvent?, frame: Frame)  { 

        if(placementTap != null && frame.camera.trackingState == TrackingState.TRACKING) {

            try {
                val foundHit = frame.hitTest(placementTap).last {hit ->
                    val trackable = hit.trackable
                    trackable is Plane && trackable.isPoseInPolygon(hit.hitPose)
                }

                createdAnchor = foundHit.createAnchor()
                SceneBuilder(ar_scene_view, this,
                                { throwable ->
                                    AlertDialog.Builder(this).setMessage("Error: "+throwable.localizedMessage).show() },
                                { gatewayNode = it })
                                .buildScene(createdAnchor!!)

                sceneIsBuilt = true
                ar_scene_view?.planeRenderer?.isEnabled = false

            } catch (e: NoSuchElementException) {

                Log.d(TAG, "ERROR PLACEMENT : "+e.localizedMessage);
                return
            }
        }
    }
malik-at-work commented 6 years ago

Looking at this, my suspicion is that the object is being placed a large distance away from the detected floor. Note this line: gateNode.localPosition = Vector3(0f,0f,-2f)

This shifts the gate by 2 meters forward. That means it's placed at least 2 meters away from the floor. Try it out with no position changes.

Jahmale commented 6 years ago

I'm still getting the same issue after removing that line.

When removing the following line however it does seem to anchor slightly better gateVisual.localPosition = Vector3(0f, - gateVisual.size().y/2f, 0f)

However I don't see why this would be an issue, as I am not changing the location of the anchornode itself, nor the mediator node: baseNode.

gstanlo commented 6 years ago

Is it possible that the model itself is offset significantly from its origin?

dsternfeld7 commented 6 years ago

It's possible that what you're seeing is actually parallaxing. Since physical objects don't occlude AR objects, it's possible that the gate is actually farther away than it appears, and that the shifting you are seeing is actually parallaxing from moving the camera because the table is below the floor in 3d space.

How does it look if you get rid of all local positions and just place the gate directly as a child of the anchor node? What is the origin point of the gate within the model?

Jahmale commented 6 years ago

the anchoring did seem a lot better for the wooden board once I removed all the local position editing, however when I replaced the wooden board with the gate from the initial vid it does still seem to be sticking to the user a bit. The video below shows that the object slightly follows you for the first meter or so and that it does seem to float along when moving to its sides. When far enough it does seem to be placed moderately alright, however the anchor performance varies from the multiple sessions I tried.

As for the origin of the models I'm using, they are all right in the center. The board is actually an upright wall of which I changed the rotation, where the origin is both vertically and horizontally in its center. The same applies to the gate in the video below.

sticky_issue_tres (I am using AS to record the videos so I am a bit restrained by the length of my usb cable when making them.)

malik-at-work commented 6 years ago

You'll want the alignment to be center/bottom, not center center...In the video above half of the model is below the floor which is why it seems to be moving.

As mentioned above, the camera image is always drawn behind the model even if it's closer than the model.

In the code I'd also suggest turning off all rotations and scales until the object is positioned as you expect.

My practice when debugging issues like this is moving the phone vertically as well as horizontally so that it's easier to tell where the object was actually placed. I understand you can't do that while filming, it might be a helpful debugging step.

Jahmale commented 6 years ago

Changing the point of origin properly did the trick. As you said it placed the entire object visibly in the scene, however the center;center of the object was placed on the tapped plane and the rest sunk through the 3d floor which gave the confusing perception.

However, while applying this fix I encountered a problem where sceneform didn't seem to respect the origin placed in the .obj files I exported. (using both 3ds max and Blender). Is this a known issue? Is there a recommended 3d editor to use?

dsternfeld7 commented 6 years ago

I'm glad that is working for you now!

The .sfa file contains a property called "recenter" that optionally adjusts the origin of the model when it is converted into an sfb. As of Sceneform 1.4, I believe the default is now "root". There is information about the different options here.