Ejemplo n.º 1
0
 public NumatbNode(string path) : base(path, "material", false)
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out Matl newMaterial))
     {
         Material = newMaterial;
     }
 }
Ejemplo n.º 2
0
 /// <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");
     }
 }
Ejemplo n.º 3
0
        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");
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out Matl newMaterial))
     {
         Material = newMaterial;
     }
 }
Ejemplo n.º 7
0
 public NuanmbNode(string path) : base(path, "animation", true)
 {
     animation = new Lazy <Anim>(() =>
     {
         Ssbh.TryParseSsbhFile(AbsolutePath, out Anim anim);
         return(anim);
     });
 }
Ejemplo n.º 8
0
 private static void DeserializeXml(string inputPath, string outputPath)
 {
     Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}.numatb...");
     using (var reader = new StringReader(File.ReadAllText(inputPath)))
     {
         var matl = MatlSerialization.DeserializeMatl(reader);
         Ssbh.TrySaveSsbhFile(outputPath, matl);
     }
 }
Ejemplo n.º 9
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile))
     {
         if (ssbhFile is Anim anim)
         {
             animation = anim;
         }
     }
 }
Ejemplo n.º 10
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile))
     {
         if (ssbhFile is Hlpb)
         {
             helperBones = (Hlpb)ssbhFile;
         }
     }
 }
Ejemplo n.º 11
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out var SSBHFile))
     {
         if (SSBHFile is Skel)
         {
             skel = (Skel)SSBHFile;
         }
     }
 }
Ejemplo n.º 12
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile))
     {
         if (ssbhFile is Matl)
         {
             Material = (Matl)ssbhFile;
         }
     }
 }
Ejemplo n.º 13
0
 public override void Open()
 {
     if (Ssbh.TryParseSsbhFile(AbsolutePath, out SsbhFile ssbhFile))
     {
         if (ssbhFile is Modl modl)
         {
             model = modl;
         }
     }
 }
Ejemplo n.º 14
0
        public static void Save(string fileName, SBScene scene, string sourceSkelPath)
        {
            var Skeleton = scene.Skeleton;

            var skelFile = new Skel();

            skelFile.MajorVersion = 1;
            skelFile.MinorVersion = 0;

            List <SkelBoneEntry> BoneEntries        = new List <SkelBoneEntry>();
            List <Matrix4x4>     Transforms         = new List <Matrix4x4>();
            List <Matrix4x4>     InvTransforms      = new List <Matrix4x4>();
            List <Matrix4x4>     WorldTransforms    = new List <Matrix4x4>();
            List <Matrix4x4>     InvWorldTransforms = new List <Matrix4x4>();

            // Attempt to match bone order to an existing SKEL if possible.
            var sortedBones = Skeleton.Bones;

            if (!string.IsNullOrEmpty(sourceSkelPath))
            {
                sortedBones = GetBoneOrderBasedOnReference(Skeleton.Bones, sourceSkelPath);
            }

            short index = 0;

            foreach (var bone in sortedBones)
            {
                var boneEntry = new SkelBoneEntry
                {
                    Name = bone.Name,
                    Type = bone.Type,
                    Id   = index++
                };
                boneEntry.Type     = 1;
                boneEntry.ParentId = -1;
                if (bone.Parent != null)
                {
                    boneEntry.ParentId = (short)Array.IndexOf(sortedBones, bone.Parent);
                }
                BoneEntries.Add(boneEntry);

                Transforms.Add(bone.Transform.ToSsbh());
                InvTransforms.Add(bone.Transform.Inverted().ToSsbh());
                WorldTransforms.Add(bone.WorldTransform.ToSsbh());
                InvWorldTransforms.Add(bone.InvWorldTransform.ToSsbh());
            }

            skelFile.BoneEntries       = BoneEntries.ToArray();
            skelFile.Transform         = Transforms.ToArray();
            skelFile.InvTransform      = InvTransforms.ToArray();
            skelFile.WorldTransform    = WorldTransforms.ToArray();
            skelFile.InvWorldTransform = InvWorldTransforms.ToArray();

            Ssbh.TrySaveSsbhFile(fileName, skelFile);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        private static void DeserializeXml(string inputPath, string outputPath, XmlSerializer serializer)
        {
            Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}.numatb...");
            using (TextReader reader = new StringReader(File.ReadAllText(inputPath)))
            {
                var result = (MaterialLibrary)serializer.Deserialize(reader);

                Matl newmatl = LibraryToMATL(result);

                Ssbh.TrySaveSsbhFile(outputPath, newmatl);
            }
        }
Ejemplo n.º 17
0
 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}");
     }
 }
Ejemplo n.º 18
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        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();
            }
        }
