用于存储3D模型的AR应用程序数据库

问题描述 投票:0回答:1

我正在学习增强现实技术,并使用Google的AR-Core开发了一个AR应用程序。它可以与单个模型配合使用,但是我在考虑是否可以在数据库和应用程序中上传不同的3D模型,从而从数据库中获取模型并显示在屏幕上。

android unity3d augmented-reality arcore
1个回答
0
投票

[我认为您的目标是通过两个模型来允许您的应用与多种模型一起工作的方式的两个例子是:

  • 在构建时在应用程序中包含多个Renderables
  • 添加了在运行时加载和构建模型的功能

第一个示例如下所示。这将在Main ACtivity的增加功能(此示例为Kotlin)的应用程序的“原始”文件夹中构建所有可渲染对象。本示例使用“ MetaRenderable”类,该类只是具有用于存储可渲染名称和可渲染自身的属性的类。它通过在名称中查找已知的文本字符串来搜索可渲染对象,但是您可以简单地为所有“ .sfb”文件分别使用它们:

  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //Check that AR is supported on this device
        if (!checkIsSupportedDeviceOrFinish(this)) {
            return
        }

        //Create the set of renderables
        val rawFields: Array<Field> = R.raw::class.java.fields
        for (i in 0 .. rawFields.count() - 1) {
            val resID = rawFields[i].getInt(rawFields[i])
            val value = TypedValue()
            resources.getValue(resID, value, true)
            val rawFileName = value.string.toString()
            if (rawFileName.contains("com_yourpackagename_")) {
                //This is a renderable so build it and add it to the list
                Log.d(TAG,"rawFileName: " + rawFileName)
                ModelRenderable.builder()
                    .setSource(this, resID)
                    .build()
                    .thenAccept{
                        val newMetaRenderable:MetaRenderable = MetaRenderable()
                        newMetaRenderable.name = rawFields[i].name.substringAfter("com_yourpackagename_renderable_")
                        newMetaRenderable.renderable = it
                        listOfMetaRenderables.add(newMetaRenderable)
                        //Set the default renderable
                        if(rawFileName.contains("your_defaul_trenderable_name")) {
                            selectedRenderable = it
                        }
                    }
                    .exceptionally {
                        Log.d(TAG, "Could not build Renderable id: " + resID)
                        Toast.makeText(this@MainActivity, "Could not build one of the renderables", Toast.LENGTH_LONG).show()
                        return@exceptionally null
                    }
            }
        }

对于第二种示例方法,即在运行时加载,可以使用RenderableSource.Builder对象。这将允许您在运行时为给定URL生成可渲染对象,尽管目前仅限于“ GLTF2”文件AFAIK。

RenderableSource.BuildersetSource(Context context,Uri modelUri,RenderableSource.SourceType sourceType)设置要导入的资产的Uri。

文档在这里:

还有一个示例项目,可从此处的Google Poly网站浏览,下载和构建模型:

© www.soinside.com 2019 - 2024. All rights reserved.