Search in sources :

Example 11 with MotionCurve

use of org.jwildfire.create.tina.base.motion.MotionCurve in project JWildfire by thargor6.

the class AbstractControlsDelegate method enableControl.

public void enableControl(JButton pMainButton, JButton pCurveBtn, String pPropertyName, boolean pDisabled) {
    boolean controlEnabled = false;
    boolean curveBtnEnabled = false;
    boolean mainButtonEnabled = false;
    boolean hasCurve = false;
    if (!pDisabled && isEnabled()) {
        controlEnabled = true;
        if (pPropertyName != null && pPropertyName.length() > 0) {
            MotionCurve curve = getCurveToEdit(pPropertyName);
            curveBtnEnabled = true;
            mainButtonEnabled = !curve.isEnabled();
            hasCurve = curve.isEnabled();
        } else {
            curveBtnEnabled = false;
            mainButtonEnabled = true;
        }
    }
    pMainButton.setEnabled(controlEnabled && mainButtonEnabled);
    if (hasCurve)
        pCurveBtn.setIcon(new ImageIcon(getClass().getResource("/org/jwildfire/swing/icons/new/curve-money2a.png")));
    else
        pCurveBtn.setIcon(new ImageIcon(getClass().getResource("/org/jwildfire/swing/icons/new/curve-money2.png")));
    pCurveBtn.setEnabled(controlEnabled && curveBtnEnabled);
}
Also used : ImageIcon(javax.swing.ImageIcon) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve)

Example 12 with MotionCurve

use of org.jwildfire.create.tina.base.motion.MotionCurve in project JWildfire by thargor6.

the class AbstractFlameReader method parseXFormAttributes.

