首页 > 解决方案 > 导入 Sceneform 资产不会生成 .sfa 和 .sfb 文件

问题描述

当我尝试导入sceneform资产并在弹出的窗口上按完成时,没有任何反应。没有.sfa,.sfb文件生成。build.gradle文件中也没有生成任何东西。我不得不提到我导入了以前在同一个项目中的sceneform资产一切正常,但现在(一段时间后)当我再次尝试时它不起作用。

标签: android-studioimportassetsarcoresceneform

解决方案


来自https://developers.google.com/sceneform/develop/

在此处输入图像描述

考虑到1.15和1.17.1相同,还有这些问题

看起来它不再处于开发阶段,他们也不会修复它。这是 android studio 3.6 及更高版本的问题。


没有解决方案,要么您可以回滚到 Android Studio 3.5,要么您可以使用快速解决方法。

  1. 在您的应用程序中创建一个新的 sampledata 目录。

    右键单击顶级应用程序级目录 > 新建 > 示例数据目录

  2. 将您的 3D 资产及其依赖项(obj、mtl、fbx、png)放入 sampledata 目录。

  3. 将类路径 'com.google.ar.sceneform:plugin:1.15.0' 添加到您的项目级 gradle。确保您在存储库中有 google() 。

    // Top-level build file where you can add configuration options. common to all sub-projects/modules
    buildscript {
        repositories {
            google()
            jcenter()
        }
        dependencies {
             classpath "com.android.tools.build:gradle:4.0.1"
             classpath 'com.google.ar.sceneform:plugin:1.15.0'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
         }
    }
    
  4. Sceneform 需要特定版本的 NDK 和 Java。并且您需要应用插件和依赖项,因为它不会自动添加到最新版本的 android studio 中。应用插件:'com.android.application' 应用插件:'com.google.ar.sceneform.plugin'

     android {
         ...
    
         defaultConfig {
             ...
    
             ndk {
                 /*
                 * Sceneform is available for the following ABIs: arm64-v8a, armv7a,
                 * x86_64 and x86. This sample app enables arm64-v8a to run on
                 * devices and x86 to run on the emulator. Your application should
                 * list the ABIs most appropriate to minimize APK size (arm64-v8a recommended).
                 */
                 abiFilters 'arm64-v8a', 'x86'
             }
             compileOptions {
                 sourceCompatibility JavaVersion.VERSION_1_8
                 targetCompatibility JavaVersion.VERSION_1_8
             }
         }
    
         buildTypes {
             ...
         }
     }
    
     dependencies {
         ...
         implementation 'com.google.ar.sceneform:core:1.15.0'
     }
    
     < sceneform.asset code - 7th step >
    
  5. 我已将Poly中的Mars 3D 资产添加到我的示例数据中。目录结构看起来像在此处输入图像描述

  6. 将原始数据目录添加到资源。
    右键单击 res > 新建 > 文件夹 > 原始资源文件夹。

  7. 将此添加到应用程序级 gradle 文件的末尾。

     sceneform.asset('sampledata/mars.obj', // 'Source Asset Path' specified during import.
         'default',                         // 'Material Path' specified during import.
         'sampledata/mars.sfa',             // '.sfa Output Path' specified during import.
         'src/main/res/raw/mars')
    
  8. 同步文件,它现在应该可以工作了。

Sceneform 已弃用对 SFB 和 SFB Sceneform Android Studio 插件的支持(可以使用 glTF) -发行说明

该文档仅适用于 sceneform 1.15.0——不包括 glTF 工作流程。您可以查看演示以了解如何使用 glTF。


推荐阅读