Ejemplo n.º 1
0
        public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton)
        {
            SBAnimation anim = new SBAnimation();

            ISSBH_File File;

            if (SSBH.TryParseSSBHFile(FileName, out File))
            {
                if (File is ANIM animation)
                {
                    anim.Name       = animation.Name;
                    anim.FrameCount = animation.FrameCount;

                    foreach (var group in animation.Animations)
                    {
                        if (group.Type == ANIM_TYPE.Visibilty)
                        {
                            ReadVisibilityAnimations(animation, group, anim);
                        }
                        if (group.Type == ANIM_TYPE.Transform)
                        {
                            ReadTransformAnimations(animation, group, anim);
                        }
                        if (group.Type == ANIM_TYPE.Material)
                        {
                            ReadMaterialAnimations(animation, group, anim);
                        }
                    }
                }
            }

            return(anim);
        }
Ejemplo n.º 2
0
        public static void Open(string FileName, SBScene Scene)
        {
            ISSBH_File 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();
                            foreach (var attr in meshObject.Attributes)
                            {
                                foreach (var atstring in attr.AttributeStrings)
                                {
                                    UltimateVertexAttribute at;
                                    if (Enum.TryParse(atstring.Name, out at))
                                    {
                                        sbMesh.EnableAttribute(at);
                                    }
                                }
                            }
                            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.º 3
0
        public static void Open(string FileName, SBScene Scene)
        {
            ISSBH_File 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 / 2);

                    Vector3 min = new Vector3(mesh.MinBoundingBoxX, mesh.MinBoundingBoxY, mesh.MinBoundingBoxZ);
                    Vector3 max = new Vector3(mesh.MaxBoundingBoxX, mesh.MaxBoundingBoxY, mesh.MaxBoundingBoxZ);

                    model.VolumeCenter = (max + min) / 2;
                    model.VolumeSize   = (max - min) / 2;

                    ((SBSceneSSBH)Scene).Model = model;

                    using (SSBHVertexAccessor accessor = new SSBHVertexAccessor(mesh))
                    {
                        foreach (var meshObject in mesh.Objects)
                        {
                            SBUltimateMesh <UltimateVertex> sbMesh = new SBUltimateMesh <UltimateVertex>();
                            foreach (var attr in meshObject.Attributes)
                            {
                                foreach (var atstring in attr.AttributeStrings)
                                {
                                    MESHAttribute at;
                                    if (Enum.TryParse <MESHAttribute>(atstring.Name, out at))
                                    {
                                        //SBConsole.WriteLine("\tLoaded:" + at.ToString());
                                        sbMesh.ExportAttributes.Add(at);
                                    }
                                }
                            }
                            sbMesh.Name           = meshObject.Name;
                            sbMesh.BoundingSphere = new Vector4(meshObject.BoundingSphereX, meshObject.BoundingSphereY, meshObject.BoundingSphereZ, meshObject.BoundingSphereRadius);
                            sbMesh.ParentBone     = meshObject.ParentBoneName;

                            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.º 4
0
 public override void Open(string Path)
 {
     if (SSBH.TryParseSSBHFile(Path, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is MODL)
         {
             _model = (MODL)ssbhFile;
         }
     }
 }
Ejemplo n.º 5
0
 public override void Open()
 {
     if (SSBH.TryParseSSBHFile(AbsolutePath, out ISSBH_File SSBHFile))
     {
         if (SSBHFile is ANIM anim)
         {
             animation = anim;
         }
     }
 }
Ejemplo n.º 6
0
 public override void Open()
 {
     if (SSBH.TryParseSSBHFile(AbsolutePath, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is MATL)
         {
             Material = (MATL)ssbhFile;
         }
     }
 }
Ejemplo n.º 7
0
 public override void Open(string Path)
 {
     if (SSBH.TryParseSSBHFile(Path, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is MESH)
         {
             mesh = (MESH)ssbhFile;
         }
     }
 }
Ejemplo n.º 8
0
 public override void Open()
 {
     if (SSBH.TryParseSSBHFile(AbsolutePath, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is MODL)
         {
             _model = (MODL)ssbhFile;
         }
     }
 }
Ejemplo n.º 9
0
 public override void Open()
 {
     if (SSBH.TryParseSSBHFile(AbsolutePath, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is HLPB)
         {
             helperBones = (HLPB)ssbhFile;
         }
     }
 }
Ejemplo n.º 10
0
 public override void Open(string Path)
 {
     if (SSBH.TryParseSSBHFile(Path, out ISSBH_File ssbhFile))
     {
         if (ssbhFile is MATL)
         {
             Material = (MATL)ssbhFile;
         }
     }
 }
Ejemplo n.º 11
0
        private static void DeserializeXml(string inputPath, string outputPath, XmlSerializer serializer)
        {
            Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}_out.numatb...");
            using (TextReader reader = new StringReader(File.ReadAllText(inputPath)))
            {
                var result = (MaterialLibrary)serializer.Deserialize(reader);

                MATL newmatl = LibraryToMATL(result);

                SSBH.TrySaveSSBHFile(outputPath + "_out.numatb", newmatl);
            }
        }
Ejemplo n.º 12
0
        public override void Open(string Path)
        {
            ISSBH_File SSBHFile;

            if (SSBH.TryParseSSBHFile(Path, out SSBHFile))
            {
                if (SSBHFile is ANIM anim)
                {
                    animation = anim;
                }
            }
        }
Ejemplo n.º 13
0
        public override void Open()
        {
            ISSBH_File SSBHFile;

            if (SSBH.TryParseSSBHFile(AbsolutePath, out SSBHFile))
            {
                if (SSBHFile is SKEL)
                {
                    _skel = (SKEL)SSBHFile;
                }
            }
        }
Ejemplo n.º 14
0
        public override void Open(string Path)
        {
            ISSBH_File SSBHFile;

            if (SSBH.TryParseSSBHFile(Path, out SSBHFile))
            {
                if (SSBHFile is SKEL)
                {
                    _skel = (SKEL)SSBHFile;
                }
            }
        }
Ejemplo n.º 15
0
        public static void Save(string FileName, SBScene Scene)
        {
            var Skeleton = Scene.Skeleton;

            var skelFile = new SKEL();

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

            List <SKEL_BoneEntry> BoneEntries        = new List <SKEL_BoneEntry>();
            List <SKEL_Matrix>    Transforms         = new List <SKEL_Matrix>();
            List <SKEL_Matrix>    InvTransforms      = new List <SKEL_Matrix>();
            List <SKEL_Matrix>    WorldTransforms    = new List <SKEL_Matrix>();
            List <SKEL_Matrix>    InvWorldTransforms = new List <SKEL_Matrix>();

            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 SKEL_BoneEntry();
                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.º 16
0
        public override void Open()
        {
            string ADJB = System.IO.Path.GetDirectoryName(AbsolutePath) + "/model.adjb";

            System.Console.WriteLine(ADJB);
            if (File.Exists(ADJB))
            {
                ExtendedMesh = new ADJB();
                ExtendedMesh.Read(ADJB);
            }

            if (SSBH.TryParseSSBHFile(AbsolutePath, out ISSBH_File ssbhFile))
            {
                if (ssbhFile is MESH)
                {
                    mesh = (MESH)ssbhFile;
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a vertex accessor from given MESH filepath
        /// </summary>
        /// <param name="FilePath"></param>
        public SSBHVertexAccessor(string meshFilePath)
        {
            if (SSBH.TryParseSSBHFile(meshFilePath, out ISSBH_File 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.º 18
0
        private static void SerializeMatl(string inputPath, string outputPath, XmlSerializer serializer)
        {
            Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}_out.xml...");
            if (SSBH.TryParseSSBHFile(inputPath, out ISSBH_File 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 + "_out.xml", serial);
                }
            }
            else
            {
                Console.WriteLine("Error reading matl file");
            }
        }
Ejemplo n.º 19
0
        public static SBSkeleton Open(string FileName, SBScene Scene)
        {
            ISSBH_File 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.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="FileName"></param>
        public override void ExportSceneToFile(string FileName)
        {
            if (Model == null)
            {
                return;
            }

            string name       = Path.GetDirectoryName(FileName) + "/" + Path.GetFileNameWithoutExtension(FileName);
            string simpleName = Path.GetFileNameWithoutExtension(FileName);

            SBConsole.WriteLine("Creating MODL...");
            var modl = MODL_Loader.CreateMODLFile((SBUltimateModel)Model);

            modl.ModelFileName     = simpleName;
            modl.SkeletonFileName  = $"{simpleName}.nusktb";
            modl.MeshString        = $"{simpleName}.numshb";
            modl.UnknownFileName   = "";
            modl.MaterialFileNames = new MODL_MaterialName[] { new MODL_MaterialName()
                                                               {
                                                                   MaterialFileName = $"{simpleName}.numatb"
                                                               } };
            SBConsole.WriteLine("Done");
            SSBH.TrySaveSSBHFile(FileName, modl);

            SBConsole.WriteLine($"Creating MESH... {name}.numshb");
            var mesh = MESH_Loader.CreateMESH((SBUltimateModel)Model, (SBSkeleton)Skeleton);

            SBConsole.WriteLine("Done");
            SSBH.TrySaveSSBHFile(name + ".numshb", mesh);

            SBConsole.WriteLine($"Creating SKEL.. {name}.nusktb");
            SKEL_Loader.Save(name + ".nusktb", this);
            SBConsole.WriteLine("Done");

            //SBConsole.WriteLine("Creating MATL...");
        }
Ejemplo n.º 21
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 == ANIM_TYPE.Transform)
                                {
                                    track.Flags |= (int)ANIM_TRACKFLAGS.ConstTransform;
                                }
                                else
                                {
                                    track.Flags |= (int)ANIM_TRACKFLAGS.Constant;
                                }

                                track.FrameCount = 1;

                                WriteValues(w, (int)track.Flags, values);
                            }
                            else
                            {
                                if (WriteValues(w, (int)track.Flags, values))
                                {
                                    track.Flags |= (int)ANIM_TRACKFLAGS.Compressed;
                                }
                                else
                                {
                                    track.Flags |= (int)ANIM_TRACKFLAGS.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.º 22
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();*/

            ISSBH_File 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();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Loads the scene from a NUMDLB file
        /// </summary>
        /// <param name="FileName"></param>
        public override void LoadFromFile(string FileName)
        {
            string folderPath = Path.GetDirectoryName(FileName);

            ISSBH_File File;

            if (!SSBH.TryParseSSBHFile(FileName, out File))
            {
                return;
            }

            MODL modl = (MODL)File;

            string meshPath = "";
            string skelPath = "";
            string matlPath = "";

            foreach (string file in Directory.EnumerateFiles(folderPath))
            {
                // load textures
                if (file.EndsWith(".nutexb"))
                {
                    NUTEX_Loader.Open(file, this);
                }

                string fileName = Path.GetFileName(file);
                if (fileName.Equals(modl.SkeletonFileName))
                {
                    skelPath = file;
                }
                if (fileName.Equals(modl.MeshString))
                {
                    meshPath = file;
                }
                if (fileName.Equals(modl.MaterialFileNames[0].MaterialFileName))
                {
                    matlPath = file;
                }
            }
            // import order Skeleton+Textures->Materials->Mesh
            // mesh needs to be loaded after skeleton
            if (skelPath != "")
            {
                SBConsole.WriteLine($"Importing skeleton: {Path.GetFileName(skelPath)}");
                SKEL_Loader.Open(skelPath, this);
            }
            if (matlPath != "")
            {
                SBConsole.WriteLine($"Importing materials: {Path.GetFileName(matlPath)}");
                MATL_Loader.Open(matlPath, this);
            }
            if (meshPath != "")
            {
                SBConsole.WriteLine($"Importing mesh: {Path.GetFileName(meshPath)}");
                MESH_Loader.Open(meshPath, this);

                // set materials
                foreach (var entry in modl.ModelEntries)
                {
                    UltimateMaterial currentMaterial = null;
                    foreach (UltimateMaterial matentry in Materials)
                    {
                        if (matentry.Label.Equals(entry.MaterialName))
                        {
                            currentMaterial = matentry;
                            break;
                        }
                    }
                    if (currentMaterial == null)
                    {
                        continue;
                    }

                    int    subindex = 0;
                    string prevMesh = "";
                    if (Model != null)
                    {
                        foreach (var mesh in Model.Meshes)
                        {
                            if (prevMesh.Equals(mesh.Name))
                            {
                                subindex++;
                            }
                            else
                            {
                                subindex = 0;
                            }
                            prevMesh = mesh.Name;
                            if (subindex == entry.SubIndex && mesh.Name.Equals(entry.MeshName))
                            {
                                mesh.Material = currentMaterial;
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
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)
        {
            ISSBH_File 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.MaterialName;
                        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.º 25
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();*/

            ISSBH_File File;

            if (SSBH.TryParseSSBHFile("", out File))
            {
                ExportFileAsXML("Test.xml", File);
            }
            //Console.ReadLine();
        }