protected void parseXFormAttributes(Flame pFlame, XForm pXForm, String pXML) {
    XMLAttributes atts = Tools.parseAttributes(pXML);
    String hs;
    if ((hs = atts.get(ATTR_NAME)) != null) {
        pXForm.setName(hs);
    }
    if ((hs = atts.get(ATTR_WEIGHT)) != null) {
        pXForm.setWeight(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MIRROR_PRE_POST_TRANSLATIONS)) != null) {
        double val = Double.parseDouble(hs);
        pXForm.setMirrorTranslations(val == 1);
    }
    if ((hs = atts.get(ATTR_COLOR)) != null) {
        pXForm.setColor(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MATERIAL)) != null) {
        pXForm.setMaterial(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MATERIAL_SPEED)) != null) {
        pXForm.setMaterialSpeed(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_GAMMA)) != null) {
        pXForm.setModGamma(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_GAMMA_SPEED)) != null) {
        pXForm.setModGammaSpeed(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_CONTRAST)) != null) {
        pXForm.setModContrast(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_CONTRAST_SPEED)) != null) {
        pXForm.setModContrastSpeed(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_SATURATION)) != null) {
        pXForm.setModSaturation(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_SATURATION_SPEED)) != null) {
        pXForm.setModSaturationSpeed(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_HUE)) != null) {
        pXForm.setModHue(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_MOD_HUE_SPEED)) != null) {
        pXForm.setModHueSpeed(Double.parseDouble(hs));
    }
    // legacy
    if ((hs = atts.get(ATTR_ANTIALIAS_AMOUNT)) != null) {
        double value = Double.parseDouble(hs);
        if (value > 0)
            pFlame.setAntialiasAmount(value);
    }
    // legacy
    if ((hs = atts.get(ATTR_ANTIALIAS_RADIUS)) != null) {
        double value = Double.parseDouble(hs);
        if (value > 0)
            pFlame.setAntialiasRadius(value);
    }
    if ((hs = atts.get(ATTR_OPACITY)) != null) {
        double opacity = Double.parseDouble(hs);
        pXForm.setOpacity(opacity);
        if (Math.abs(opacity) <= MathLib.EPSILON) {
            pXForm.setDrawMode(DrawMode.HIDDEN);
        } else if (Math.abs(opacity - 1.0) > MathLib.EPSILON) {
            pXForm.setDrawMode(DrawMode.OPAQUE);
        } else {
            pXForm.setDrawMode(DrawMode.NORMAL);
        }
    }
    if ((hs = atts.get(ATTR_SYMMETRY)) != null) {
        pXForm.setColorSymmetry(Double.parseDouble(hs));
    }
    if ((hs = atts.get(ATTR_XY_COEFS)) != null) {
        String[] s = hs.split(" ");
        pXForm.setXYCoeff00(Double.parseDouble(s[0]));
        pXForm.setXYCoeff01(Double.parseDouble(s[1]));
        pXForm.setXYCoeff10(Double.parseDouble(s[2]));
        pXForm.setXYCoeff11(Double.parseDouble(s[3]));
        pXForm.setXYCoeff20(Double.parseDouble(s[4]));
        pXForm.setXYCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_XY_POST)) != null) {
        String[] s = hs.split(" ");
        pXForm.setXYPostCoeff00(Double.parseDouble(s[0]));
        pXForm.setXYPostCoeff01(Double.parseDouble(s[1]));
        pXForm.setXYPostCoeff10(Double.parseDouble(s[2]));
        pXForm.setXYPostCoeff11(Double.parseDouble(s[3]));
        pXForm.setXYPostCoeff20(Double.parseDouble(s[4]));
        pXForm.setXYPostCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_YZ_COEFS)) != null) {
        String[] s = hs.split(" ");
        pXForm.setYZCoeff00(Double.parseDouble(s[0]));
        pXForm.setYZCoeff01(Double.parseDouble(s[1]));
        pXForm.setYZCoeff10(Double.parseDouble(s[2]));
        pXForm.setYZCoeff11(Double.parseDouble(s[3]));
        pXForm.setYZCoeff20(Double.parseDouble(s[4]));
        pXForm.setYZCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_YZ_POST)) != null) {
        String[] s = hs.split(" ");
        pXForm.setYZPostCoeff00(Double.parseDouble(s[0]));
        pXForm.setYZPostCoeff01(Double.parseDouble(s[1]));
        pXForm.setYZPostCoeff10(Double.parseDouble(s[2]));
        pXForm.setYZPostCoeff11(Double.parseDouble(s[3]));
        pXForm.setYZPostCoeff20(Double.parseDouble(s[4]));
        pXForm.setYZPostCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_ZX_COEFS)) != null) {
        String[] s = hs.split(" ");
        pXForm.setZXCoeff00(Double.parseDouble(s[0]));
        pXForm.setZXCoeff01(Double.parseDouble(s[1]));
        pXForm.setZXCoeff10(Double.parseDouble(s[2]));
        pXForm.setZXCoeff11(Double.parseDouble(s[3]));
        pXForm.setZXCoeff20(Double.parseDouble(s[4]));
        pXForm.setZXCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_ZX_POST)) != null) {
        String[] s = hs.split(" ");
        pXForm.setZXPostCoeff00(Double.parseDouble(s[0]));
        pXForm.setZXPostCoeff01(Double.parseDouble(s[1]));
        pXForm.setZXPostCoeff10(Double.parseDouble(s[2]));
        pXForm.setZXPostCoeff11(Double.parseDouble(s[3]));
        pXForm.setZXPostCoeff20(Double.parseDouble(s[4]));
        pXForm.setZXPostCoeff21(Double.parseDouble(s[5]));
    }
    if ((hs = atts.get(ATTR_CHAOS)) != null) {
        String[] s = hs.split(" ");
        for (int i = 0; i < s.length; i++) {
            pXForm.getModifiedWeights()[i] = Double.parseDouble(s[i]);
        }
    }
    readMotionCurves(pXForm, atts, null);
    // variations
    {
        List<String> variationNameList = VariationFuncList.getNameList();
        Map<String, String> aliasMap = VariationFuncList.getAliasMap();
        for (XMLAttribute attr : atts.getAttributes()) {
            String rawName = attr.getName();
            String name = removeIndexFromAttr(rawName);
            String varName = name;
            boolean hasVariation = variationNameList.indexOf(varName) >= 0;
            if (!hasVariation) {
                String aliasName = aliasMap.get(name);
                if (aliasName != null) {
                    varName = aliasName;
                    hasVariation = variationNameList.indexOf(varName) >= 0;
                }
            }
            if (hasVariation) {
                VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(varName);
                Variation variation = pXForm.addVariation(Double.parseDouble(atts.get(rawName)), varFunc);
                String priority = atts.get(rawName + "_" + ATTR_FX_PRIORITY);
                if (priority != null && priority.length() > 0) {
                    variation.setPriority(Integer.parseInt(priority));
                }
                // ressources
                {
                    String[] ressNames = variation.getFunc().getRessourceNames();
                    if (ressNames != null) {
                        for (String pName : ressNames) {
                            String pHs;
                            if ((pHs = atts.get(rawName + "_" + pName)) != null) {
                                variation.getFunc().setRessource(pName, Tools.hexStringToByteArray(pHs));
                            }
                        }
                    }
                }
                // params
                {
                    String[] paramNames = variation.getFunc().getParameterNames();
                    String[] paramAltNames = variation.getFunc().getParameterAlternativeNames();
                    if (paramNames != null) {
                        if (paramAltNames != null && paramAltNames.length != paramNames.length) {
                            paramAltNames = null;
                        }
                        for (int i = 0; i < paramNames.length; i++) {
                            String pName = paramNames[i];
                            String pHs;
                            if ((pHs = atts.get(rawName + "_" + pName)) != null) {
                                variation.getFunc().setParameter(pName, Double.parseDouble(pHs));
                            } else // altNames can only be come from flames which were not created by JWF, so no need to handle index here
                            if (paramAltNames != null && ((pHs = atts.get(paramAltNames[i])) != null)) {
                                variation.getFunc().setParameter(pName, Double.parseDouble(pHs));
                            }
                            // curve
                            {
                                String namePrefix = rawName + "_" + pName + "_";
                                if (atts.get(namePrefix + AbstractFlameReader.CURVE_ATTR_POINT_COUNT) != null) {
                                    MotionCurve curve = variation.getMotionCurve(pName);
                                    if (curve == null) {
                                        curve = variation.createMotionCurve(pName);
                                    }
                                    readMotionCurveAttributes(atts, curve, namePrefix);
                                }
                            }
                        }
                    }
                }
                // then changes to parameter B cannot in turn cause additional parameters to be added/removed
                if (variation.getFunc().dynamicParameterExpansion()) {
                    String[] paramNames = variation.getFunc().getParameterNames();
                    String[] paramAltNames = variation.getFunc().getParameterAlternativeNames();
                    if (paramNames != null) {
                        if (paramAltNames != null && paramAltNames.length != paramNames.length) {
                            paramAltNames = null;
                        }
                        for (int i = 0; i < paramNames.length; i++) {
                            String pName = paramNames[i];
                            String pHs;
                            if ((pHs = atts.get(rawName + "_" + pName)) != null) {
                                variation.getFunc().setParameter(pName, Double.parseDouble(pHs));
                            } else // altNames can only be come from flames which were not created by JWF, so no need to handle index here
                            if (paramAltNames != null && ((pHs = atts.get(paramAltNames[i])) != null)) {
                                variation.getFunc().setParameter(pName, Double.parseDouble(pHs));
                            }
                            // curve
                            {
                                String namePrefix = rawName + "_" + pName + "_";
                                if (atts.get(namePrefix + AbstractFlameReader.CURVE_ATTR_POINT_COUNT) != null) {
                                    MotionCurve curve = variation.getMotionCurve(pName);
                                    if (curve == null) {
                                        curve = variation.createMotionCurve(pName);
                                    }
                                    readMotionCurveAttributes(atts, curve, namePrefix);
                                }
                            }
                        }
                    }
                }
                // curves
                readMotionCurves(variation, atts, rawName + "_");
            // 
            }
        }
    }
}
Also used : XMLAttributes(org.jwildfire.base.Tools.XMLAttributes) XMLAttribute(org.jwildfire.base.Tools.XMLAttribute) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) VariationFuncList(org.jwildfire.create.tina.variation.VariationFuncList) List(java.util.List) Variation(org.jwildfire.create.tina.variation.Variation) Map(java.util.Map) VariationFunc(org.jwildfire.create.tina.variation.VariationFunc)

