use of org.jwildfire.create.tina.variation.VariationFunc 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();
}
}
}
}
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class AnimationModelService method addVariationToModel.
private static void addVariationToModel(PropertyModel pXFormNode, Variation pVariation, PropertyVisitor pVisitor, VisitState pState) {
Class<?> cls = pVariation.getClass();
PropertyModel variationNode = new PropertyModel(pXFormNode, pVariation.getFunc().getName(), cls);
pXFormNode.getChields().add(variationNode);
for (Field field : cls.getDeclaredFields()) {
if (pState.isCancelSignalled()) {
return;
}
field.setAccessible(true);
if (field.getAnnotation(AnimAware.class) != null) {
Class<?> fCls = field.getType();
if (isPrimitiveProperty(fCls)) {
PlainProperty property = new PlainProperty(variationNode, field.getName(), cls);
variationNode.getProperties().add(property);
if (pVisitor != null) {
pState.updateState(pVisitor.accept(pVariation, field, property));
}
}
}
}
VariationFunc varFunc = pVariation.getFunc();
String[] params = varFunc.getParameterNames();
Object[] vals = varFunc.getParameterValues();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (pState.isCancelSignalled()) {
return;
}
Object val = vals[i];
if (val instanceof Double) {
PlainProperty property = new PlainProperty(variationNode, params[i], Double.class);
variationNode.getProperties().add(property);
if (pVisitor != null) {
pState.updateState(pVisitor.accept(varFunc, property));
}
} else if (val instanceof Integer) {
PlainProperty property = new PlainProperty(variationNode, params[i], Integer.class);
variationNode.getProperties().add(property);
if (pVisitor != null) {
pState.updateState(pVisitor.accept(varFunc, property));
}
}
}
}
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class TinaController method refreshParamControls.
public void refreshParamControls(TinaNonlinearControlsRow pRow, XForm pXForm, Variation pVar, boolean pSelectFirst) {
if (pXForm == null || pVar == null) {
pRow.getNonlinearVarCmb().setSelectedIndex(-1);
pRow.getNonlinearVarREd().setText(null);
pRow.getNonlinearParamsCmb().setSelectedIndex(-1);
pRow.getNonlinearParamsREd().setText(null);
pRow.getNonlinearParamsLeftButton().setEnabled(false);
pRow.getNonlinearParamsPreButton().setSelected(false);
pRow.getNonlinearParamsPreButton().setEnabled(false);
pRow.getNonlinearParamsPostButton().setSelected(false);
pRow.getNonlinearParamsPostButton().setEnabled(false);
pRow.getToggleParamsPnlButton().setEnabled(false);
if (pRow.getNonlinearParamsUpButton() != null) {
pRow.getNonlinearParamsUpButton().setEnabled(false);
}
} else {
VariationFunc varFunc = pVar.getFunc();
pRow.getNonlinearParamsPreButton().setEnabled(true);
pRow.getNonlinearParamsPreButton().setSelected(pVar.getPriority() < 0 || pVar.getPriority() == 2);
pRow.getNonlinearParamsPostButton().setEnabled(true);
pRow.getNonlinearParamsPostButton().setSelected(pVar.getPriority() > 0 || pVar.getPriority() == -2);
if (pRow.getNonlinearParamsUpButton() != null) {
pRow.getNonlinearParamsUpButton().setEnabled(true);
}
pRow.getNonlinearVarCmb().setSelectedItem(varFunc.getName());
if (pRow.getNonlinearVarCmb().getSelectedIndex() < 0) {
pRow.getNonlinearVarCmb().addItem(varFunc.getName());
pRow.getNonlinearVarCmb().setSelectedItem(varFunc.getName());
pRow.getNonlinearVarLbl().getFont().getStyle();
}
if (VariationFuncList.getExcludedNameList().contains(varFunc.getName())) {
Font font = pRow.getNonlinearVarLbl().getFont();
Map attributes = font.getAttributes();
if (!attributes.containsKey(TextAttribute.STRIKETHROUGH)) {
attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
pRow.getNonlinearVarLbl().setFont(new Font(attributes));
}
} else {
Font font = pRow.getNonlinearVarLbl().getFont();
Map attributes = font.getAttributes();
if (attributes.containsKey(TextAttribute.STRIKETHROUGH)) {
attributes.remove(TextAttribute.STRIKETHROUGH);
pRow.getNonlinearVarLbl().setFont(new Font(attributes));
}
}
pRow.getNonlinearVarREd().setText(Tools.doubleToString(pVar.getAmount()));
pRow.getNonlinearParamsCmb().removeAllItems();
// ressources
int resCount = 0;
String[] resNames = varFunc.getRessourceNames();
if (resNames != null) {
for (String name : resNames) {
pRow.getNonlinearParamsCmb().addItem(name);
resCount++;
}
}
// params
String[] paramNames = varFunc.getParameterNames();
if (paramNames != null) {
for (String name : paramNames) {
pRow.getNonlinearParamsCmb().addItem(name);
}
}
if (paramNames != null && (paramNames.length > 1 || paramNames.length > 0 && resCount > 0)) {
pRow.getToggleParamsPnlButton().setEnabled(true);
} else {
pRow.getToggleParamsPnlButton().setEnabled(false);
}
// preselection
if (pSelectFirst) {
if (resCount > 0) {
pRow.getNonlinearParamsCmb().setSelectedIndex(0);
pRow.getNonlinearParamsREd().setText(null);
enableNonlinearControls(pRow, true);
} else if (varFunc.getParameterNames().length > 0) {
pRow.getNonlinearParamsCmb().setSelectedIndex(0);
Object val = varFunc.getParameterValues()[0];
pRow.getNonlinearParamsREd().setOnlyIntegers(false);
if (val instanceof Double) {
pRow.getNonlinearParamsREd().setText(Tools.doubleToString((Double) val));
} else if (val instanceof Integer) {
pRow.getNonlinearParamsREd().setOnlyIntegers(true);
pRow.getNonlinearParamsREd().setText(val.toString());
} else {
pRow.getNonlinearParamsREd().setText(val.toString());
}
enableNonlinearControls(pRow, false);
} else {
pRow.getNonlinearParamsCmb().setSelectedIndex(-1);
pRow.getNonlinearParamsREd().setText(null);
pRow.getNonlinearParamsREd().setOnlyIntegers(false);
}
}
}
pRow.rebuildParamsPnl(pXForm, pVar);
resizeNonlinearParamsPanel();
}
use of org.jwildfire.create.tina.variation.VariationFunc in project JWildfire by thargor6.
the class TinaController method nonlinearVarCmbChanged.
public void nonlinearVarCmbChanged(int pIdx) {
if (cmbRefreshing) {
return;
}
boolean oldCmbRefreshing = cmbRefreshing;
cmbRefreshing = true;
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)) {
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(fName);
var.setFunc(varFunc);
var.setPriority(varFunc.getPriority());
}
}
} else {
var = new Variation();
String varStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().getText();
if (varStr == null || varStr.length() == 0) {
varStr = "0";
}
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(fName);
var.setFunc(varFunc);
var.setPriority(varFunc.getPriority());
var.setAmount(Tools.stringToDouble(varStr));
xForm.addVariation(var);
}
refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, true);
refreshXFormUI(xForm);
refreshFlameImage(true, false, 1, true, false);
data.transformationsTable.invalidate();
data.transformationsTable.repaint();
}
} finally {
cmbRefreshing = oldCmbRefreshing;
}
}
use of org.jwildfire.create.tina.variation.VariationFunc 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 + "_");
//
}
}
}
}
Aggregations