This commit is contained in:
KillzXGaming 2019-10-12 12:47:05 -04:00
commit ca390b977a
4 changed files with 368 additions and 361 deletions

View file

@ -964,22 +964,6 @@ namespace Bfres.Structs
}
public void CreateBoneList(STGenericObject ob, FMDL mdl, bool ForceSkinCount, int ForcedSkinAmount = 4)
{
if (mdl.Skeleton.Node_Array == null)
mdl.Skeleton.Node_Array = new int[0];
string[] nodeArrStrings = new string[mdl.Skeleton.Node_Array.Length];
short[] nodeRigidIndex = new short[mdl.Skeleton.Node_Array.Length];
int CurNode = 0;
foreach (int thing in mdl.Skeleton.Node_Array)
{
nodeArrStrings[CurNode] = mdl.Skeleton.bones[thing].Text;
nodeRigidIndex[CurNode] = mdl.Skeleton.bones[thing].RigidMatrixIndex;
CurNode++;
}
List<string> BonesNotMatched = new List<string>();
if (ForceSkinCount && !ob.HasIndices && VertexSkinCount != 0)
{
var attributeIndex = new FSHP.VertexAttribute();
@ -1009,47 +993,66 @@ namespace Bfres.Structs
bool UseRigidSkinning = ob.VertexSkinCount == 1;
int vtxIndex = 0;
var bones = new Dictionary<string, STBone>();
foreach (var bone in mdl.Skeleton.bones)
{
if (bones.ContainsKey(bone.Text))
{
STConsole.WriteLine($"There are multiple bones named {bone.Text}. Using the first one.", System.Drawing.Color.Red);
}
else
{
bones.Add(bone.Text, bone);
}
}
List<string> BonesNotMatched = new List<string>();
foreach (Vertex v in ob.vertices)
{
List<int> RigidIds = new List<int>();
foreach (string bn in v.boneNames)
{
bool HasMatch = false;
//Generate a list of smooth indicies from the node array
int i = 0;
foreach (var defBn in nodeArrStrings.Select((Value, Index) => new { Value, Index }))
STBone bone;
bool hasMatch = bones.TryGetValue(bn, out bone);
if (hasMatch)
{
if (bn == defBn.Value)
if (!UseRigidSkinning && bone.SmoothMatrixIndex != -1)
{
HasMatch = true;
//Add these after smooth matrices
if (nodeRigidIndex[i] != -1)
if (v.boneIds.Count < ForcedSkinAmount)
{
if (UseRigidSkinning)
RigidIds.Add(nodeRigidIndex[i]);
else
RigidIds.Add(defBn.Index);
STConsole.WriteLine(bone.SmoothMatrixIndex + " mesh " + Text + " bone " + bn);
v.boneIds.Add(bone.SmoothMatrixIndex);
}
}
else if (bone.RigidMatrixIndex != -1)
{
RigidIds.Add(bone.RigidMatrixIndex);
}
else if (bone.SmoothMatrixIndex != -1)
{
STConsole.WriteLine(bone.SmoothMatrixIndex + " mesh " + Text + " bone " + bn);
v.boneIds.Add(bone.SmoothMatrixIndex);
}
else
{
if (v.boneIds.Count < 4)
// last-ditch effort if no rigid or smooth index
var index = Array.FindIndex(mdl.Skeleton.Node_Array, boneIndex => mdl.Skeleton.bones[boneIndex].Text == bn);
if (index != -1)
{
STConsole.WriteLine(defBn.Index + " mesh " + Text + " bone " + bn);
v.boneIds.Add(defBn.Index);
v.boneIds.Add(index);
}
else
{
BonesNotMatched.Add(bn);
STConsole.WriteLine($"Bone {bn} is not skinnable. Vertices will remain unmapped for this bone!", System.Drawing.Color.Red);
}
}
}
i++;
}
if (!HasMatch && !BonesNotMatched.Contains(bn))
else if (!BonesNotMatched.Contains(bn))
{
BonesNotMatched.Add(bn);
STConsole.WriteLine($"No bone matches {bn}. Vertices will remain unmapped for this bone!", System.Drawing.Color.Red);
}
} // else bone not matched but already generated warning for it
}
//Sort smooth bones
@ -1104,15 +1107,9 @@ namespace Bfres.Structs
}
}
}
vtxIndex++;
}
}
nodeArrStrings.Clone();
nodeRigidIndex.Clone();
BonesNotMatched.Clear();
}
public void CreateNewBoundingBoxes()
{
boundingBoxes.Clear();

View file

@ -105,8 +105,7 @@ namespace HedgehogLibrary
PacNodeTree tree = new PacNodeTree();
tree.Read(reader, header3);
var rootNode = tree.RootNode;
LoadTree(rootNode);
LoadTree(tree);
}
else
{
@ -172,8 +171,7 @@ namespace HedgehogLibrary
PacNodeTree tree = new PacNodeTree();
tree.Read(reader, header3);
var rootNode = tree.RootNode;
LoadTree(rootNode, splitName);
LoadTree(tree);
if (header3.SplitCount != 0)
{
@ -308,22 +306,32 @@ namespace HedgehogLibrary
HasSplit = 5
}
public void LoadTree(PacNode node, string fullPath = "")
private void LoadNode(PacNode node, string fullPath)
{
bool IsFile = node.HasData && node.Data != null;
if (!string.IsNullOrEmpty(node.Name))
fullPath += node.Name;
if (IsFile)
if (node.HasData && node.Data is byte[])
{
FileEntry newNode = new FileEntry(node);
newNode.FileName = $"{fullPath}.{newNode.Name}";
files.Add(newNode);
var fileEntry = new FileEntry(node);
fileEntry.FileName = $"{fullPath}.{node.Extension}";
fileEntry.Name = fileEntry.FileName;
files.Add(fileEntry);
}
else if (node.HasData && node.Data is PacNodeTree)
{
LoadTree((PacNodeTree)node.Data);
}
else
{
foreach (var childNode in node.Children)
LoadNode(childNode, fullPath);
}
}
if (node.Name != "Node" && node.Name != null)
fullPath += $"/{node.Name}";
for (int i = 0; i < node.Children.Count; i++)
LoadTree(node.Children[i], fullPath);
public void LoadTree(PacNodeTree nodeTree)
{
LoadNode(nodeTree.RootNode, string.Empty);
}
public class FileEntry : ArchiveFileInfo
@ -331,7 +339,7 @@ namespace HedgehogLibrary
public FileEntry(PacNode node)
{
Name = node.Name;
FileData = node.Data;
FileData = node.Data as byte[];
if (node.Name == null) Name = "File Node";
if (FileData == null) FileData = new byte[0];
}
@ -360,11 +368,12 @@ namespace HedgehogLibrary
{
public HeaderV3 PacFile;
public byte[] Data;
public object Data;
public PacNodeTree ParentTree;
public string Name { get; set; }
public bool HasData { get; set; }
public string Extension { get; set; }
public List<PacNode> Children = new List<PacNode>();
public DataType DataType;
@ -421,8 +430,7 @@ namespace HedgehogLibrary
if (extensionOffset != 0)
{
reader.SeekBegin((long)extensionOffset);
string extension = reader.ReadZeroTerminatedString();
Name += extension;
Extension = reader.ReadZeroTerminatedString();
}
if (dataBlockOffset != 0)
@ -436,7 +444,7 @@ namespace HedgehogLibrary
reader.SeekBegin((long)dataOffset);
PacNodeTree tree = new PacNodeTree();
tree.Read(reader, PacFile);
Children.Add(tree.RootNode);
Data = tree;
}
}
if (childIndicesOffset != 0)

View file

@ -122,6 +122,7 @@ In the event that the tool cannot compile, check references. All the libraries a
- Sage of Mirrors for SuperBMDLib.
- Ambrosia for BTI and TXE support.
- Kuriimu for some IO and file parsing help
- Skyth and Radfordhound for PAC documentation
## Resources
- [Treeview Icons by icons8](https://icons8.com/)

View file

@ -127,6 +127,7 @@
- Syroot for helpful IO extensions and libraies
- GDK Chan for some DDS decode methods
- AboodXD for BNTX texture swizzling
- MelonSpeedruns for logo.</value>
- MelonSpeedruns for logo.
- Skyth and Radfordhound for PAC documentation</value>
</data>
</root>