use of com.talosvfx.talos.editor.addons.scene.logic.components.CurveComponent in project talos by rockbite.
the class CurveGizmo method draw.
@Override
public void draw(Batch batch, float parentAlpha) {
if (gameObject.hasComponent(CurveComponent.class)) {
CurveComponent curve = gameObject.getComponent(CurveComponent.class);
Array<Vector2> points = curve.points;
if (selected) {
for (int i = 0; i < points.size; i++) {
if (i % 3 == 0) {
drawCircle(toWorld(points.get(i)), batch);
}
}
}
for (int i = 0; i < curve.getNumSegments(); i++) {
Vector2[] pointsInSegment = curve.getPointsInSegment(i);
if (selected) {
Color color = Color.GRAY;
if (curve.automaticControl) {
color = darkerLine;
}
ctrlOne.set(pointsInSegment[1]);
ctrlTwo.set(pointsInSegment[2]);
if (animatingAnchor >= 0) {
if (i * 3 + 2 == animatingAnchor - 1) {
tmp.set(ctrlTwo).sub(curve.points.get(animatingAnchor)).scl(animateActor.getX()).add(curve.points.get(animatingAnchor));
ctrlTwo.set(tmp);
} else if (i * 3 + 1 == animatingAnchor + 1) {
tmp.set(ctrlOne).sub(curve.points.get(animatingAnchor)).scl(animateActor.getX()).add(curve.points.get(animatingAnchor));
ctrlOne.set(tmp);
}
}
drawLine(batch, toWorld(ctrlOne, tmp2), toWorld(pointsInSegment[0], tmp3), color);
drawLine(batch, toWorld(ctrlTwo, tmp2), toWorld(pointsInSegment[3], tmp3), color);
if (!curve.automaticControl) {
drawCircle(toWorld(ctrlOne), batch);
drawCircle(toWorld(ctrlTwo), batch);
}
}
bezier.set(pointsInSegment);
Vector2 prev = bezier.valueAt(tmp, 0);
float step = 1f / 20f;
for (float t = step; t <= 1f; t += step) {
Vector2 curr = bezier.valueAt(tmp2, t);
if (selectedSegmentIndex == i) {
drawLine(batch, toWorld(prev, tmp3), toWorld(curr, tmp4), Color.YELLOW);
} else {
drawLine(batch, toWorld(prev, tmp3), toWorld(curr, tmp4), Color.RED);
}
prev.set(curr);
}
Vector2 curr = bezier.valueAt(tmp2, 1f);
if (selectedSegmentIndex == i) {
drawLine(batch, toWorld(prev, tmp3), toWorld(curr, tmp4), Color.YELLOW);
} else {
drawLine(batch, toWorld(prev, tmp3), toWorld(curr, tmp4), Color.RED);
}
}
}
if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
IProject project = TalosMain.Instance().ProjectController().getProject();
if (project instanceof SceneEditorProject) {
SceneEditorProject sceneEditorProject = (SceneEditorProject) project;
sceneEditorProject.sceneEditorAddon.workspace.requestSelectionClear();
}
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.CurveComponent in project talos by rockbite.
the class CurveGizmo method touchDown.
@Override
public void touchDown(float x, float y, int button) {
CurveComponent curve = gameObject.getComponent(CurveComponent.class);
int touchedPoint = getTouchedPoint(x, y);
if (button == 0) {
if (touchedPoint >= 0) {
touchedPointRef = gameObject.getComponent(CurveComponent.class).points.get(touchedPoint);
touchedPointIndex = touchedPoint;
} else {
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
// adding new points then
curve.addSegment(toLocal(new Vector2(x, y)));
touchedPointIndex = curve.points.size - 1;
touchedPointRef = curve.points.get(touchedPointIndex);
} else if (selectedSegmentIndex >= 0) {
curve.splitSegment(toLocal(new Vector2(x, y)), selectedSegmentIndex);
touchedPointIndex = selectedSegmentIndex * 3 + 3;
touchedPointRef = curve.points.get(touchedPointIndex);
animateAnchor(touchedPointIndex);
}
}
} else if (button == 1) {
if (touchedPoint % 3 == 0) {
curve.deleteSegment(touchedPoint);
}
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.CurveComponent in project talos by rockbite.
the class CurveGizmo method touchDragged.
@Override
public void touchDragged(float x, float y) {
if (touchedPointRef != null) {
CurveComponent curve = gameObject.getComponent(CurveComponent.class);
Vector2 pos = toLocal(tmp3.set(x, y));
curve.movePoint(touchedPointIndex, pos.x, pos.y);
}
}
use of com.talosvfx.talos.editor.addons.scene.logic.components.CurveComponent in project talos by rockbite.
the class CurveGizmo method mouseMoved.
@Override
public void mouseMoved(float x, float y) {
float threshold = worldPerPixel * 10f;
selectedSegmentIndex = -1;
Vector2 local = toLocal(tmp, x, y);
CurveComponent curve = gameObject.getComponent(CurveComponent.class);
for (int i = 0; i < curve.getNumSegments(); i++) {
Vector2[] pointsInSegment = curve.getPointsInSegment(i);
bezier.set(pointsInSegment);
float dst = getDistanceToBezier(bezier, local);
if (dst < threshold) {
selectedSegmentIndex = i;
}
}
if (selectedSegmentIndex >= 0) {
// debug info here
}
}
Aggregations