Package org.jwildfire.create.tina.variation

Examples of org.jwildfire.create.tina.variation.Variation


            hasVariation = variationNameList.indexOf(varName) >= 0;
          }
        }
        if (hasVariation) {
          VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(varName);
          Variation variation = pXForm.addVariation(Double.parseDouble(atts.get(rawName)), varFunc);
          // 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));
                }
                // altNames can only be come from flames which were not created by JWF, so no need to handle index here
                else 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 + "_");
          // ressources
          {
            String ressNames[] = variation.getFunc().getRessourceNames();
            if (ressNames != null) {
              for (String pName : ressNames) {
                String pHs;
                if ((pHs = atts.get(name + "_" + pName)) != null) {
                  variation.getFunc().setRessource(pName, Tools.hexStringToByteArray(pHs));
                }
              }
            }
          }
          //
View Full Code Here


        RGBPalette gradient = (RGBPalette) field.get(pObject);
        _evalMotionCurves(gradient, pFrame);
      }
    }
    if (pObject instanceof Variation) {
      Variation var = (Variation) pObject;
      VariationFunc func = var.getFunc();
      for (String name : func.getParameterNames()) {
        MotionCurve curve = var.getMotionCurve(name);
        if (curve != null && curve.isEnabled()) {
          double value = evalCurve(pFrame, curve);
          try {
            func.setParameter(name, value);
          }
View Full Code Here

        RGBPalette gradient = (RGBPalette) field.get(pObject);
        _disableMotionCurves(gradient);
      }
    }
    if (pObject instanceof Variation) {
      Variation var = (Variation) pObject;
      VariationFunc func = var.getFunc();
      for (String name : func.getParameterNames()) {
        MotionCurve curve = var.getMotionCurve(name);
        if (curve != null && curve.isEnabled()) {
          curve.setEnabled(false);
        }
      }
    }
View Full Code Here

    }
    attrList.add(pXB.createAttr("symmetry", pXForm.getColorSymmetry()));

    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()));
      // 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);
            }
          }
        }
View Full Code Here

    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();
            }
