Example #1
0
        /// <summary>
        /// Returns the first MMAT file that links to the same Texture File as the passed mmat.
        /// </summary>
        /// <param name="fullmap"></param>
        /// <param name="subset"></param>
        /// <returns></returns>
        /// <param name="mmat">If none was found, the first MMAT will be returned. Can also be null if no MMATS are available</param>
        protected ArrayList FindTxtrMatchingMmat(SimPe.Plugin.MmatWrapper mmat, Hashtable fullmap, string subset)
        {
            ArrayList ret = null;


            if ((fullmap.ContainsKey(subset)) && mmat.TXTR != null)
            {
                Hashtable ht = (Hashtable)fullmap[subset];
                foreach (ArrayList list in ht.Values)
                {
                    foreach (SimPe.Plugin.MmatWrapper cur in list)
                    {
                        if (ret == null)
                        {
                            ret = list;
                        }
                        if (cur.TXTR == null)
                        {
                            continue;
                        }

                        if (mmat.TXTR.FileName == cur.TXTR.FileName)
                        {
                            return(list);
                        }
                    }
                }
            }
            return(ret);
        }
Example #2
0
        public void GraphItemClick(object sender, EventArgs e)
        {
            GraphItem gi = (GraphItem)sender;
            Hashtable ht = null;

            llopen.Enabled = false;
            selpfd         = null;
            if (gi.Tag.GetType() == typeof(string))
            {
                this.tbflname.Text = (string)gi.Tag;
                this.cbrefnames.Items.Clear();
                cbrefnames.Text = "";
            }
            else if (gi.Tag.GetType() == typeof(GenericRcol))
            {
                GenericRcol rcol = (GenericRcol)gi.Tag;
                this.tbflname.Text = rcol.FileName;
                this.cbrefnames.Items.Clear();
                cbrefnames.Text = "";
                ht = rcol.ReferenceChains;

                if (rcol.Package.FileName == open_pkg.FileName)
                {
                    selpfd = rcol.FileDescriptor;
                }
            }
            else if (gi.Tag.GetType() == typeof(SimPe.Plugin.MmatWrapper))
            {
                SimPe.Plugin.MmatWrapper mmat = (SimPe.Plugin.MmatWrapper)gi.Tag;
                this.tbflname.Text = mmat.SubsetName;
                this.cbrefnames.Items.Clear();
                cbrefnames.Text = "";
                ht = mmat.ReferenceChains;

                if (mmat.Package.FileName == open_pkg.FileName)
                {
                    selpfd = mmat.FileDescriptor;
                }
            }

            llopen.Enabled = (selpfd != null);

            if (ht != null)
            {
                foreach (string s in ht.Keys)
                {
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in (ArrayList)ht[s])
                    {
                        this.cbrefnames.Items.Add(pfd.Filename);
                    }
                }
            }

            if (cbrefnames.Items.Count > 0)
            {
                cbrefnames.SelectedIndex = 0;
            }
        }
Example #3
0
        public int Compare(object x, object y)
        {
            SimPe.Plugin.MmatWrapper mmat1 = (SimPe.Plugin.MmatWrapper)x;
            SimPe.Plugin.MmatWrapper mmat2 = (SimPe.Plugin.MmatWrapper)y;

            int cmp = mmat1.GetSaveItem("materialStateFlags").IntegerValue - mmat2.GetSaveItem("materialStateFlags").IntegerValue;

            if (cmp == 0)
            {
                cmp = mmat1.GetSaveItem("objectStateIndex").IntegerValue - mmat2.GetSaveItem("objectStateIndex").IntegerValue;
            }

            return(cmp);
        }
