Esempio n. 1
0
        private async void compile_Click(object sender, EventArgs e)
        {
            Stopwatch trackCompileTime = new Stopwatch();

            trackCompileTime.Start();

            output.Text = "";
            outputQueue.Clear();
            compileProgress.Value = 0;

            foreach (Control control in CONTROLS_TO_DISABLE_WHEN_COMPILING)
            {
                control.Enabled = false;
            }

            Compiler.UseWaitCursor = true;
            ModelCompiler.PreScheduleTasks();

            Func <AssemblerData> assemble;

            if (compilerTypeSelect.Text == "Avatar")
            {
                var assembler  = new CharacterAssembler();
                var userAvatar = UserAvatar.FromUsername(currentUser.Username);
                assemble = new Func <AssemblerData>(() => assembler.Assemble(userAvatar));
            }
            else
            {
                var assembler = new CatalogItemAssembler();
                assemble = new Func <AssemblerData>(() => assembler.Assemble(currentAssetId));
            }

            Task <AssemblerData> buildModel = Task.Run(assemble);

            while (!buildModel.IsCompleted)
            {
                await UpdateCompilerState();
            }

            if (buildModel.IsFaulted)
            {
                LogException(buildModel, "assemble");
            }
            else
            {
                AssemblerData data         = buildModel.Result;
                Task <string> compileModel = ModelCompiler.Compile(selectedGame, data);

                while (!compileModel.IsCompleted)
                {
                    await UpdateCompilerState();
                }

                if (compileModel.IsFaulted)
                {
                    LogException(compileModel, "compile");
                }
                else
                {
                    PrintHeader("FINISHED MODEL!");
                    trackCompileTime.Stop();

                    Print("Assembled in {0} seconds.", trackCompileTime.Elapsed.TotalSeconds);

                    await UpdateCompilerState();

                    compileModel.Wait();

                    latestCompiledModel  = compileModel.Result;
                    latestCompiledOnGame = selectedGame;
                }
            }

            foreach (Control control in CONTROLS_TO_DISABLE_WHEN_COMPILING)
            {
                control.Enabled = true;
            }

            if (trackCompileTime.IsRunning)
            {
                trackCompileTime.Stop();
            }

            Compiler.UseWaitCursor = false;
            progressQueue.Clear();
        }
Esempio n. 2
0
        public static async Task <string> Compile(GameInfo gameInfo, AssemblerData data)
        {
            if (!gameInfo.ReadyToUse)
            {
                throw new Exception("This gameinfo.txt file isn't ready to use!");
            }

            Rbx2Source.PrintHeader("COMPILING MODEL");
            string studioMdlPath = gameInfo.StudioMdlPath;

            ThirdPartyUtility studioMdl = new ThirdPartyUtility(studioMdlPath);

            studioMdl.AddParameter("game", gameInfo.GameDirectory);
            studioMdl.AddParameter("nop4");
            studioMdl.AddParameter(UtilParameter.FilePush(data.CompilerScript));
            await studioMdl.Run();

            Rbx2Source.MarkTaskCompleted("CompileModel");

            Rbx2Source.PrintHeader("COMPILING TEXTURES");
            if (!File.Exists(vtfCompilerPath))
            {
                byte[]       vtfZip  = ResourceUtility.GetResource("VTFCmd.zip");
                MemoryStream extract = new MemoryStream(vtfZip);
                ZipArchive   archive = new ZipArchive(extract);
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    string name   = entry.Name;
                    string path   = Path.Combine(utilityDir, name);
                    Stream stream = entry.Open();
                    byte[] file   = FileUtility.ReadFullStream(stream);
                    FileUtility.WriteFile(path, file);
                }
            }

            string pngWildcard = Path.Combine(data.TextureDirectory, "*.png");

            vtfCompiler = new ThirdPartyUtility(vtfCompilerPath);
            vtfCompiler.AddParameter("folder", pngWildcard);
            vtfCompiler.AddParameter("resize");
            vtfCompiler.AddParameter("format", "ABGR8888");             // No compression? THIS IS FINE.png
            vtfCompiler.AddParameter("output", data.MaterialDirectory);
            await vtfCompiler.Run();

            Rbx2Source.MarkTaskCompleted("CompileTextures");

            string gameDirectory = gameInfo.GameDirectory;
            string modelPath     = Path.Combine(gameDirectory, "models", data.ModelName);
            string materialPath  = Path.Combine(gameDirectory, "materials", "models", data.CompileDirectory);

            FileUtility.InitiateEmptyDirectories(materialPath);

            foreach (string filePath in Directory.GetFiles(data.MaterialDirectory))
            {
                FileInfo info         = new FileInfo(filePath);
                string   fileName     = info.Name;
                string   destFileName = Path.Combine(materialPath, fileName);
                info.CopyTo(destFileName);
            }

            Rbx2Source.MarkTaskCompleted("MoveTextures");
            return(modelPath);
        }