Search in sources :

Example 1 with PbrMaterial

use of io.github.voidzombie.nhglib.graphics.utils.PbrMaterial in project nhglib by VoidZombie.

the class SceneManager method loadAssets.

private void loadAssets(Integer entity) {
    final ModelComponent modelComponent = modelMapper.get(entity);
    // Group all assets
    final Array<Asset> allAssets = new Array<>();
    final Asset modelAsset = modelComponent.asset;
    for (PbrMaterial mat : modelComponent.pbrMaterials) {
        if (mat.albedoAsset != null) {
            allAssets.add(mat.albedoAsset);
        }
        if (mat.metalnessAsset != null) {
            allAssets.add(mat.metalnessAsset);
        }
        if (mat.roughnessAsset != null) {
            allAssets.add(mat.roughnessAsset);
        }
        if (mat.normalAsset != null) {
            allAssets.add(mat.normalAsset);
        }
        if (mat.ambientOcclusionAsset != null) {
            allAssets.add(mat.ambientOcclusionAsset);
        }
    }
    // Start loading them
    assets.queueAsset(modelAsset);
    // Wait for them
    messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {

        @Override
        public void accept(Message message) throws Exception {
            Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
            if (asset != null) {
                if (asset.is(modelAsset.alias)) {
                    Model model = assets.get(asset);
                    modelComponent.model = new ModelInstance(model);
                    if (modelComponent.model.animations.size > 0) {
                        modelComponent.animationController = new AnimationController(modelComponent.model);
                    }
                    assets.queueAssets(allAssets);
                } else {
                    if (allAssets.contains(asset, false)) {
                        temporaryLoadedAssets.add(asset);
                        allAssets.removeValue(asset, false);
                        Bundle bundle = new Bundle();
                        bundle.put("size", allAssets.size);
                        bundle.put("modelComponent", modelComponent);
                        sizeSubject.onNext(bundle);
                    }
                }
            }
        }
    });
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) Bundle(io.github.voidzombie.nhglib.utils.data.Bundle) Array(com.badlogic.gdx.utils.Array) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model) Asset(io.github.voidzombie.nhglib.assets.Asset) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

Example 2 with PbrMaterial

use of io.github.voidzombie.nhglib.graphics.utils.PbrMaterial in project nhglib by VoidZombie.

the class PbrMaterialJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    pbrMaterial = new PbrMaterial();
    pbrMaterial.targetNode = jsonValue.getString("targetNode", "");
    JsonValue albedoJson = jsonValue.get("albedo");
    JsonValue metalnessJson = jsonValue.get("metalness");
    JsonValue roughnessJson = jsonValue.get("roughness");
    JsonValue normalJson = jsonValue.get("normal");
    JsonValue ambientOcclusionJson = jsonValue.get("ambientOcclusion");
    TextureLoader.TextureParameter params = new TextureLoader.TextureParameter();
    params.minFilter = Texture.TextureFilter.MipMap;
    params.magFilter = Texture.TextureFilter.Linear;
    params.genMipMaps = true;
    if (albedoJson != null) {
        AssetJson albedoAssetJson = new AssetJson();
        albedoAssetJson.parse(albedoJson.get("asset"));
        pbrMaterial.albedoAsset = albedoAssetJson.get();
        pbrMaterial.albedoAsset.parameters = params;
    }
    if (metalnessJson != null) {
        AssetJson metalnessAssetJson = new AssetJson();
        metalnessAssetJson.parse(metalnessJson.get("asset"));
        pbrMaterial.metalnessAsset = metalnessAssetJson.get();
        pbrMaterial.metalnessAsset.parameters = params;
    }
    if (roughnessJson != null) {
        AssetJson roughnessAssetJson = new AssetJson();
        roughnessAssetJson.parse(roughnessJson.get("asset"));
        pbrMaterial.roughnessAsset = roughnessAssetJson.get();
        pbrMaterial.roughnessAsset.parameters = params;
    }
    if (normalJson != null) {
        AssetJson normalAssetJson = new AssetJson();
        normalAssetJson.parse(normalJson.get("asset"));
        pbrMaterial.normalAsset = normalAssetJson.get();
        pbrMaterial.normalAsset.parameters = params;
    }
    if (ambientOcclusionJson != null) {
        AssetJson ambientOcclusionAssetJson = new AssetJson();
        ambientOcclusionAssetJson.parse(ambientOcclusionJson.get("asset"));
        pbrMaterial.ambientOcclusionAsset = ambientOcclusionAssetJson.get();
        pbrMaterial.ambientOcclusionAsset.parameters = params;
    }
}
Also used : TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) JsonValue(com.badlogic.gdx.utils.JsonValue) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

Aggregations

PbrMaterial (io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)2 TextureLoader (com.badlogic.gdx.assets.loaders.TextureLoader)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)1 Array (com.badlogic.gdx.utils.Array)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 Asset (io.github.voidzombie.nhglib.assets.Asset)1 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)1 Message (io.github.voidzombie.nhglib.runtime.messaging.Message)1 Bundle (io.github.voidzombie.nhglib.utils.data.Bundle)1