首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用灯丝android进行3d时,加载glb文件失败

在使用灯丝android进行3d时,加载glb文件失败
EN

Stack Overflow用户
提问于 2022-01-03 22:46:23
回答 1查看 348关注 0票数 1

嗨,我正在试图加载一个glb文件在我的android应用程序的3d视图。我发现了android长丝,并试图实现它,但我得到的是在使用Engine.create()时无法创建引擎错误。

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

这是我的密码:

代码语言:javascript
复制
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是:

代码语言:javascript
复制
<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>

下面是我使用的依赖项:

'com.google.android.filament:filament-android:1.15.1‘实现'com.google.android.filament:filament-utils-android:1.15.1’实现'com.google.android.filament:gltfio-android:1.15.1‘

安卓工作室的版本是4.2.1。任何帮助都是非常感谢的。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-10-24 11:23:37

我是科特林:

代码语言:javascript
复制
fun loadEnviromentt(context: Context, ibl2: String) {
    // Create the sky box and add it to the scene.
    val buffer = readAsset(context, ibl2)
    KTXLoader.createSkybox(modelViewer.engine, buffer).apply {
        modelViewer.scene.skybox = this
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70572246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档