Example #1
0
        /// <summary>
        /// Adds the SlaveSubsets to the map
        /// </summary>
        /// <param name="map">Contains the MMATs that should be added</param>
        /// <param name="fullmap">Contains a List of all available MMATs</param>
        /// <remarks>The slave MMAT files will be added to the map</remarks>
        protected void AddSlavesSubsets(Hashtable map, Hashtable fullmap)
        {
            Hashtable slavemap = Scenegraph.GetSlaveSubsets(package);
            Hashtable newmap   = new Hashtable();

            int ct = 0;

            foreach (string k in map.Keys)
            {
                if (!fullmap.ContainsKey(k))
                {
                    if (slavemap.ContainsKey(k))
                    {
                        if (map.ContainsKey(k))
                        {
                            ArrayList slaves   = (ArrayList)slavemap[k];
                            Hashtable families = (Hashtable)map[k];
                            foreach (ArrayList list in families.Values)
                            {
                                foreach (SimPe.Plugin.MmatWrapper mmat in list)
                                {
                                    foreach (string subset in slaves)
                                    {
                                        ArrayList slavemmat = this.FindTxtrMatchingMmat(mmat, fullmap, subset);
                                        if (slavemmat != null)
                                        {
                                            Hashtable slaveht = new Hashtable();
                                            slaveht["simpe_slave_loader_" + subset + "-" + ct.ToString()] = slavemmat;
                                            newmap[subset] = slaveht;
                                            ct++;
                                        }
                                    }     //foreach subset
                                }         //foreach mmat
                            }             //foreach list
                        }                 //if (map.ContainsKey(k))
                    }
                }
            }

            Hashtable nmap = new Hashtable();

            foreach (string k in newmap.Keys)
            {
                if (!map.ContainsKey(k))
                {
                    nmap[k] = newmap[k];
                }
            }

            if (newmap.Count > 0)
            {
                AddSlavesSubsets(nmap, fullmap);
            }
            foreach (string k in nmap.Keys)
            {
                map[k] = nmap[k];
            }
        }
Example #2
0
        /// <summary>
        /// Create a new Color Options package
        /// </summary>
        /// <param name="newpkg">The Package the color Option should be added to</param>
        /// <param name="ask">if ask is true, a Dialog will be displayed that lets the
        /// user decide which Subsets to recolor</param>
        public void Create(IPackageFile newpkg)
        {
            WaitingScreen.Wait();
            try
            {
                //this.newpkg = newpkg;

                WaitingScreen.UpdateMessage("Loading available Color Options");
                Hashtable fullmap        = Scenegraph.GetMMATMap(package);
                Hashtable map            = fullmap;
                ArrayList allowedSubsets = Scenegraph.GetRecolorableSubsets(package);

                //Check if the User can select a Subset
                bool userselect = false;
                if (map.Count > 1)
                {
                    userselect = true;
                }
                else
                {
                    if (map.Count == 1)
                    {
                        foreach (string s in map.Keys)
                        {
                            Hashtable ht = (Hashtable)map[s];
                            if (ht.Count > 1)
                            {
                                userselect = true;
                            }
                        }
                    }
                }

                //let the user Select now
                if (userselect)
                {
                    map = SubsetSelectForm.Execute(map, allowedSubsets);
                }



                ProcessMmatMap(newpkg, map, fullmap);
            }
            finally
            {
                WaitingScreen.Stop();
            }
        }
