Search in sources :

Example 1 with BezierPolygon

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);
    }
}
Also used : ArrayList(java.util.ArrayList) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 2 with BezierPolygon

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);
    }
}
Also used : Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) BezierPolygonPoint(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)

Example 3 with BezierPolygon

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;
}
Also used : Button(javafx.scene.control.Button) Component(com.helospark.lightdi.annotation.Component) ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) MouseButton(javafx.scene.input.MouseButton) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AddKeyframeForPropertyCommand(com.helospark.tactview.ui.javafx.commands.impl.AddKeyframeForPropertyCommand) EffectParametersRepository(com.helospark.tactview.core.timeline.effect.EffectParametersRepository) Glyph(org.controlsfx.glyphfont.Glyph) BezierPolygonProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.BezierPolygonProvider) KeyframeAddedRequest(com.helospark.tactview.core.timeline.message.KeyframeAddedRequest) InputModeRepository(com.helospark.tactview.ui.javafx.inputmode.InputModeRepository) ResultType(com.helospark.tactview.ui.javafx.inputmode.strategy.ResultType) Optional(java.util.Optional) FontAwesome(org.controlsfx.glyphfont.FontAwesome) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) UiTimelineManager(com.helospark.tactview.ui.javafx.UiTimelineManager) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) KeyframeAddedRequest(com.helospark.tactview.core.timeline.message.KeyframeAddedRequest) Glyph(org.controlsfx.glyphfont.Glyph) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) AddKeyframeForPropertyCommand(com.helospark.tactview.ui.javafx.commands.impl.AddKeyframeForPropertyCommand)

Example 4 with BezierPolygon

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;
}
Also used : BezierPolygonRenderServiceRequest(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonRenderServiceRequest) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 5 with BezierPolygon

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;
    }
}
Also used : BezierPolygonRenderServiceRequest(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonRenderServiceRequest) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) BezierPolygon(com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Aggregations

BezierPolygon (com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygon)5 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)2 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)2 BezierPolygonPoint (com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint)2 BezierPolygonRenderServiceRequest (com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonRenderServiceRequest)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Component (com.helospark.lightdi.annotation.Component)1 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)1 EffectParametersRepository (com.helospark.tactview.core.timeline.effect.EffectParametersRepository)1 ValueProviderDescriptor (com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor)1 Color (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)1 BezierPolygonProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.BezierPolygonProvider)1 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)1 KeyframeAddedRequest (com.helospark.tactview.core.timeline.message.KeyframeAddedRequest)1 UiCommandInterpreterService (com.helospark.tactview.ui.javafx.UiCommandInterpreterService)1 UiTimelineManager (com.helospark.tactview.ui.javafx.UiTimelineManager)1 AddKeyframeForPropertyCommand (com.helospark.tactview.ui.javafx.commands.impl.AddKeyframeForPropertyCommand)1 InputModeRepository (com.helospark.tactview.ui.javafx.inputmode.InputModeRepository)1 ResultType (com.helospark.tactview.ui.javafx.inputmode.strategy.ResultType)1