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);
}
}
}
}
});
}
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;
}
}
Aggregations