【发布时间】:2021-04-25 07:49:33
【问题描述】:
我的问题是我试图让SurfaceView 显示一个 3D 模型,它只是整个应用程序布局的一小部分。布局包括用于显示其他数据的多个视图;但是,一旦我创建了ModelViewer,SurfaceView 就会消失。当我使用 Filament 的 1.9.9 版本时,会显示布局,但像素化严重,并且似乎使其他布局元素消失。使用v1.7.0 时,其他元素不会消失,但不会显示任何内容。
我在 Gradle 文件中使用以下版本:
implementation 'com.google.android.filament:filament-android:1.7.0'
implementation 'com.google.android.filament:filament-utils-android:1.7.0'
implementation 'com.google.android.filament:gltfio-android:1.7.0'
正如我在 Kotlin 示例中看到的那样,我有一个模型复制到资产文件夹: https://github.com/google/filament/tree/main/android/samples/sample-gltf-viewer
这是我的 Java 尝试加载从 Blender 导出的自定义 GLTF 2.0 模型:
import android.content.Context;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.view.Choreographer;
import android.view.SurfaceView;
import com.google.android.filament.Engine;
import com.google.android.filament.utils.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
public class Model implements Choreographer.FrameCallback {
static {
Utils.INSTANCE.init();
}
private final String TAG = Model.class.getSimpleName();
private Context context;
private SurfaceView surfaceView;
private ModelViewer modelViewer;
private Engine engine;
private Choreographer choreographer;
private final String modelFilename = "models/modelTest.glb";
@Override
public void doFrame(long currentTime) {
choreographer.postFrameCallback(this);
modelViewer.render(currentTime);
}
public Model(Context context, ConstraintLayout layout) {
this.context = context;
choreographer = Choreographer.getInstance();
surfaceView = new SurfaceView(context);
layout.addView(surfaceView);
engine = Engine.create();
modelViewer = new ModelViewer(surfaceView, engine, null);
loadModel(modelFilename);
choreographer.postFrameCallback(this);
}
private void loadModel(String filepath) {
try {
InputStream buffer = context.getAssets().open(filepath);
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) {
}
}
}
编辑 1:
这是使用 1.9.4 以上的任何版本时显示的内容。编舞循环使静态部分看起来像电视上的静态噪声。红色部分似乎是模型的一小部分。
【问题讨论】: