/// <summary> /// Creates a rigging accessor from a filepath /// </summary> /// <param name="meshFilePath"></param> public SsbhRiggingAccessor(string meshFilePath) { if (!Ssbh.TryParseSsbhFile(meshFilePath, out meshFile)) { throw new FormatException("Given file was not a MESH file"); } }
private static void SerializeMatl(string inputPath, string outputPath, XmlSerializer serializer) { if (outputPath == null) { outputPath = GetFullPathWithoutExtension(inputPath) + "_out.xml"; } Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}..."); if (Ssbh.TryParseSsbhFile(inputPath, out SsbhFile file)) { Matl matlFile = (Matl)file; MaterialLibrary library = MATLtoLibrary(matlFile); using (TextWriter writer = new StringWriter()) { serializer.Serialize(writer, library); string serial = writer.ToString(); File.WriteAllText(outputPath, serial); } } else { Console.WriteLine("Error reading matl file"); } }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out Matl newMaterial)) { Material = newMaterial; } }
public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton) { SBAnimation anim = new SBAnimation(); SsbhFile File; if (Ssbh.TryParseSsbhFile(FileName, out File)) { if (File is Anim animation) { anim.Name = animation.Name; anim.FrameCount = animation.FinalFrameIndex + 1; foreach (var group in animation.Animations) { if (group.Type == AnimType.Visibility) { ReadVisibilityAnimations(animation, group, anim); } if (group.Type == AnimType.Transform) { ReadTransformAnimations(animation, group, anim); } if (group.Type == AnimType.Material) { ReadMaterialAnimations(animation, group, anim); } } } } return(anim); }
private static SBBone[] GetBoneOrderBasedOnReference(SBBone[] targetBones, string sourceSkelPath) { // TODO: This is quite inefficient. if (Ssbh.TryParseSsbhFile(sourceSkelPath, out SsbhFile sourceSkelFile)) { if (sourceSkelFile is Skel sourceSkel) { // Match the existing bone order when possible. // Ignore any bones in the source SKEL not found in targetBones. var sortedResult = new List <SBBone>(); foreach (var sourceBone in sourceSkel.BoneEntries) { var targetBone = targetBones.FirstOrDefault(b => b.Name == sourceBone.Name); if (targetBone != null) { sortedResult.Add(targetBone); } } // Bones not found in the source SKEL should be placed at the end. foreach (var targetBone in targetBones) { if (sourceSkel.BoneEntries.FirstOrDefault(b => b.Name == targetBone.Name) == null) { sortedResult.Add(targetBone); } } return(sortedResult.ToArray()); } } return(targetBones); }
public NumatbNode(string path) : base(path, "material", false) { if (Ssbh.TryParseSsbhFile(AbsolutePath, out Matl newMaterial)) { Material = newMaterial; } }
public NuanmbNode(string path) : base(path, "animation", true) { animation = new Lazy <Anim>(() => { Ssbh.TryParseSsbhFile(AbsolutePath, out Anim anim); return(anim); }); }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile)) { if (ssbhFile is Anim anim) { animation = anim; } } }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile)) { if (ssbhFile is Modl modl) { model = modl; } } }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile)) { if (ssbhFile is Hlpb) { helperBones = (Hlpb)ssbhFile; } } }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile)) { if (ssbhFile is Matl) { Material = (Matl)ssbhFile; } } }
public override void Open() { if (Ssbh.TryParseSsbhFile(AbsolutePath, out var SSBHFile)) { if (SSBHFile is Skel) { skel = (Skel)SSBHFile; } } }
private void Open() { string adjb = Path.GetDirectoryName(AbsolutePath) + "/model.adjb"; if (File.Exists(adjb)) { ExtendedMesh = new Adjb(); ExtendedMesh.Read(adjb); } Ssbh.TryParseSsbhFile(AbsolutePath, out mesh); }
private static void TestFileExport <T>(string input, string output) where T : SsbhFile { Ssbh.TryParseSsbhFile(input, out T file); Ssbh.TrySaveSsbhFile(output, file); if (!Enumerable.SequenceEqual(File.ReadAllBytes(input), File.ReadAllBytes(output))) { Console.WriteLine($"Files {input} and {output} do not match"); } else { Console.WriteLine($"1:1 Export for type {typeof(T).Name}"); } }
public static void Open(string FileName, SBScene Scene) { SsbhFile File; if (Ssbh.TryParseSsbhFile(FileName, out File)) { if (File is Mesh mesh) { if (mesh.VersionMajor != 1 && mesh.VersionMinor != 10) { SBConsole.WriteLine($"Mesh Version {mesh.VersionMajor}.{mesh.VersionMinor} not supported"); return; } if (mesh.UnknownOffset != 0 || mesh.UnknownSize != 0) { SBConsole.WriteLine($"Warning: Unknown Mesh format detected"); } SBUltimateModel model = new SBUltimateModel(); model.Name = mesh.ModelName; model.BoundingSphere = new Vector4(mesh.BoundingSphereX, mesh.BoundingSphereY, mesh.BoundingSphereZ, mesh.BoundingSphereRadius); ((SBSceneSSBH)Scene).Model = model; SsbhVertexAccessor accessor = new SsbhVertexAccessor(mesh); { foreach (var meshObject in mesh.Objects) { SBUltimateMesh sbMesh = new SBUltimateMesh(); sbMesh.EnableAttributes(meshObject); sbMesh.Name = meshObject.Name; sbMesh.ParentBone = meshObject.ParentBoneName; sbMesh.BoundingSphere = new BoundingSphere(meshObject.BoundingSphereX, meshObject.BoundingSphereY, meshObject.BoundingSphereZ, meshObject.BoundingSphereRadius); sbMesh.AABoundingBox = new AABoundingBox(new Vector3(meshObject.MinBoundingBoxX, meshObject.MinBoundingBoxY, meshObject.MinBoundingBoxZ), new Vector3(meshObject.MaxBoundingBoxX, meshObject.MaxBoundingBoxY, meshObject.MaxBoundingBoxZ)); sbMesh.OrientedBoundingBox = new OrientedBoundingBox(new Vector3(meshObject.ObbCenterX, meshObject.ObbCenterY, meshObject.ObbCenterZ), new Vector3(meshObject.ObbSizeX, meshObject.ObbSizeY, meshObject.ObbSizeZ), new Matrix3(meshObject.M11, meshObject.M12, meshObject.M13, meshObject.M21, meshObject.M22, meshObject.M23, meshObject.M31, meshObject.M32, meshObject.M33)); sbMesh.Indices = new List <uint>(accessor.ReadIndices(0, meshObject.IndexCount, meshObject)); sbMesh.Vertices = CreateVertices(mesh, Scene.Skeleton, meshObject, accessor, sbMesh.Indices.ToArray()); model.Meshes.Add(sbMesh); } } } } }
public NuanimData(string path) { if (Ssbh.TryParseSsbhFile(path, out Anim animation)) { if (animation == null) { throw new NullReferenceException("Could not parse file."); } decoder = new SsbhAnimTrackDecoder(animation); Animations = animation.Animations.Select(group => new AnimGroupData(group, decoder)).ToArray(); } }
private static void SerializeMatl(string inputPath, string outputPath) { Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}..."); if (Ssbh.TryParseSsbhFile(inputPath, out Matl matlFile)) { using (var writer = new StringWriter()) { MatlSerialization.SerializeMatl(writer, matlFile); File.WriteAllText(outputPath, writer.ToString()); } } else { Console.WriteLine("Error reading matl file"); } }
public override void Open() { string adjb = Path.GetDirectoryName(AbsolutePath) + "/model.adjb"; if (File.Exists(adjb)) { ExtendedMesh = new Adjb(); ExtendedMesh.Read(adjb); } if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile)) { if (ssbhFile is Mesh) { mesh = (Mesh)ssbhFile; } } }
/// <summary> /// Creates a vertex accessor from given MESH filepath /// </summary> /// <param name="FilePath"></param> public SsbhVertexAccessor(string meshFilePath) { if (Ssbh.TryParseSsbhFile(meshFilePath, out SsbhFile file)) { if (file == null) { throw new FileNotFoundException("File was null"); } if (file is Mesh mesh) { meshFile = mesh; } else { throw new FormatException("Given file was not a MESH file"); } } }
private static void TestFileExport <T>(string inputFile) where T : SsbhFile { Ssbh.TryParseSsbhFile(inputFile, out T file); var stream = new MemoryStream(); using (var exporter = new SsbhExporter(stream)) { exporter.WriteSsbhFile(file); } // Saving the output is only needed if the bytes differ. if (!Enumerable.SequenceEqual(File.ReadAllBytes(inputFile), stream.ToArray())) { Console.WriteLine($"{Path.GetFileName(inputFile)} did not export 1:1"); File.WriteAllBytes($"{inputFile}.out", stream.ToArray()); } else { Console.WriteLine($"1:1 Export for type {typeof(T).Name}"); } }
public static SBSkeleton Open(string FileName, SBScene Scene) { SsbhFile File; if (Ssbh.TryParseSsbhFile(FileName, out File)) { if (File is Skel skel) { var Skeleton = new SBSkeleton(); Scene.Skeleton = Skeleton; Dictionary <int, SBBone> idToBone = new Dictionary <int, SBBone>(); Dictionary <SBBone, int> needParent = new Dictionary <SBBone, int>(); foreach (var b in skel.BoneEntries) { SBBone bone = new SBBone(); bone.Name = b.Name; bone.Type = b.Type; bone.Transform = Skel_to_TKMatrix(skel.Transform[b.Id]); idToBone.Add(b.Id, bone); if (b.ParentId == -1) { Skeleton.AddRoot(bone); } else { needParent.Add(bone, b.ParentId); } } foreach (var v in needParent) { v.Key.Parent = idToBone[v.Value]; } return(Skeleton); } } return(null); }
public override void Open() { Ssbh.TryParseSsbhFile(AbsolutePath, out animation); }
static void Main(string[] args) { /*string[] files = Directory.GetFiles("", "*.numshb*", SearchOption.AllDirectories); * * List<string> ErrorReading = new List<string>(); * List<string> VertexAttributes = new List<string>(); * int Unk8 = 0; * int Bid = 0; * int VersionM = 0; * int Versionm = 0; * foreach(string s in files) * { * ISSBH_File File; * try * { * if (SSBH.TryParseSSBHFile(s, out File)) * { * if (File is MESH) * { * VersionM = Math.Max(VersionM, ((MESH)File).VersionMajor); * Versionm = Math.Max(Versionm, ((MESH)File).VersionMinor); * foreach (MESH_Object o in ((MESH)File).Objects) * { * Unk8 = Math.Max(Unk8, o.Unk8); * Bid = Math.Max(Bid, o.BID); * foreach (MESH_Attribute a in o.Attributes) * { * if (!VertexAttributes.Contains(a.AttributeStrings[0].Name)) * VertexAttributes.Add(a.AttributeStrings[0].Name); * } * } * } * } * } * catch(Exception) * { * ErrorReading.Add(s); * } * * } * * StreamWriter w = new StreamWriter(new FileStream("outmsh.txt", FileMode.Create)); * * w.WriteLine("Unk8 " + Unk8.ToString("X")); * w.WriteLine("M " + VersionM.ToString("X")); * w.WriteLine(", " + Versionm.ToString("X")); * w.WriteLine("BID " + Bid.ToString("X")); * w.WriteLine("Attributes: "); * foreach(string s in VertexAttributes) * { * w.WriteLine(s); * } * * w.WriteLine("Errors: "); * foreach (string s in ErrorReading) * { * w.WriteLine(s); * } * * w.Close();*/ SsbhFile File; if (Ssbh.TryParseSsbhFile(Directory.GetCurrentDirectory() + "//" + args[0], out File)) { if (File is Anim anim) { var decoder = new SsbhAnimTrackDecoder(anim); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace }; string FileName = Directory.GetCurrentDirectory() + "//" + Path.GetDirectoryName(args[0]) + "\\" + Path.GetFileNameWithoutExtension(args[0]) + ".xml"; XmlWriter o = XmlWriter.Create(new FileStream(FileName, FileMode.Create), settings); o.WriteStartDocument(); o.WriteStartElement("NamcoAnimation"); foreach (var an in anim.Animations) { o.WriteStartElement("Animation"); o.WriteAttributeString("Type", an.Type.ToString()); foreach (var node in an.Nodes) { o.WriteStartElement("Node"); o.WriteAttributeString("Name", node.Name); foreach (var track in node.Tracks) { o.WriteStartElement("Track"); o.WriteAttributeString("Name", track.Name); o.WriteAttributeString("FrameCount", track.FrameCount.ToString()); //o.WriteAttributeString("Flags", track.Flags.ToString("X")); var values = decoder.ReadTrack(track); if (values != null && values.Length > 0) { o.WriteAttributeString("Type", values[0].GetType().Name); } for (int i = 0; i < values.Length; i++) { o.WriteStartElement("Key"); o.WriteAttributeString("Frame", (i + 1).ToString()); o.WriteString(values[i].ToString()); o.WriteEndElement(); } o.WriteEndElement(); } o.WriteEndElement(); } o.WriteEndElement(); } o.WriteEndElement(); o.Close(); } } /*ISSBH_File File; * if(SSBH.TryParseSSBHFile("", out File)) * { * ExportFileAsXML("Test.xml", File); * }*/ //Console.ReadLine(); }
public NuhlpbNode(string path) : base(path, "skeleton", false) { Ssbh.TryParseSsbhFile(AbsolutePath, out helperBones); }
public NusktbNode(string path) : base(path, "skeleton", false) { Ssbh.TryParseSsbhFile(AbsolutePath, out skel); Renderable = new Lazy <IRenderable>(() => SkelToRenderable.CreateRSkeleton(skel)); }
public NumdlbNode(string path) : base(path, "model", true) { Ssbh.TryParseSsbhFile(AbsolutePath, out model); Renderable = new Lazy <IRenderable>(() => GetRenderableNode()); }
public override void Open() { Ssbh.TryParseSsbhFile(AbsolutePath, out model); }
/// <summary> /// Load an ultimate mesh from file to the given scene /// </summary> /// <param name="FileName"></param> /// <param name="Scene"></param> public static void Open(string FileName, SBScene Scene) { SsbhFile File; if (Ssbh.TryParseSsbhFile(FileName, out File)) { if (File is Matl matl) { if (matl.MajorVersion != 1 && matl.MinorVersion != 6) { SBConsole.WriteLine($"Warning: Mesh Version {matl.MajorVersion}.{matl.MinorVersion} not supported"); } var MaterialProps = typeof(UltimateMaterial).GetProperties(); // use dictionary for faster lookup Dictionary <string, PropertyInfo> NameToProperty = new Dictionary <string, PropertyInfo>(); foreach (var prop in MaterialProps) { var attrName = prop.Name; if (attrName != null) { NameToProperty.Add(attrName, prop); } } foreach (var entry in matl.Entries) { UltimateMaterial material = new UltimateMaterial(); material.Name = entry.ShaderLabel; material.Label = entry.MaterialLabel; Scene.Materials.Add(material); foreach (var attr in entry.Attributes) { if (NameToProperty.ContainsKey(attr.ParamId.ToString())) { var prop = NameToProperty[attr.ParamId.ToString()]; if (prop.PropertyType == typeof(SBMatAttrib <string>)) { material.SetProperty(attr.ParamId.ToString(), attr.DataObject.ToString()); } else if (prop.PropertyType == typeof(SBMatAttrib <Vector4>)) { material.SetProperty(attr.ParamId.ToString(), MATLVectorToGLVector((MatlAttribute.MatlVector4)attr.DataObject)); } else { material.SetProperty(attr.ParamId.ToString(), attr.DataObject); } } else { switch (attr.ParamId) { case MatlEnums.ParamId.RasterizerState0: material.RasterizerState = (MatlAttribute.MatlRasterizerState)attr.DataObject; break; case MatlEnums.ParamId.BlendState0: material.BlendState = (MatlAttribute.MatlBlendState)attr.DataObject; break; default: //SBConsole.WriteLine("Extra Param: " + attr.ParamID.ToString() + " = " + attr.DataObject.ToString()); material.extraParams.Add(attr.ParamId, attr.DataObject); break; } } } } } } }
public override void Open() { Ssbh.TryParseSsbhFile(AbsolutePath, out helperBones); }