Skip to content

Commit

Permalink
0.9
Browse files Browse the repository at this point in the history
Added: Launcher
Added: Animation Model Selector for Preview
  • Loading branch information
rickomax committed Apr 22, 2019
1 parent 99b0d5c commit b49f016
Show file tree
Hide file tree
Showing 19 changed files with 4,293 additions and 592 deletions.
5 changes: 5 additions & 0 deletions Classes/Animation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Drawing.Design;

namespace PSXPrev
{
Expand All @@ -16,6 +17,10 @@ public class Animation
[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
16 changes: 8 additions & 8 deletions Classes/AnimationBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public void SetupAnimationBatch(Animation animation)
//_scene.LineBatch.Reset();
}

public void SetupAnimationFrame(int frame, EntityBase selectedEntity = null)
public void SetupAnimationFrame(int frame)
{
_animationProcessIndex = 0;
ProcessAnimationObject(_animation.RootAnimationObject, frame, null, selectedEntity);
ProcessAnimationObject(_animation.RootAnimationObject, frame, null);
}

private void ProcessAnimationObject(AnimationObject animationObject, int frameIndex, Matrix4? parentMatrix, EntityBase selectedEntity = null)
private void ProcessAnimationObject(AnimationObject animationObject, int frameIndex, Matrix4? parentMatrix)
{
var animationFrames = animationObject.AnimationFrames;
var totalFrames = animationFrames.Count;
Expand Down Expand Up @@ -101,19 +101,19 @@ private void ProcessAnimationObject(AnimationObject animationObject, int frameIn
worldMatrix = localMatrix;
}

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

foreach (var childObject in animationObject.Children)
{
ProcessAnimationObject(childObject, frameIndex, worldMatrix, selectedEntity);
ProcessAnimationObject(childObject, frameIndex, worldMatrix);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Classes/AnimationObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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 Down
12 changes: 12 additions & 0 deletions Classes/MeshBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public void BindTestMesh(Matrix4 matrix, int index, bool isSelected)
}
}
var mesh = GetMesh(index);
if (mesh == null)
{
return;
}
mesh.WorldMatrix = matrix;
mesh.Texture = _scene.TextureBinder.GetTexture(0);
mesh.SetData(numTriangles * 3, positionList, normalList, colorList, uvList);
Expand Down Expand Up @@ -185,6 +189,10 @@ private void BindMesh(ModelEntity modelEntity, int index, Matrix4? matrix = null
}
}
var mesh = GetMesh(index);
if (mesh == null)
{
return;
}
mesh.WorldMatrix = matrix ?? modelEntity.WorldMatrix;
mesh.Visible = modelEntity.Visible;
mesh.SetData(numTriangles * 3, positionList, normalList, colorList, uvList);
Expand Down Expand Up @@ -218,6 +226,10 @@ public void Reset(int nMeshes)

private Mesh GetMesh(int index)
{
if (index >= _meshes.Length)
{
return null;
}
if (_meshes[index] == null)
{
_meshes[index] = new Mesh(_ids[index]);
Expand Down
49 changes: 49 additions & 0 deletions Classes/RootEntitySelectorEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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
{
public class RootEntitySelectorEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (Program.Scanning)
{
MessageBox.Show("Please wait until the scan finishes.");
return null;
}
var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (svc != null)
{
using (var form = new SelectTMDForm())
{
if (svc.ShowDialog(form) == DialogResult.OK)
{
return form.SelectedTMD;
}
}
}
else
{
using (var form = new SelectTMDForm())
{
if (form.ShowDialog() == DialogResult.OK)
{
return form.SelectedTMD;
}
}
}
return base.EditValue(context, provider, value);
}
}
}
Loading

0 comments on commit b49f016

Please sign in to comment.