Пример #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
        protected GenericRcol LoadTXTR(GenericRcol txmt)
        {
            if (txmt == null)
            {
                return(null);
            }

            try
            {
                MaterialDefinition md       = (MaterialDefinition)txmt.Blocks[0];
                string             txtrname = md.FindProperty("stdMatBaseTextureName").Value.Trim().ToLower();
                if (!txtrname.EndsWith("_txtr"))
                {
                    txtrname += "_txtr";
                }

                Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(txtrname, Data.MetaData.TXTR, Data.MetaData.LOCAL_GROUP, true);
                if (item != null)
                {
                    SimPe.Plugin.GenericRcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(item, false);

                    return(rcol);
                }
            }
            catch {}

            return(null);
        }
Пример #3
0
        protected string AddTxtr(GenericRcol txtr, string unique, GenericRcol txmt, MaterialDefinition md)
        {
            string old = Hashes.StripHashFromName(txtr.FileName.Trim().ToLower());

            if (old.EndsWith("_txtr"))
            {
                old = old.Substring(0, old.Length - 5);
            }
            //Console.WriteLine("Adding Texture: "+old);

            string name = txtr.FileName.Trim();

            if (name.ToLower().EndsWith("_txtr"))
            {
                name = name.Substring(0, name.Length - 5);
            }

            string tname = RenameForm.ReplaceOldUnique(name, unique, true);

            txtr.FileName = tname + "_txtr";

            txtr.FileDescriptor = ScenegraphHelper.BuildPfd(txtr.FileName, Data.MetaData.TXTR, Data.MetaData.CUSTOM_GROUP);

            for (int i = 0; i < md.Listing.Length; i++)
            {
                if (Hashes.StripHashFromName(md.Listing[i].Trim().ToLower()) == old)
                {
                    md.Listing[i] = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + tname;
                }
            }

            //update References
            foreach (string k in txmt.ReferenceChains.Keys)
            {
                if (k == "TXTR" || k == "Generic")
                {
                    continue;
                }
                //Console.WriteLine("    Checking Property "+k);
                string thisname = Hashes.StripHashFromName(md.FindProperty(k).Value.Trim().ToLower());

                if (thisname == old)
                {
                    string nname = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + tname;
                    //Console.WriteLine("    --> Updating to "+nname);
                    md.FindProperty(k).Value = nname;
                }
            }

            //Load the Lifos into the Texture File
            ImageData id = (ImageData)txtr.Blocks[0];

            id.GetReferencedLifos();

            return(name);
        }
Пример #4
0
        private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            if (this.tabPage3.Tag == null)
            {
                return;
            }

            MaterialDefinition md = (MaterialDefinition)this.tabPage3.Tag;

            md.Sort();
            md.Refresh();
        }
Пример #5
0
        public Hashtable GetMaterials(Hashtable txmts, Ambertation.Scenes.Scene scn)
        {
            Hashtable list = new Hashtable();

            foreach (string s in txmts.Keys)
            {
                Rcol rcol             = (Rcol)txmts[s];
                MaterialDefinition md = (MaterialDefinition)rcol.Blocks[0];

                list[s] = md.ToSceneMaterial(scn, Hashes.StripHashFromName(rcol.FileName));
            }
            return(list);
        }
Пример #6
0
        /// <summary>
        /// Clone the Makeup of a Sim
        /// </summary>
        /// <returns>the new Package for the patient Sim</returns>
        /// <param name="eyecolor">true, if you want to alter the eyecolor</param>
        /// <param name="makeups">true, if you want to alter the makeup</param>
        public SimPe.Packages.GeneratableFile CloneMakeup(bool eyecolor, bool makeups)
        {
            SimPe.Packages.GeneratableFile ret = SimPe.Packages.GeneratableFile.LoadFromFile((string)null);

            ArrayList list = new ArrayList();

            list.Add((uint)0xE86B1EEF);             //make sure the compressed Directory won't be copied!
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in patient.Index)
            {
                if (!list.Contains(pfd.Type))
                {
                    Interfaces.Files.IPackedFile fl = patient.Read(pfd);

                    Interfaces.Files.IPackedFileDescriptor newpfd = ret.NewDescriptor(pfd.Type, pfd.SubType, pfd.Group, pfd.Instance);
                    newpfd.UserData = fl.UncompressedData;
                    ret.Add(newpfd);
                }
            }

            //Update TXMT Files for the Face
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = ret.FindFiles(Data.MetaData.TXMT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, ret);

                MaterialDefinition md = (MaterialDefinition)rcol.Blocks[0];
                this.UpdateMakeup(md, eyecolor, makeups);

                rcol.SynchronizeUserData();
            }

            if (eyecolor)
            {
                //Update DNA File
                Interfaces.Files.IPackedFileDescriptor dna  = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, spatient.Instance);
                Interfaces.Files.IPackedFileDescriptor adna = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, sarchetype.Instance);
                if ((dna != null) && (adna != null))
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                    cpf.ProcessData(dna, ngbh);

                    SimPe.PackedFiles.Wrapper.Cpf acpf = new Cpf();
                    acpf.ProcessData(adna, ngbh);
                    cpf.GetSaveItem("3").StringValue = acpf.GetSaveItem("3").StringValue;

                    cpf.SynchronizeUserData();
                }
            }
            return(ret);
        }
