Search in sources :

Example 6 with MotionCurve

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

the class AnimationService method _evalMotionCurves.

private static void _evalMotionCurves(Object pObject, double pFrame) throws IllegalAccessException {
    Class<?> cls = pObject.getClass();
    for (Field field : cls.getDeclaredFields()) {
        field.setAccessible(true);
        if (field.getType() == MotionCurve.class && field.getName().endsWith(Tools.CURVE_POSTFIX)) {
            MotionCurve curve = (MotionCurve) field.get(pObject);
            if (curve.isEnabled()) {
                double value = evalCurve(pFrame, curve);
                String propName = field.getName().substring(0, field.getName().length() - Tools.CURVE_POSTFIX.length());
                curve.getChangeHandler().processValueChange(pObject, propName, value);
                if (pObject instanceof RGBPalette) {
                    curve.getChangeHandler().processValueChange(pObject, "modified", 1.0);
                }
            // setPropertyValue(pObject, propName, value);
            // System.out.println(propName + " " + value);
            }
        } else if (field.getType().isAssignableFrom(ArrayList.class)) {
            List<?> childs = (List<?>) field.get(pObject);
            for (Object child : childs) {
                _evalMotionCurves(child, pFrame);
            }
        } else if (field.getType().isAssignableFrom(RGBPalette.class)) {
            RGBPalette gradient = (RGBPalette) field.get(pObject);
            _evalMotionCurves(gradient, pFrame);
        } else if (field.getType().isAssignableFrom(SolidRenderSettings.class)) {
            SolidRenderSettings settings = (SolidRenderSettings) field.get(pObject);
            _evalMotionCurves(settings, 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);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ArrayList(java.util.ArrayList) SolidRenderSettings(org.jwildfire.create.tina.base.solidrender.SolidRenderSettings) Field(java.lang.reflect.Field) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) ArrayList(java.util.ArrayList) List(java.util.List) Variation(org.jwildfire.create.tina.variation.Variation) VariationFunc(org.jwildfire.create.tina.variation.VariationFunc)

Example 7 with MotionCurve

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

the class EnvelopeDialog method findMotionCurve.

private MotionCurve findMotionCurve(Object pObject, List<String> pPath, int pPathIndex) {
    String pathName;
    String index;
    {
        String fullPathName = pPath.get(pPathIndex);
        int p1 = fullPathName.lastIndexOf("[");
        int p2 = fullPathName.indexOf("]", p1 + 1);
        if (p1 > 0 && p2 > p1) {
            pathName = fullPathName.substring(0, p1);
            index = fullPathName.substring(p1 + 1, p2);
        } else {
            pathName = fullPathName;
            index = "";
        }
    }
    if (pPath.size() > 0) {
        Class<?> cls = pObject.getClass();
        if (pPathIndex == pPath.size() - 1) {
            for (Field field : cls.getDeclaredFields()) {
                field.setAccessible(true);
                Object fieldValue;
                try {
                    fieldValue = field.get(pObject);
                } catch (Exception ex) {
                    fieldValue = null;
                }
                if (fieldValue != null && field.getName().equals(pathName)) {
                    if (fieldValue instanceof MotionCurve) {
                        return (MotionCurve) fieldValue;
                    } else if (fieldValue instanceof Map) {
                        Map<?, ?> map = (Map<?, ?>) fieldValue;
                        Object curve = map.get(index);
                        if (curve != null && curve instanceof MotionCurve) {
                            return (MotionCurve) curve;
                        }
                    }
                }
            }
        } else {
            for (Field field : cls.getDeclaredFields()) {
                field.setAccessible(true);
                Object fieldValue;
                try {
                    fieldValue = field.get(pObject);
                } catch (Exception ex) {
                    fieldValue = null;
                }
                if (fieldValue != null) {
                    if (fieldValue instanceof List && field.getName().equals(pathName) && index.length() > 0) {
                        List<?> list = (List<?>) fieldValue;
                        MotionCurve subResult = findMotionCurve(list.get(Integer.parseInt(index)), pPath, pPathIndex + 1);
                        if (subResult != null) {
                            return subResult;
                        }
                    } else if (fieldValue instanceof Map && field.getName().equals(pathName) && index.length() > 0) {
                        Map<?, ?> map = (Map<?, ?>) fieldValue;
                        MotionCurve subResult = findMotionCurve(map.get(index), pPath, pPathIndex + 1);
                        if (subResult != null) {
                            return subResult;
                        }
                    } else if (field.getName().equals(pathName)) {
                        MotionCurve subResult = findMotionCurve(fieldValue, pPath, pPathIndex + 1);
                        if (subResult != null) {
                            return subResult;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 8 with MotionCurve

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

the class EnvelopeDialog method getFlame.

@Override
public Flame getFlame() {
    if (flameToPreview != null) {
        Flame res = flameToPreview.makeCopy();
        res.setFrame(frameToPreview);
        switch(flamePreviewType) {
            case MOTION_CURVE:
                if (curveToPreviewPropertyPath != null) {
                    MotionCurve curve = getMotionCurve(res, curveToPreviewPropertyPath);
                    if (curve != null) {
                        curve.setPoints(new int[] { frameToPreview }, new double[] { curveValueToPreview });
                        curve.setInterpolation(Interpolation.LINEAR);
                        curve.setEnabled(true);
                    }
                }
                break;
            case COLOR_CURVE:
                if (curveToPreviewPropertyPath != null) {
                    MotionCurve curve = getMotionCurve(res, curveToPreviewPropertyPath);
                    if (curve != null) {
                        curve.assignFromEnvelope(ctrl.getCurrEnvelope());
                    }
                }
                break;
            default:
                // nothing to do
                break;
        }
        return res;
    }
    return null;
}
Also used : MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 9 with MotionCurve

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

the class ChannelMixerPanelDelegate method notifyChange.

private void notifyChange(int pSelectedPoint, int pX, double pY) {
    Flame flame = owner.getOwner().getCurrFlame();
    if (owner.isUseUndoManager()) {
        owner.getOwner().undoManager.saveUndoPoint(flame);
    }
    MotionCurve curve = getCurve(flame);
    curve.assignFromEnvelope(ctrl.getCurrEnvelope());
    owner.getOwner().refreshFlameImage(true, false, 1, true, true);
}
Also used : MotionCurve(org.jwildfire.create.tina.base.motion.MotionCurve) Flame(org.jwildfire.create.tina.base.Flame)

Example 10 with MotionCurve

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

the class AbstractControlsDelegate method editMotionCurve.

protected void editMotionCurve(String pPropName, String pLabel) {
    MotionCurve curve = getCurveToEdit(pPropName);
    double initialValue;
    try {
        initialValue = getInitialValue(pPropName);
    } catch (Exception ex) {
        initialValue = 0.0;
    }
    editMotionCurve(curve, initialValue, pPropName, pLabel);
}
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