简体   繁体   English

如何在 ARCore 中显示 PNG 图像?

[英]How to display PNG image in ARCore?

I want to display 2d png image in Arcore.我想在 Arcore 中显示 2d png 图像。 I don't want to use obj, .smf ,imgdb file, and 3D image.我不想使用 obj、.smf、imgdb 文件和 3D 图像。 I have already referred many links but none of them showing how to display only 2d png image using Arcore.我已经提到了许多链接,但没有一个显示如何使用 Arcore 仅显示 2d png 图像。

https://github.com/google-ar/arcore-android-sdk https://github.com/google-ar/arcore-android-sdk

https://developers.google.com/ar/develop/java/quickstart https://developers.google.com/ar/develop/java/quickstart

If you use ViewRenderable of Sceneform , then you can create a wall in AR space from 2D png image just like standard android widgets.如果您使用Sceneform 的 ViewRenderable ,那么您可以像标准的 android 小部件一样从 2D png 图像在 AR 空间中创建墙。

This is an example of layout xml for ViewRenderable.这是 ViewRenderable 的布局 xml 示例。 As you know, it's just a layout xml for Android apps ;)如您所知,它只是 Android 应用程序的布局 xml ;)

<?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.您可以在 Java 代码中获取 ImageView 实例,如下所示,以动态设置源图像。

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.这是我使用 ViewRenderable 拍摄的示例,最右侧的对象是从 png 图像创建的。 场景AR截图

I made a free app that tiles hundreds of png files (for a computer science prof).我制作了一个免费的应用程序,可以平铺数百个 png 文件(针对计算机科学教授)。 You can try it in a big area about 2x4 meters: https://play.google.com/store/apps/details?id=a.FlatKmapAR您可以在大约 2x4 米的大区域内试用: 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.首先,以 HelloAR 为例,将 Andy.obj 文件替换为一个正方形对象(少于 10 行文本)的 square.obj 并将 Andy.png 替换为您的 square.png 文件。 Since they use the wave object format, that's the easiest way I know how to do it.由于他们使用 wave 对象格式,这是我知道的最简单的方法。 Once you've got that, to tile them create a grid.obj with multiple squares, and so forth...一旦你得到了它,为了平铺它们,创建一个带有多个正方形的 grid.obj 等等......

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:是的,它实际上需要一些 vt 来定义纹理,此外至少需要一个 vn 来定义法线,所以 f 需要 / 用于多边形/纹理/法线,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM