Пример #1
0
 private void ProcessItem(
     ProgramContext.ItemInfo item,
     string outputDir,
     byte[] havokCollisionShapes,
     bool checkOpenBoundaries,
     float[] lodDistances,
     bool overrideLods)
 {
     if (item.Configuration == null)
     {
         ProgramContext.m_buildLogger.LogMessage(MessageType.Info, string.Format("Model skipped! No configuration for '{0}'", (object)item.Path), "");
     }
     else
     {
         new MyModelBuilder().Build(item.Path,
                                    "tmp",
                                    outputDir,
                                    item.Configuration,
                                    havokCollisionShapes,
                                    checkOpenBoundaries,
                                    lodDistances,
                                    overrideLods,
                                    new Func <string, MyMaterialConfiguration>(ProgramContext.GetMaterialByRef),
                                    (IMyBuildLogger)ProgramContext.m_buildLogger);
     }
 }
Пример #2
0
        private bool ProcessFile(
            string file,
            string outputDir,
            Dictionary <string, object> defaultVars,
            bool exportXml,
            bool forceBuild,
            bool checkOpenBoundaries,
            string lodDistances,
            bool overrideLods)
        {
            DateTime             sourceDateTime = File.GetLastWriteTimeUtc(file);
            string               str1           = Path.ChangeExtension(file, "xml");
            bool                 flag           = false;
            MyModelConfiguration configuration  = (MyModelConfiguration)null;

            if (File.Exists(str1))
            {
                DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(str1);
                if (lastWriteTimeUtc > sourceDateTime)
                {
                    sourceDateTime = lastWriteTimeUtc;
                }
                configuration = ProgramContext.ImportXml(str1);
            }
            else
            {
                flag = exportXml;
            }
            if (configuration == null)
            {
                configuration = new MyModelConfiguration()
                {
                    Name       = "Default",
                    Parameters = defaultVars.Select <KeyValuePair <string, object>, MyModelParameter>((Func <KeyValuePair <string, object>, MyModelParameter>)(s => new MyModelParameter()
                    {
                        Name  = s.Key,
                        Value = s.Value.ToString()
                    })).ToArray <MyModelParameter>()
                }
            }
            ;
            if (configuration.MaterialRefs != null)
            {
                foreach (MyModelParameter materialRef in configuration.MaterialRefs)
                {
                    ProgramContext.LoadMaterialByRef(materialRef.Name);
                }
            }
            byte[] havokCollisionShapes = this.ReadExternalFile("hkt", file, ref sourceDateTime);
            if (this.appLastChangeDateTime.HasValue && this.appLastChangeDateTime.Value > sourceDateTime)
            {
                sourceDateTime = this.appLastChangeDateTime.Value;
            }
            FileInfo fileInfo = new FileInfo(MyModelProcessor.GetOutputPath(file, outputDir));

            if (fileInfo.Exists && fileInfo.LastWriteTimeUtc > sourceDateTime && !forceBuild)
            {
                if (flag)
                {
                    ProgramContext.ExportXml(str1, configuration);
                }
                return(false);
            }
            ProgramContext.ItemInfo itemInfo = new ProgramContext.ItemInfo()
            {
                Index         = 0,
                Path          = file,
                Name          = Path.GetFileNameWithoutExtension(file),
                Configuration = configuration
            };
            float[] numArray;
            if (lodDistances == null)
            {
                numArray = new float[0];
            }
            else
            {
                numArray = Array.ConvertAll <string, float>(lodDistances.Trim().Split(' '), new Converter <string, float>(float.Parse));
            }
            float[] lodDistances1 = numArray;
            this.ProcessItem(itemInfo, outputDir, havokCollisionShapes, checkOpenBoundaries, lodDistances1, overrideLods);
            if (exportXml)
            {
                List <string> materialsToRef = new List <string>();
                foreach (MyMaterialConfiguration material in configuration.Materials)
                {
                    if (ProgramContext.GetMaterialByRef(material.Name) != null)
                    {
                        materialsToRef.Add(material.Name);
                    }
                }
                if (materialsToRef.Count > 0)
                {
                    configuration.Materials = ((IEnumerable <MyMaterialConfiguration>)configuration.Materials).Where <MyMaterialConfiguration>((Func <MyMaterialConfiguration, bool>)(x => !materialsToRef.Contains(x.Name))).ToArray <MyMaterialConfiguration>();
                    if (configuration.MaterialRefs == null)
                    {
                        configuration.MaterialRefs = materialsToRef.ConvertAll <MyModelParameter>((Converter <string, MyModelParameter>)(x => new MyModelParameter()
                        {
                            Name = x
                        })).ToArray();
                    }
                    else
                    {
                        List <MyModelParameter> myModelParameterList = new List <MyModelParameter>();
                        foreach (string str2 in materialsToRef)
                        {
                            string mat = str2;
                            if (!((IEnumerable <MyModelParameter>)configuration.MaterialRefs).Any <MyModelParameter>((Func <MyModelParameter, bool>)(x => x.Name == mat)))
                            {
                                myModelParameterList.Add(new MyModelParameter()
                                {
                                    Name = mat
                                });
                            }
                        }
                        configuration.MaterialRefs = ((IEnumerable <MyModelParameter>)configuration.MaterialRefs).Union <MyModelParameter>((IEnumerable <MyModelParameter>)myModelParameterList).ToArray <MyModelParameter>();
                    }
                }
                ProgramContext.ExportXml(str1, configuration);
            }
            return(true);
        }