Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions HSDRawViewer/ContextMenus/JOBJContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ public JOBJContextMenu() : base()
};
Items.Add(Import);

ToolStripMenuItem ImportSheet = new ToolStripMenuItem("Import Model Info Sheet From File");
ImportSheet.Click += (sender, args) =>
{
if (MainForm.SelectedDataNode.Accessor is HSD_JOBJ root)
{
MainForm.SelectedDataNode.Collapse();
var f = Tools.FileIO.OpenFile("JSON (*.json)|*.json");
if (f != null)
{
ModelInfoSheet infoSheet = ModelInfoSheet.Import(f);
infoSheet.updateJobj(root);
}
}
};
Items.Add(ImportSheet);

ToolStripMenuItem GenerateMatAnimJoint = new ToolStripMenuItem("Generate and Export MatAnimJoint Structure");
GenerateMatAnimJoint.Click += (sender, args) =>
Expand Down
59 changes: 58 additions & 1 deletion HSDRawViewer/Converters/ModelInfoSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using System.Windows.Forms;

namespace HSDRawViewer.Converters
{
Expand All @@ -30,7 +31,12 @@ public class ModelInfoSheet
{
private HashSet<byte[]> textures = new HashSet<byte[]>();

public List<MI_Object> Objects { get; set; } = new List<MI_Object>();
public List<MI_Object> Objects { get; set; } = new List<MI_Object>();

public ModelInfoSheet()
{
// Necessary in order to deserialize
}

/// <summary>
///
Expand Down Expand Up @@ -88,6 +94,47 @@ private void ProcessTexture(HSD_TOBJ texture)
}
}

public void updateJobj(HSD_JOBJ jobj)
{
int sheetSize = Objects.Count;
int nodeSize = 0;
foreach (var x in jobj.TreeList)
{
if (x.Dobj != null)
{
nodeSize += x.Dobj.List.Count;
}
}
if (sheetSize != nodeSize)
{
string message = "The model info sheet you are importing has {0} objects but the current model has {1}.";
MessageBox.Show(String.Format(message, sheetSize, nodeSize), "Invalid Model Info Sheet");
return;
}

int objectIndex = 0;
foreach (var j in jobj.TreeList)
{
if (j.Dobj != null)
{
foreach (var dobj in j.Dobj.List)
{
MI_Object current = this.Objects[objectIndex];

var mobj = dobj.Mobj;
var mat = mobj.Material;

mat.AmbientColor = System.Drawing.Color.FromArgb(Convert.ToInt32(current.Ambient, 16));
mat.DiffuseColor = System.Drawing.Color.FromArgb(Convert.ToInt32(current.Diffuse, 16));
mat.SpecularColor = System.Drawing.Color.FromArgb(Convert.ToInt32(current.Specular, 16));
mat.Shininess = current.Shininess;
mat.Alpha = current.Alpha;
objectIndex++;
}
}
}
}

/// <summary>
///
/// </summary>
Expand All @@ -98,6 +145,16 @@ public void Export(string filepath)
File.WriteAllText(filepath, json);
}

/// <summary>
///
/// </summary>
/// <param name="filepath"></param>
public static ModelInfoSheet Import(string filepath)
{
string json = File.ReadAllText(filepath);
return JsonSerializer.Deserialize<ModelInfoSheet>(json);
}

/// <summary>
///
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions HSDRawViewer/GUI/Controls/JObjEditor/JObjEditorNew.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions HSDRawViewer/GUI/Controls/JObjEditor/JObjEditorNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,18 @@ private void importModelFromFileToolStripMenuItem_Click(object sender, EventArgs
SetJOBJ(_root);
}

private void importModelInfoSheetToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearAnimation();
var f = Tools.FileIO.OpenFile("JSON (*.json)|*.json");
if (f != null)
{
ModelInfoSheet infoSheet = ModelInfoSheet.Import(f);
infoSheet.updateJobj(_root);
}
SetJOBJ(_root);
}

/// <summary>
///
/// </summary>
Expand Down