Skip to content

Commit

Permalink
0.9.2
Browse files Browse the repository at this point in the history
Improved: TOD Animations Support.
Added: Gizmo Position Manipulators.
Added: Merged Exporting Mode.
Fixed: Misc. Issues.
  • Loading branch information
rickomax committed May 13, 2019
1 parent 4381bf6 commit 6ffbdf4
Show file tree
Hide file tree
Showing 37 changed files with 1,604 additions and 1,062 deletions.
7 changes: 1 addition & 6 deletions Classes/Animation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Drawing.Design;

namespace PSXPrev
{
Expand All @@ -11,16 +10,12 @@ public class Animation
[DisplayName("Frame Count"), ReadOnly(true)]
public uint FrameCount { get; set; }

[DisplayName("Frames per Second"), ReadOnly(true)]
[DisplayName("Frames per Second")]
public float FPS { get; set; }

[DisplayName("Children"), ReadOnly(true)]
public int ObjectCount { get; set; }

[DisplayName("Preview Model")]
[Editor(typeof(RootEntitySelectorEditor), typeof(UITypeEditor))]
public RootEntity RootEntity { get; set; }

[Browsable(false)]
public AnimationObject RootAnimationObject { get; set; }
}
Expand Down
108 changes: 50 additions & 58 deletions Classes/AnimationBatch.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using OpenTK;


