Search in sources :

Example 1 with TimelinePosition

use of com.helospark.tactview.core.timeline.TimelinePosition in project tactview by helospark.

the class NoiseProceduralClip method getDescriptorsInternal.

@Override
public List<ValueProviderDescriptor> getDescriptorsInternal() {
    List<ValueProviderDescriptor> descriptors = super.getDescriptorsInternal();
    ValueProviderDescriptor fractalTypeDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(fractalKindProvider).withName("type").build();
    ValueProviderDescriptor seedDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(seedProvider).withName("seed").withRenderHints(Map.of(RenderTypeHint.TYPE, SliderValueType.INPUT_FIELD)).build();
    ValueProviderDescriptor xOffsetDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(xOffsetProvider).withName("X offset").build();
    ValueProviderDescriptor yOffsetDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(yOffsetProvider).withName("Y offset").build();
    ValueProviderDescriptor frequencyDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(frequencyProvider).withName("frequency").build();
    ValueProviderDescriptor colorProviderDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(colorProvider).withName("color").build();
    Function<TimelinePosition, Boolean> enabledIfCellular = globalPosition -> fractalKindProvider.getValueAt(globalPosition).getId().equals("cellular");
    ValueProviderDescriptor cellularReturnTypeDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(cellularReturnTypeProvider).withName("cell ReturnType").withEnabledIf(enabledIfCellular).build();
    ValueProviderDescriptor cellularDistanceDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(cellularDistanceFunctionProvider).withName("cell distance").withEnabledIf(enabledIfCellular).build();
    Function<TimelinePosition, Boolean> enabledIfFractal = globalPosition -> fractalKindProvider.getValueAt(globalPosition).getId().contains("Fractal");
    ValueProviderDescriptor octaveDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(octaveProvider).withName("fractal octave").withEnabledIf(enabledIfFractal).build();
    ValueProviderDescriptor octaveCombinerDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(fractalOctaveCombinderProvider).withName("fractal octaveCombiner").withEnabledIf(enabledIfFractal).build();
    ValueProviderDescriptor lacunarityDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(lacunarityProvider).withName("fractal lacunarity").withEnabledIf(enabledIfFractal).build();
    ValueProviderDescriptor gainDescriptor = ValueProviderDescriptor.builder().withKeyframeableEffect(gainProvider).withName("fractal gain").withEnabledIf(enabledIfFractal).build();
    descriptors.add(fractalTypeDescriptor);
    descriptors.add(seedDescriptor);
    descriptors.add(xOffsetDescriptor);
    descriptors.add(yOffsetDescriptor);
    descriptors.add(colorProviderDescriptor);
    descriptors.add(frequencyDescriptor);
    descriptors.add(cellularReturnTypeDescriptor);
    descriptors.add(cellularDistanceDescriptor);
    descriptors.add(octaveDescriptor);
    descriptors.add(octaveCombinerDescriptor);
    descriptors.add(lacunarityDescriptor);
    descriptors.add(gainDescriptor);
    return descriptors;
}
Also used : Arrays(java.util.Arrays) Random(java.util.Random) CellularReturnType(me.jordanpeck.FastNoise.CellularReturnType) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) Function(java.util.function.Function) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) RenderTypeHint(com.helospark.tactview.core.timeline.effect.interpolation.hint.RenderTypeHint) ColorProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.ColorProvider) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) ValueListProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.ValueListProvider) IntegerProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.IntegerProvider) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) IndependentPixelOperation(com.helospark.tactview.core.util.IndependentPixelOperation) FastNoise(me.jordanpeck.FastNoise) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) StepStringInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.StepStringInterpolator) ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) DoubleProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.DoubleProvider) ReflectionUtil(com.helospark.tactview.core.util.ReflectionUtil) ImageMetadata(com.helospark.tactview.core.decoder.ImageMetadata) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) GetFrameRequest(com.helospark.tactview.core.timeline.GetFrameRequest) MultiKeyframeBasedDoubleInterpolator(com.helospark.tactview.core.timeline.effect.interpolation.interpolator.MultiKeyframeBasedDoubleInterpolator) Collectors(java.util.stream.Collectors) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) List(java.util.List) ValueListElement(com.helospark.tactview.core.timeline.effect.interpolation.provider.ValueListElement) SliderValueType(com.helospark.tactview.core.timeline.effect.interpolation.hint.SliderValueType) CellularDistanceFunction(me.jordanpeck.FastNoise.CellularDistanceFunction) Color(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Color) ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) FractalType(me.jordanpeck.FastNoise.FractalType) ValueProviderDescriptor(com.helospark.tactview.core.timeline.effect.interpolation.ValueProviderDescriptor) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition)