Пример #7
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();
                    }
                }
            }
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
        /// <summary>
        /// Updates the SkinTone References in the 3IDR Files
        /// </summary>
        /// <param name="md">The Metreial Definition</param>
        /// <param name="eyecolor">true, if you want to alter the eyecolor</param>
        /// <param name="makeups">true, if you want to alter the makeup</param>
        void UpdateMakeup(MaterialDefinition md, bool eyecolor, bool makeups)
        {
            string age    = md.FindProperty("paramAge").Value;
            string gender = md.FindProperty("paramGender").Value;

            //find a matching Package in the arechtype
            Interfaces.Files.IPackedFileDescriptor[] pfds = this.archetype.FindFiles(Data.MetaData.TXMT);
            SimPe.Plugin.Rcol  atxmt = new GenericRcol(null, false);
            MaterialDefinition amd   = null;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                atxmt.ProcessData(pfd, this.archetype);

                amd = (MaterialDefinition)atxmt.Blocks[0];
                if ((amd.FindProperty("paramAge").Value == age) && (amd.FindProperty("paramGender").Value == gender))
                {
                    break;
                }
            }

            if (amd != null)
            {
                int count = 0;
                md.Add(amd.FindProperty("numTexturesToComposite"));
                try{ count = Convert.ToInt32(md.FindProperty("numTexturesToComposite").Value); } catch {}

                string txmtname = "";
                for (int i = 0; i < count; i++)
                {
                    MaterialDefinitionProperty val = amd.FindProperty("baseTexture" + i.ToString());
                    if (i != 0)
                    {
                        md.Add(val);
                    }
                    if (i == 1)
                    {
                        if (eyecolor)
                        {
                            md.Add(val);
                        }
                        else if (makeups)
                        {
                            md.Add(val);
                        }
                    }

                    string name = val.Value.Trim();
                    if (!name.ToLower().EndsWith("_txtr"))
                    {
                        name += "_txtr";
                    }
                    name = this.FindTxtrName(name);

                    if (i != 0)
                    {
                        txmtname += "_";
                    }
                    txmtname += name;
                }

                md.FindProperty("compositeBaseTextureName").Value = txmtname;
                string[] list = new string[1];
                list[0]    = txmtname;
                md.Listing = list;

                if (makeups)
                {
                    count = 0;
                    md.Add(amd.FindProperty("cafNumOverlays"));
                    try{ count = Convert.ToInt32(md.FindProperty("cafNumOverlays").Value); }
                    catch {}

                    for (int i = 0; i < count; i++)
                    {
                        MaterialDefinitionProperty val = amd.FindProperty("cafOverlay" + i.ToString());
                        md.Add(val);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Change the SkinTone of a Sim
        /// </summary>
        /// <param name="skin">the new skintone</param>
        /// param name="skinfiles">a Hashtable listing al Proerty Sets for each available skintone (key=skintone string, value= ArrayList of Cpf Objects)</param>
        /// <returns>the new Package for the patient Sim</returns>
        public SimPe.Packages.GeneratableFile CloneSkinTone(string skin, Hashtable skinfiles)
        {
            SimPe.Packages.GeneratableFile ret = SimPe.Packages.GeneratableFile.LoadFromFile((string)null);
            string pskin = GetSkintone(this.patient);

            ArrayList list = new ArrayList();

            list.Add((uint)0xE86B1EEF);             //make sure the compressed Directory won't be copied!
            foreach (Interfaces.Files.IPackedFileDescriptor pfd in patient.Index)
            {
                if (!list.Contains(pfd.Type))
                {
                    Interfaces.Files.IPackedFile fl = patient.Read(pfd);

                    Interfaces.Files.IPackedFileDescriptor newpfd = ret.NewDescriptor(pfd.Type, pfd.SubType, pfd.Group, pfd.Instance);
                    newpfd.UserData = fl.UncompressedData;
                    ret.Add(newpfd);

                    switch (newpfd.Type)
                    {
                    case (uint)0xAC598EAC:                             //AGED
                    {
                        SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                        cpf.ProcessData(newpfd, ret);
                        cpf.GetSaveItem("skincolor").StringValue = skin;

                        cpf.SynchronizeUserData();
                        break;
                    }

                    case Data.MetaData.GZPS:
                    {
                        SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                        cpf.ProcessData(newpfd, ret);
                        cpf.GetSaveItem("skintone").StringValue = skin;

                        cpf.SynchronizeUserData();
                        break;
                    }

                    case Data.MetaData.TXMT:
                    {
                        SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                        rcol.ProcessData(newpfd, ret);
                        MaterialDefinition txmt = (MaterialDefinition)rcol.Blocks[0];
                        txmt.FindProperty("cafSkinTone").Value = skin;

                        rcol.SynchronizeUserData();
                        break;
                    }
                    }
                }
            }

            //Update DNA File
            Interfaces.Files.IPackedFileDescriptor dna = ngbh.FindFile(0xEBFEE33F, 0, Data.MetaData.LOCAL_GROUP, spatient.Instance);
            if (dna != null)
            {
                SimPe.PackedFiles.Wrapper.Cpf cpf = new Cpf();
                cpf.ProcessData(dna, ngbh);
                cpf.GetSaveItem("2").StringValue = skin;
                cpf.GetSaveItem("6").StringValue = skin;

                cpf.SynchronizeUserData();
            }

            //Update 3IDR Files
            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = ret.FindFiles(0xAC506764);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.RefFile reffile = new RefFile();
                reffile.ProcessData(pfd, ret);

                UpdateSkintone(reffile, skin, skinfiles);
            }

            //Update TXMT Files for the Face
            pfds = ret.FindFiles(Data.MetaData.TXMT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, ret);

                MaterialDefinition md = (MaterialDefinition)rcol.Blocks[0];
                this.UpdateSkintone(md, skin, skinfiles);

                rcol.SynchronizeUserData();
            }


            return(ret);
        }
Пример #12
0
        /// <summary>
        /// Updates the SkinTone References in the 3IDR Files
        /// </summary>
        /// <param name="md">The Metreial Definition</param>
        /// <param name="skinfiles">a Hashtable listing al Proerty Sets for each available skintone (key=skintone string, value= ArrayList of Cpf Objects)</param>
        /// <param name="sourceskin">the hash for the source skin</param>
        /// <param name="targetskin">the hash for the target skin</param>
        void UpdateSkintone(MaterialDefinition md, string targetskin, Hashtable skinfiles)
        {
            uint age = (uint)Data.MetaData.AgeTranslation((Data.MetaData.LifeSections)spatient.CharacterDescription.Age);

            try { age = (uint)Math.Pow(2, Convert.ToInt32(md.FindProperty("paramAge").Value)); }  catch {}
            try { patientgender = Convert.ToUInt32(md.FindProperty("paramGender").Value); }  catch {}

            if (skinfiles[targetskin] == null)
            {
                return;
            }
            foreach (Cpf newcpf in (ArrayList)skinfiles[targetskin])
            {
                if (newcpf.GetSaveItem("override0subset").StringValue.Trim().ToLower() == "face")
                {
                    if ((newcpf.GetSaveItem("age").UIntegerValue & age) == age)
                    {
                        if ((newcpf.GetSaveItem("gender").UIntegerValue & patientgender) == patientgender)
                        {
                            SimPe.Plugin.SkinChain sc = new SkinChain(newcpf);
                            Interfaces.Files.IPackedFileDescriptor[] pfds = newcpf.Package.FindFile(0xAC506764, newcpf.FileDescriptor.SubType, newcpf.FileDescriptor.Instance);

                            Rcol txmt = sc.TXMT;
                            Rcol txtr = sc.TXTR;
                            if (txtr != null && txmt != null)
                            {
                                string txmtname = txmt.FileName.Trim();
                                if (txmtname.ToLower().EndsWith("_txmt"))
                                {
                                    txmtname = txmtname.Substring(0, txmtname.Length - 5);
                                }

                                string basename = txtr.FileName.Trim();
                                if (basename.ToLower().EndsWith("_txtr"))
                                {
                                    basename = basename.Substring(0, basename.Length - 5);
                                }

                                if (txmtname.IndexOf("#") == 0)
                                {
                                    txmtname = "_" + txmtname;
                                }

                                int count = 0;
                                try { count = Convert.ToInt32(md.FindProperty("numTexturesToComposite").Value); }
                                catch {}

                                if (count > 0)
                                {
                                    md.FindProperty("baseTexture0").Value          = basename;
                                    md.FindProperty("stdMatBaseTextureName").Value = basename;

                                    for (int i = 1; i < count; i++)
                                    {
                                        string name = md.FindProperty("baseTexture" + i.ToString()).Value.Trim();
                                        if (!name.ToLower().EndsWith("_txtr"))
                                        {
                                            name += "_txtr";
                                        }
                                        name = this.FindTxtrName(name);

                                        if (i != 0)
                                        {
                                            txmtname += "_";
                                        }
                                        txmtname += name;
                                    }

                                    md.FindProperty("compositeBaseTextureName").Value = txmtname;
                                    string[] list = new string[1];
                                    list[0]    = txmtname;
                                    md.Listing = list;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="map"></param>
        /// <param name="rcol"></param>
        public void FixResource(Hashtable map, Rcol rcol)
        {
            switch (rcol.FileDescriptor.Type)
            {
            case Data.MetaData.TXMT:                     //MATD
            {
                MaterialDefinition matd = (MaterialDefinition)rcol.Blocks[0];

                FixTxtrRef("stdMatBaseTextureName", matd, map, rcol);
                FixTxtrRef("stdMatNormalMapTextureName", matd, map, rcol);
                break;
            }

            case Data.MetaData.SHPE:                     //SHPE
            {
                Shape shp = (Shape)rcol.Blocks[0];
                foreach (ShapeItem item in shp.Items)
                {
                    string newref = (string)map[Hashes.StripHashFromName(item.FileName.Trim().ToLower())];
                    if (newref != null)
                    {
                        item.FileName = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + newref;
                    }
                }

                foreach (ShapePart part in shp.Parts)
                {
                    string newref = (string)map[Hashes.StripHashFromName(part.FileName.Trim().ToLower()) + "_txmt"];
                    if (newref != null)
                    {
                        part.FileName = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + newref.Substring(0, newref.Length - 5);
                    }
                }
                break;
            }

            case Data.MetaData.TXTR:                     //TXTR
            {
                ImageData id = (ImageData)rcol.Blocks[0];
                foreach (SimPe.Plugin.MipMapBlock mmb in id.MipMapBlocks)
                {
                    foreach (MipMap mm in mmb.MipMaps)
                    {
                        //this is a Lifo Reference
                        if (mm.Texture == null)
                        {
                            Interfaces.Files.IPackedFileDescriptor[] pfd = package.FindFile(mm.LifoFile, 0xED534136);
                            if (pfd.Length > 0)
                            {
                                Lifo lifo = new Lifo(null, false);
                                lifo.ProcessData(pfd[0], package);
                                LevelInfo li = (LevelInfo)lifo.Blocks[0];

                                mm.Texture = null;
                                mm.Data    = li.Data;

                                pfd[0].MarkForDelete = true;
                            }
                            else
                            {
                                string newref = Hashes.StripHashFromName((string)map[mm.LifoFile.Trim().ToLower()]);
                                if (newref != null)
                                {
                                    mm.LifoFile = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + newref;
                                }
                            }
                        }
                    }
                }
                break;
            }

            case Data.MetaData.CRES:                     //CRES
            {
                ResourceNode rn   = (ResourceNode)rcol.Blocks[0];
                string       name = Hashes.StripHashFromName(rcol.FileName);

                if (ver == FixVersion.UniversityReady2)
                {
                    rn.GraphNode.FileName = name;
                }
                else if (ver == FixVersion.UniversityReady)
                {
                    rn.GraphNode.FileName = "##0x1c050000!" + name;
                }

                break;
            }

            case Data.MetaData.GMND:                     //GMND
            {
                GeometryNode gn   = (GeometryNode)rcol.Blocks[0];
                string       name = Hashes.StripHashFromName(rcol.FileName);

                if (ver == FixVersion.UniversityReady2)
                {
                    gn.ObjectGraphNode.FileName = name;
                }
                else if (ver == FixVersion.UniversityReady)
                {
                    gn.ObjectGraphNode.FileName = "##0x1c050000!" + name;
                }

                break;
            }

            case Data.MetaData.LDIR:
            case Data.MetaData.LAMB:
            case Data.MetaData.LPNT:
            case Data.MetaData.LSPT:
            {
                DirectionalLight dl = (DirectionalLight)rcol.Blocks[0];
                dl.LightT.NameResource.FileName = dl.NameResource.FileName;

                break;
            }
            }
        }
Пример #14
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);
                    }
                }
            }
        }
Пример #15
0
        protected string AddTxtr(IPackageFile newpkg, GenericRcol txtr, string unique, GenericRcol txmt, MaterialDefinition md)
        {
            string name = AddTxtr(txtr, unique, txmt, md);

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

            return(name);
        }