namespace PSXPrev
{
public class AnimationBatch
{
private Animation _animation;
private Scene _scene;
private readonly Scene _scene;
private int _animationProcessIndex;

public AnimationBatch(Scene scene)
{
_scene = scene;
Expand All @@ -18,17 +17,20 @@ public void SetupAnimationBatch(Animation animation)
{
var objectCount = animation.ObjectCount;
_scene.MeshBatch.Reset(objectCount + 1);
_scene.BoundsBatch.Reset();
_scene.SkeletonBatch.Reset();
_scene.GizmosMeshBatch.Reset(0);
_animation = animation;
//_scene.LineBatch.Reset();
}

public void SetupAnimationFrame(int frame)
public void SetupAnimationFrame(int frame, AnimationObject animationObject = null, RootEntity selectedEntity = null)
{
_scene.SkeletonBatch.Reset();
_animationProcessIndex = 0;
ProcessAnimationObject(_animation.RootAnimationObject, frame, null);
ProcessAnimationObject(_animation.RootAnimationObject, frame, null, animationObject, selectedEntity);
}

private void ProcessAnimationObject(AnimationObject animationObject, int frameIndex, Matrix4? parentMatrix)
private void ProcessAnimationObject(AnimationObject animationObject, int frameIndex, Matrix4? parentMatrix, AnimationObject selectedAnimationObject = null, RootEntity selectedEntity = null)
{
var animationFrames = animationObject.AnimationFrames;
var totalFrames = animationFrames.Count;
Expand All @@ -39,81 +41,71 @@ private void ProcessAnimationObject(AnimationObject animationObject, int frameIn
{
continue;
}
var sumFrame = animationFrames[f];

var matrix = Matrix4.Identity;
var anyMatrix = sumFrame.AbsoluteMatrix;
if (anyMatrix != null)
{
//var modelMatrix = sumFrame.Matrix;
//if (modelMatrix != null)
//{
// matrix = (Matrix4)modelMatrix;
//}
//else
//{

if (sumFrame.Rotation != null)
{
var rotation = (Vector3)sumFrame.Rotation;
var r = GeomUtils.CreateR(rotation);
matrix = matrix * r;
}
var sumFrame = animationFrames[f];

if (sumFrame.Scale != null)
{
var scale = (Vector3)sumFrame.Scale;
var s = GeomUtils.CreateS(scale.X);
matrix = matrix * s;
}
if (sumFrame.Rotation != null)
{
var r = Matrix4.CreateFromQuaternion(sumFrame.Rotation.Value);
matrix = matrix * r;
}
else if (sumFrame.EulerRotation != null)
{
var r = GeomUtils.CreateR(sumFrame.EulerRotation.Value);
matrix = matrix * r;
}

if (sumFrame.Translation != null)
{
var translation = (Vector3)sumFrame.Translation;
var t = GeomUtils.CreateT(translation);
matrix = matrix * t;
}
if (sumFrame.Scale != null)
{
var scale = (Vector3)sumFrame.Scale;
var s = GeomUtils.CreateS(scale.X);
matrix = matrix * s;
}

var absoluteMatrixValue = (bool)anyMatrix;
if (!absoluteMatrixValue)
{
matrix = matrix * localMatrix;
}
localMatrix = matrix;
if (sumFrame.Translation != null)
{
var translation = (Vector3)sumFrame.Translation;
var t = GeomUtils.CreateT(translation);
matrix = matrix * t;
}

var absoluteMatrixValue = sumFrame.AbsoluteMatrix;
if (!absoluteMatrixValue)
{
matrix = matrix * localMatrix;
}
localMatrix = matrix;
}

Matrix4 worldMatrix;
if (parentMatrix != null)
{
var parentMatrixValue = (Matrix4)parentMatrix;
worldMatrix = localMatrix * parentMatrixValue;
//if (animationObject.Visible)
//{
// _scene.LineBatch.AddLine(new Line
// {
// p1 = Vector4.One * parentMatrixValue,
// p2 = Vector4.One * worldMatrix
// });
//}
worldMatrix = localMatrix * parentMatrix.Value;
_scene.SkeletonBatch.AddLine(Vector3.TransformPosition(Vector3.One, parentMatrix.Value), Vector3.TransformPosition(Vector3.One, worldMatrix), animationObject == selectedAnimationObject ? Color.Blue : Color.Red);
}
else
{
worldMatrix = localMatrix;
}

if (_animation.RootEntity != null)
if (selectedEntity != null)
{
var childEntities = _animation.RootEntity.ChildEntities;
if (animationObject.TMDID > 0 && animationObject.TMDID <= childEntities.Length)
var objectId = animationObject.TMDID.GetValueOrDefault();
if (objectId > 0)
{
var model = (ModelEntity) childEntities[animationObject.TMDID - 1];
_scene.MeshBatch.BindModelBatch(model, _animationProcessIndex++, worldMatrix);
var models = selectedEntity.GetModelsWithTMDID(objectId-1);
foreach (var model in models)
{
_scene.MeshBatch.BindModelBatch(model, _animationProcessIndex++, worldMatrix, _scene.TextureBinder);
}
}
}

foreach (var childObject in animationObject.Children)
{
ProcessAnimationObject(childObject, frameIndex, worldMatrix);
ProcessAnimationObject(childObject, frameIndex, worldMatrix, selectedAnimationObject, selectedEntity);
}
}
}
Expand Down
37 changes: 34 additions & 3 deletions Classes/AnimationFrame.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
using OpenTK;
using System.ComponentModel;

namespace PSXPrev
{
public class AnimationFrame
{
public bool? AbsoluteMatrix { get; set; }
public Vector3? Rotation { get; set; }
[Browsable(false)]
public AnimationObject AnimationObject { get; set; }
[Browsable(false)]
public bool AbsoluteMatrix { get; set; }
[Browsable(false)]
public Quaternion? Rotation { get; set; }
[Browsable(false)]
public Vector3? EulerRotation { get; set; }
[Browsable(false)]
public Vector3? Scale { get; set; }
[Browsable(false)]
public Vector3? Translation { get; set; }
public Matrix4? Matrix { get; set; }

[ReadOnly(true)]
public int FrameTime { get; set; }

public float RotationX => Rotation?.X ?? 0f;


public float RotationY => Rotation?.Y ?? 0f;

public float RotationZ => Rotation?.Z ?? 0f;

public float ScaleX => Scale?.X ?? 0f;


public float ScaleY => Scale?.Y ?? 0f;

public float ScaleZ => Scale?.Z ?? 0f;

public float PositionX => Translation?.X ?? 0f;


public float PositionY => Translation?.Y ?? 0f;

public float PositionZ => Translation?.Z ?? 0f;
}
}
16 changes: 4 additions & 12 deletions Classes/AnimationObject.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using PSXPrev.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace PSXPrev
{
Expand All @@ -22,17 +17,14 @@ public class AnimationObject
[Browsable(false)]
public Animation Animation { get; set; }

[DisplayName("Visible")]
public bool Visible { get; set; }

[Browsable(false)]
public int ParentID { get; set; }

[DisplayName("TMD ID")]
public int TMDID { get; set; }
[ReadOnly(true)]
public int ID { get; set; }

[Browsable(false)]
public bool IsSelected { get; set; }
[DisplayName("TMD ID")]
public int? TMDID { get; set; }

public AnimationObject()
{
Expand Down
72 changes: 56 additions & 16 deletions Classes/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,82 @@ public Vector3[] Corners
}
}

public float Magnitude => (Max - Min).Length;
public Vector3 Center => Vector3.Lerp(Min, Max, 0.5f);

public Vector3 Extents => Size * 0.5f;

public Vector3 Size => Max - Min;

public float Magnitude => Size.Length;

public float MagnitudeFromCenter
{
get
{
var min = Min;
var max = Max;
GetMinMax(ref min, ref max, Vector3.Zero);
return (max - min).Length;
}
}

public Vector3 Center => new Vector3(Min.X + Max.X * 0.5f, Min.Y + Max.Y * 0.5f, Min.Z + Max.Z * 0.5f);

public Vector3 Min;

public Vector3 Max;

public void AddPoint(Vector3 point)
private bool _isSet;

private void GetMinMax(ref Vector3 min, ref Vector3 max, Vector3 point)
{
if (point.X < Min.X)
if (point.X < min.X)
{
Min.X = point.X;
min.X = point.X;
}
else if (point.X > Max.X)
else if (point.X > max.X)
{
Max.X = point.X;
max.X = point.X;
}
if (point.Y < Min.Y)
if (point.Y < min.Y)
{
Min.Y = point.Y;
min.Y = point.Y;
}
else if (point.Y > Max.Y)
else if (point.Y > max.Y)
{
Max.Y = point.Y;
max.Y = point.Y;
}
if (point.Z < Min.Z)
if (point.Z < min.Z)
{
Min.Z = point.Z;
min.Z = point.Z;
}
else if (point.Z > Max.Z)
else if (point.Z > max.Z)
{
Max.Z = point.Z;
max.Z = point.Z;
}
}

public void AddPoints(Vector3[] points)
{
foreach (var point in points)
{
AddPoint(point);
}
}

public void AddPoint(Vector3 point)
{
if (!_isSet)
{
Min = point;
Max = point;
_isSet = true;
}
else
{
GetMinMax(ref Min, ref Max, point);
}

}

public override string ToString()
{
return $"({Min.X}, {Min.Y}, {Min.Z}) - ({Max.X}, {Max.Y}, {Max.Z})";
Expand Down
12 changes: 12 additions & 0 deletions Classes/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
{
public class Color
{
public static readonly Color Red = new Color(1f, 0f, 0f);
public static readonly Color Green = new Color(0f, 1f, 0f);
public static readonly Color Blue = new Color(0f, 0f, 1f);
public static readonly Color White = new Color(1f, 1f, 1f);

public float R;
public float G;
public float B;

public Color(float r, float g, float b)
{
R = r;
G = g;
B = b;
}

public override string ToString()
{
return R + "|" + G + "|" + B;
Expand Down
Loading

0 comments on commit 6ffbdf4

Please sign in to comment.