Search in sources :

Example 1 with XMLAttribute

use of org.jwildfire.base.Tools.XMLAttribute 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)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 XMLAttribute (org.jwildfire.base.Tools.XMLAttribute)1 XMLAttributes (org.jwildfire.base.Tools.XMLAttributes)1 MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)1 Variation (org.jwildfire.create.tina.variation.Variation)1 VariationFunc (org.jwildfire.create.tina.variation.VariationFunc)1 VariationFuncList (org.jwildfire.create.tina.variation.VariationFuncList)1