Skip to content

Commit

Permalink
Converted EmbedFS readers to interface to simplify the code for acces…
Browse files Browse the repository at this point in the history
…ing individual files and eve installations

First steps for rendering .red models
Added SharpDX DX9 as dependency to start

Signed-off-by: Alexis Maiquez Murcia <[email protected]>
  • Loading branch information
Almamu committed Oct 7, 2022
1 parent 752cad7 commit 6caee1a
Show file tree
Hide file tree
Showing 39 changed files with 632 additions and 171 deletions.
33 changes: 33 additions & 0 deletions EVEmuTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,105 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Editor Debug|Any CPU = Editor Debug|Any CPU
Editor Debug|x64 = Editor Debug|x64
Editor Debug|x86 = Editor Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|x64.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|x64.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|x86.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Debug|x86.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|Any CPU.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|x64.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|x64.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|x86.ActiveCfg = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Editor Debug|x86.Build.0 = Debug|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|Any CPU.Build.0 = Release|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|x64.ActiveCfg = Release|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|x64.Build.0 = Release|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|x86.ActiveCfg = Release|Any CPU
{5C202FBF-DDB2-4827-A637-0948B329F8C0}.Release|x86.Build.0 = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|x64.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|x64.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|x86.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Debug|x86.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|Any CPU.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|x64.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|x64.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|x86.ActiveCfg = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Editor Debug|x86.Build.0 = Debug|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|Any CPU.Build.0 = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|x64.ActiveCfg = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|x64.Build.0 = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|x86.ActiveCfg = Release|Any CPU
{6055C65E-F54F-4254-BAF8-98C9C853305E}.Release|x86.Build.0 = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|x64.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|x64.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|x86.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Debug|x86.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|Any CPU.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|x64.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|x64.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|x86.ActiveCfg = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Editor Debug|x86.Build.0 = Debug|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|Any CPU.Build.0 = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|x64.ActiveCfg = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|x64.Build.0 = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|x86.ActiveCfg = Release|Any CPU
{8A9E3C2C-28E0-4AB9-9034-F9406B5CBBDF}.Release|x86.Build.0 = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|x64.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|x64.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Debug|x86.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|Any CPU.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|x64.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|x64.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|x86.ActiveCfg = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Editor Debug|x86.Build.0 = Debug|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|Any CPU.Build.0 = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|x64.ActiveCfg = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|x64.Build.0 = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|x86.ActiveCfg = Release|Any CPU
{9EF5A968-08F8-40CF-BC97-975C7FFB21E4}.Release|x86.Build.0 = Release|Any CPU
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|Any CPU.ActiveCfg = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|Any CPU.Build.0 = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|x64.ActiveCfg = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|x64.Build.0 = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|x86.ActiveCfg = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Debug|x86.Build.0 = Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|Any CPU.ActiveCfg = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|Any CPU.Build.0 = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|x64.ActiveCfg = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|x64.Build.0 = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|x86.ActiveCfg = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Editor Debug|x86.Build.0 = Editor Debug|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|Any CPU.ActiveCfg = Release|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|Any CPU.Build.0 = Release|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|x64.ActiveCfg = Release|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|x64.Build.0 = Release|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|x86.ActiveCfg = Release|x64
{D8B26B12-E45C-47EA-88F7-56628EB2CCD1}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions Editor/EVEmuTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="Serilog.Expressions" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.2-dev-00890" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00947" />
<PackageReference Include="SharpDX.Direct3D9" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
<PackageReference Include="WPFHexaEditor" Version="2.1.6" />
<PackageReference Include="YamlDotNet" Version="12.0.1" />
Expand Down
3 changes: 3 additions & 0 deletions Editor/EVEmuTool.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<Compile Update="Forms\Components\ModelViewerComponent.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="Forms\Components\RedInspector.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="Forms\Components\TriRenderComponent.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
37 changes: 37 additions & 0 deletions Editor/EmbedFS/EmbedFSDirectory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace EVEmuTool.EmbedFS
{
public class EmbedFSDirectory : IEmbedFS
{
private List<IEmbedFS> mFiles = new List<IEmbedFS>();

public IEnumerable<StuffEntry> Files => this.mFiles.SelectMany(x => x.Files);

public EmbedFSDirectory(string[] files)
{
foreach (string file in files)
this.mFiles.Add(new EmbedFSFile(File.OpenRead(file)));
}


public void InitializeFile()
{
foreach (IEmbedFS file in this.mFiles)
file.InitializeFile();
}

public void Export(Stream output, StuffEntry entry)
{
// directories are just a holder for a list of embedFS files
// call the original container and export the file
entry.Origin.Export(output, entry);
}
}
}
13 changes: 7 additions & 6 deletions Editor/EmbedFS/EmbedFSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ namespace EVEmuTool.EmbedFS
/// <summary>
/// Simple class that allows working on .stuff files from EVE Online
/// </summary>
public class EmbedFSFile
public class EmbedFSFile : IEmbedFS
{
private BinaryReader mInput;
private List<StuffEntry> mFiles = new List<StuffEntry>();
/// <summary>
/// The found files in the stuff file
/// </summary>
public List<StuffEntry> Files { get; } = new List<StuffEntry>();
public IEnumerable<StuffEntry> Files => this.mFiles;

public EmbedFSFile (Stream input)
{
this.mInput = new BinaryReader (input);
}

public void ReadFile ()
public void InitializeFile ()
{
this.ReadFileHeader();
this.ReadFileTree();
Expand Down Expand Up @@ -54,7 +55,7 @@ private void ReadFileTree()
string filename = Encoding.ASCII.GetString(this.mInput.ReadBytes(nameLength));
this.mInput.BaseStream.Seek(1, SeekOrigin.Current); // skip the nullbyte

this.Files.Add(
this.mFiles.Add(
new StuffEntry
{
Origin = this,
Expand All @@ -68,8 +69,8 @@ private void ReadFileTree()

for (int i = 0; i < fileCount; i++)
{
this.Files[i].Offset = baseOffset;
baseOffset += this.Files[i].Length;
this.mFiles[i].Offset = baseOffset;
baseOffset += this.mFiles[i].Length;
}
}

Expand Down
51 changes: 51 additions & 0 deletions Editor/EmbedFS/IEmbedFS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EVEmuTool.EmbedFS
{
public interface IEmbedFS
{
/// <summary>
/// Provides access to all the files inside this container
/// </summary>
public IEnumerable<StuffEntry> Files { get; }

/// <summary>
/// Initializes the file and reads the headers
/// </summary>
public void InitializeFile();

/// <summary>
/// Obtains a MemoryStream of the given path inside the EmbedFS container
/// </summary>
/// <param name="path">File to get contents from</param>
/// <returns>The contents of the file</returns>
public MemoryStream ResolveFile(string path)
{
path = path.ToLower();

// remove the : from the beginning as that's not used
path = path.Replace("res:/", "res/");

StuffEntry entry = this.Files.FirstOrDefault(y => y.FileName.ToLower() == path);
MemoryStream stream = new MemoryStream(entry.Length);

entry.Origin.Export(stream, entry);

stream.Seek(0, SeekOrigin.Begin);

return stream;
}

/// <summary>
/// Exports a file from the container into the given output stream
/// </summary>
/// <param name="output"></param>
/// <param name="entry"></param>
public void Export(Stream output, StuffEntry entry);
}
}
2 changes: 1 addition & 1 deletion Editor/EmbedFS/StuffEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace EVEmuTool.EmbedFS
{
public class StuffEntry
{
public EmbedFSFile Origin { get; init; }
public IEmbedFS Origin { get; init; }
public string FileName { get; init; }
public long Offset { get; set; } = 0;
public int Length { get; init; }
Expand Down
6 changes: 4 additions & 2 deletions Editor/Forms/Components/GR2RenderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public GR2RenderComponent(Root model)
InitializeComponent();

this.mModel = model;
this.mRefreshTimer = new Timer
this.mRefreshTimer = new Timer ()
{
Interval = 16,
Enabled = true
};

this.mRefreshTimer.Tick += (_, _) => { Invalidate(); };
this.mRefreshTimer.Tick += (_, _) => {
Invalidate();
};
}

private void CalculateBoundingBox()
Expand Down
69 changes: 57 additions & 12 deletions Editor/Forms/Components/ModelViewerComponent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using LSLib.Granny.Model;
using EVEmuTool.Trinity.Objects;
using LSLib.Granny;
using LSLib.Granny.Model;
using OpenTK.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -14,27 +18,22 @@ namespace EVEmuTool.Forms.Components
{
public partial class ModelViewerComponent : UserControl
{
private GLControl mRender;
private Control mRender;

public ModelViewerComponent(Root model)
{
InitializeComponent();

this.mRender = new GR2RenderComponent(model);
this.mRender.Dock = DockStyle.Fill;
this.Controls.Add(this.mRender);

this.surfaceCountLabel.Text = model.Meshes.Sum(x => x.PrimaryTopology.Groups.Count).ToString();
this.surfaceTypeLabel.Text = "GR2";
this.vertexCountLabel.Text = model.VertexDatas.Sum(x => x.Vertices.Count).ToString();
this.vertexSizeLabel.Text = "GR2";
// TODO: CALCULATE BOUNDING BOX SIZE
LoadGR2Model(model);
}

public ModelViewerComponent(Trinity.TriModel model)
{
InitializeComponent();
LoadTrinityModel(model);
}

private void LoadTrinityModel(Trinity.TriModel model)
{
this.mRender = new TriRenderComponent(model);
this.mRender.Dock = DockStyle.Fill;
this.Controls.Add(this.mRender);
Expand All @@ -46,5 +45,51 @@ public ModelViewerComponent(Trinity.TriModel model)
this.boundingBoxMinLabel.Text = model.BoundingBox.min.ToString();
this.boundingBoxMaxLabel.Text = model.BoundingBox.max.ToString();
}

private void LoadGR2Model(Root model)
{
this.mRender = new GR2RenderComponent(model);
this.mRender.Dock = DockStyle.Fill;
this.Controls.Add(this.mRender);

this.surfaceCountLabel.Text = model.Meshes.Sum(x => x.PrimaryTopology.Groups.Count).ToString();
this.surfaceTypeLabel.Text = "GR2";
this.vertexCountLabel.Text = model.VertexDatas.Sum(x => x.Vertices.Count).ToString();
this.vertexSizeLabel.Text = "GR2";
// TODO: CALCULATE BOUNDING BOX SIZE
}

public ModelViewerComponent(EveEntity entity)
{
InitializeComponent();

// determine what mesh we're using
string extension = entity.HighDetailMesh.GeometryResPath.Split(".")[^1];
MemoryStream stream = entity.Source.ResolveFile(entity.HighDetailMesh.GeometryResPath);

try
{
if (extension == "tri")
{
LoadTrinityModel(new Trinity.TriModel(stream));
}
else if (extension == "gr2")
{
LoadGR2Model(GR2Utils.LoadModel(stream));
}
else
{
MessageBox.Show("Cannot determine high poly model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch(Exception ex)
{
this.Controls.Add(new Label() { Text = ex.ToString(), Dock = DockStyle.Fill });
}
finally
{
stream.Close();
}
}
}
}
Loading

0 comments on commit 6caee1a

Please sign in to comment.