I'm making a small AR app on Android to detect GIFs from a snapshot and overlay the actual GIF using AugmentedImages
, but I can't get the size of the ViewRenderable
to match up with the detected image so it perfectly overlays.
I'm following the AugmentedImages Sceneform sample from Google, changing it to Kotlin and using my own images manually added to the AugmentedImageDatabase
.
Below is the closest I've been able to get, but it still doesn't match up completely. gifView
is set with the ViewRenderable.builder()
and uses a simple XML file, shown after the code block. I'm using Glide in the .thenAccept
of the builder to load the correct GIF from a URL.
AugmentedImageNode
private var gifView: ViewRenderable? = null
...
fun setImageToNode(image: AugmentedImage) {
anchor = image.createAnchor(image.centerPose)
gifView?.sizer = FixedHeightViewSizer(image.extentZ)
val pose = Pose.makeTranslation(0.0f, 0.0f, 0.0f)
val localPosition = Vector3(pose.tx(), pose.ty(), pose.tz())
val centerNode = Node()
centerNode.setParent(this)
centerNode.localPosition = localPosition
centerNode.localRotation = Quaternion(pose.qx(), 90f, -90f, pose.qw())
centerNode.renderable = gifView
centerNode.localScale = Vector3(image.extentX * 15f, image.extentZ * 30f, 1.0f)
}
R.layout.image_item
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/easy_button" />
No error messages are appearing, but the rendered image does not match the size of the detected image. I would like this to be dynamic since obviously not every GIF has the same dimensions.
See this screenshot and notice how the detected image is slightly larger and looks like it's making a border around the clearer rendered image? (Not related to this question, but my camera isn't autofocusing even though I set the correct configuration setting)