Ejemplo n.º 20
0
        public static void Save(string FileName, SBScene Scene)
        {
            var Skeleton = Scene.Skeleton;

            var skelFile = new Skel();

            skelFile.MajorVersion = 1;
            skelFile.MinorVersion = 0;

            List <SkelBoneEntry> BoneEntries        = new List <SkelBoneEntry>();
            List <SkelMatrix>    Transforms         = new List <SkelMatrix>();
            List <SkelMatrix>    InvTransforms      = new List <SkelMatrix>();
            List <SkelMatrix>    WorldTransforms    = new List <SkelMatrix>();
            List <SkelMatrix>    InvWorldTransforms = new List <SkelMatrix>();

            short index = 0;
            Dictionary <SBBone, short> BoneToIndex = new Dictionary <SBBone, short>();
            var OrderedBones = SortBones(Skeleton.Bones);

            foreach (var bone in OrderedBones)
            {
                BoneToIndex.Add(bone, index);
                var boneentry = new SkelBoneEntry();
                boneentry.Name     = bone.Name;
                boneentry.Type     = bone.Type;
                boneentry.Id       = index++;
                boneentry.Type     = 1;
                boneentry.ParentId = -1;
                if (bone.Parent != null)// && BoneToIndex.ContainsKey(bone.Parent))
                {
                    boneentry.ParentId = (short)OrderedBones.IndexOf(bone.Parent);
                }
                BoneEntries.Add(boneentry);

                Transforms.Add(TKMatrix_to_Skel(bone.Transform));
                InvTransforms.Add(TKMatrix_to_Skel(bone.Transform.Inverted()));
                WorldTransforms.Add(TKMatrix_to_Skel(bone.WorldTransform));
                InvWorldTransforms.Add(TKMatrix_to_Skel(bone.InvWorldTransform));
            }

            skelFile.BoneEntries       = BoneEntries.ToArray();
            skelFile.Transform         = Transforms.ToArray();
            skelFile.InvTransform      = InvTransforms.ToArray();
            skelFile.WorldTransform    = WorldTransforms.ToArray();
            skelFile.InvWorldTransform = InvWorldTransforms.ToArray();

            Ssbh.TrySaveSsbhFile(FileName, skelFile);
        }
Ejemplo n.º 21
0
 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");
     }
 }
Ejemplo n.º 22
0
        public void SaveMatl(string outputPath)
        {
            // TODO: This probably doesn't need to be part of the viewmodel.
            if (rnumdl == null || rnumdl.Material == null)
            {
                return;
            }

            foreach (var entry in rnumdl.Material.Entries)
            {
                // TODO: This only checks materials that are already assigned to a mesh.
                if (!rnumdl.MaterialByName.ContainsKey(entry.MaterialLabel))
                {
                    continue;
                }

                var material = rnumdl.MaterialByName[entry.MaterialLabel];
                foreach (var attribute in entry.Attributes)
                {
                    // The data type isn't known, so check each type.
                    if (material.floatByParamId.ContainsKey(attribute.ParamId))
                    {
                        attribute.DataObject = material.floatByParamId[attribute.ParamId];
                    }
                    else if (material.boolByParamId.ContainsKey(attribute.ParamId))
                    {
                        attribute.DataObject = material.boolByParamId[attribute.ParamId];
                    }
                    else if (material.vec4ByParamId.ContainsKey(attribute.ParamId))
                    {
                        var value = material.vec4ByParamId[attribute.ParamId];
                        attribute.DataObject = new MatlAttribute.MatlVector4 {
                            X = value.X, Y = value.Y, Z = value.Z, W = value.W
                        };
                    }
                    else if (material.textureNameByParamId.ContainsKey(attribute.ParamId))
                    {
                        attribute.DataObject = new MatlAttribute.MatlString {
                            Text = material.textureNameByParamId[attribute.ParamId]
                        };
                    }
                }
            }

            Ssbh.TrySaveSsbhFile(outputPath, rnumdl.Material);
        }
Ejemplo n.º 23
0
        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;
                }
            }
        }
Ejemplo n.º 24
0
        /// <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");
                }
            }
        }
Ejemplo n.º 25
0
        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}");
            }
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Generates and saves the new ANIM file
        /// </summary>
        /// <param name="fname"></param>
        public void Save(string fname)
        {
            // Prep Anim File
            animFile.Name       = Path.GetFileName(fname);
            animFile.Animations = groups.ToArray();

            // Create Buffer
            MemoryStream buffer = new MemoryStream();

            using (BinaryWriter w = new BinaryWriter(buffer))
            {
                foreach (var animation in animFile.Animations)
                {
                    foreach (var node in animation.Nodes)
                    {
                        foreach (var track in node.Tracks) // TODO: these nodes need to be in ordinal order
                        {
                            var values = trackToValues[track];

                            track.DataOffset = (uint)buffer.Position;

                            track.FrameCount = (uint)values.Count;

                            if (values.Count > 0)
                            {
                                track.Flags |= (uint)GetTrackTypeFlag(values[0]);
                            }

                            if (values.Count == 1)
                            {
                                if (animation.Type == AnimType.Transform)
                                {
                                    track.Flags |= (int)AnimTrackFlags.ConstTransform;
                                }
                                else
                                {
                                    track.Flags |= (int)AnimTrackFlags.Constant;
                                }

                                track.FrameCount = 1;

                                WriteValues(w, (int)track.Flags, values);
                            }
                            else
                            {
                                if (WriteValues(w, (int)track.Flags, values))
                                {
                                    track.Flags |= (int)AnimTrackFlags.Compressed;
                                }
                                else
                                {
                                    track.Flags |= (int)AnimTrackFlags.Direct;
                                }
                            }

                            track.DataSize = (uint)(buffer.Position - track.DataOffset);

                            int padding = (int)(0x40 - (w.BaseStream.Position % 0x40));
                            w.Write(new byte[padding]);

                            //Console.WriteLine(w.BaseStream.Position.ToString("X") + " " + values.Count + " " + track.Flags.ToString("X"));
                        }
                    }
                }
            }

            animFile.Buffer = buffer.ToArray();
            buffer.Close();
            buffer.Dispose();

            Ssbh.TrySaveSsbhFile(fname, animFile);
        }
Ejemplo n.º 28
0
        /// <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;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
 public NumdlbNode(string path) : base(path, "model", true)
 {
     Ssbh.TryParseSsbhFile(AbsolutePath, out model);
     Renderable = new Lazy <IRenderable>(() => GetRenderableNode());
 }
Ejemplo n.º 30
0
        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();
        }