Search in sources :

Example 1 with ParticleEffect

use of com.badlogic.gdx.graphics.g3d.particles.ParticleEffect in project libgdx by libgdx.

the class FlameMain method openEffect.

public ParticleEffect openEffect(File file, boolean replaceCurrentWorkspace) {
    try {
        ParticleEffect loadedEffect = load(file.getAbsolutePath(), ParticleEffect.class, null, new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches()));
        loadedEffect = loadedEffect.copy();
        loadedEffect.init();
        if (replaceCurrentWorkspace) {
            effect = loadedEffect;
            controllersData.clear();
            particleSystem.removeAll();
            particleSystem.add(effect);
            for (ParticleController controller : effect.getControllers()) controllersData.add(new ControllerData(controller));
            rebuildActiveControllers();
        }
        reloadRows();
        return loadedEffect;
    } catch (Exception ex) {
        System.out.println("Error loading effect: " + file.getAbsolutePath());
        ex.printStackTrace();
        JOptionPane.showMessageDialog(this, "Error opening effect.");
    }
    return null;
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController) ParticleEffectLoader(com.badlogic.gdx.graphics.g3d.particles.ParticleEffectLoader)

Example 2 with ParticleEffect

use of com.badlogic.gdx.graphics.g3d.particles.ParticleEffect in project libgdx by libgdx.

the class FlameMain method getParticleEffects.

public Array<ParticleEffect> getParticleEffects(Array<ParticleController> controllers, Array<ParticleEffect> out) {
    out.clear();
    assetManager.getAll(ParticleEffect.class, out);
    for (int i = 0; i < out.size; ) {
        ParticleEffect effect = out.get(i);
        Array<ParticleController> effectControllers = effect.getControllers();
        boolean remove = true;
        for (ParticleController controller : controllers) {
            if (effectControllers.contains(controller, true)) {
                remove = false;
                break;
            }
        }
        if (remove) {
            out.removeIndex(i);
            continue;
        }
        ++i;
    }
    return out;
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController)

Example 3 with ParticleEffect

use of com.badlogic.gdx.graphics.g3d.particles.ParticleEffect in project libgdx by libgdx.

the class ParticleControllerInfluencerPanel method reloadControllers.

private void reloadControllers() {
    Array<ParticleEffect> effects = new Array<ParticleEffect>();
    Array<ParticleController> controllers = new Array<ParticleController>();
    editor.assetManager.getAll(ParticleEffect.class, effects);
    for (ParticleEffect effect : effects) {
        controllers.addAll(effect.getControllers());
    }
    controllerPicker.setLoadedTemplates(controllers);
}
Also used : Array(com.badlogic.gdx.utils.Array) ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController)

Example 4 with ParticleEffect

use of com.badlogic.gdx.graphics.g3d.particles.ParticleEffect in project libgdx by libgdx.

the class ParticleControllerInfluencer method load.

@Override
public void load(AssetManager manager, ResourceData resources) {
    SaveData data = resources.getSaveData();
    Array<IntArray> effectsIndices = data.load("indices");
    AssetDescriptor descriptor;
    Iterator<IntArray> iterator = effectsIndices.iterator();
    while ((descriptor = data.loadAsset()) != null) {
        ParticleEffect effect = (ParticleEffect) manager.get(descriptor);
        if (effect == null)
            throw new RuntimeException("Template is null");
        Array<ParticleController> effectControllers = effect.getControllers();
        IntArray effectIndices = iterator.next();
        for (int i = 0, n = effectIndices.size; i < n; i++) {
            templates.add(effectControllers.get(effectIndices.get(i)));
        }
    }
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) IntArray(com.badlogic.gdx.utils.IntArray) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController) SaveData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 5 with ParticleEffect

use of com.badlogic.gdx.graphics.g3d.particles.ParticleEffect in project libgdx by libgdx.

the class ParticleControllerInfluencer method save.

@Override
public void save(AssetManager manager, ResourceData resources) {
    SaveData data = resources.createSaveData();
    Array<ParticleEffect> effects = manager.getAll(ParticleEffect.class, new Array<ParticleEffect>());
    Array<ParticleController> controllers = new Array<ParticleController>(templates);
    Array<IntArray> effectsIndices = new Array<IntArray>();
    for (int i = 0; i < effects.size && controllers.size > 0; ++i) {
        ParticleEffect effect = effects.get(i);
        Array<ParticleController> effectControllers = effect.getControllers();
        Iterator<ParticleController> iterator = controllers.iterator();
        IntArray indices = null;
        while (iterator.hasNext()) {
            ParticleController controller = iterator.next();
            int index = -1;
            if ((index = effectControllers.indexOf(controller, true)) > -1) {
                if (indices == null) {
                    indices = new IntArray();
                }
                iterator.remove();
                indices.add(index);
            }
        }
        if (indices != null) {
            data.saveAsset(manager.getAssetFileName(effect), ParticleEffect.class);
            effectsIndices.add(indices);
        }
    }
    data.save("indices", effectsIndices);
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g3d.particles.ParticleEffect) Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) IntArray(com.badlogic.gdx.utils.IntArray) ParticleController(com.badlogic.gdx.graphics.g3d.particles.ParticleController) SaveData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData)

Aggregations

ParticleController (com.badlogic.gdx.graphics.g3d.particles.ParticleController)7 ParticleEffect (com.badlogic.gdx.graphics.g3d.particles.ParticleEffect)7 SaveData (com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData)2 Array (com.badlogic.gdx.utils.Array)2 IntArray (com.badlogic.gdx.utils.IntArray)2 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)1 ParticleEffectLoader (com.badlogic.gdx.graphics.g3d.particles.ParticleEffectLoader)1 File (java.io.File)1