use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class GradientController method gradientLibraryGradientChanged.
public void gradientLibraryGradientChanged() {
AbstractGradientNode selNode;
if (!cmbRefreshing && (selNode = getSelGradientNode()) != null) {
if (tinaController.getCurrFlame() != null && gradientsList.getSelectedIndex() >= 0 && gradientsList.getSelectedIndex() < selNode.getGradientLibraryList().size()) {
tinaController.saveUndoPoint();
RGBPalette palette = selNode.getGradientLibraryList().get(gradientsList.getSelectedIndex()).makeCopy();
tinaController.getCurrLayer().setPalette(palette);
tinaController.setLastGradient(palette);
tinaController.registerToEditor(tinaController.getCurrFlame(), tinaController.getCurrLayer());
tinaController.refreshPaletteUI(palette);
tinaController.refreshFlameImage(true, false, 1, true, false);
}
}
}
use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class AnimationService method _disableMotionCurves.
private static void _disableMotionCurves(Object pObject) 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()) {
curve.setEnabled(false);
}
} else if (field.getType().isAssignableFrom(ArrayList.class)) {
List<?> childs = (List<?>) field.get(pObject);
for (Object child : childs) {
_disableMotionCurves(child);
}
} else if (field.getType().isAssignableFrom(RGBPalette.class)) {
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);
}
}
}
}
use of org.jwildfire.create.tina.palette.RGBPalette 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.palette.RGBPalette in project JWildfire by thargor6.
the class FlameMorphService method morphFlames_morph.
private static Flame morphFlames_morph(Prefs pPrefs, Flame pFlame1, Flame pFlame2, int pFrame, int pFrames) {
if (pFrame < 1 || pFrames < 2)
return pFlame1;
double fScl = (double) (pFrame - 1) / (pFrames - 1);
if (fScl <= MathLib.EPSILON) {
return pFlame1;
} else if (fScl >= 1.0 - MathLib.EPSILON) {
return pFlame2;
}
Flame res = pFlame1.makeCopy();
res.getLayers().clear();
int layerSize1 = pFlame1.getLayers().size();
int layerSize2 = pFlame2.getLayers().size();
int maxLayerSize = layerSize1 > layerSize2 ? layerSize1 : layerSize2;
for (int lIdx = 0; lIdx < maxLayerSize; lIdx++) {
Layer layer = new Layer();
res.getLayers().add(layer);
// Morph layers
if (lIdx < layerSize1 && lIdx < layerSize2) {
Layer layer1 = pFlame1.getLayers().get(lIdx);
Layer layer2 = pFlame2.getLayers().get(lIdx);
layer.assign(layer1);
layer.getXForms().clear();
layer.getFinalXForms().clear();
layer.setWeight(morphValue(layer1.getWeight(), layer2.getWeight(), fScl));
// morph XForms
{
int size1 = layer1.getXForms().size();
int size2 = layer2.getXForms().size();
int maxSize = size1 > size2 ? size1 : size2;
for (int i = 0; i < maxSize; i++) {
XForm xForm1 = i < size1 ? layer1.getXForms().get(i) : null;
if (xForm1 == null) {
xForm1 = new XForm();
xForm1.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
xForm1.setWeight(0.0);
}
XForm xForm2 = i < size2 ? layer2.getXForms().get(i) : null;
if (xForm2 == null) {
xForm2 = new XForm();
xForm2.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
xForm2.setWeight(0.0);
}
XForm morphedXForm = morphXForms(pPrefs, xForm1, xForm2, fScl, pFrame, pFrames);
layer.getXForms().add(morphedXForm);
}
}
// morph final XForms
{
int size1 = layer1.getFinalXForms().size();
int size2 = layer2.getFinalXForms().size();
int maxSize = size1 > size2 ? size1 : size2;
for (int i = 0; i < maxSize; i++) {
XForm xForm1 = i < size1 ? layer1.getFinalXForms().get(i) : null;
if (xForm1 == null) {
xForm1 = new XForm();
xForm1.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
xForm1.setWeight(0.0);
}
XForm xForm2 = i < size2 ? layer2.getFinalXForms().get(i) : null;
if (xForm2 == null) {
xForm2 = new XForm();
xForm2.addVariation(0.0, VariationFuncList.getVariationFuncInstance("linear3D", true));
xForm2.setWeight(0.0);
}
XForm morphedXForm = morphXForms(pPrefs, xForm1, xForm2, fScl, pFrame, pFrames);
layer.getFinalXForms().add(morphedXForm);
}
}
// morph colors
RGBPalette palette1 = layer1.getPalette();
RGBPalette palette2 = layer2.getPalette();
for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
RGBColor color1 = palette1.getColor(i);
RGBColor color2 = palette2.getColor(i);
int red = Tools.roundColor(color1.getRed() + (color2.getRed() - color1.getRed()) * fScl);
int green = Tools.roundColor(color1.getGreen() + (color2.getGreen() - color1.getGreen()) * fScl);
int blue = Tools.roundColor(color1.getBlue() + (color2.getBlue() - color1.getBlue()) * fScl);
layer.getPalette().setColor(i, red, green, blue);
}
} else // fade out layer1 to black
if (lIdx < layerSize1) {
Layer layer1 = pFlame1.getLayers().get(lIdx);
layer.assign(layer1);
layer.setWeight(morphValue(layer1.getWeight(), 0.0, fScl));
} else // fade in layer2 from black
if (lIdx < layerSize2) {
Layer layer2 = pFlame2.getLayers().get(lIdx);
layer.assign(layer2);
layer.setWeight(morphValue(0.0, layer2.getWeight(), fScl));
}
}
// morph camera settings etc.
morphFlameValues(pFlame1, pFlame2, fScl, res);
return res;
}
use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class AnimationModelService method visitModel.
@SuppressWarnings("unchecked")
public static void visitModel(PropertyModel res, Flame pFlame, PropertyVisitor pVisitor) {
VisitState state = new VisitState(pVisitor);
Class<?> cls = pFlame.getClass();
for (Field field : cls.getDeclaredFields()) {
if (state.isCancelSignalled()) {
return;
}
field.setAccessible(true);
if (field.getAnnotation(AnimAware.class) != null) {
Class<?> fCls = field.getType();
if (isPrimitiveProperty(fCls)) {
PlainProperty property = new PlainProperty(res, field.getName(), cls);
res.getProperties().add(property);
if (pVisitor != null) {
state.updateState(pVisitor.accept(pFlame, field, property));
}
} else if (fCls == RGBPalette.class) {
try {
RGBPalette palette = (RGBPalette) field.get(pFlame);
addGradientToModel(res, palette, pVisitor, state);
} catch (Exception e) {
e.printStackTrace();
}
} else if (fCls == List.class) {
ParameterizedType listType = (ParameterizedType) field.getGenericType();
Class<?> listSubClass = (Class<?>) listType.getActualTypeArguments()[0];
if (listSubClass.isAssignableFrom(Layer.class)) {
List<Layer> layers;
try {
layers = (List<Layer>) field.get(pFlame);
} catch (Exception e) {
layers = null;
e.printStackTrace();
}
if (layers != null) {
int idx = 0;
for (Layer layer : layers) {
addLayerToModel(res, idx++, layer, pVisitor, state);
}
}
}
}
}
}
}
Aggregations