Search in sources :

Example 1 with Rectangle

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.

the class DrawnRectangleHighlightProceduralEffect method createProceduralFrame.

@Override
public ClipImage createProceduralFrame(GetFrameRequest request, TimelinePosition relativePosition) {
    ClipImage result = ClipImage.fromSize(request.getExpectedWidth(), request.getExpectedHeight());
    double progress;
    double endSeconds = endPositionProvider.getValueAt(relativePosition);
    double actualSeconds = relativePosition.getSeconds().doubleValue();
    if (endSeconds > actualSeconds) {
        progress = actualSeconds / endSeconds;
    } else {
        progress = 1.0;
    }
    Rectangle rectangle = rectangleProvider.getValueAt(relativePosition);
    double overshoot = overshootProvider.getValueAt(relativePosition);
    double totalLength = rectangle.getLength() * (1.0 + overshoot * 2 * 4);
    double lengthToDraw = progress * totalLength;
    int brushSize = (int) (brushSizeProvider.getValueAt(relativePosition) * request.getScale());
    if (brushSize < 1) {
        brushSize = 1;
    }
    String brushFilePath = brushFileProvider.getValueOrDefault(relativePosition, "classpath:/brushes/Sponge-02.gbr");
    Point brushHalfSize = new Point((double) brushSize / request.getExpectedWidth() / 2.0, (double) brushSize / request.getExpectedHeight() / 2.0);
    Color color = colorProvider.getValueAt(relativePosition);
    for (int i = 0; i < 4 && lengthToDraw > 0.0; ++i) {
        // 0->1, 1->2, 2->3, 3->0
        Point start = rectangle.points.get(i).subtract(brushHalfSize);
        Point end = rectangle.points.get((i + 1) % 4).subtract(brushHalfSize);
        Point overshootOffsetVector = end.subtract(start).normalize().scalarMultiply(overshoot);
        start = start.subtract(overshootOffsetVector);
        end = end.add(overshootOffsetVector);
        double distance = start.distanceFrom(end);
        double lineProgress = lengthToDraw > distance ? 1.0 : lengthToDraw / distance;
        Point startInPixels = start.multiply(request.getExpectedWidth(), request.getExpectedHeight());
        Point endInPixels = end.multiply(request.getExpectedWidth(), request.getExpectedHeight());
        DrawLineRequest drawLineRequest = DrawLineRequest.builder().withBrushFilePath(brushFilePath).withBrushSize(brushSize).withColor(color).withPixels(bresenhemPixelProvider.linePixels(startInPixels, endInPixels)).withProgress(lineProgress).withResult(result).build();
        drawLineService.drawLine(drawLineRequest);
        lengthToDraw -= distance;
    }
    return result;
}
Also used : ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) DrawLineRequest(com.helospark.tactview.core.timeline.proceduralclip.lines.impl.DrawLineRequest) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 2 with Rectangle

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.

the class RectangleProviderValueSetterChainItem method handle.

@Override
protected EffectLine handle(RectangleProvider rectangleProvider, ValueProviderDescriptor descriptor) {
    List<EffectLine> pointProviders = new ArrayList<>();
    for (int i = 0; i < 4; ++i) {
        pointProviders.add(pointProviderValueSetterChainItem.create(descriptor, rectangleProvider.getChildren().get(i)));
    }
    Button button = new Button("", new Glyph("FontAwesome", FontAwesome.Glyph.SQUARE));
    VBox vbox = new VBox();
    pointProviders.stream().forEach(a -> vbox.getChildren().add(a.visibleNode));
    HBox hbox = new HBox();
    hbox.getChildren().add(vbox);
    hbox.getChildren().add(button);
    CompositeEffectLine result = CompositeEffectLine.builder().withVisibleNode(hbox).withValues(pointProviders).withDescriptorId(rectangleProvider.getId()).withEffectParametersRepository(effectParametersRepository).withCommandInterpreter(commandInterpreter).withDescriptor(descriptor).withUpdateFromValue(value -> {
        Rectangle line = (Rectangle) value;
        for (int i = 0; i < 4; ++i) {
            pointProviders.get(i).getUpdateFromValue().accept(line.points.get(i));
        }
    }).build();
    button.setOnMouseClicked(event -> {
        if (event.getButton() == MouseButton.PRIMARY) {
            Rectangle previousValue = rectangleProvider.getValueAt(uiTimelineManager.getCurrentPosition());
            inputModeRepository.requestRectangle(rectangle -> {
                boolean revertable = this.inputModeRepository.getResultType().equals(ResultType.DONE);
                KeyframeAddedRequest keyframeRequest = KeyframeAddedRequest.builder().withDescriptorId(rectangleProvider.getId()).withGlobalTimelinePosition(uiTimelineManager.getCurrentPosition()).withValue(rectangle).withPreviousValue(Optional.ofNullable(previousValue)).withRevertable(revertable).build();
                commandInterpreter.sendWithResult(new AddKeyframeForPropertyCommand(effectParametersRepository, keyframeRequest));
            }, getCurrentValue(pointProviders), rectangleProvider.getSizeFunction());
        }
    });
    contextMenuAppender.addContextMenu(result, rectangleProvider, descriptor, button);
    return result;
}
Also used : Button(javafx.scene.control.Button) Component(com.helospark.lightdi.annotation.Component) ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) HBox(javafx.scene.layout.HBox) MouseButton(javafx.scene.input.MouseButton) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) AddKeyframeForPropertyCommand(com.helospark.tactview.ui.javafx.commands.impl.AddKeyframeForPropertyCommand) RectangleProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.RectangleProvider) EffectParametersRepository(com.helospark.tactview.core.timeline.effect.EffectParametersRepository) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) ContextMenuAppender(com.helospark.tactview.ui.javafx.uicomponents.propertyvalue.contextmenu.ContextMenuAppender) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) ArrayList(java.util.ArrayList) List(java.util.List) Glyph(org.controlsfx.glyphfont.Glyph) 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) UiTimelineManager(com.helospark.tactview.ui.javafx.UiTimelineManager) HBox(javafx.scene.layout.HBox) KeyframeAddedRequest(com.helospark.tactview.core.timeline.message.KeyframeAddedRequest) ArrayList(java.util.ArrayList) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) AddKeyframeForPropertyCommand(com.helospark.tactview.ui.javafx.commands.impl.AddKeyframeForPropertyCommand) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) Glyph(org.controlsfx.glyphfont.Glyph) VBox(javafx.scene.layout.VBox)

