use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent in project nhglib by VoidZombie.
the class SceneManager method unloadScene.
public void unloadScene(final Scene scene) {
Observable.fromIterable(scene.sceneGraph.getEntities()).filter(new Predicate<Integer>() {
@Override
public boolean test(Integer entity) throws Exception {
return modelMapper.has(entity);
}
}).doFinally(new Action() {
@Override
public void run() throws Exception {
int rootEntity = scene.sceneGraph.getRootEntity();
NodeComponent nodeComponent = nodeMapper.get(rootEntity);
nodeComponent.setTranslation(0, 0, 0);
nodeComponent.setRotation(0, 0, 0);
nodeComponent.setScale(1, 1, 1);
nodeComponent.applyTransforms();
}
}).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
ModelComponent modelComponent = modelMapper.get(integer);
assets.unloadAsset(modelComponent.asset);
}
});
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent in project nhglib by VoidZombie.
the class GraphicsSystem method inserted.
@Override
protected void inserted(int entityId) {
super.inserted(entityId);
final ModelComponent modelComponent = modelMapper.get(entityId);
messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {
@Override
public void accept(Message message) throws Exception {
if (modelComponent.type == ModelComponent.Type.STATIC) {
Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
if (asset.is(modelComponent.asset.alias)) {
rebuildCache(modelComponent.model);
}
}
}
});
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent in project nhglib by VoidZombie.
the class GraphicsSystem method process.
@Override
protected void process(int entityId) {
ModelComponent modelComponent = modelMapper.get(entityId);
NodeComponent nodeComponent = nodeMapper.get(entityId);
if (modelComponent.enabled) {
if (modelComponent.animationController != null) {
modelComponent.animationController.update(Gdx.graphics.getDeltaTime());
}
if (modelComponent.type == ModelComponent.Type.DYNAMIC && modelComponent.model != null) {
modelComponent.model.transform.set(nodeComponent.getTransform());
for (ModelCache modelCache : dynamicCaches) {
modelCache.add(modelComponent.model);
}
}
}
}
use of io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent 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.runtime.ecs.components.graphics.ModelComponent in project nhglib by VoidZombie.
the class ModelComponentJson method parse.
@Override
public void parse(JsonValue jsonValue) {
ModelComponent modelComponent = entities.createComponent(entity, ModelComponent.class);
String type = jsonValue.getString("graphicsType");
JsonValue asset = jsonValue.get("asset");
boolean enabled = jsonValue.getBoolean("enabled", true);
AssetJson assetJson = new AssetJson();
assetJson.parse(asset);
JsonValue materialsJson = jsonValue.get("materials");
if (materialsJson != null) {
for (JsonValue mat : materialsJson) {
PbrMaterialJson pbrMaterialJson = new PbrMaterialJson();
pbrMaterialJson.parse(mat);
modelComponent.pbrMaterials.add(pbrMaterialJson.get());
}
}
modelComponent.type = ModelComponent.Type.fromString(type);
modelComponent.asset = assetJson.get();
modelComponent.enabled = enabled;
output = modelComponent;
}
Aggregations