Search in sources :

Example 1 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class MutaGenController method loadFlameFromFileBtn_clicked.

public void loadFlameFromFileBtn_clicked() {
    try {
        JFileChooser chooser = new FlameFileChooser(prefs);
        if (prefs.getInputFlamePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showOpenDialog(rootPanel) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            List<Flame> flames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
            Flame flame = flames.get(0);
            prefs.setLastInputFlameFile(file);
            if (flame != null) {
                importFlame(flame);
            }
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FlameReader(org.jwildfire.create.tina.io.FlameReader) FlameFileChooser(org.jwildfire.create.tina.swing.FlameFileChooser) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 2 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class IFlamesController method getBaseFlame.

private Flame getBaseFlame() {
    IFlamesFunc iflame = getIFlamesFunc();
    String flameXML = iflame != null ? iflame.getFlameParams(getCurrFlameIndex()).getFlameXML() : null;
    return flameXML != null && flameXML.length() > 0 ? new FlameReader(prefs).readFlamesfromXML(flameXML).get(0) : null;
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) IFlamesFunc(org.jwildfire.create.tina.variation.iflames.IFlamesFunc)

Example 3 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class FlameMorphService method morphXForms.

private static XForm morphXForms(Prefs pPrefs, XForm pXForm1, XForm pXForm2, double pFScl, int pFrame, int pFrames) {
    pXForm1 = pXForm1.makeCopy();
    pXForm2 = pXForm2.makeCopy();
    prepareMorphXForm(pXForm1);
    prepareMorphXForm(pXForm2);
    XForm res = new XForm();
    res.setWeight(morphValue(pXForm1.getWeight(), pXForm2.getWeight(), pFScl));
    res.setColor(morphValue(pXForm1.getColor(), pXForm2.getColor(), pFScl));
    res.setColorSymmetry(morphValue(pXForm1.getColorSymmetry(), pXForm2.getColorSymmetry(), pFScl));
    res.setMaterial(morphValue(pXForm1.getMaterial(), pXForm2.getMaterial(), pFScl));
    res.setMaterialSpeed(morphValue(pXForm1.getMaterialSpeed(), pXForm2.getMaterialSpeed(), pFScl));
    res.setXYCoeff00(morphValue(pXForm1.getXYCoeff00(), pXForm2.getXYCoeff00(), pFScl));
    res.setXYCoeff01(morphValue(pXForm1.getXYCoeff01(), pXForm2.getXYCoeff01(), pFScl));
    res.setXYCoeff10(morphValue(pXForm1.getXYCoeff10(), pXForm2.getXYCoeff10(), pFScl));
    res.setXYCoeff11(morphValue(pXForm1.getXYCoeff11(), pXForm2.getXYCoeff11(), pFScl));
    res.setXYCoeff20(morphValue(pXForm1.getXYCoeff20(), pXForm2.getXYCoeff20(), pFScl));
    res.setXYCoeff21(morphValue(pXForm1.getXYCoeff21(), pXForm2.getXYCoeff21(), pFScl));
    res.setYZCoeff00(morphValue(pXForm1.getYZCoeff00(), pXForm2.getYZCoeff00(), pFScl));
    res.setYZCoeff01(morphValue(pXForm1.getYZCoeff01(), pXForm2.getYZCoeff01(), pFScl));
    res.setYZCoeff10(morphValue(pXForm1.getYZCoeff10(), pXForm2.getYZCoeff10(), pFScl));
    res.setYZCoeff11(morphValue(pXForm1.getYZCoeff11(), pXForm2.getYZCoeff11(), pFScl));
    res.setYZCoeff20(morphValue(pXForm1.getYZCoeff20(), pXForm2.getYZCoeff20(), pFScl));
    res.setYZCoeff21(morphValue(pXForm1.getYZCoeff21(), pXForm2.getYZCoeff21(), pFScl));
    res.setZXCoeff00(morphValue(pXForm1.getZXCoeff00(), pXForm2.getZXCoeff00(), pFScl));
    res.setZXCoeff01(morphValue(pXForm1.getZXCoeff01(), pXForm2.getZXCoeff01(), pFScl));
    res.setZXCoeff10(morphValue(pXForm1.getZXCoeff10(), pXForm2.getZXCoeff10(), pFScl));
    res.setZXCoeff11(morphValue(pXForm1.getZXCoeff11(), pXForm2.getZXCoeff11(), pFScl));
    res.setZXCoeff20(morphValue(pXForm1.getZXCoeff20(), pXForm2.getZXCoeff20(), pFScl));
    res.setZXCoeff21(morphValue(pXForm1.getZXCoeff21(), pXForm2.getZXCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setXYPostCoeff00(morphValue(pXForm1.getXYPostCoeff00(), pXForm2.getXYPostCoeff00(), pFScl));
    res.setXYPostCoeff01(morphValue(pXForm1.getXYPostCoeff01(), pXForm2.getXYPostCoeff01(), pFScl));
    res.setXYPostCoeff10(morphValue(pXForm1.getXYPostCoeff10(), pXForm2.getXYPostCoeff10(), pFScl));
    res.setXYPostCoeff11(morphValue(pXForm1.getXYPostCoeff11(), pXForm2.getXYPostCoeff11(), pFScl));
    res.setXYPostCoeff20(morphValue(pXForm1.getXYPostCoeff20(), pXForm2.getXYPostCoeff20(), pFScl));
    res.setXYPostCoeff21(morphValue(pXForm1.getXYPostCoeff21(), pXForm2.getXYPostCoeff21(), pFScl));
    res.setYZPostCoeff00(morphValue(pXForm1.getYZPostCoeff00(), pXForm2.getYZPostCoeff00(), pFScl));
    res.setYZPostCoeff01(morphValue(pXForm1.getYZPostCoeff01(), pXForm2.getYZPostCoeff01(), pFScl));
    res.setYZPostCoeff10(morphValue(pXForm1.getYZPostCoeff10(), pXForm2.getYZPostCoeff10(), pFScl));
    res.setYZPostCoeff11(morphValue(pXForm1.getYZPostCoeff11(), pXForm2.getYZPostCoeff11(), pFScl));
    res.setYZPostCoeff20(morphValue(pXForm1.getYZPostCoeff20(), pXForm2.getYZPostCoeff20(), pFScl));
    res.setYZPostCoeff21(morphValue(pXForm1.getYZPostCoeff21(), pXForm2.getYZPostCoeff21(), pFScl));
    res.setZXPostCoeff00(morphValue(pXForm1.getZXPostCoeff00(), pXForm2.getZXPostCoeff00(), pFScl));
    res.setZXPostCoeff01(morphValue(pXForm1.getZXPostCoeff01(), pXForm2.getZXPostCoeff01(), pFScl));
    res.setZXPostCoeff10(morphValue(pXForm1.getZXPostCoeff10(), pXForm2.getZXPostCoeff10(), pFScl));
    res.setZXPostCoeff11(morphValue(pXForm1.getZXPostCoeff11(), pXForm2.getZXPostCoeff11(), pFScl));
    res.setZXPostCoeff20(morphValue(pXForm1.getZXPostCoeff20(), pXForm2.getZXPostCoeff20(), pFScl));
    res.setZXPostCoeff21(morphValue(pXForm1.getZXPostCoeff21(), pXForm2.getZXPostCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setDrawMode(pFScl >= 0.5 ? pXForm2.getDrawMode() : pXForm1.getDrawMode());
    for (int i = 0; i < pXForm1.getModifiedWeights().length; i++) {
        res.getModifiedWeights()[i] = morphValue(pXForm1.getModifiedWeights()[i], pXForm2.getModifiedWeights()[i], pFScl);
    }
    res.clearVariations();
    List<Variation> vars1 = new ArrayList<Variation>();
    List<Variation> vars2 = new ArrayList<Variation>();
    HashMap<String, String> processed = new HashMap<String, String>();
    for (int i = 0; i < pXForm1.getVariationCount(); i++) {
        Variation var1 = pXForm1.getVariation(i);
        String fncName = var1.getFunc().getName();
        processed.put(fncName, fncName);
        vars1.add(var1);
        // search the same func in xForm2
        Variation var2 = null;
        for (int j = 0; j < pXForm2.getVariationCount(); j++) {
            var2 = pXForm2.getVariation(j);
            if (var2.getFunc().getName().equals(fncName)) {
                break;
            } else {
                var2 = null;
            }
        }
        if (var2 != null) {
            vars2.add(var2);
        } else {
            vars2.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var1.getFunc().getName(), true)));
        }
    }
    for (int i = 0; i < pXForm2.getVariationCount(); i++) {
        Variation var2 = pXForm2.getVariation(i);
        String fncName = var2.getFunc().getName();
        if (processed.get(fncName) == null) {
            vars2.add(var2);
            vars1.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var2.getFunc().getName(), true)));
        }
    }
    if (vars1.size() != vars2.size()) {
        throw new IllegalStateException();
    }
    for (int i = 0; i < vars1.size(); i++) {
        Variation var1 = vars1.get(i);
        Variation var2 = vars2.get(i);
        if (!var1.getFunc().getName().equals(var2.getFunc().getName())) {
            throw new IllegalStateException();
        }
        // System.out.println(i + ": " + var1.getFunc().getName() + " " + var1.getAmount() + " " + var2.getAmount());
        double amount = morphValue(var1.getAmount(), var2.getAmount(), pFScl);
        Variation var = res.addVariation(amount, var1.getFunc());
        // params
        if (var.getFunc().getParameterNames() != null && var.getFunc().getParameterNames().length > 0) {
            Object[] val = var.getFunc().getParameterValues();
            Object[] val1 = var1.getFunc().getParameterValues();
            Object[] val2 = var2.getFunc().getParameterValues();
            for (int j = 0; j < var.getFunc().getParameterNames().length; j++) {
                String name = var.getFunc().getParameterNames()[j];
                if (val[j] instanceof Integer) {
                    int mVal = morphValue((Integer) val1[j], (Integer) val2[j], pFScl);
                    if (mVal == 0 && name.equals("power")) {
                        mVal = 1;
                    }
                    // int mVal = pFScl >= 0.5 ? (Integer) val2[j] : (Integer) val1[j];
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else if (val[j] instanceof Double) {
                    double mVal = morphValue((Double) val1[j], (Double) val2[j], pFScl);
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else {
                    throw new IllegalStateException();
                }
            }
        }
        // ressources
        if (var.getFunc().getRessourceNames() != null && var.getFunc().getRessourceNames().length > 0) {
            Object[] ress1 = var1.getFunc().getRessourceValues();
            Object[] ress2 = var2.getFunc().getRessourceValues();
            for (int j = 0; j < var.getFunc().getRessourceNames().length; j++) {
                String name = var.getFunc().getRessourceNames()[j];
                if (name.equalsIgnoreCase(SubFlameWFFunc.RESSOURCE_FLAME) && var.getFunc().getName().indexOf("subflame_wf") >= 0) {
                    String flame1XML = new String((byte[]) ress1[j]);
                    String flame2XML = new String((byte[]) ress2[j]);
                    try {
                        Flame flame1 = new FlameReader(pPrefs).readFlamesfromXML(flame1XML).get(0);
                        Flame flame2 = new FlameReader(pPrefs).readFlamesfromXML(flame2XML).get(0);
                        Flame morphedFlame = morphFlames(pPrefs, FlameMorphType.MORPH, flame1, flame2, pFrame, pFrames);
                        String morphedFlameXML = new FlameWriter().getFlameXML(morphedFlame);
                        var.getFunc().setRessource(SubFlameWFFunc.RESSOURCE_FLAME, morphedFlameXML.getBytes());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
    return res;
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) XForm(org.jwildfire.create.tina.base.XForm) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Variation(org.jwildfire.create.tina.variation.Variation) Flame(org.jwildfire.create.tina.base.Flame)

Example 4 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class DancingFractalsController method loadFlameFromClipboardButton_clicked.

public void loadFlameFromClipboardButton_clicked() {
    List<Flame> newFlames = null;
    try {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable clipData = clipboard.getContents(clipboard);
        if (clipData != null) {
            if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
                newFlames = new FlameReader(prefs).readFlamesfromXML(xml);
            }
        }
        if (newFlames == null || newFlames.size() < 1) {
            throw new Exception("There is currently no valid flame in the clipboard");
        } else {
            for (Flame newFlame : newFlames) {
                project.getFlames().add(validateDancingFlame(newFlame));
            }
            refreshProjectFlames();
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 5 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class DancingFractalsController method loadFlameButton_clicked.

public void loadFlameButton_clicked() {
    try {
        JFileChooser chooser = new FlameFileChooser(prefs);
        if (prefs.getInputFlamePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(poolFlamePreviewPnl) == JFileChooser.APPROVE_OPTION) {
            for (File file : chooser.getSelectedFiles()) {
                List<Flame> newFlames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
                prefs.setLastInputFlameFile(file);
                if (newFlames != null && newFlames.size() > 0) {
                    for (Flame newFlame : newFlames) {
                        project.getFlames().add(validateDancingFlame(newFlame));
                    }
                }
            }
            refreshProjectFlames();
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FlameReader(org.jwildfire.create.tina.io.FlameReader) FlameFileChooser(org.jwildfire.create.tina.swing.FlameFileChooser) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

FlameReader (org.jwildfire.create.tina.io.FlameReader)25 Flame (org.jwildfire.create.tina.base.Flame)24 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)20 File (java.io.File)12 JFileChooser (javax.swing.JFileChooser)10 Clipboard (java.awt.datatransfer.Clipboard)7 Transferable (java.awt.datatransfer.Transferable)7 FlameFileChooser (org.jwildfire.create.tina.swing.FlameFileChooser)5 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)3 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)3 ArrayList (java.util.ArrayList)2 ThumbnailCacheKey (org.jwildfire.create.tina.swing.ThumbnailCacheKey)2 HashMap (java.util.HashMap)1 ImageIcon (javax.swing.ImageIcon)1 XForm (org.jwildfire.create.tina.base.XForm)1 FACLFlameWriter (org.jwildfire.create.tina.faclrender.FACLFlameWriter)1 FACLRenderResult (org.jwildfire.create.tina.faclrender.FACLRenderResult)1 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)1 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)1 Variation (org.jwildfire.create.tina.variation.Variation)1