1

嗨,我正在尝试在我的 android 应用程序中加载一个 glb 文件以获取 3d 视图。我发现了有关 android 长丝的信息并尝试实现它,但在使用 Engine.create() 时出现无法创建引擎错误。

java.lang.RuntimeException:无法启动活动 ComponentInfo {ConfigurationActivity}:java.lang.IllegalStateException:无法创建引擎

这是我的代码:

public class ConfigurationActivity extends AppCompatActivity  implements Choreographer.FrameCallback {
private SurfaceView surfaceView;
private Choreographer choreographer;
private ModelViewer modelViewer;
private Engine engine;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_configuration);
    //Filament.init();
    Utils.INSTANCE.init();
    initialiseComponents();
    initialise();
}

private void initialiseComponents() {
    surfaceView = findViewById(R.id.configuration_sv_main);
}

private void initialise() {
    choreographer = Choreographer.getInstance();
    engine = Engine.create();
    modelViewer= new ModelViewer(surfaceView, engine, null);
    surfaceView.setOnTouchListener(modelViewer);

    choreographer.postFrameCallback(this);

    loadModel();
}

private void loadModel() {
    try {
        InputStream buffer = getAssets().open("test_final.glb");
        byte[] bytes = new byte[buffer.available()];
        buffer.read(bytes);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        modelViewer.loadModelGlb(byteBuffer);
        modelViewer.transformToUnitCube(new Float3(0,0,0));
    } catch (IOException e) {
        e.printStackTrace();
    }
}


@Override
public void doFrame(long l) {
    choreographer.postFrameCallback(this);
    modelViewer.render(l);
}

@Override
protected void onResume() {
    super.onResume();
    choreographer.postFrameCallback(this);
}

@Override
protected void onPause() {
    super.onPause();
    choreographer.removeFrameCallback(this);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    choreographer.removeFrameCallback(this);
    engine.destroy();
}
}

我的xml是:

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ConfigurationActivity">

<SurfaceView
    android:id="@+id/configuration_sv_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

以下是我使用的依赖项:

implementation 'com.google.android.filament:filament-android:1.15.1'
implementation 'com.google.android.filament:filament-utils-android:1.15.1'
implementation 'com.google.android.filament:gltfio-android:1.15.1'

而android studio版本是4.2.1。任何帮助表示赞赏。谢谢你。

4

0 回答 0