SimPe.Interfaces.Scenegraph.IScenegraphItem BuildMmat(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, SimPe.Interfaces.Files.IPackageFile pkg, GraphItem gi) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(pfd, pkg); gi.Text = mmat.GetSaveItem("subsetName").StringValue + " (family=" + mmat.GetSaveItem("family").StringValue + ", objectStateIndex=" + Helper.HexString(mmat.GetSaveItem("objectStateIndex").UIntegerValue) + ", materialStateFlags=" + Helper.HexString(mmat.GetSaveItem("materialStateFlags").UIntegerValue) + ", objectGuid=" + Helper.HexString(mmat.GetSaveItem("objectGUID").UIntegerValue) + ")"; gi.Properties["Default"].Value = mmat.GetSaveItem("defaultMaterial").BooleanValue.ToString(); gi.Properties["cres"].Value = mmat.GetSaveItem("modelName").StringValue.ToString(); gi.Properties["txmt"].Value = mmat.GetSaveItem("name").StringValue.ToString(); gi.Size = new Size(gi.Size.Width, 96); gi.Tag = mmat; return(mmat); }
/// <summary> /// Return al Hashtable (subset) of Hashtable (family) of ArrayLists (mmat Files) specifiying all available Material Overrides /// </summary> /// <param name="pkg">The package you want to scan</param> /// <returns>The Hashtable</returns> public static Hashtable GetMMATMap(SimPe.Interfaces.Files.IPackageFile pkg) { if (pkg == null) { return(new Hashtable()); } SimPe.Interfaces.Files.IPackedFileDescriptor[] mmats = pkg.FindFiles(Data.MetaData.MMAT); Hashtable ht = new Hashtable(); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in mmats) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(pfd, pkg); string subset = mmat.GetSaveItem("subsetName").StringValue.Trim().ToLower(); string family = mmat.GetSaveItem("family").StringValue; //get the available families Hashtable families = null; if (!ht.ContainsKey(subset)) { families = new Hashtable(); ht[subset] = families; } else { families = (Hashtable)ht[subset]; } //get listing of the current Family ArrayList list = null; if (!families.ContainsKey(family)) { list = new ArrayList(); families[family] = list; } else { list = (ArrayList)families[family]; } //add the MMAT File list.Add(mmat); } return(ht); }
/// <summary> /// Adds all know MMATs that reference one of the models; /// </summary> /// <param name="pkg"></param> /// <param name="onlydefault">true, if you only want to read default MMATS</param> /// <param name="subitems">true, if you also want to load MMAT Files that reference Files ouside the passed package</param> /// <param name="exception">true if you want to throw an exception when something goes wrong</param> /// <returns>List of all referenced GUIDs</returns> public void AddMaterialOverrides(SimPe.Interfaces.Files.IPackageFile pkg, bool onlydefault, bool subitems, bool exception) { LoadCache(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.MMAT, true); ArrayList itemlist = new ArrayList(); ArrayList contentlist = new ArrayList(); ArrayList defaultfam = new ArrayList(); ArrayList guids = new ArrayList(); //create an UpTo Date Cache bool chgcache = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { string pname = item.Package.FileName.Trim().ToLower(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] citems = cachefile.FileIndex.FindFile(item.FileDescriptor, item.Package); bool have = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem citem in citems) { if (citem.FileDescriptor.Filename == pname) { have = true; break; } } //Not in cache, so add that File if (!have) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item.FileDescriptor, item.Package); cachefile.AddItem(mmat); chgcache = true; } } if (chgcache) { SaveCache(); } //collect a list of Default Material Override family values first if (onlydefault) { foreach (SimPe.Cache.MMATCacheItem mci in (SimPe.Cache.CacheItems)cachefile.DefaultMap[true]) { defaultfam.Add(mci.Family); } } //now do the real collect foreach (string k in modelnames) { SimPe.Cache.CacheItems list = (SimPe.Cache.CacheItems)cachefile.ModelMap[k.Trim().ToLower()]; if (list != null) { foreach (SimPe.Cache.MMATCacheItem mci in list) { if (onlydefault && !defaultfam.Contains(mci.Family)) { continue; } string name = k; items = FileTable.FileIndex.FindFile(mci.FileDescriptor, null); foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { if (itemlist.Contains(item)) { continue; } itemlist.Add(item); SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item); string content = Scenegraph.MmatContent(mmat); content = content.Trim().ToLower(); if (!contentlist.Contains(content)) { mmat.FileDescriptor = Clone(mmat.FileDescriptor); mmat.SynchronizeUserData(); if (subitems) { if (pkg.FindFile(mmat.FileDescriptor) == null) { pkg.Add(mmat.FileDescriptor); } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem txmtitem = SimPe.FileTable.FileIndex.FindFileByName(mmat.GetSaveItem("name").StringValue + "_txmt", Data.MetaData.TXMT, Data.MetaData.LOCAL_GROUP, true); if (txmtitem != null) { try { SimPe.Plugin.GenericRcol sub = new GenericRcol(null, false); sub.ProcessData(txmtitem.FileDescriptor, txmtitem.Package, false); ArrayList newfiles = new ArrayList(); LoadReferenced(this.modelnames, this.exclude, newfiles, itemlist, sub, txmtitem, true, setup); BuildPackage(newfiles, pkg); } catch (Exception ex) { Helper.ExceptionMessage("", new CorruptedFileException(txmtitem, ex)); } } else { continue; //if (exception) throw new ScenegraphException("Invalid Scenegraph Link", new ScenegraphException("Unable to find Referenced File "+name+"_txmt.", mmat.FileDescriptor), mmat.FileDescriptor); } } else { if (pkg.FindFile(mmat.FileDescriptor) == null) { string txmtname = mmat.GetSaveItem("name").StringValue.Trim(); if (!txmtname.EndsWith("_txmt")) { txmtname += "_txmt"; } if (pkg.FindFile(txmtname, Data.MetaData.TXMT).Length > 0) { pkg.Add(mmat.FileDescriptor); } } } contentlist.Add(content); } //if contentlist } //foreach item } //foreach MMATCacheItem } // if list !=null } }