Search in sources :

Example 6 with ModelData

use of com.badlogic.gdx.graphics.g3d.model.data.ModelData in project nhglib by VoidZombie.

the class NhgModelLoader method loadSync.

@Override
public Model loadSync(AssetManager manager, String fileName, FileHandle file, P parameters) {
    ModelData data = null;
    synchronized (items) {
        for (int i = 0; i < items.size; i++) {
            if (items.get(i).key.equals(fileName)) {
                data = items.get(i).value;
                items.removeIndex(i);
            }
        }
    }
    if (data == null)
        return null;
    final Model result = new Model(data, new TextureProvider.AssetTextureProvider(manager));
    // need to remove the textures from the managed disposables, or else ref counting
    // doesn't work!
    Iterator<Disposable> disposables = result.getManagedDisposables().iterator();
    while (disposables.hasNext()) {
        Disposable disposable = disposables.next();
        if (disposable instanceof Texture) {
            disposables.remove();
        }
    }
    // Automatically convert all materials to PBR
    for (Material material : result.materials) {
        TextureAttribute textureAttribute = (TextureAttribute) material.get(TextureAttribute.Diffuse);
        if (textureAttribute != null) {
            material.set(PbrTextureAttribute.createAlbedo(textureAttribute.textureDescription.texture));
        }
    }
    data = null;
    return result;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) TextureProvider(com.badlogic.gdx.graphics.g3d.utils.TextureProvider) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) PbrTextureAttribute(io.github.voidzombie.nhglib.graphics.shaders.attributes.PbrTextureAttribute)

Aggregations

ModelData (com.badlogic.gdx.graphics.g3d.model.data.ModelData)6 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)4 ModelTexture (com.badlogic.gdx.graphics.g3d.model.data.ModelTexture)4 Texture (com.badlogic.gdx.graphics.Texture)3 Array (com.badlogic.gdx.utils.Array)3 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 TextureProvider (com.badlogic.gdx.graphics.g3d.utils.TextureProvider)2 Disposable (com.badlogic.gdx.utils.Disposable)2 ObjectMap (com.badlogic.gdx.utils.ObjectMap)2 TextureLoader (com.badlogic.gdx.assets.loaders.TextureLoader)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)1 ModelMesh (com.badlogic.gdx.graphics.g3d.model.data.ModelMesh)1 ModelMeshPart (com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart)1 ModelNode (com.badlogic.gdx.graphics.g3d.model.data.ModelNode)1 ModelNodePart (com.badlogic.gdx.graphics.g3d.model.data.ModelNodePart)1 Quaternion (com.badlogic.gdx.math.Quaternion)1 Vector3 (com.badlogic.gdx.math.Vector3)1