Пример #1
0
        /// <summary>
        /// Fix a Txtr Reference in the Properties of a TXMT File
        /// </summary>
        /// <param name="name"></param>
        /// <param name="matd"></param>
        void FixTxtrRef(string propname, MaterialDefinition matd, Hashtable map, Rcol rcol)
        {
            string reference = matd.GetProperty(propname).Value.Trim().ToLower();
            string newref    = (string)map[Hashes.StripHashFromName(reference) + "_txtr"];

            if (newref != null)
            {
                newref = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + Hashes.StripHashFromName(newref);
                matd.GetProperty(propname).Value = newref.Substring(0, newref.Length - 5);
            }

            for (int i = 0; i < matd.Listing.Length; i++)
            {
                newref = (string)map[Hashes.StripHashFromName(matd.Listing[i].Trim().ToLower()) + "_txtr"];
                if (newref != null)
                {
                    matd.Listing[i] = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + Hashes.StripHashFromName(newref.Substring(0, newref.Length - 5));
                }
            }

            string name = Hashes.StripHashFromName(rcol.FileName);

            if (name.Length > 5)
            {
                name = name.Substring(0, name.Length - 5);
            }
            matd.FileDescription = name;
        }
Пример #2
0
        /// <summary>
        /// This adds all second Leve Textures to the Recolor (like normal Maps)
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="md"></param>
        protected void AddReferencedTxtr(IPackageFile newpkg, GenericRcol txmt, MaterialDefinition md, string unique)
        {
            foreach (string k in txmt.ReferenceChains.Keys)
            {
                if (k.ToLower() == "stdmatnormalmaptexturename")               //at the moment i only know of NormalMaps that need to be added
                {
                    MaterialDefinitionProperty mdp = md.GetProperty(k);
                    if (mdp != null)
                    {
                        string name = Hashes.StripHashFromName(mdp.Value).Trim();
                        if (!name.EndsWith("_txtr"))
                        {
                            name += "_txtr";
                        }

                        //Console.Write("loading second txtr "+mdp.Name+" = "+mdp.Value);
                        IPackageFile pkg = txmt.Package;
                        SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(name, Data.MetaData.TXTR);
                        if (pfds.Length > 0)
                        {
                            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
                            //Console.Write(" [found in local Package]");

                            GenericRcol txtr = new GenericRcol();
                            txtr.ProcessData(pfd, pkg);

                            AddTxtr(newpkg, txtr, unique, txmt, md);
                        }

                        /*else  //we don't pull from the Filetable, as we expect, that all needed Files are already cloned!
                         * {
                         *      SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(name, Data.MetaData.TXTR, Hashes.GetHashGroupFromName(mdp.Value, Data.MetaData.GLOBAL_GROUP), true);
                         *      if (item!=null)
                         *      {
                         *              Console.Write(" [found in FileTable]");
                         *      }
                         * }*/


                        //Console.WriteLine();
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Find the TXTRs that are referenced by the passed TXMTs
        /// </summary>
        /// <param name="txmts"></param>
        /// <param name="flname">null, or the Filename of a package to search in</param>
        /// <returns>null or the first found shpe</returns>
        public Hashtable FindReferencedTXTR(Hashtable txmts, string flname)
        {
            Hashtable ht = new Hashtable();

            if (txmts == null)
            {
                return(ht);
            }

            SimPe.Interfaces.Files.IPackageFile lpackage = package;
            if (flname != null)
            {
                lpackage = SimPe.Packages.File.LoadFromFile(flname);
            }

            foreach (string subset in txmts.Keys)
            {
                Rcol rcol = (Rcol)txmts[subset];
                MaterialDefinition txmt     = (MaterialDefinition)rcol.Blocks[0];
                string             txtrname = Hashes.StripHashFromName(txmt.GetProperty("stdMatBaseTextureName").Value) + "_txtr";
                txtrname = txtrname.Trim().ToLower();

                Interfaces.Files.IPackedFileDescriptor[] pfds = lpackage.FindFile(txtrname, 0x1C4A276C);
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    Rcol txtr = new GenericRcol(null, false);
                    txtr.ProcessData(pfd, lpackage);

                    if (Hashes.StripHashFromName(txtr.FileName).Trim().ToLower() == txtrname)
                    {
                        if (!ht.Contains(subset))
                        {
                            ht.Add(subset, txtr);
                        }
                    }
                }
            }


            return(ht);
        }
Пример #4
0
        /// <summary>
        /// Fix all links
        /// </summary>
        public string Fix(string family, uint group, ref int ct, Hashtable matdrep, Hashtable txtrrep, ArrayList guids)
        {
            //make sure the references are loaded
            txtr = TXTR;

            string groups = "#0x" + Helper.HexString(group) + "!";

            groups = "##0x1c050000!";
            MMAT.GetSaveItem("family").StringValue = family;
            string matdname = Hashes.StripHashFromName(MMAT.GetSaveItem("name").StringValue) + "_" + family;

            if (matdrep[MMAT.GetSaveItem("name").StringValue] == null)
            {
                matdrep.Add(MMAT.GetSaveItem("name").StringValue, groups + matdname);
                MMAT.GetSaveItem("name").StringValue = groups + matdname;
            }
            else
            {
                MMAT.GetSaveItem("name").StringValue = (string)matdrep[MMAT.GetSaveItem("name").StringValue];
            }

            //make sure we use a supported GUID
            if (guids.Count > 0)
            {
                if (!guids.Contains(MMAT.GetSaveItem("objectGUID").UIntegerValue))
                {
                    MMAT.GetSaveItem("objectGUID").UIntegerValue = (uint)guids[0];
                }
            }

            MMAT.GetSaveItem("defaultMaterial").BooleanValue = false;
            MMAT.FileDescriptor.Instance = (uint)(0x4000 + ct++);
            MMAT.FileDescriptor.Group    = 0xffffffff;

            string txtrname = groups + "_" + family;
            string org      = "";

            if (MATD != null)
            {
                MaterialDefinition md = (MaterialDefinition)MATD.Blocks[0];
                md.FileDescription = matdname;
                MATD.FileName      = groups + matdname + "_txmt";
                SimPe.Packages.PackedFileDescriptor matdpfd = new PackedFileDescriptor();

                matdpfd.Type              = MATD.FileDescriptor.Type;
                MATD.FileDescriptor       = matdpfd;
                MATD.FileDescriptor.Group = 0x1c050000;                 //group; //0x1C0532FA;

                MATD.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(MATD.FileName));
                MATD.FileDescriptor.SubType  = Hashes.SubTypeHash(Hashes.StripHashFromName(MATD.FileName));

                org = TxtrRef;
                string realtxtrname = "";                 //Hashes.StripHashFromName(md.GetProperty("stdMatBaseTextureName").Value);
                if (TXTR != null)
                {
                    realtxtrname = Hashes.StripHashFromName(TXTR.FileName);
                    if (realtxtrname.Length > 5)
                    {
                        realtxtrname = realtxtrname.Substring(0, realtxtrname.Length - 5);
                    }
                }

                //we foudn a texture
                if (realtxtrname.Trim() != "")
                {
                    txtrname = realtxtrname + "_" + family;
                    if (txtrrep[realtxtrname] == null)
                    {
                        txtrrep.Add(realtxtrname, txtrname);
                        txtrrep.Add(txtrname, txtrname);
                    }
                    else
                    {
                        txtrname = (string)txtrrep[realtxtrname];
                    }

                    md.GetProperty("stdMatBaseTextureName").Value = /*groups +*/ Hashes.StripHashFromName(txtrname);

                    string[] files = new string[1];
                    files[0]   = /*groups +*/ Hashes.StripHashFromName(txtrname);
                    md.Listing = files;
                }
            }


            if (TXTR != null)
            {
                TXTR.FileName = groups + txtrname + "_txtr";
                SimPe.Packages.PackedFileDescriptor txtrpfd = new PackedFileDescriptor();

                txtrpfd.Type              = TXTR.FileDescriptor.Type;
                TXTR.FileDescriptor       = txtrpfd;
                TXTR.FileDescriptor.Group = 0x1c050000;                 //group; //0x1C0532FA;

                TXTR.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(TXTR.FileName));
                TXTR.FileDescriptor.SubType  = Hashes.SubTypeHash(Hashes.StripHashFromName(TXTR.FileName));
            }

            return(org);
        }