Example 3 with Rectangle

use of com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle in project tactview by helospark.

the class RectangleWarpEffect method createFrame.

@Override
public ReadOnlyClipImage createFrame(StatelessEffectRequest request) {
    ClipImage result = ClipImage.fromSize(request.getCanvasWidth(), request.getCanvasHeight());
    Rectangle rectangle = rectangleProvider.getValueAt(request.getEffectPosition());
    List<Point> points = rectangle.points.stream().map(a -> a.multiply(request.getCurrentFrame().getWidth(), request.getCurrentFrame().getHeight())).collect(Collectors.toList());
    SimpleVertex a = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(0).x, points.get(0).y)).withTextureCoordinates(new Vector2D(0, 0)).build();
    SimpleVertex b = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(1).x, points.get(1).y)).withTextureCoordinates(new Vector2D(1, 0)).build();
    SimpleVertex c = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(2).x, points.get(2).y)).withTextureCoordinates(new Vector2D(1, 1)).build();
    SimpleVertex d = SimpleVertex.builder().withColor(Color.of(1.0, 1.0, 1.0)).withPosition(new Vector2D(points.get(3).x, points.get(3).y)).withTextureCoordinates(new Vector2D(0, 1)).build();
    drawTriangle(request, result, a, c, b);
    drawTriangle(request, result, a, d, c);
    return result;
}
Also used : ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) ReflectionUtil(com.helospark.tactview.core.util.ReflectionUtil) StatelessVideoEffect(com.helospark.tactview.core.timeline.StatelessVideoEffect) RectangleProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.RectangleProvider) StatelessEffectRequest(com.helospark.tactview.core.timeline.effect.StatelessEffectRequest) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) Collectors(java.util.stream.Collectors) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) SimpleVertex(com.helospark.tactview.core.timeline.effect.warp.rasterizer.SimpleVertex) Simple2DRasterizer(com.helospark.tactview.core.timeline.effect.warp.rasterizer.Simple2DRasterizer) List(java.util.List) TriangleRasterizationRequest(com.helospark.tactview.core.timeline.effect.warp.rasterizer.TriangleRasterizationRequest) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) SimpleTriangle(com.helospark.tactview.core.timeline.effect.warp.rasterizer.SimpleTriangle) JsonNode(com.fasterxml.jackson.databind.JsonNode) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) SimpleVertex(com.helospark.tactview.core.timeline.effect.warp.rasterizer.SimpleVertex) Vector2D(org.apache.commons.math3.geometry.euclidean.twod.Vector2D) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) Rectangle(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Aggregations

Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)3 Rectangle (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Rectangle)3 ValueProviderDescriptor (com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor)2 Color (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color)2 RectangleProvider (com.helospark.tactview.core.timeline.effect.interpolation.provider.RectangleProvider)2 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Component (com.helospark.lightdi.annotation.Component)1 CloneRequestMetadata (com.helospark.tactview.core.clone.CloneRequestMetadata)1 LoadMetadata (com.helospark.tactview.core.save.LoadMetadata)1 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)1 StatelessVideoEffect (com.helospark.tactview.core.timeline.StatelessVideoEffect)1 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)1 EffectParametersRepository (com.helospark.tactview.core.timeline.effect.EffectParametersRepository)1 StatelessEffectRequest (com.helospark.tactview.core.timeline.effect.StatelessEffectRequest)1 Simple2DRasterizer (com.helospark.tactview.core.timeline.effect.warp.rasterizer.Simple2DRasterizer)1 SimpleTriangle (com.helospark.tactview.core.timeline.effect.warp.rasterizer.SimpleTriangle)1 SimpleVertex (com.helospark.tactview.core.timeline.effect.warp.rasterizer.SimpleVertex)1