Switch-Toolbox/Switch_FileFormatsMain/GUI/Byaml/CourseMuunt/Base/RenderablePathPoint.cs

281 lines
8.9 KiB
C#
Raw Normal View History

using Gl_EditorFramework;
using GL_EditorFramework.GL_Core;
using GL_EditorFramework.Interfaces;
using OpenTK;
2019-04-07 21:14:55 +00:00
using OpenTK.Graphics.OpenGL;
using Switch_Toolbox.Library.IO;
using static GL_EditorFramework.EditorDrawables.EditorSceneBase;
using FirstPlugin.Turbo.CourseMuuntStructs;
using FirstPlugin.Turbo;
namespace GL_EditorFramework.EditorDrawables
{
public class RenderablePathPoint : EditableObject
{
2019-04-06 19:13:55 +00:00
public bool CanConnect = true;
2019-04-06 17:29:42 +00:00
public object NodeObject;
public bool IsNormalTanTransform = false;
protected Vector3 position = new Vector3(0, 0, 0);
protected Vector3 scale = new Vector3(1, 1, 1);
protected Vector3 rotate = new Vector3(0, 0, 0);
protected Vector3 Normal = new Vector3(0, 0, 0);
protected Vector3 Tangent = new Vector3(0, 0, 0);
protected bool Selected = false;
public override bool IsSelected() => Selected;
public override bool IsSelected(int partIndex) => Selected;
2019-04-07 00:34:12 +00:00
public Vector4 Color = new Vector4(0f, 0.25f, 1f, 1f);
2019-04-07 00:34:12 +00:00
public RenderablePathPoint(Vector4 color, Vector3 pos, Vector3 rot, Vector3 sca, object nodeObject) {
2019-04-06 17:29:42 +00:00
NodeObject = nodeObject;
2019-04-07 00:34:12 +00:00
Color = color;
UpdateTransform(pos, rot, sca);
}
public RenderablePathPoint(Vector3 pos, Vector3 normal, Vector3 tangent, Vector3 sca) {
UpdateTransform(pos, normal, tangent, sca);
}
public void UpdateTransform(Vector3 pos, Vector3 rot, Vector3 sca)
{
position = pos;
rotate = rot;
scale = new Vector3(sca / 2);
}
public void UpdateTransform(Vector3 pos, Vector3 normal, Vector3 tangent, Vector3 scale)
{
IsNormalTanTransform = true;
Normal = normal;
Tangent = tangent;
scale = new Vector3(scale / 2);
}
public override void Draw(GL_ControlModern control, Pass pass, EditorSceneBase editorScene)
{
2019-04-07 23:37:31 +00:00
if (pass == Pass.TRANSPARENT)
return;
2019-04-22 21:52:21 +00:00
bool hovered = editorScene.Hovered == this;
if (IsNormalTanTransform)
{
control.UpdateModelMatrix(Matrix4.CreateScale(scale) *
MatrixExenstion.CreateRotation(Normal, Tangent) *
2019-04-22 21:52:21 +00:00
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(Position) : Position));
}
else
{
control.UpdateModelMatrix(Matrix4.CreateScale(scale) *
(Matrix4.CreateRotationX(rotate.X) *
Matrix4.CreateRotationY(rotate.Y) *
Matrix4.CreateRotationZ(rotate.Z)) *
2019-04-22 21:52:21 +00:00
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(Position) : Position));
}
Vector4 blockColor;
Vector4 lineColor;
if (hovered && Selected)
lineColor = hoverColor;
else if (hovered || Selected)
lineColor = selectColor;
else
lineColor = Color;
if (hovered && Selected)
blockColor = Color * 0.5f + hoverColor * 0.5f;
else if (hovered || Selected)
blockColor = Color * 0.5f + selectColor * 0.5f;
else
blockColor = Color;
2019-04-22 21:52:21 +00:00
Renderers.ColorBlockRenderer.Draw(control, pass, blockColor, lineColor, control.NextPickingColor());
}
public override void Draw(GL_ControlModern control, Pass pass)
{
2019-04-07 23:37:31 +00:00
if (pass == Pass.TRANSPARENT)
return;
control.UpdateModelMatrix(Matrix4.CreateScale(0.5f) *
Matrix4.CreateTranslation(position));
2019-04-22 21:52:21 +00:00
Renderers.ColorBlockRenderer.Draw(control, pass, Color, Color, control.NextPickingColor());
}
public override void Draw(GL_ControlLegacy control, Pass pass, EditorSceneBase editorScene)
{
2019-04-07 23:37:31 +00:00
if (pass == Pass.TRANSPARENT)
return;
2019-04-22 21:52:21 +00:00
bool hovered = editorScene.Hovered == this;
control.UpdateModelMatrix(Matrix4.CreateScale(0.5f) *
2019-04-22 21:52:21 +00:00
Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));
Vector4 blockColor;
Vector4 lineColor;
if (hovered && Selected)
lineColor = hoverColor;
else if (hovered || Selected)
lineColor = selectColor;
else
lineColor = Color;
if (hovered && Selected)
blockColor = Color * 0.5f + hoverColor * 0.5f;
else if (hovered || Selected)
blockColor = Color * 0.5f + selectColor * 0.5f;
else
blockColor = Color;
2019-04-22 21:52:21 +00:00
Renderers.ColorBlockRenderer.Draw(control, pass, blockColor, lineColor, control.NextPickingColor());
}
public override void Draw(GL_ControlLegacy control, Pass pass)
{
2019-04-07 23:37:31 +00:00
if (pass == Pass.TRANSPARENT)
return;
control.UpdateModelMatrix(Matrix4.CreateScale(0.5f) *
Matrix4.CreateTranslation(position));
2019-04-22 21:52:21 +00:00
Renderers.ColorBlockRenderer.Draw(control, pass, Color, Color, control.NextPickingColor());
}
public override void Prepare(GL_ControlModern control)
{
Renderers.ColorBlockRenderer.Initialize();
}
public override void Prepare(GL_ControlLegacy control)
{
}
public virtual void Translate(Vector3 lastPos, Vector3 translate, int subObj)
{
position = lastPos + translate;
UpdateNodePosition();
}
2019-04-06 19:13:55 +00:00
public virtual void UpdatePosition(int subObj) {
}
public override BoundingBox GetSelectionBox() => new BoundingBox(
position.X - scale.X,
position.X + scale.X,
position.Y - scale.Y,
position.Y + scale.Y,
position.Z - scale.Z,
position.Z + scale.Z
);
public override uint SelectAll(GL_ControlBase control)
{
Selected = true;
return REDRAW;
}
public override uint SelectDefault(GL_ControlBase control)
{
Selected = true;
return REDRAW;
}
public override uint Select(int partIndex, GL_ControlBase control)
{
Selected = true;
return REDRAW;
}
public override uint Deselect(int partIndex, GL_ControlBase control)
{
Selected = false;
return REDRAW;
}
public override uint DeselectAll(GL_ControlBase control)
{
Selected = false;
return REDRAW;
}
public override void ApplyTransformActionToSelection(AbstractTransformAction transformAction)
{
2019-04-22 21:52:21 +00:00
position = transformAction.NewPos(position);
UpdateNodePosition();
}
2019-04-22 21:52:21 +00:00
public override LocalOrientation GetLocalOrientation(int partIndex)
{
return new LocalOrientation(position);
}
public override bool TryStartDragging(DragActionType actionType, int hoveredPart, out LocalOrientation localOrientation, out bool dragExclusively)
{
localOrientation = new LocalOrientation(position);
dragExclusively = false;
return Selected;
}
public override bool IsInRange(float range, float rangeSquared, Vector3 pos)
{
return (pos - position).LengthSquared < rangeSquared;
}
private void UpdateNodePosition()
{
2019-04-08 01:14:39 +00:00
if (NodeObject is BasePathPoint)
{
2019-04-08 01:14:39 +00:00
((BasePathPoint)NodeObject).Translate = position;
((BasePathPoint)NodeObject).Scale = scale;
((BasePathPoint)NodeObject).Rotate = rotate;
2019-04-06 19:13:55 +00:00
2019-04-08 01:14:39 +00:00
if (((BasePathPoint)NodeObject).OnPathMoved != null)
((BasePathPoint)NodeObject).OnPathMoved();
}
if (NodeObject is Course_MapCamera_bin)
{
if (Color == new Vector4(1, 0, 0, 1))
{
((Course_MapCamera_bin)NodeObject).cameraData.PositionX = position.X;
((Course_MapCamera_bin)NodeObject).cameraData.PositionY = position.Y;
((Course_MapCamera_bin)NodeObject).cameraData.PositionZ = position.Z;
}
else
{
((Course_MapCamera_bin)NodeObject).cameraData.TargetX = position.X;
((Course_MapCamera_bin)NodeObject).cameraData.TargetY = position.Y;
((Course_MapCamera_bin)NodeObject).cameraData.TargetZ = position.Z;
}
}
}
public override Vector3 Position
{
get
{
return position;
}
set
{
position = value;
}
}
}
}