use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.
the class SolidJulia3DRandomFlameGenerator method prepareFlame.
@Override
public Flame prepareFlame(RandomFlameGeneratorState pState) {
Flame flame = new Flame();
Layer layer = flame.getFirstLayer();
flame.setCamRoll(0);
flame.setCamPitch(90.0 - Math.random() * 180.0);
flame.setCamYaw(30.0 - Math.random() * 60.0);
flame.setCamPerspective(Math.random() * 0.2);
flame.setWidth(601);
flame.setHeight(338);
flame.setPixelsPerUnit(92.48366013);
flame.setCamZoom(0.3 + Math.random() * 0.5);
randomizeSolidRenderingSettings(flame);
layer.getFinalXForms().clear();
layer.getXForms().clear();
// create transform 1
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(0.5);
xForm.setColor(0.16556899);
xForm.setColorSymmetry(0);
xForm.setMaterial(0);
xForm.setMaterialSpeed(0);
// a
xForm.setCoeff00(1);
// b
xForm.setCoeff10(0);
// e
xForm.setCoeff20(0);
// c
xForm.setCoeff01(0);
// d
xForm.setCoeff11(1);
// f
xForm.setCoeff21(0);
xForm.setPostCoeff00(1);
xForm.setPostCoeff10(0);
xForm.setPostCoeff01(0);
xForm.setPostCoeff11(1);
xForm.setPostCoeff20(0);
xForm.setPostCoeff21(0);
// variation 1
{
xForm.addVariation(0.5 + Math.random() * 2.0, getRandom3DShape());
}
// variation 2
if (Math.random() > 0.75) {
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance("pre_wave3D_wf", true);
varFunc.setParameter("wavelen", 0.75 + Math.random() * 0.5);
varFunc.setParameter("phase", 0.5 + Math.random());
varFunc.setParameter("damping", 0.01);
Variation variation = xForm.addVariation(0.2 + Math.random() * 0.2, varFunc);
variation.setPriority(0);
}
// set default edit plane
flame.setEditPlane(EditPlane.XY);
// random affine transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, false);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), false);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), false);
// random affine post transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, true);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), true);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), true);
}
// create transform 2
{
XForm xForm = new XForm();
layer.getXForms().add(xForm);
xForm.setWeight(0.5);
xForm.setColor(0.02637356);
xForm.setColorSymmetry(0);
xForm.setMaterial(0);
xForm.setMaterialSpeed(0);
// a
xForm.setXYCoeff00(0.53041695);
// b
xForm.setXYCoeff10(-0.14810786);
// e
xForm.setXYCoeff20(2.09422612);
// c
xForm.setXYCoeff01(0.14810786);
// d
xForm.setXYCoeff11(0.53041695);
// f
xForm.setXYCoeff21(0.23893855);
xForm.setXYPostCoeff00(1);
xForm.setXYPostCoeff10(0);
xForm.setXYPostCoeff01(0);
xForm.setXYPostCoeff11(1);
xForm.setXYPostCoeff20(0);
xForm.setXYPostCoeff21(0);
xForm.setYZCoeff00(1);
xForm.setYZCoeff10(0);
xForm.setYZCoeff20(0.01405521);
xForm.setYZCoeff01(0);
xForm.setYZCoeff11(1);
xForm.setYZCoeff21(-0.01405521);
xForm.setYZPostCoeff00(1);
xForm.setYZPostCoeff10(0);
xForm.setYZPostCoeff01(0);
xForm.setYZPostCoeff11(1);
xForm.setYZPostCoeff20(0);
xForm.setYZPostCoeff21(0);
xForm.setZXCoeff00(0.74081053);
xForm.setZXCoeff10(-0.04366518);
xForm.setZXCoeff20(-0.07027604);
xForm.setZXCoeff01(0.04366518);
xForm.setZXCoeff11(0.74081053);
xForm.setZXCoeff21(-0.14055209);
xForm.setZXPostCoeff00(1);
xForm.setZXPostCoeff10(0);
xForm.setZXPostCoeff01(0);
xForm.setZXPostCoeff11(1);
xForm.setZXPostCoeff20(0);
xForm.setZXPostCoeff21(0);
// variation 1
xForm.addVariation(1, VariationFuncList.getVariationFuncInstance("linear3D", true));
// variation 2
xForm.addVariation(-0.524, VariationFuncList.getVariationFuncInstance("zscale", true));
// set default edit plane
flame.setEditPlane(EditPlane.XY);
// random affine transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, false);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), false);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), false);
// random affine post transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, true);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), true);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), true);
}
// create final transform 1
{
XForm xForm = new XForm();
layer.getFinalXForms().add(xForm);
xForm.setWeight(0);
xForm.setColor(0);
xForm.setColorSymmetry(0);
xForm.setMaterial(0);
xForm.setMaterialSpeed(0);
// a
xForm.setCoeff00(1);
// b
xForm.setCoeff10(0);
// e
xForm.setCoeff20(0);
// c
xForm.setCoeff01(0);
// d
xForm.setCoeff11(1);
// f
xForm.setCoeff21(0);
xForm.setPostCoeff00(1);
xForm.setPostCoeff10(0);
xForm.setPostCoeff01(0);
xForm.setPostCoeff11(1);
xForm.setPostCoeff20(0);
xForm.setPostCoeff21(0);
// variation 1
{
VariationFunc varFunc = VariationFuncList.getVariationFuncInstance("julia3Dq", true);
varFunc.setParameter("power", Tools.FTOI(3 + Math.random() * 4.0));
varFunc.setParameter("divisor", Math.random() > 0.5 ? 2 : 1.0 + Math.random() * 2.0);
xForm.addVariation(1, varFunc);
}
// set default edit plane
flame.setEditPlane(EditPlane.XY);
// random affine transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, false);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), false);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), false);
// random affine post transforms (uncomment to play around)
// XFormTransformService.scale(xForm, 1.25-Math.random()*0.5, true, true, true);
// XFormTransformService.rotate(xForm, 360.0*Math.random(), true);
// XFormTransformService.localTranslate(xForm, 1.0-2.0*Math.random(), 1.0-2.0*Math.random(), true);
}
return flame;
}
use of org.jwildfire.create.tina.variation.Variation 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.variation.Variation 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.Variation in project JWildfire by thargor6.
the class FlameMorphService method morphXForms.
private static XForm morphXForms(Prefs pPrefs, XForm pXForm1, XForm pXForm2, double pFScl, int pFrame, int pFrames) {
pXForm1 = pXForm1.makeCopy();
pXForm2 = pXForm2.makeCopy();
prepareMorphXForm(pXForm1);
prepareMorphXForm(pXForm2);
XForm res = new XForm();
res.setWeight(morphValue(pXForm1.getWeight(), pXForm2.getWeight(), pFScl));
res.setColor(morphValue(pXForm1.getColor(), pXForm2.getColor(), pFScl));
res.setColorSymmetry(morphValue(pXForm1.getColorSymmetry(), pXForm2.getColorSymmetry(), pFScl));
res.setMaterial(morphValue(pXForm1.getMaterial(), pXForm2.getMaterial(), pFScl));
res.setMaterialSpeed(morphValue(pXForm1.getMaterialSpeed(), pXForm2.getMaterialSpeed(), pFScl));
res.setXYCoeff00(morphValue(pXForm1.getXYCoeff00(), pXForm2.getXYCoeff00(), pFScl));
res.setXYCoeff01(morphValue(pXForm1.getXYCoeff01(), pXForm2.getXYCoeff01(), pFScl));
res.setXYCoeff10(morphValue(pXForm1.getXYCoeff10(), pXForm2.getXYCoeff10(), pFScl));
res.setXYCoeff11(morphValue(pXForm1.getXYCoeff11(), pXForm2.getXYCoeff11(), pFScl));
res.setXYCoeff20(morphValue(pXForm1.getXYCoeff20(), pXForm2.getXYCoeff20(), pFScl));
res.setXYCoeff21(morphValue(pXForm1.getXYCoeff21(), pXForm2.getXYCoeff21(), pFScl));
res.setYZCoeff00(morphValue(pXForm1.getYZCoeff00(), pXForm2.getYZCoeff00(), pFScl));
res.setYZCoeff01(morphValue(pXForm1.getYZCoeff01(), pXForm2.getYZCoeff01(), pFScl));
res.setYZCoeff10(morphValue(pXForm1.getYZCoeff10(), pXForm2.getYZCoeff10(), pFScl));
res.setYZCoeff11(morphValue(pXForm1.getYZCoeff11(), pXForm2.getYZCoeff11(), pFScl));
res.setYZCoeff20(morphValue(pXForm1.getYZCoeff20(), pXForm2.getYZCoeff20(), pFScl));
res.setYZCoeff21(morphValue(pXForm1.getYZCoeff21(), pXForm2.getYZCoeff21(), pFScl));
res.setZXCoeff00(morphValue(pXForm1.getZXCoeff00(), pXForm2.getZXCoeff00(), pFScl));
res.setZXCoeff01(morphValue(pXForm1.getZXCoeff01(), pXForm2.getZXCoeff01(), pFScl));
res.setZXCoeff10(morphValue(pXForm1.getZXCoeff10(), pXForm2.getZXCoeff10(), pFScl));
res.setZXCoeff11(morphValue(pXForm1.getZXCoeff11(), pXForm2.getZXCoeff11(), pFScl));
res.setZXCoeff20(morphValue(pXForm1.getZXCoeff20(), pXForm2.getZXCoeff20(), pFScl));
res.setZXCoeff21(morphValue(pXForm1.getZXCoeff21(), pXForm2.getZXCoeff21(), pFScl));
res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
res.setXYPostCoeff00(morphValue(pXForm1.getXYPostCoeff00(), pXForm2.getXYPostCoeff00(), pFScl));
res.setXYPostCoeff01(morphValue(pXForm1.getXYPostCoeff01(), pXForm2.getXYPostCoeff01(), pFScl));
res.setXYPostCoeff10(morphValue(pXForm1.getXYPostCoeff10(), pXForm2.getXYPostCoeff10(), pFScl));
res.setXYPostCoeff11(morphValue(pXForm1.getXYPostCoeff11(), pXForm2.getXYPostCoeff11(), pFScl));
res.setXYPostCoeff20(morphValue(pXForm1.getXYPostCoeff20(), pXForm2.getXYPostCoeff20(), pFScl));
res.setXYPostCoeff21(morphValue(pXForm1.getXYPostCoeff21(), pXForm2.getXYPostCoeff21(), pFScl));
res.setYZPostCoeff00(morphValue(pXForm1.getYZPostCoeff00(), pXForm2.getYZPostCoeff00(), pFScl));
res.setYZPostCoeff01(morphValue(pXForm1.getYZPostCoeff01(), pXForm2.getYZPostCoeff01(), pFScl));
res.setYZPostCoeff10(morphValue(pXForm1.getYZPostCoeff10(), pXForm2.getYZPostCoeff10(), pFScl));
res.setYZPostCoeff11(morphValue(pXForm1.getYZPostCoeff11(), pXForm2.getYZPostCoeff11(), pFScl));
res.setYZPostCoeff20(morphValue(pXForm1.getYZPostCoeff20(), pXForm2.getYZPostCoeff20(), pFScl));
res.setYZPostCoeff21(morphValue(pXForm1.getYZPostCoeff21(), pXForm2.getYZPostCoeff21(), pFScl));
res.setZXPostCoeff00(morphValue(pXForm1.getZXPostCoeff00(), pXForm2.getZXPostCoeff00(), pFScl));
res.setZXPostCoeff01(morphValue(pXForm1.getZXPostCoeff01(), pXForm2.getZXPostCoeff01(), pFScl));
res.setZXPostCoeff10(morphValue(pXForm1.getZXPostCoeff10(), pXForm2.getZXPostCoeff10(), pFScl));
res.setZXPostCoeff11(morphValue(pXForm1.getZXPostCoeff11(), pXForm2.getZXPostCoeff11(), pFScl));
res.setZXPostCoeff20(morphValue(pXForm1.getZXPostCoeff20(), pXForm2.getZXPostCoeff20(), pFScl));
res.setZXPostCoeff21(morphValue(pXForm1.getZXPostCoeff21(), pXForm2.getZXPostCoeff21(), pFScl));
res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
res.setDrawMode(pFScl >= 0.5 ? pXForm2.getDrawMode() : pXForm1.getDrawMode());
for (int i = 0; i < pXForm1.getModifiedWeights().length; i++) {
res.getModifiedWeights()[i] = morphValue(pXForm1.getModifiedWeights()[i], pXForm2.getModifiedWeights()[i], pFScl);
}
res.clearVariations();
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();
}
}
}
}
}
return res;
}
use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.
the class TinaController method nonlinearParamsPriorityChanged.
public void nonlinearParamsPriorityChanged(int pIdx, int pPriority) {
if (cmbRefreshing) {
return;
}
cmbRefreshing = true;
try {
XForm xForm = getCurrXForm();
if (xForm != null) {
saveUndoPoint();
if (pIdx < xForm.getVariationCount()) {
final Variation var = xForm.getVariation(pIdx);
var.setPriority(pPriority);
if (pPriority == 0 || pPriority == 1) {
data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsPreButton().setSelected(false);
}
if (pPriority == 0 || pPriority == -1) {
data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsPostButton().setSelected(false);
}
refreshFlameImage(true, false, 1, true, false);
}
}
} finally {
cmbRefreshing = false;
}
}
Aggregations