View Full Code Here

      flame.setCamPerspective(0.05 + Math.random() * 0.2);

      flame.setCamDOFArea(0.2 + Math.random() * 0.5);

      for (Layer layer : flame.getLayers()) {
        Variation crackle = null;
        for (XForm xform : layer.getXForms()) {
          for (int i = xform.getVariationCount() - 1; i >= 0; i--) {
            Variation var = xform.getVariation(i);
            if (var.getFunc().getName().equals(CrackleFunc.VAR_NAME)) {
              VariationFunc varFunc = var.getFunc();
              double scale = (Double) varFunc.getParameter(CrackleFunc.PARAM_SCALE);
              if (MathLib.fabs(scale) < MathLib.EPSILON) {
                crackle = var;
                xform.setColor(Math.random());
                break;
View Full Code Here

          if (pXForm == null || idx >= pXForm.getVariationCount()) {
            refreshParamCmb(row, null, null);
            row.getNonlinearParamsLeftButton().setEnabled(false);
          }
          else {
            Variation var = pXForm.getVariation(idx);
            refreshParamCmb(row, pXForm, var);
          }
          idx++;
        }
      }
View Full Code Here

    try {
      XForm xForm = getCurrXForm();
      if (xForm != null) {
        saveUndoPoint();
        String fName = (String) data.TinaNonlinearControlsRows[pIdx].getNonlinearVarCmb().getSelectedItem();
        Variation var;
        if (pIdx < xForm.getVariationCount()) {
          var = xForm.getVariation(pIdx);
          if (fName == null || fName.length() == 0) {
            xForm.removeVariation(var);
          }
          else {
            if (var.getFunc() == null || !var.getFunc().getName().equals(fName)) {
              var.setFunc(VariationFuncList.getVariationFuncInstance(fName));
            }
          }
        }
        else {
          var = new Variation();
          String varStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().getText();
          if (varStr == null || varStr.length() == 0) {
            varStr = "0";
          }
          var.setFunc(VariationFuncList.getVariationFuncInstance(fName));
          var.setAmount(Tools.stringToDouble(varStr));
          xForm.addVariation(var);
        }
        refreshParamCmb(data.TinaNonlinearControlsRows[pIdx], xForm, var);
        refreshXFormUI(xForm);
        //        String selected = (String) TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().getSelectedItem();
View Full Code Here

    cmbRefreshing = true;
    try {
      XForm xForm = getCurrXForm();
      if (xForm != null) {
        if (pIdx < xForm.getVariationCount()) {
          Variation var = xForm.getVariation(pIdx);
          String varStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().getText();
          if (varStr == null || varStr.length() == 0) {
            varStr = "0";
          }
          var.setAmount(Tools.stringToDouble(varStr) + pDelta);
          data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().setText(Tools.doubleToString(var.getAmount()));
          refreshFlameImage(false);
        }
      }
    }
    finally {
View Full Code Here

      String selected = (String) data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().getSelectedItem();
      XForm xForm = getCurrXForm();
      if (xForm != null && selected != null && selected.length() > 0) {
        saveUndoPoint();
        if (pIdx < xForm.getVariationCount()) {
          final Variation var = xForm.getVariation(pIdx);
          int idx;
          if ((idx = var.getFunc().getParameterIndex(selected)) >= 0) {
            String valStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().getText();
            if (valStr == null || valStr.length() == 0) {
              valStr = "0";
            }
            // round the delta to whole numbers if the parameter is of type integer
            if (Math.abs(pDelta) > MathLib.EPSILON) {
              Object val = var.getFunc().getParameterValues()[idx];
              if (val != null && val instanceof Integer) {
                if (Math.abs(pDelta) < 1.0) {
                  pDelta = pDelta < 0 ? -1 : 1;
                }
                else {
                  pDelta = Math.round(pDelta);
                }
              }
            }

            double val = Tools.stringToDouble(valStr) + pDelta;
            var.getFunc().setParameter(selected, val);
            data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().setText(Tools.doubleToString(val));
          }
          else if ((idx = var.getFunc().getRessourceIndex(selected)) >= 0) {
            final String rName = var.getFunc().getRessourceNames()[idx];
            RessourceType resType = var.getFunc().getRessourceType(rName);
            switch (resType) {
              case FONT_NAME: {
                String oldFontname = null;
                {
                  byte val[] = var.getFunc().getRessourceValues()[idx];
                  if (val != null) {
                    oldFontname = new String(val);
                  }
                }
                Font oldFont = new Font(oldFontname != null ? oldFontname : "Arial", Font.PLAIN, 24);
                Font selectedFont = JFontChooser.showDialog(centerPanel, "Choose font", oldFont);
                if (selectedFont != null) {
                  String valStr = selectedFont.getFontName();
                  byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                  var.getFunc().setRessource(rName, valByteArray);
                }
              }
                break;
              case IMAGE_FILENAME: {
                String oldFilename = null;
                {
                  byte val[] = var.getFunc().getRessourceValues()[idx];
                  if (val != null) {
                    oldFilename = new String(val);
                  }
                }
                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                if (oldFilename != null && oldFilename.length() > 0) {
                  try {
                    chooser.setCurrentDirectory(new File(oldFilename).getAbsoluteFile().getParentFile());
                    chooser.setSelectedFile(new File(oldFilename));
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
                }
                else {
                  if (prefs.getInputImagePath() != null) {
                    try {
                      chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                    }
                    catch (Exception ex) {
                      ex.printStackTrace();
                    }
                  }
                }
                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                  File file = chooser.getSelectedFile();
                  String valStr = file.getAbsolutePath();
                  byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                  var.getFunc().setRessource(rName, valByteArray);
                }
              }
                break;

              case IMAGE_FILE: {
                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                if (prefs.getInputImagePath() != null) {
                  try {
                    chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
                }
                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                  try {
                    File file = chooser.getSelectedFile();
                    byte[] imgData = Tools.readFile(file.getAbsolutePath());
                    var.getFunc().setRessource(rName, imgData);
                  }
                  catch (Exception ex) {
                    errorHandler.handleError(ex);
                  }
                }
              }
                break;
              case SVG_FILE: {
                JFileChooser chooser = new SvgFileChooser(prefs);
                if (prefs.getTinaSVGPath() != null) {
                  try {
                    chooser.setCurrentDirectory(new File(prefs.getTinaSVGPath()));
                  }
                  catch (Exception ex) {
                    ex.printStackTrace();
                  }
                }
                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                  try {
                    File file = chooser.getSelectedFile();
                    String svg = Tools.readUTF8Textfile(file.getAbsolutePath());
                    byte[] valByteArray = svg != null ? svg.getBytes() : null;
                    var.getFunc().setRessource(rName, valByteArray);
                  }
                  catch (Exception ex) {
                    errorHandler.handleError(ex);
                  }
                }
              }
                break;
              default: {
                final RessourceDialog dlg = new RessourceDialog(SwingUtilities.getWindowAncestor(centerPanel), prefs, errorHandler);
                dlg.setRessourceName(rName);
                byte val[] = var.getFunc().getRessourceValues()[idx];
                if (val != null) {
                  dlg.setRessourceValue(new String(val));
                }
                dlg.addValidation(new RessourceValidation() {
                  @Override
                  public void validate() {
                    String valStr = dlg.getRessourceValue();
                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                    byte[] oldValue = var.getFunc().getRessource(rName);
                    try {
                      var.getFunc().setRessource(rName, valByteArray);
                      var.getFunc().validate();
                    }
                    catch (Throwable ex) {
                      var.getFunc().setRessource(rName, oldValue);
                      throw new RuntimeException(ex);
                    }
                  }
                });

                dlg.setModal(true);
                dlg.setVisible(true);

                if (dlg.isConfirmed()) {
                  try {
                    String valStr = dlg.getRessourceValue();
                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                    var.getFunc().setRessource(rName, valByteArray);
                  }
                  catch (Throwable ex) {
                    errorHandler.handleError(ex);
                  }
                }
View Full Code Here

TOP

Related Classes of org.jwildfire.create.tina.variation.Variation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.