Пример #1
0
        public static MyMaterialConfiguration LoadMaterialByRef(
            string materialRef)
        {
            MyMaterialConfiguration materialByRef = ProgramContext.GetMaterialByRef(materialRef);

            if (materialByRef == null)
            {
                ProgramContext.m_buildLogger.LogMessage(MessageType.Error, "Referenced material: " + materialRef + " was not found in material libraries", "");
            }
            return(materialByRef);
        }
Пример #2
0
        public static void LoadMaterialLibs()
        {
            ProgramContext.m_materialLibs = new List <MyMaterialsLib>();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyMaterialsLib));

            new XmlSerializerNamespaces().Add(string.Empty, string.Empty);
            if (Directory.Exists(ProgramContext.m_materialsPath))
            {
                try
                {
                    foreach (string file in Directory.GetFiles(ProgramContext.m_materialsPath))
                    {
                        string xmlFile = file;
                        if (xmlFile.EndsWith(".xml"))
                        {
                            ProgramContext.m_buildLogger.LogMessage(MessageType.Info, "Materialslib", xmlFile);
                            using (FileStream fileStream = File.Open(xmlFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                try
                                {
                                    lock (ProgramContext.m_materialLibs)
                                    {
                                        if (ProgramContext.m_materialLibs.Find((Predicate <MyMaterialsLib>)(x => x.FilePath == xmlFile)) == null)
                                        {
                                            MyMaterialsLib myMaterialsLib = (MyMaterialsLib)xmlSerializer.Deserialize((Stream)fileStream);
                                            myMaterialsLib.FilePath = xmlFile;
                                            ProgramContext.m_materialLibs.Add(myMaterialsLib);
                                        }
                                    }
                                }
                                catch
                                {
                                    ProgramContext.m_buildLogger.LogMessage(MessageType.Error, "This xml library: " + xmlFile + " couldn't been loaded. Probably wrong XML format.", "");
                                }
                            }
                        }
                    }
                }
                catch (IOException ex)
                {
                    ProgramContext.m_buildLogger.LogMessage(MessageType.Error, "Libs in " + ProgramContext.m_materialsPath + " couldn't been loaded.. Wrong material library path?", "");
                }
            }

            Trace.Assert(ProgramContext.m_materialLibs != null, "No material libraries were loaded from path: " + ProgramContext.m_materialsPath + " !");
            if (ProgramContext.m_materialLibs == null)
            {
                return;
            }

            ProgramContext.m_buildLogger.LogMessage(MessageType.Info, "Material libraries were successfully loaded from path: " + ProgramContext.m_materialsPath, "Material Libraries");
            ProgramContext.CheckForMaterialDuplicates();
        }
Пример #3
0
        public static void ExportXml(string xmlFile, MyModelConfiguration configuration)
        {
            XmlSerializer           xmlSerializer = new XmlSerializer(typeof(MyModelConfiguration));
            XmlSerializerNamespaces namespaces    = new XmlSerializerNamespaces();

            namespaces.Add(string.Empty, string.Empty);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (FileStream fileStream = File.Open(xmlFile, FileMode.OpenOrCreate))
                {
                    xmlSerializer.Serialize((Stream)memoryStream, (object)configuration, namespaces);
                    memoryStream.Position = 0L;
                    fileStream.Position   = 0L;
                    if (memoryStream.Length == fileStream.Length && ProgramContext.StreamEquals((Stream)memoryStream, (Stream)fileStream))
                    {
                        return;
                    }
                    fileStream.SetLength(0L);
                    fileStream.Position   = 0L;
                    memoryStream.Position = 0L;
                    memoryStream.WriteTo((Stream)fileStream);
                }
            }
        }