Example #4
0
        /// <summary>
        /// Add a small Scenegraph Chain
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="mmat">the MAterial override File for this Subset</param>
        /// <param name="txmtname">Name of the MAster TXMT</param>
        /// <param name="unique">A unique String for the Filenames</param>
        void LoadSlaveTxmt(IPackageFile newpkg, SimPe.Plugin.MmatWrapper mmat, string txmtname, string unique, Hashtable slavemap)
        {
            foreach (string k in slavemap.Keys)
            {
                foreach (string slave in (ArrayList)slavemap[k])
                {
                    string newname = txmtname.Replace("_" + k + "_", "_" + slave + "_");
                    if (newname != txmtname)
                    {
                        Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFile(newname, Data.MetaData.TXMT);
                        if (pfds.Length > 0)
                        {
                            GenericRcol txmt = new GenericRcol(null, false);
                            txmt.ProcessData(pfds[0], package);

                            AddTxmt(newpkg, mmat, txmt, null, unique, null);
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Return the Thumbnail for the mmat with the passed Index
        /// </summary>
        /// <param name="index"></param>
        /// <param name="mmats"></param>
        /// <param name="sz">Size of the Thumbnail</param>
        /// <returns>a valid Image</returns>
        protected Image GetItemThumb(int index, ArrayList mmats, Size sz)
        {
            if ((index < 0) || (index >= mmats.Count))
            {
                return(new Bitmap(sz.Width, sz.Height));
            }

            SimPe.Plugin.MmatWrapper mmat = (SimPe.Plugin.MmatWrapper)mmats[index];
            GenericRcol txtr = mmat.TXTR;

            if (txtr != null)
            {
                ImageData id = (ImageData)txtr.Blocks[0];
                MipMap    mm = id.LargestTexture;

                if (mm != null)
                {
                    return(ImageLoader.Preview(mm.Texture, sz));
                }
            }

            return(new Bitmap(sz.Width, sz.Height));
        }
Example #6
0
        protected void PostponedRender(object sender, EventArgs e)
        {
            Wait.SubStart();
            Wait.Message = "Building Preview";
            PackageInfo nfo = sender as PackageInfo;

            object[] data = nfo.RenderData as object[];
            tmppkg = SimPe.Packages.GeneratableFile.LoadFromFile(data[1].ToString());
            if (tmppkg == null)
            {
                return;
            }

            SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fii = SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.AddNewChild();
            SimPe.Plugin.MmatWrapper mmat = data[0] as SimPe.Plugin.MmatWrapper;

            mmat.ProcessData(mmat.FileDescriptor, tmppkg);
            if (mmat != null)
            {
                fii.AddIndexFromPackage(mmat.Package, true);
                try
                {
                    Ambertation.Scenes.Scene scn = SimPe.Plugin.PreviewForm.RenderScene(mmat);
                    nfo.RenderedImage = Downloads.DefaultTypeHandler.Get3dPreview(scn);
                    scn.Dispose();
                    mmat.Dispose();
                }
                catch {}
            }


            fii.CloseAssignedPackages();
            SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.RemoveChild(fii);

            this.DisposeTmpPkg();
            Wait.SubStop();
        }
Example #7
0
        /// <summary>
        /// This takes care of the MMAT Resources
        /// </summary>
        /// <param name="map"></param>
        /// <param name="uniquefamily"></param>
        /// <param name="grouphash"></param>
        void FixMMAT(Hashtable map, bool uniquefamily, string grouphash)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating Material Overrides");
            }
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);             //MMAT
            Hashtable familymap = new Hashtable();
            uint      mininst   = 0x5000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.Plugin.MmatWrapper mmat = new SimPe.Plugin.MmatWrapper();
                mmat.ProcessData(pfd, package);
                //make the MMAT Instance number unique
                pfd.Instance = mininst++;

                //get unique family value
                if (uniquefamily)
                {
                    string family  = mmat.GetSaveItem("family").StringValue;
                    string nfamily = (string)familymap[family];

                    if (nfamily == null)
                    {
                        nfamily           = System.Guid.NewGuid().ToString();
                        familymap[family] = nfamily;
                    }

                    mmat.Family = nfamily;
                }


                string newref = (string)map[Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt"];
                if (newref != null)
                {
                    newref    = Hashes.StripHashFromName(newref);
                    newref    = newref.Substring(0, newref.Length - 5);
                    mmat.Name = grouphash + newref;
                }
                else
                {
                    mmat.Name = grouphash + Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue);
                }

                newref = (string)map[Hashes.StripHashFromName(mmat.ModelName.Trim().ToLower())];
                if (newref != null)
                {
                    newref         = Hashes.StripHashFromName(newref);
                    mmat.ModelName = newref;
                }
                else
                {
                    mmat.ModelName = Hashes.StripHashFromName(mmat.ModelName);
                }

                if (ver == FixVersion.UniversityReady)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(mmat.ModelName, Data.MetaData.CRES, Data.MetaData.GLOBAL_GROUP, true);

                    bool addfl = true;
                    if (item != null)
                    {
                        if (item.FileDescriptor.Group == Data.MetaData.GLOBAL_GROUP)
                        {
                            addfl = false;
                        }
                    }

                    if (addfl)
                    {
                        mmat.ModelName = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + mmat.ModelName;
                    }
                }

                //mmat.FileDescriptor.Group = Data.MetaData.LOCAL_GROUP;
                mmat.SynchronizeUserData();
            }
        }
