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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations