Exemplo n.º 1
0
        /// <summary>
        /// Clone an object based on way Files are linked
        /// </summary>
        /// <param name="pfd"></param>
        /// <param name="localgroup"></param>
        /// <param name="onlydefault"></param>
        protected static SimPe.Packages.GeneratableFile RecolorClone(CloneSettings.BaseResourceType br, SimPe.Packages.GeneratableFile ppkg, Interfaces.Files.IPackedFileDescriptor pfd, uint localgroup, ObjectWorkshopSettings settings, bool pkgcontainsonlybase)
        {
            SimPe.Packages.GeneratableFile package = null;
            if (ppkg != null)
            {
                package = (SimPe.Packages.GeneratableFile)ppkg.Clone();
            }
            if (ppkg == null || pkgcontainsonlybase)
            {
                if (!pkgcontainsonlybase)
                {
                    package = SimPe.Packages.GeneratableFile.CreateNew();
                }
                //Get the Base Object Data from the Objects.package File
                string[] modelname = new string[0];
                if (br == CloneSettings.BaseResourceType.Objd)
                {
                    modelname = BaseClone(localgroup, package, pkgcontainsonlybase);
                }
                else
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] fii = FileTable.FileIndex.FindFile(pfd, null);
                    if (fii.Length > 0)
                    {
                        SimPe.Interfaces.Files.IPackedFileDescriptor cpfd = fii[0].FileDescriptor.Clone();
                        cpfd          = cpfd.Clone();
                        cpfd.UserData = fii[0].Package.Read(fii[0].FileDescriptor).UncompressedData;
                        package.Add(cpfd);
                    }
                }
                ObjectCloner objclone = new ObjectCloner(package);
                ArrayList    exclude  = new ArrayList();



                //allways for recolors
                if (settings is OWRecolorSettings)
                {
                    exclude.Add("stdMatEnvCubeTextureName");
                    exclude.Add("TXTR");
                }
                else
                {
                    exclude.Add("tsMaterialsMeshName");
                    exclude.Add("TXTR");
                    exclude.Add("stdMatEnvCubeTextureName");
                }

                //do the recolor
                objclone.Setup = settings;
                objclone.Setup.BaseResource     = br;
                objclone.Setup.OnlyDefaultMmats = (settings.OnlyDefaultMmats && br != CloneSettings.BaseResourceType.Xml);
                objclone.Setup.UpdateMmatGuids  = objclone.Setup.OnlyDefaultMmats;

                /*objclone.Setup.IncludeWallmask = settings.IncludeWallmask;
                 * objclone.Setup.IncludeAnimationResources = settings.IncludeAnimationResources;
                 * objclone.Setup.KeepOriginalMesh = settings.KeepOriginalMesh;
                 * objclone.Setup.PullResourcesByStr = settings.PullResourcesByStr;
                 * objclone.Setup.StrInstances = settings.StrInstances;*/


                objclone.RcolModelClone(modelname, exclude);

                //for clones only when cbparent is checked
                if (settings is OWCloneSettings)
                {
                    if (((OWCloneSettings)settings).StandAloneObject || br == CloneSettings.BaseResourceType.Xml)
                    {
                        string[]            names = Scenegraph.LoadParentModelNames(package, true);
                        SimPe.Packages.File pkg   = SimPe.Packages.File.LoadFromFile(null);

                        ObjectCloner pobj = new ObjectCloner(pkg);
                        pobj.Setup = settings;
                        pobj.Setup.BaseResource     = br;
                        pobj.Setup.OnlyDefaultMmats = (settings.OnlyDefaultMmats && br != CloneSettings.BaseResourceType.Xml);;
                        pobj.Setup.UpdateMmatGuids  = pobj.Setup.OnlyDefaultMmats;

                        /*pobj.Setup.IncludeWallmask = settings.IncludeWallmask;
                         * pobj.Setup.IncludeAnimationResources = settings.IncludeAnimationResources;
                         * pobj.Setup.KeepOriginalMesh = settings.KeepOriginalMesh;
                         * pobj.Setup.PullResourcesByStr = settings.PullResourcesByStr;
                         * pobj.Setup.StrInstances = settings.StrInstances;*/


                        pobj.RcolModelClone(names, exclude);
                        pobj.AddParentFiles(modelname, package);
                    }
                    else
                    {
                        string[] modelnames = modelname;
                        if (!((OWCloneSettings)settings).RemoveUselessResource)
                        {
                            modelnames = null;
                        }
                        objclone.RemoveSubsetReferences(Scenegraph.GetParentSubsets(package), modelnames);
                    }
                }
            }

            return(package);
        }