Example #8
0
        /// <summary>
        /// Add a small Scenegraph Chain
        /// </summary>
        /// <param name="mmat">the MAterial override File for this Subset</param>
        /// <param name="txmt">The Material Definition File for this Subset</param>
        /// <param name="txtr">The Txtr File for this Subset (can be null)</param>
        /// <param name="unique">A unique String for the Filenames</param>
        /// <param name="slavemap">The Slavemap as generated by Scenegraph.GetSlaveSubsets() (if null, no slave txmts are loaded)</param>
        void AddTxmt(IPackageFile newpkg, SimPe.Plugin.MmatWrapper mmat, GenericRcol txmt, GenericRcol txtr, string unique, Hashtable slavemap)
        {
            //Get/Update Material Definition
            if (txmt != null)
            {
                string name = Hashes.StripHashFromName(txmt.FileName.Trim());

                //load Slave TXMTs
                if (slavemap != null)
                {
                    LoadSlaveTxmt(newpkg, mmat, name, unique, slavemap);
                }

                if (name.ToLower().EndsWith("_txmt"))
                {
                    name = name.Substring(0, name.Length - 5);
                }
                txmt.FileName       = FixObject.GetUniqueTxmtName(name, unique, mmat.SubsetName, true);          ///*"##0x"+Helper.HexString(Data.MetaData.CUSTOM_GROUP)+"!"+*/name+"_"+unique+"_txmt";
                txmt.FileDescriptor = ScenegraphHelper.BuildPfd(txmt.FileName, Data.MetaData.TXMT, Data.MetaData.CUSTOM_GROUP);

                mmat.Name = "##0x" + Helper.HexString(txmt.FileDescriptor.Group) + "!" + FixObject.GetUniqueTxmtName(name, unique, mmat.SubsetName, false);

                MaterialDefinition md = (MaterialDefinition)txmt.Blocks[0];
                if (txtr == null)
                {
                    txtr = mmat.GetTxtr(txmt);
                    if (txtr != null)
                    {
                        txtr.FileDescriptor = (Interfaces.Files.IPackedFileDescriptor)txtr.FileDescriptor.Clone();
                    }
                }

                //Get/Update Texture
                if (txtr != null)
                {
                    name = AddTxtr(txtr, unique, txmt, md);

                    md.FileDescription = Hashes.StripHashFromName(txmt.FileName).Trim();
                    if (md.FileDescription.ToLower().EndsWith("_txmt"))
                    {
                        md.FileDescription = md.FileDescription.Substring(0, md.FileDescription.Length - 5);
                    }
                }

                if (txtr != null)
                {
                    txtr.SynchronizeUserData();
                    if (newpkg.FindFile(txtr.FileDescriptor) == null)
                    {
                        newpkg.Add(txtr.FileDescriptor);
                    }
                }

                AddReferencedTxtr(newpkg, txmt, md, unique);

                if (txmt != null)
                {
                    txmt.SynchronizeUserData();
                    if (newpkg.FindFile(txmt.FileDescriptor) == null)
                    {
                        newpkg.Add(txmt.FileDescriptor);
                    }
                }
            }
        }