use of org.jwildfire.create.tina.dance.DancingFlame in project JWildfire by thargor6.
the class PostRecordFlameGenerator method createRecordedFlameFiles.
public void createRecordedFlameFiles(String pAbsolutePath) throws Exception {
if (recorder.getRecordedActions().size() >= 2) {
List<Flame> flames = new ArrayList<Flame>();
int actionIdx = 0;
StartAction startAction = (StartAction) recorder.getRecordedActions().get(actionIdx++);
DancingFlameStack flameStack = new DancingFlameStack(prefs);
flameStack.addFlame(startAction.getFlame(), 0, project.getMotions(startAction.getFlame()));
RecordedAction nextAction = recorder.getRecordedActions().get(actionIdx++);
long timeRenderStarted = System.currentTimeMillis();
long nextFrame = (long) (timeRenderStarted + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
while (true) {
long time = System.currentTimeMillis();
while (time < nextFrame) {
try {
Thread.sleep(1);
} catch (Exception ex) {
ex.printStackTrace();
}
time = System.currentTimeMillis();
}
nextFrame = (long) (time + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
DancingFlame dancingFlame = flameStack.getFlame();
Flame renderFlame;
long currTime = time - timeRenderStarted;
short[] currFFT;
if (fftData == null) {
// t.createTransformedFlame() --> motion.computeValue() handles null currFFT values
// if _using_ fftMotion, currFFT == null will result in no change from base offset
// if _not_using_ fftMotion, currFFT is ignored
currFFT = null;
} else {
currFFT = fftData.getDataByTimeOffset(currTime);
}
Flame transformedFlame = transformer.createTransformedFlame(dancingFlame, currFFT, currTime, thread.getFramesPerSecond());
renderFlame = new FlamePreparer(prefs).createRenderFlame(transformedFlame);
flames.add(renderFlame);
if (time >= timeRenderStarted + nextAction.getTime()) {
if (nextAction instanceof StopAction) {
break;
} else if (nextAction instanceof FlameChangeAction) {
Flame nextFlame = ((FlameChangeAction) nextAction).getFlame();
flameStack.addFlame(nextFlame, ((FlameChangeAction) nextAction).getMorphFrameCount(), project.getMotions(nextFlame));
nextAction = recorder.getRecordedActions().get(actionIdx++);
} else {
throw new Exception("Unknown action type <" + nextAction.getClass() + ">");
}
}
}
if (flames.size() > 0) {
File file = new File(pAbsolutePath);
String fn = file.getName();
{
int p = fn.indexOf(".flame");
if (p > 0 && p == fn.length() - 6) {
fn = fn.substring(0, p);
}
}
int fileIdx = 1;
for (Flame flame : flames) {
String hs = String.valueOf(fileIdx++);
while (hs.length() < 5) {
hs = "0" + hs;
}
new FlameWriter().writeFlame(flame, new File(file.getParent(), fn + hs + ".flame").getAbsolutePath());
}
} else {
throw new Exception("No flame files where created");
}
} else {
throw new Exception("No valid recording");
}
}
use of org.jwildfire.create.tina.dance.DancingFlame in project JWildfire by thargor6.
the class DanceFlameTransformer method createTransformedFlame.
public Flame createTransformedFlame(DancingFlame pFlame, short[] pFFTData, long pTime, int pFPS) {
Flame res = pFlame.getFlame().makeCopy();
List<Motion> motions = project.getMotions(res);
Flame refFlame = res.makeCopy();
for (FlamePreprocessor preprocessor : project.getPreprocessors()) {
if (preprocessor.isActive(pTime, pFPS)) {
res = preprocessor.preprocessFlame(project, res).makeCopy();
if (preprocessor instanceof FlameMotionPreprocessor) {
motions = ((FlameMotionPreprocessor) preprocessor).preprocessMotions(project, motions);
refFlame = res.makeCopy();
}
}
}
for (Motion motion : motions) {
if (motion.getParent() == null && motion.isActive(pTime, pFPS)) {
double value = 0.0;
int iter = 0;
Motion currMotion = motion;
while (currMotion != null) {
value += currMotion.computeValue(pFFTData, pTime, pFPS);
Motion refMotion = currMotion;
currMotion = null;
for (Motion nextMotion : motions) {
if (nextMotion.isActive(pTime, pFPS) && nextMotion.getParent() == refMotion) {
currMotion = nextMotion;
break;
}
}
iter++;
if (iter > 100) {
throw new RuntimeException("Probably endless loop detected");
}
}
for (MotionLink link : motion.getMotionLinks()) {
if (link.getProperyPath().getFlame().isEqual(refFlame)) {
AnimationModelService.setFlameProperty(res, link.getProperyPath(), value);
}
}
}
}
return res;
}
Aggregations