use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint 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.BezierPolygonPoint 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.BezierPolygonPoint in project tactview by helospark.
the class BezierPolygonProviderDesSerFactory method deserialize.
@Override
public BezierPolygonProvider deserialize(JsonNode data, SavedContentAddable<?> currentFieldValue, LoadMetadata loadMetadata) {
try {
List<BezierPolygonPoint> defaultValues = objectMapper.readValue(objectMapper.treeAsTokens(data.get("defaultValue")), objectMapper.getTypeFactory().constructType(new TypeReference<List<BezierPolygonPoint>>() {
}));
TreeMap<TimelinePosition, List<BezierPolygonPoint>> values = objectMapper.readValue(objectMapper.treeAsTokens(data.get("values")), objectMapper.getTypeFactory().constructType(new TypeReference<TreeMap<TimelinePosition, List<BezierPolygonPoint>>>() {
}));
UnivariateInterpolator interpolator;
interpolator = (UnivariateInterpolator) Class.forName(data.get("interpolatorImplementation").asText()).newInstance();
boolean useKeyframes = data.get("useKeyframes").asBoolean();
return new BezierPolygonProvider(useKeyframes, defaultValues, values, interpolator);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.
the class BezierPolygonInputTypeStrategy method draw.
@Override
public void draw(DrawRequestParameter parameterObject) {
double translateX = parameterObject.getCanvasTranslateX();
double translateY = parameterObject.getCanvasTranslateY();
parameterObject.getCanvas().setFill(Color.BLUE);
parameterObject.getCanvas().setStroke(Color.BLUE);
Point previousRealPoint = null;
for (int i = 0; i < result.size(); ++i) {
BezierPolygonPoint currentBezier = result.get(i);
Point current = pointFromBezierPoint(currentBezier).multiply(parameterObject.getWidth(), parameterObject.getHeight());
int diameter = 10;
if (isMouseCloseToFirstPoint && i == 0 && !finishOnRightClick) {
diameter = 20;
}
if (mouseCloseTo.isPresent() && mouseCloseTo.get().equals(i)) {
parameterObject.getCanvas().setFill(Color.RED);
} else {
if (currentBezier.type == SplinePolygonType.SPLINE) {
parameterObject.getCanvas().setFill(Color.GRAY);
} else {
parameterObject.getCanvas().setFill(Color.BLUE);
}
}
parameterObject.getCanvas().fillOval(current.x - diameter / 2 + translateX, current.y - diameter / 2 + translateY, diameter, diameter);
if (currentBezier.type == SplinePolygonType.SPLINE) {
parameterObject.getCanvas().setStroke(Color.GRAY);
} else {
parameterObject.getCanvas().setStroke(Color.BLUE);
}
if (previousRealPoint != null) {
parameterObject.getCanvas().strokeLine(previousRealPoint.x + translateX, previousRealPoint.y + translateY, current.x + translateX, current.y + translateY);
}
if (currentBezier.type == SplinePolygonType.POINT) {
previousRealPoint = current;
}
}
}
use of com.helospark.tactview.core.timeline.proceduralclip.polygon.impl.bezier.BezierPolygonPoint in project tactview by helospark.
the class BezierPolygonInputTypeStrategy method onMouseDownEvent.
@Override
public void onMouseDownEvent(StrategyMouseInput input) {
if (input.mouseEvent.isSecondaryButtonDown()) {
isFinished = true;
} else {
double x = input.x;
double y = input.y;
pointIndexToUpdate = findPointNear(new Point(input.x, input.y));
if (input.mouseEvent.isMiddleButtonDown()) {
if (pointIndexToUpdate.isPresent()) {
int indexToRemove = pointIndexToUpdate.get();
result.remove(indexToRemove);
if (indexToRemove < result.size() && result.get(indexToRemove).type == SplinePolygonType.SPLINE) {
// next point
result.remove(indexToRemove);
}
}
return;
}
if (isCloseToFirstPoint(new Point(input.x, input.y)) && !finishOnRightClick) {
if (result.size() > 1) {
BezierPolygonPoint controlPoint = createControlPoint(result.get(0), result.get(result.size() - 1));
result.add(controlPoint);
}
isFinished = true;
} else {
if (pointIndexToUpdate.isPresent()) {
int index = pointIndexToUpdate.get();
updatePointAtIndex(input, index);
} else {
BezierPolygonPoint currentPoint = new BezierPolygonPoint(x, y, SplinePolygonType.POINT);
if (result.size() >= 1) {
BezierPolygonPoint controlPoint = createControlPoint(currentPoint, result.get(result.size() - 1));
result.add(controlPoint);
}
result.add(currentPoint);
}
}
}
}
Aggregations