예제 #1
0
 /// <summary>
 /// Update all VMeshWire nodes with newVMeshLibId.
 /// </summary>
 /// <param name="crc"></param>
 /// <returns></returns>
 public void UpdateVWireData(TreeNode[] nodes, uint newVMeshLibId)
 {
     foreach (TreeNode node in nodes)
     {
         VWireData data = new VWireData(node.Tag as byte[]);
         data.VMeshLibId = newVMeshLibId;
         node.Tag        = data.GetBytes();
     }
 }
예제 #2
0
        /// <summary>
        /// Find all vmeshwire nodes with the matching flmodelcrc.
        /// </summary>
        /// <param name="crc"></param>
        /// <returns></returns>
        public TreeNode[] FindVWireData(TreeNode root, uint vMeshLibId)
        {
            List <TreeNode> nodes = new List <TreeNode>();

            try
            {
                foreach (TreeNode node in root.Nodes.Find("VWireData", true))
                {
                    try
                    {
                        VWireData data = new VWireData(node.Tag as byte[]);
                        if (data.VMeshLibId == vMeshLibId)
                        {
                            nodes.Add(node);
                        }
                    }
                    catch { }
                }
            }
            catch { }
            return(nodes.ToArray());
        }
예제 #3
0
        /// <summary>
        /// Build the update package in the background.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScanForNonUniqueMeshNodes(object sender, DoWorkEventArgs e)
        {
            matList.Clear();
            nodelist.Clear();
            string folderpath = (string)e.Argument;

            string[] files = System.IO.Directory.GetFiles(folderpath, "*.*", System.IO.SearchOption.AllDirectories);

            int max = files.Length;

            AddLog("Loading mats");
            int curr = 0;

            foreach (string file in files)
            {
                if (bgScanMeshNodesWkr.CancellationPending)
                {
                    return;
                }

                if ((++curr % 100) == 0)
                {
                    AddLog(String.Format("\nProcessing {0}/{1}", curr, max));
                }

                if (file.EndsWith(".mat"))
                {
                    UTFFile  utf  = new UTFFile();
                    TreeNode root = utf.LoadUTFFile(file);
                    LoadMaterials(file, root);
                }
            }

            AddLog("Loading cmp/3db");
            curr = 0;
            foreach (string file in files)
            {
                if (file.EndsWith(".3db") || file.EndsWith(".cmp"))
                {
                    try
                    {
                        List <string> files_with_duplicates = new List <string>();
                        UTFFile       utf  = new UTFFile();
                        TreeNode      root = utf.LoadUTFFile(file);

                        LoadMaterials(file, root);

                        foreach (TreeNode node in root.Nodes.Find("VMeshData", true))
                        {
                            VMeshNodeInfo info = new VMeshNodeInfo();
                            info.file = file;
                            info.name = node.Parent.Name;
                            info.crc  = Utilities.FLModelCRC(info.name);
                            if (nodelist.ContainsKey(info.crc))
                            {
                                AddLog("\nError duplicate node name=" + info.name);
                                AddLog(" file1=" + info.file);
                                AddLog(" file2=" + nodelist[info.crc].file);
                                if (!files_with_duplicates.Contains(info.file))
                                {
                                    files_with_duplicates.Add(info.file);
                                }
                                if (!files_with_duplicates.Contains(nodelist[info.crc].file))
                                {
                                    files_with_duplicates.Add(nodelist[info.crc].file);
                                }
                            }
                            else
                            {
                                nodelist[info.crc] = info;
                            }

                            VMeshData meshData = new VMeshData(node.Tag as byte[]);
                            foreach (VMeshData.TMeshHeader m in meshData.Meshes)
                            {
                                if (matList.ContainsKey(m.MaterialId))
                                {
                                    matList[m.MaterialId].usedBy[file] = node.Name;
                                }
                                else
                                {
                                    AddLog(String.Format("\nError no material entry for name={0} materialID={1}", node.Parent.Parent.Name, m.MaterialId));
                                    AddLog(" file1=" + file);
                                }
                            }
                        }

                        if (root.Nodes.Find("VMeshLibrary", true).Length > 0)
                        {
                            foreach (TreeNode node in root.Nodes.Find("VMeshRef", true))
                            {
                                VMeshRef data = new VMeshRef(node.Tag as byte[]);
                                if (FindVMeshName(root, data.VMeshLibId) == null)
                                {
                                    AddLog("\nError no vmeshlibrary entry");
                                    try { AddLog(" name=" + node.Parent.Parent.Parent.Parent.Name); }
                                    catch { }
                                    AddLog(" file1=" + file);

                                    if (scanOptions == "Open File On Error")
                                    {
                                        parent.LoadUTFFile(file);
                                    }
                                }
                            }

                            foreach (TreeNode node in root.Nodes.Find("VWireData", true))
                            {
                                VWireData data = new VWireData(node.Tag as byte[]);
                                if (FindVMeshName(root, data.VMeshLibId) == null)
                                {
                                    AddLog("\nError no vmeshlibrary entry for name=" + node.Parent.Parent.Name);
                                    AddLog(" file1=" + file);

                                    if (scanOptions == "Open File On Error")
                                    {
                                        OpenEdit(file);
                                    }
                                }
                            }
                        }


                        foreach (string file_to_fix in files_with_duplicates)
                        {
                            if (scanOptions == "Automatically Fix Errors")
                            {
                                FixVMeshNodeNames(file_to_fix);
                            }
                            else if (scanOptions == "Automatically Fix Errors")
                            {
                                DialogResult r = MessageBox.Show(String.Format("Rebuild VMeshData Node Names in {0}?", file_to_fix), "Rebuild?", MessageBoxButtons.YesNoCancel);

                                if (r == DialogResult.Yes)
                                {
                                    FixVMeshNodeNames(file_to_fix);
                                }
                                else if (r == DialogResult.Cancel)
                                {
                                    AddLog("Cancelled");
                                    return;
                                }
                            }
                            else if (scanOptions == "Open File On Error")
                            {
                                parent.LoadUTFFile(file);
                            }
                        }
                    }
                    catch
                    {
                        AddLog("Error loading " + file);
                    }
                }
            }

            foreach (MaterialInfo mi in matList.Values)
            {
                if (mi.errors.Count > 0 && mi.usedBy.Count > 1)
                {
                    AddLog(String.Format("\nError for material={0} id={1} id2={2}", mi.matName, mi.matID, mi.matID2));
                    AddLog(String.Format("Material found in:"));
                    foreach (string file in mi.refs.Keys)
                    {
                        AddLog(" " + file);
                    }
                    AddLog(String.Format("Errors:"));
                    foreach (KeyValuePair <string, string> item in mi.errors)
                    {
                        AddLog(String.Format(" file={0} error={1}", item.Key, item.Value));
                    }
                    AddLog(String.Format("Used By:"));
                    foreach (KeyValuePair <string, string> item in mi.usedBy)
                    {
                        AddLog(String.Format(" model={0} mesh={1}", item.Key, item.Value));
                    }
                }
            }

            // Check for same textures, different names.
            Dictionary <uint, List <MaterialInfo> > textures = new Dictionary <uint, List <MaterialInfo> >();

            foreach (MaterialInfo mi in matList.Values)
            {
                if (!textures.ContainsKey(mi.texCRC))
                {
                    textures[mi.texCRC] = new List <MaterialInfo>();
                }
                textures[mi.texCRC].Add(mi);
            }
            foreach (List <MaterialInfo> ml in textures.Values)
            {
                if (ml.Count > 1)
                {
                    AddLog(String.Format("Same texture/different name:"));
                    foreach (MaterialInfo mi in ml)
                    {
                        AddLog(String.Format(" name={0} texture_file_name={1} matid={2}", mi.matName, mi.texFileName, mi.matID));
                        AddLog(String.Format(" Material found in:"));
                        foreach (string file in mi.refs.Keys)
                        {
                            AddLog("  " + file);
                        }
                    }
                }
            }
        }