Example 13 with MotionCurve

use of org.jwildfire.create.tina.base.motion.MotionCurve in project JWildfire by thargor6.

the class AbstractFlameReader method readMotionCurves.

protected void readMotionCurves(Object source, XMLAttributes atts, String pNamePrefix) {
    for (MotionCurveAttribute attribute : AnimationService.getAllMotionCurves(source)) {
        MotionCurve curve = attribute.getMotionCurve();
        String namePrefix = pNamePrefix == null ? attribute.getName() + "_" : pNamePrefix + attribute.getName() + "_";
        readMotionCurveAttributes(atts, curve, namePrefix);
    }
}
Also used : MotionCurveAttribute(org.jwildfire.create.tina.animate.AnimationService.MotionCurveAttribute) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve)

Example 14 with MotionCurve

use of org.jwildfire.create.tina.base.motion.MotionCurve in project JWildfire by thargor6.

the class AbstractFlameWriter method createXFormAttrList.

protected List<SimpleXMLBuilder.Attribute<?>> createXFormAttrList(SimpleXMLBuilder pXB, Layer pLayer, XForm pXForm) throws Exception {
    List<SimpleXMLBuilder.Attribute<?>> attrList = new ArrayList<SimpleXMLBuilder.Attribute<?>>();
    attrList.add(pXB.createAttr("weight", pXForm.getWeight()));
    attrList.add(pXB.createAttr("color", pXForm.getColor()));
    attrList.add(pXB.createAttr("symmetry", pXForm.getColorSymmetry()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MIRROR_PRE_POST_TRANSLATIONS, pXForm.getMirrorTranslations() ? 1 : 0));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MATERIAL, pXForm.getMaterial()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MATERIAL_SPEED, pXForm.getMaterialSpeed()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_GAMMA, pXForm.getModGamma()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_GAMMA_SPEED, pXForm.getModGammaSpeed()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_CONTRAST, pXForm.getModContrast()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_CONTRAST_SPEED, pXForm.getModContrastSpeed()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_SATURATION, pXForm.getModSaturation()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_SATURATION_SPEED, pXForm.getModSaturationSpeed()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_HUE, pXForm.getModHue()));
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_MOD_HUE_SPEED, pXForm.getModHueSpeed()));
    if (pXForm.getDrawMode().equals(DrawMode.OPAQUE)) {
        attrList.add(pXB.createAttr("opacity", pXForm.getOpacity()));
    } else if (pXForm.getDrawMode().equals(DrawMode.HIDDEN)) {
        attrList.add(pXB.createAttr("opacity", 0.0));
    }
    UniqueNamesMaker namesMaker = new UniqueNamesMaker();
    for (int vIdx = 0; vIdx < pXForm.getVariationCount(); vIdx++) {
        Variation v = pXForm.getVariation(vIdx);
        VariationFunc func = v.getFunc();
        String fName = namesMaker.makeUnique(func.getName());
        attrList.add(pXB.createAttr(fName, v.getAmount()));
        attrList.add(pXB.createAttr(fName + "_" + AbstractFlameReader.ATTR_FX_PRIORITY, v.getPriority()));
        // params
        {
            String[] params = func.getParameterNames();
            if (params != null) {
                Object[] vals = func.getParameterValues();
                for (int i = 0; i < params.length; i++) {
                    if (vals[i] instanceof Integer) {
                        attrList.add(pXB.createAttr((fName + "_" + params[i]), (Integer) vals[i]));
                    } else if (vals[i] instanceof Double) {
                        attrList.add(pXB.createAttr((fName + "_" + params[i]), (Double) vals[i]));
                    } else {
                        throw new IllegalStateException();
                    }
                    MotionCurve curve = v.getMotionCurve(params[i]);
                    if (curve != null) {
                        writeMotionCurve(pXB, attrList, fName + "_" + params[i], curve);
                    }
                }
            }
        }
        // curves
        List<String> blackList = Collections.emptyList();
        writeMotionCurves(v, pXB, attrList, fName + "_", blackList);
        // ressources
        {
            String[] ressNames = func.getRessourceNames();
            if (ressNames != null) {
                byte[][] vals = func.getRessourceValues();
                for (int i = 0; i < ressNames.length; i++) {
                    String hexStr = vals[i] != null && vals[i].length > 0 ? Tools.byteArrayToHexString(vals[i]) : "";
                    attrList.add(pXB.createAttr((fName + "_" + ressNames[i]), hexStr));
                }
            }
        }
    }
    attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_XY_COEFS, pXForm.getXYCoeff00() + " " + pXForm.getXYCoeff01() + " " + pXForm.getXYCoeff10() + " " + pXForm.getXYCoeff11() + " " + pXForm.getXYCoeff20() + " " + pXForm.getXYCoeff21()));
    if (pXForm.isHasXYPostCoeffs()) {
        attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_XY_POST, pXForm.getXYPostCoeff00() + " " + pXForm.getXYPostCoeff01() + " " + pXForm.getXYPostCoeff10() + " " + pXForm.getXYPostCoeff11() + " " + pXForm.getXYPostCoeff20() + " " + pXForm.getXYPostCoeff21()));
    }
    if (pXForm.isHasYZCoeffs()) {
        attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_YZ_COEFS, pXForm.getYZCoeff00() + " " + pXForm.getYZCoeff01() + " " + pXForm.getYZCoeff10() + " " + pXForm.getYZCoeff11() + " " + pXForm.getYZCoeff20() + " " + pXForm.getYZCoeff21()));
    }
    if (pXForm.isHasYZPostCoeffs()) {
        attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_YZ_POST, pXForm.getYZPostCoeff00() + " " + pXForm.getYZPostCoeff01() + " " + pXForm.getYZPostCoeff10() + " " + pXForm.getYZPostCoeff11() + " " + pXForm.getYZPostCoeff20() + " " + pXForm.getYZPostCoeff21()));
    }
    if (pXForm.isHasZXCoeffs()) {
        attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_ZX_COEFS, pXForm.getZXCoeff00() + " " + pXForm.getZXCoeff01() + " " + pXForm.getZXCoeff10() + " " + pXForm.getZXCoeff11() + " " + pXForm.getZXCoeff20() + " " + pXForm.getZXCoeff21()));
    }
    if (pXForm.isHasZXPostCoeffs()) {
        attrList.add(pXB.createAttr(AbstractFlameReader.ATTR_ZX_POST, pXForm.getZXPostCoeff00() + " " + pXForm.getZXPostCoeff01() + " " + pXForm.getZXPostCoeff10() + " " + pXForm.getZXPostCoeff11() + " " + pXForm.getZXPostCoeff20() + " " + pXForm.getZXPostCoeff21()));
    }
    {
        String hs = "";
        for (int i = 0; i < pLayer.getXForms().size() - 1; i++) {
            hs += pXForm.getModifiedWeights()[i] + " ";
        }
        hs += pXForm.getModifiedWeights()[pLayer.getXForms().size() - 1];
        attrList.add(pXB.createAttr("chaos", hs));
    }
    String xName = pXForm.getName().replaceAll("\"", "");
    if (!xName.equals("")) {
        attrList.add(pXB.createAttr("name", xName));
    }
    List<String> blackList = Collections.emptyList();
    writeMotionCurves(pXForm, pXB, attrList, null, blackList);
    return attrList;
}
Also used : MotionCurveAttribute(org.jwildfire.create.tina.animate.AnimationService.MotionCurveAttribute) ArrayList(java.util.ArrayList) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) Variation(org.jwildfire.create.tina.variation.Variation) VariationFunc(org.jwildfire.create.tina.variation.VariationFunc)

