use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon in project tactview by helospark.
the class BezierPolygonProvider method doInterpolate.
private BezierPolygon doInterpolate(Entry<TimelinePosition, List<BezierPolygonPoint>> previousEntry, Entry<TimelinePosition, List<BezierPolygonPoint>> nextEntry, TimelinePosition currentPosition) {
List<BezierPolygonPoint> lastPoints = previousEntry.getValue();
List<BezierPolygonPoint> nextPoints = nextEntry.getValue();
if (lastPoints.size() != nextPoints.size()) {
// we cannot interpolate a polygon with changing sides
return new BezierPolygon(lastPoints);
} else {
List<BezierPolygonPoint> newPoints = new ArrayList<>();
for (int i = 0; i < lastPoints.size(); ++i) {
BezierPolygonPoint point1 = lastPoints.get(i);
BezierPolygonPoint point2 = nextPoints.get(i);
double xCoordinate = interpolateAxis(previousEntry, nextEntry, currentPosition, new double[] { point1.getX(), point2.getX() });
double yCoordinate = interpolateAxis(previousEntry, nextEntry, currentPosition, new double[] { point1.getY(), point2.getY() });
newPoints.add(new BezierPolygonPoint(xCoordinate, yCoordinate, point1.getType()));
}
return new BezierPolygon(newPoints);
}
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon in project tactview by helospark.
the class BezierPolygonProvider method getValueAt.
@Override
public BezierPolygon getValueAt(TimelinePosition position) {
Entry<TimelinePosition, List<BezierPolygonPoint>> lastEntry = values.lastEntry();
Entry<TimelinePosition, List<BezierPolygonPoint>> firstEntry = values.firstEntry();
if (values.isEmpty() || !useKeyframes) {
return new BezierPolygon(defaultValues);
} else if (values.size() == 1) {
return new BezierPolygon(values.firstEntry().getValue());
} else if (position.isGreaterThan(lastEntry.getKey())) {
return new BezierPolygon(lastEntry.getValue());
} else if (position.isLessThan(firstEntry.getKey())) {
return new BezierPolygon(firstEntry.getValue());
} else {
Entry<TimelinePosition, List<BezierPolygonPoint>> previousEntry = values.floorEntry(position);
Entry<TimelinePosition, List<BezierPolygonPoint>> nextEntry = values.ceilingEntry(position);
if (previousEntry.getKey().getSeconds().doubleValue() >= nextEntry.getKey().getSeconds().doubleValue()) {
return new BezierPolygon(previousEntry.getValue());
}
return doInterpolate(previousEntry, nextEntry, position);
}
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon in project tactview by helospark.
the class BezierPolygonSetterChainItem method handle.
@Override
protected EffectLine handle(BezierPolygonProvider polygonProvider, ValueProviderDescriptor descriptor) {
Button button = new Button("", new Glyph("FontAwesome", FontAwesome.Glyph.DIAMOND));
PrimitiveEffectLine result = PrimitiveEffectLine.builder().withCurrentValueProvider(() -> effectParametersRepository.getValueAtAsObject(polygonProvider.getId(), uiTimelineManager.getCurrentPosition())).withVisibleNode(button).withDescriptorId(polygonProvider.getId()).withEffectParametersRepository(effectParametersRepository).withCommandInterpreter(commandInterpreter).withDescriptor(descriptor).withUpdateFunction(position -> {
// TODO
}).withUpdateFromValue(value -> {
// TODO
}).build();
button.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY) {
BezierPolygon currentPolygon = (BezierPolygon) effectParametersRepository.getValueAtAsObject(polygonProvider.getId(), uiTimelineManager.getCurrentPosition());
if (currentPolygon.getPoints().isEmpty()) {
inputModeRepository.requestBezierPolygon(polygon -> {
boolean revertable = this.inputModeRepository.getResultType().equals(ResultType.DONE);
KeyframeAddedRequest keyframeRequest = KeyframeAddedRequest.builder().withDescriptorId(polygonProvider.getId()).withGlobalTimelinePosition(uiTimelineManager.getCurrentPosition()).withValue(polygon).withRevertable(revertable).withPreviousValue(Optional.of(currentPolygon)).build();
commandInterpreter.sendWithResult(new AddKeyframeForPropertyCommand(effectParametersRepository, keyframeRequest));
}, polygonProvider.getSizeFunction());
} else {
inputModeRepository.requestBezierPolygonPrefilled(polygon -> {
KeyframeAddedRequest keyframeRequest = KeyframeAddedRequest.builder().withDescriptorId(polygonProvider.getId()).withGlobalTimelinePosition(uiTimelineManager.getCurrentPosition()).withValue(polygon).withRevertable(true).build();
commandInterpreter.sendWithResult(new AddKeyframeForPropertyCommand(effectParametersRepository, keyframeRequest));
}, polygonProvider.getSizeFunction(), currentPolygon.getPoints());
}
}
});
return result;
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon in project tactview by helospark.
the class BezierPolygonProceduralClip method createProceduralFrame.
@Override
public ReadOnlyClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
int fuzzyEdge = (int) (fuzzyEdgeProvider.getValueAt(relativePosition) * request.getExpectedWidth());
BezierPolygon polygon = polygonProvider.getValueAt(relativePosition).multiplyPoints(new Point(request.getExpectedWidth(), request.getExpectedHeight()));
Color color = colorProvider.getValueAt(relativePosition);
if (polygon.getPoints().size() <= 2) {
return ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
}
BezierPolygonRenderServiceRequest serviceRequest = BezierPolygonRenderServiceRequest.builder().withColor(color).withExpectedHeight(request.getExpectedHeight()).withExpectedWidth(request.getExpectedWidth()).withFuzzyEdge(fuzzyEdge).withPolygon(polygon).build();
ReadOnlyClipImage result = polygonRenderService.drawBezierPolygon(serviceRequest);
return result;
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon in project tactview by helospark.
the class BezierMaskEffect method createFrame.
@Override
public ReadOnlyClipImage createFrame(StatelessEffectRequest request) {
int fuzzyEdge = (int) (fuzzyProvider.getValueAt(request.getEffectPosition()) * request.getCurrentFrame().getWidth());
BezierPolygon polygon = polygonProvider.getValueAt(request.getEffectPosition()).multiplyPoints(new Point(request.getCurrentFrame().getWidth(), request.getCurrentFrame().getHeight()));
boolean invert = invertProvider.getValueAt(request.getEffectPosition());
boolean layerMaskEnabled = layerMaskEnabledProvider.getValueAt(request.getEffectPosition());
if (polygon.getPoints().size() > 2 && layerMaskEnabled) {
BezierPolygonRenderServiceRequest polygonDrawerServiceRequest = BezierPolygonRenderServiceRequest.builder().withColor(Color.of(1.0, 1.0, 1.0)).withExpectedWidth(request.getCurrentFrame().getWidth()).withExpectedHeight(request.getCurrentFrame().getHeight()).withFuzzyEdge(fuzzyEdge).withPolygon(polygon).build();
ReadOnlyClipImage layerMask = bezierPolygonRenderService.drawBezierPolygon(polygonDrawerServiceRequest);
LayerMaskApplyRequest layerMaskApplyRequest = LayerMaskApplyRequest.builder().withCalculator(layerMaskAlphaToAlpha).withCurrentFrame(request.getCurrentFrame()).withInvert(invert).withMask(layerMask).withScaleLayerMask(false).build();
ClipImage result = layerMaskApplier.createNewImageWithLayerMask(layerMaskApplyRequest);
GlobalMemoryManagerAccessor.memoryManager.returnBuffer(layerMask.getBuffer());
return result;
} else {
ClipImage result = ClipImage.sameSizeAs(request.getCurrentFrame());
result.copyFrom(request.getCurrentFrame());
return result;
}
}
Aggregations