How to display PNG image in ARCore?

Viewed 6988
3 Answers

If you use ViewRenderable of Sceneform, then you can create a wall in AR space from 2D png image just like standard android widgets.

This is an example of layout xml for ViewRenderable. As you know, it's just a layout xml for Android apps ;)

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imageCard"
    android:layout_width="123dp"
    android:layout_height="197dp"
    android:src="@drawable/Your_Image_Resource" />

And you can get ImageView instance in your Java code like below to set a source image dynamically.

ViewRenderable.builder()
    .setView(fragment.getContext(), R.layout.imgboard)
    .build()
    .thenAccept(renderable -> {
        ImageView imgView = (ImageView)renderrable.getView();
    });

This is my sample shot with using ViewRenderable, the object on the far right was created from a png image. screenshot of sceneform AR

I made a free app that tiles hundreds of png files (for a computer science prof). You can try it in a big area about 2x4 meters: https://play.google.com/store/apps/details?id=a.FlatKmapAR

To start with, just take the HelloAR example and replace the Andy.obj file with a square.obj that's only a square object (less than 10 lines of text) and replace Andy.png with your square.png file. Since they use the wave object format, that's the easiest way I know how to do it. Once you've got that, to tile them create a grid.obj with multiple squares, and so forth...

Yes it actually needs some vt to define the texture, in addition to at least one vn to define a normal, so then the f needs / for polygon/texture/normal like this:

v 0.000000 2.000000 0.000000
v 0.000000 0.000000 0.000000
v 2.000000 0.000000 0.000000
v 2.000000 2.000000 0.000000
vt 0.0 0.0
vt 1.0 0.0
vt 1.0 1.0
vt 1.0 1.0
vn 0.0 1.0 0.0
f 1/1/1 2/2/1 3/3/1 4/4/1
Related