Example 2 with TimelinePosition

use of com.helospark.tactview.core.timeline.TimelinePosition in project tactview by helospark.

the class ParticleSystemProceduralClip method simulateParticles.

private List<Particle> simulateParticles(TimelinePosition requestedPosition, List<Particle> particles, BigDecimal startSecond) {
    BigDecimal timeSinceLastCache = BigDecimal.ZERO;
    BigDecimal roundedEndPosition = requestedPosition.getSeconds().setScale(2, RoundingMode.CEILING);
    BigDecimal roundedStartPosition = startSecond.setScale(2, RoundingMode.CEILING).add(SIMULATION_TIME);
    while (roundedStartPosition.compareTo(roundedEndPosition) < 0) {
        TimelinePosition currentSimlutatedTimelinePosition = new TimelinePosition(roundedStartPosition);
        Random random = repeatableRandom.createRandomForPosition(roundedStartPosition);
        double gravity = gravityProvider.getValueAt(currentSimlutatedTimelinePosition);
        for (Particle particle : particles) {
            particle.x += particle.xVel;
            particle.y += particle.yVel;
            particle.yVel += gravity;
        }
        int numberOfParticlesToCreate = (int) numberOfParticlesCreatedInStep.getValueAt(currentSimlutatedTimelinePosition).doubleValue();
        Point center = emitterCenterProvider.getValueAt(currentSimlutatedTimelinePosition);
        Point startDirection = startDirectionProvider.getValueAt(currentSimlutatedTimelinePosition);
        double randomXSpeed = startDirectionXRandomSpeedProvider.getValueAt(currentSimlutatedTimelinePosition);
        double randomYSpeed = startDirectionYRandomSpeedProvider.getValueAt(currentSimlutatedTimelinePosition);
        double emitterRandomization = emitterRandomizationProvider.getValueAt(currentSimlutatedTimelinePosition);
        DoubleRange lifeRange = ageRangeProvider.getValueAt(currentSimlutatedTimelinePosition);
        for (int i = 0; i < numberOfParticlesToCreate; ++i) {
            Particle particle = new Particle();
            particle.x = center.x + ((random.nextDouble() * 2.0 - 1.0) * emitterRandomization);
            particle.y = center.y + ((random.nextDouble() * 2.0 - 1.0) * emitterRandomization);
            particle.xVel = startDirection.x + (random.nextDouble() * 2.0 - 1.0) * randomXSpeed;
            particle.yVel = startDirection.y + (random.nextDouble() * 2.0 - 1.0) * randomYSpeed;
            particle.maxAge = lifeRange.lowEnd + random.nextDouble() * (lifeRange.highEnd - lifeRange.lowEnd);
            particle.bornTime = roundedStartPosition.doubleValue();
            particles.add(particle);
        }
        double currentSecondDouble = roundedStartPosition.doubleValue();
        particles.removeIf(particle -> particle.bornTime + particle.maxAge <= currentSecondDouble);
        timeSinceLastCache.add(SIMULATION_TIME);
        if (timeSinceLastCache.compareTo(CACHE_TIME) > 0) {
            timeSinceLastCache = timeSinceLastCache.subtract(CACHE_TIME);
            particlesCache.put(roundedStartPosition, cloneParticles(particles));
        }
        roundedStartPosition = roundedStartPosition.add(SIMULATION_TIME);
    }
    return particles;
}
Also used : DoubleRange(com.helospark.tactview.core.timeline.effect.interpolation.pojo.DoubleRange) Random(java.util.Random) RepeatableRandom(com.helospark.tactview.core.util.RepeatableRandom) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BigDecimal(java.math.BigDecimal) Point(com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)

Example 3 with TimelinePosition

use of com.helospark.tactview.core.timeline.TimelinePosition in project tactview by helospark.

the class DoubleInterpolator method integrate.