Example #3
0
        /// <summary>
        /// Remove some unreferenced and useless Files
        /// </summary>
        public void CleanUp()
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Cleaning up");
            }
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);             //MMAT
            ArrayList mmats = new ArrayList();

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
                mmat.ProcessData(pfd, package);

                string content = Scenegraph.MmatContent(mmat);

                if (!mmats.Contains(content))
                {
                    string txmtname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt";
                    string cresname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("modelName").StringValue.Trim().ToLower());

                    if (package.FindFile(Hashes.StripHashFromName(txmtname), 0x49596978).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }
                    if (package.FindFile(Hashes.StripHashFromName(cresname), 0xE519C933).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }

                    if (!pfd.MarkForDelete)
                    {
                        mmats.Add(content);
                    }
                }
                else
                {
                    pfd.MarkForDelete = true;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Adds the MMAT Files specified in the map to the new package
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="map">Contains the MMATs that should be added</param>
        /// <param name="fullmap">Contains a List of all available MMATs</param>
        public void ProcessMmatMap(IPackageFile newpkg, Hashtable map, Hashtable fullmap)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Slave Subsets");
            }
            AddSlavesSubsets(map, fullmap);
            Hashtable slaves = Scenegraph.GetSlaveSubsets(package);

            uint   inst   = 0x6000;
            string unique = RenameForm.GetUniqueName(true);

            foreach (Hashtable ht in map.Values)
            {
                foreach (ArrayList list in ht.Values)
                {
                    string family = System.Guid.NewGuid().ToString();
                    if (unique == null)
                    {
                        unique = family;
                    }

                    foreach (SimPe.Plugin.MmatWrapper mmat in list)
                    {
                        mmat.FileDescriptor          = Scenegraph.Clone(mmat.FileDescriptor);
                        mmat.FileDescriptor.Instance = inst++;
                        mmat.FileDescriptor.Group    = Data.MetaData.LOCAL_GROUP;
                        mmat.Family          = family;
                        mmat.DefaultMaterial = false;

                        GenericRcol txmt = mmat.TXMT;
                        GenericRcol txtr = mmat.TXTR;
                        this.AddTxmt(newpkg, mmat, txmt, txtr, unique, slaves);

                        mmat.SynchronizeUserData();
                        newpkg.Add(mmat.FileDescriptor);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Clone a InGane Object based on the relations of the RCOL Files
        /// </summary>
        /// <param name="onlydefault">true if you only want default MMAT Files</param>
        /// <param name="exclude">List of ReferenceNames that should be excluded</param>
        public void RcolModelClone(string[] modelnames, ArrayList exclude)
        {
            if (modelnames == null)
            {
                return;
            }

            Scenegraph.FileExcludeList = Scenegraph.DefaultFileExcludeList;

            SimPe.FileTable.FileIndex.Load();
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Walking Scenegraph");
            }
            Scenegraph sg = new Scenegraph(modelnames, exclude, this.setup);

            if ((Setup.BaseResource & CloneSettings.BaseResourceType.Ref) == CloneSettings.BaseResourceType.Ref)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Reading 3IDR References");
                }
                sg.AddFrom3IDR(package);
            }
            if ((Setup.BaseResource & CloneSettings.BaseResourceType.Xml) == CloneSettings.BaseResourceType.Xml)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Reading XObject Definition");
                }
                sg.AddFromXml(package);
            }
            if (Setup.IncludeWallmask)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for Wallmasks");
                }
                sg.AddWallmasks(modelnames);
            }
            if (Setup.PullResourcesByStr)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for #Str-linked Resources");
                }
                sg.AddStrLinked(package, Setup.StrInstances);
            }
            if (Setup.IncludeAnimationResources)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Scanning for Animations");
                }
                sg.AddAnims(this.GetAnimNames());
            }
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect Slave TXMTs");
            }
            sg.AddSlaveTxmts(sg.GetSlaveSubsets());

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Building Package");
            }
            sg.BuildPackage(package);
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect MMAT Files");
            }
            sg.AddMaterialOverrides(package, setup.OnlyDefaultMmats, true, setup.ThrowExceptions);
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Collect Slave TXMTs");
            }
            Scenegraph.AddSlaveTxmts(package, Scenegraph.GetSlaveSubsets(package));


            if (setup.UpdateMmatGuids)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateMessage("Fixing MMAT Files");
                }
                this.UpdateMMATGuids(this.GetGuidList(), this.GetPrimaryGuid());
            }
        }
Example #6
0
        /// <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
            }
        }
Example #7
0
        /// <summary>
        /// Create a new Color Options package
        /// </summary>
        /// <param name="newpkg">The Package the color Option should be added to</param>
        /// <param name="fkt">The function that ahs to be called wne the Selection should be displayed</param>
        public void Create(IPackageFile newpkg, CreateSelectionCallback fkt)
        {
            WaitingScreen.Wait();
            try
            {
                //this.newpkg = newpkg;

                WaitingScreen.UpdateMessage("Loading available Color Options");
                Hashtable fullmap        = Scenegraph.GetMMATMap(package);
                Hashtable map            = fullmap;
                ArrayList allowedSubsets = Scenegraph.GetRecolorableSubsets(package);

                //Check if the User can select a Subset
                bool userselect = false;
                if (map.Count > 1)
                {
                    userselect = true;
                }
                else
                {
                    if (map.Count == 1)
                    {
                        foreach (string s in map.Keys)
                        {
                            Hashtable ht = (Hashtable)map[s];
                            if (ht.Count > 1)
                            {
                                userselect = true;
                            }
                        }
                    }
                }

                SubsetSelectForm ssf = SubsetSelectForm.Prepare(map, allowedSubsets);
                fkt(ssf, userselect, fullmap);
            }
            finally
            {
                WaitingScreen.Stop();
            }
            return;

            /*string[] subsets = GetSubsets();
             *
             * //let the user Select
             * if ((subsets.Length>1) && (ask))
             * {
             *      Listing l = new Listing();
             *      subsets = l.Execute(subsets);
             * }
             *
             * WaitingScreen.Wait();
             * WaitingScreen.UpdateMessage("Getting slave Subsets");
             * SubsetItem[] subsetsi = GetSlaveSubsets(subsets);
             *
             * WaitingScreen.UpdateMessage("Getting Resource Nodes");
             * ArrayList cres = GetCresNames(subsetsi);
             *
             * WaitingScreen.UpdateMessage("Getting Material Overrides");
             * Hashtable mmats = GetMMATs(subsetsi, cres);
             * ArrayList guids = GetGUIDs();
             *
             * LoadSubSetList(mmats, guids, subsetsi);
             *
             * WaitingScreen.UpdateMessage("Load LIFO Files");
             * GetLifoFiles();
             *
             * WaitingScreen.Stop();*/
        }