Example 15 with MotionCurve

use of org.jwildfire.create.tina.base.motion.MotionCurve in project JWildfire by thargor6.

the class LeapMotionConnectedProperty method init.

public void init(Flame pFlame) {
    outputChannel.init(this, pFlame);
    MotionCurve curve = outputChannel.getMotionCurve(this, pFlame);
    if (curve != null && curve.isEnabled()) {
        curve.setEnabled(false);
    }
}
Also used : MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve)

Aggregations

MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)26 Field (java.lang.reflect.Field)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Variation (org.jwildfire.create.tina.variation.Variation)5 VariationFunc (org.jwildfire.create.tina.variation.VariationFunc)4 MotionCurveAttribute (org.jwildfire.create.tina.animate.AnimationService.MotionCurveAttribute)3 Flame (org.jwildfire.create.tina.base.Flame)3 Envelope (org.jwildfire.envelope.Envelope)3 Map (java.util.Map)2 XMLAttributes (org.jwildfire.base.Tools.XMLAttributes)2 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)2 VariationFuncList (org.jwildfire.create.tina.variation.VariationFuncList)2 HashMap (java.util.HashMap)1 ImageIcon (javax.swing.ImageIcon)1 XMLAttribute (org.jwildfire.base.Tools.XMLAttribute)1 XForm (org.jwildfire.create.tina.base.XForm)1 DistantLight (org.jwildfire.create.tina.base.solidrender.DistantLight)1 MaterialSettings (org.jwildfire.create.tina.base.solidrender.MaterialSettings)1 SolidRenderSettings (org.jwildfire.create.tina.base.solidrender.SolidRenderSettings)1