public default BigDecimal integrate(TimelinePosition from, TimelinePosition to) {
    TimelinePosition currentPosition = from;
    BigDecimal area = BigDecimal.ZERO;
    while (currentPosition.isLessThan(to)) {
        BigDecimal lowValue = BigDecimal.valueOf(valueAt(currentPosition));
        BigDecimal highValue = BigDecimal.valueOf(valueAt(currentPosition.add(interpolationResolition)));
        // trapezoid area
        area = area.add(lowValue.add(highValue).divide(two).multiply(interpolationResolition));
        currentPosition = currentPosition.add(interpolationResolition);
    }
    return area;
}
Also used : TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BigDecimal(java.math.BigDecimal)

Example 4 with TimelinePosition

use of com.helospark.tactview.core.timeline.TimelinePosition in project tactview by helospark.

the class KeyframeSupportingDoubleInterpolator method integrate.

@Override
public BigDecimal integrate(TimelinePosition from, TimelinePosition to) {
    if (!isUsingKeyframes()) {
        BigDecimal constantValue = BigDecimal.valueOf(valueAt(from));
        BigDecimal toSeconds = to.getSeconds();
        BigDecimal fromSeconds = from.getSeconds();
        return toSeconds.subtract(fromSeconds).multiply(constantValue);
    }
    if (integralCache == null) {
        synchronized (this) {
            if (integralCache == null) {
                integralCache = new TreeMap<>();
                integralCache.put(TimelinePosition.ofZero(), BigDecimal.ZERO);
            }
        }
    }
    // TODO: check below
    Entry<TimelinePosition, BigDecimal> startFloorEntry = integralCache.floorEntry(from);
    Entry<TimelinePosition, BigDecimal> endFloorEntry = integralCache.floorEntry(to);
    BigDecimal resultArea;
    synchronized (this) {
        // TODO: Use concurrent TreeMap collection somehow
        TimelinePosition currentTime;
        if (startFloorEntry != null && endFloorEntry != null) {
            resultArea = endFloorEntry.getValue().subtract(startFloorEntry.getValue());
            currentTime = endFloorEntry.getKey();
        } else {
            currentTime = TimelinePosition.ofZero();
            resultArea = BigDecimal.ZERO;
        }
        TimelinePosition newTo = to.subtract(new TimelineLength(integralCacheResolution));
        while (currentTime.isLessThan(newTo)) {
            BigDecimal partialArea = DoubleInterpolator.super.integrate(currentTime, currentTime.add(integralCacheResolution));
            resultArea = resultArea.add(partialArea);
            currentTime = currentTime.add(integralCacheResolution);
            integralCache.put(currentTime, resultArea);
        }
        resultArea = resultArea.add(DoubleInterpolator.super.integrate(currentTime, to));
    }
    return resultArea;
}
Also used : TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) BigDecimal(java.math.BigDecimal) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Example 5 with TimelinePosition

use of com.helospark.tactview.core.timeline.TimelinePosition in project tactview by helospark.

the class MultiKeyframeBasedDoubleInterpolator method deepClone.

@Override
public MultiKeyframeBasedDoubleInterpolator deepClone(CloneRequestMetadata cloneRequestMetadata) {
    TreeMap<TimelinePosition, Double> newValues = new TreeMap<>(values);
    UnivariateInterpolator newInterpolatorImplementation = interpolatorImplementation;
    MultiKeyframeBasedDoubleInterpolator result = new MultiKeyframeBasedDoubleInterpolator(defaultValue);
    result.values = newValues;
    result.interpolatorImplementation = newInterpolatorImplementation;
    result.useKeyframes = useKeyframes;
    result.initializationDefaultValue = initializationDefaultValue;
    result.initializationValues = new TreeMap<>(initializationValues);
    return result;
}
Also used : TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TreeMap(java.util.TreeMap) UnivariateInterpolator(org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator)

Aggregations

TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)104 BigDecimal (java.math.BigDecimal)22 List (java.util.List)22 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)20 ArrayList (java.util.ArrayList)18 Collectors (java.util.stream.Collectors)15 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)14 File (java.io.File)14 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)13 Bean (com.helospark.lightdi.annotation.Bean)12 Order (com.helospark.lightdi.annotation.Order)11 Component (com.helospark.lightdi.annotation.Component)10 TimelineLength (com.helospark.tactview.core.timeline.TimelineLength)10 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)9 DefaultMenuContribution (com.helospark.tactview.ui.javafx.menu.DefaultMenuContribution)9 Optional (java.util.Optional)9 Point (com.helospark.tactview.core.timeline.effect.interpolation.pojo.Point)8 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)8 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)8 MoveClipRequest (com.helospark.tactview.core.timeline.MoveClipRequest)7