Libgdx AssetManager一次加载多个模型

时间:2017-08-18 19:07:20

标签: java android opengl-es libgdx

我正在尝试使用资产管理器来加载模型异步,而不是中断渲染。我制作了一个带顶点和索引的自定义文件(只有一个模型的顶点太多)。我正在尝试使用AssetManager中的自定义加载程序加载此文件。加载器看起来像这样:

public class MyLoader extends AsynchronousAssetLoader<Terrain, MyLoader.TerrainParameter> {

    private FileHandleResolver fileHandleResolver;

    public MyLoader(FileHandleResolver fileHandleResolver) {
        super(fileHandleResolver);
    }

    private Terrain terrain;

    @Override
    public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, TerrainParameter parameter) {
        return null;
    }

    @Override
    public void loadAsync(AssetManager manager, String fileName, FileHandle file, TerrainParameter parameter) {
        this.terrain = loadTerrain(file);

        List<CustomObject> terrainParts = terrain.getTerrainParts();

        ModelBuilder modelBuilder = new ModelBuilder();

        //-----Block of code-------
        for (CustomObject terrainPart: terrainParts) {
            modelBuilder.begin();
            MeshPartBuilder meshBuilder = modelBuilder.part("terrainPart", GL20.GL_TRIANGLES, Usage.Position,
                    new Material());
            meshBuilder.addMesh(terrainPart.getVertices(), terrainPart.getIndices());
            Model terrainPartModel = modelBuilder.end();
            terrain.getTerrainPartModels().add(terrainPartModel);
        }
        //-----End Block of code-------
    }

    @Override
    public Terrain loadSync(AssetManager manager, String fileName, FileHandle file, TerrainParameter parameter) {
        Terrain terrain = this.terrain;
        this.terrain = null;
        return terrain;
    }

    private Terrain loadTerrain(FileHandle fileHandle) {
          // Reading file here
    }


    public static class TerrainParameter extends AssetLoaderParameters<Terrain> {

    }
}

这不起作用,当我渲染时出现以下错误:

08-18 18:58:19.933 31830-31862/com.pickaline.se E/emuglGLESv2_enc: device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBufferData:427 GL error 0x502
08-18 18:58:19.933 31830-31862/com.pickaline.se D/emuglGLESv2_enc: sendVertexAttributes: bad offset / len!!!!!
08-18 18:58:19.933 31830-31862/com.pickaline.se A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc in tid 31862 (GLThread 423)

                                                    [ 08-18 18:58:19.934  1259: 1259 W/         ]
                                                    debuggerd: handling request: pid=31830 uid=10084 gid=10084 tid=31862

但是,如果我在我的Loader之外移动那个完全相同的“代码块”,那么它可以完美地运行。此外,如果我只在Loader中创建第一个正确加载的模型。是否可以以某种方式加载异步或在模型构建器上加载多少?我只是想不出来。

0 个答案:

没有答案