Пример #4
0
        public int Work(object data, IMyBuildLogger[] loggers = null)
        {
            if (loggers != null)
            {
                foreach (IMyBuildLogger logger in loggers)
                {
                    ProgramContext.m_buildLogger.AddLogger(logger);
                }
            }
            ProgramContext.m_buildLogger.AddLogger((IMyBuildLogger)ProgramContext.m_fileLogger);
            this.m_watch = new Stopwatch();
            this.m_watch.Start();
            this.m_args.RegisterArg("s", "/s:SOURCE", (string)null, "Path to source FBX file(s), directory or file. Directories are read recursively. Defaults to current directory.");
            this.m_args.RegisterArg("o", "/o:OUTPUT", "C:\\Program Files (x86)\\Steam\\SteamApps\\common\\SpaceEngineers\\Content\\", "Path to output");
            this.m_args.RegisterArg("m", "/m:MASK", "*.fbx", "File mask of files to process, defaults to *.FBX");
            this.m_args.RegisterArg("l", "/l:LOGFILE", (string)null, "Path to logfile");
            this.m_args.RegisterArg("t", "/t:THREADS", "1", "Run model build on several threads");
            this.m_args.RegisterArg("cob", (string)null, (string)null, "Check if model contains open boundaries");
            this.m_args.RegisterArg("e", (string)null, (string)null, "Force XML export");
            this.m_args.RegisterArg("a", (string)null, (string)null, "Split logfile to separate errors and warnings to separate logfiles .warn log and .err log");
            this.m_args.RegisterArg("u", (string)null, (string)null, "Log file when file is up to date");
            this.m_args.RegisterArg("f", (string)null, (string)null, "Rebuild files even when up-to-date");
            this.m_args.RegisterArg("g", (string)null, (string)null, "Don't compare app build date to files");
            this.m_args.RegisterArg("p", (string)null, (string)null, "Wait for key after build");
            this.m_args.RegisterArg("i", (string)null, (string)null, (string)null);
            this.m_args.RegisterArg("c", (string)null, (string)null, (string)null);
            this.m_args.RegisterArg("do", "/do", (string)null, "Override LOD Distances");
            this.m_args.RegisterArg("d", "/d:LODS", (string)null, "Float values separated by space, defining default values for LOD 1-n");
            this.m_args.RegisterArg("x", "/x:MATERIALSLIB", "C:\\KeenSWH\\Sandbox\\MediaBuild\\MEContent\\Materials", "Path to materials library");

            string[] args = (string[])data;
            try
            {
                this.m_args.Parse(args);
                if (this.m_args.Empty)
                {
                    this.m_args.WriteHelp();
                    return(1);
                }
                if (((IEnumerable <string>)args).FirstOrDefault <string>((Func <string, bool>)(a => a.StartsWith("/o"))) == null)
                {
                    ProgramContext.m_buildLogger.LogMessage(MessageType.Error, "Output path was not specified!", "");
                    return(1);
                }
                if (!Directory.Exists(this.m_args.GetValue("o")))
                {
                    ProgramContext.m_buildLogger.LogMessage(MessageType.Error, "Cannot find output path: " + this.m_args.GetValue("o"), "");
                    return(1);
                }
                if (this.m_args.GetValue("f") == null && this.m_args.GetValue("g") == null)
                {
                    this.appLastChangeDateTime = new DateTime?(File.GetLastWriteTimeUtc(Assembly.GetCallingAssembly().Location));
                }
                if (this.m_args.GetValue("i") != null)
                {
                    this.RunAsJobWorker();
                    return(0);
                }

                if (this.m_args.GetValue("l") != null)
                {
                    string path = this.m_args.GetValue("l");
                    m_fileLogger.InfoLog = new StreamWriter(path);
                    if (this.m_args.GetValue("a") != null)
                    {
                        m_fileLogger.WarningLog = new StreamWriter(Path.ChangeExtension(path, ".warn" + Path.GetExtension(path)));
                        m_fileLogger.ErrorLog   = new StreamWriter(Path.ChangeExtension(path, ".err" + Path.GetExtension(path)));
                    }
                }

                string[] strArray = this.LoadFiles(this.m_args.GetValue("s"), this.m_args.GetValue("m"));

                this.setMaterialsPathForSource(this.m_args.GetValue("x"));
                ProgramContext.LoadMaterialLibs();
                this.m_count = strArray.Length;

                if (this.m_args.GetValue("t") != null)
                {
                    int int32 = Convert.ToInt32(this.m_args.GetValue("t"));
                    if (int32 > 1)
                    {
                        int num = new MyWorkDispatcher((IEnumerable <string>)strArray, this.m_args.GetValue("o"), (string)null, this.m_args.GetValue("f") != null, this.m_args.GetValue("g") != null, this.m_args.GetValue("e") != null, this.m_args.GetValue("cob") != null, this.m_args.GetValue("d")).Run(int32, this.m_args.GetValue("u") != null) ? 0 : 1;
                        ProgramContext.m_buildLogger.Close();
                        this.WaitForKey();
                        return(num);
                    }
                }
                foreach (string file in strArray)
                {
                    this.ProcessFileSafe(file);
                }
            }
            catch (Exception ex)
            {
                ProgramContext.m_buildLogger.LogMessage(MessageType.Error, ex.ToString(), "");
                this.WaitForKey();
                return(1);
            }
            ProgramContext.m_buildLogger.Close();
            this.WaitForKey();
            return(0);
        }
Пример #5
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);
        }