private void Export(object sender, EventArgs e) { if (!File.Exists(Path.Combine(Settings.Default.ProjectPath, "Bin32", "rc", "rc.exe"))) { MessageBox.Show("Invalid project folder specified, couldn't locate the resource compiler."); return; } if (!File.Exists(uxSourceTextbox.Text) || new FileInfo(uxSourceTextbox.Text).Extension.ToLower() != ".fbx") { MessageBox.Show("Nonexistent file specified, or file is not an FBX file."); return; } var dialog = new SaveFileDialog { Filter = "CryENGINE Model (*.cgf)|*.cgf" }; if (dialog.ShowDialog() == DialogResult.OK) { var scene = Scene.Import(uxSourceTextbox.Text); scene.ConvertAxes(AxisConversionType.Max); scene.RootNode.Scale *= (float)uxScaleUpDown.Value; scene.BakeTransform(scene.RootNode); var node = scene.RootNode.ChildNodes.FirstOrDefault(n => n.Attributes.Any(a => a.Type == NodeAttributeType.Mesh)); if (node == default(SceneNode)) { MessageBox.Show("No mesh found in the FBX scene; ensure your mesh is not parented."); return; } var mesh = node.Mesh; mesh.UVLayer = (int)uxUVLayer.Value; var writer = new StringWriter(); Logging.Log += (text, type) => writer.WriteLine(text); var output = new FileInfo(dialog.FileName); var dae = new FileInfo(output.FullName.ToLower().Replace(".cgf", ".dae")); FbxConverter.ToCollada(mesh, dae); ColladaConverter.CEPath = new DirectoryInfo(Settings.Default.ProjectPath); ColladaConverter.ToCgf(dae); dae.Delete(); File.Delete(dae + ".rcdone"); uxLog.Text = writer.ToString(); var selected = ActiveControl; ActiveControl = uxLog; uxLog.SelectionStart = 0; uxLog.ScrollToCaret(); ActiveControl = selected; } }
private void CompileSelection(params FileInfo[] files) { foreach (var file in files) { var scene = Scene.Import(file.FullName); scene.ConvertAxes(AxisConversionType.Max); scene.RootNode.Scale *= (float)uxScaleUpDown.Value; scene.BakeTransform(scene.RootNode); var node = scene.RootNode.ChildNodes.FirstOrDefault(n => n.Attributes.Any(a => a.Type == NodeAttributeType.Mesh)); if (node == default(SceneNode)) { m_worker.ReportProgress(0, "No suitable mesh found in file: " + file.FullName); continue; } var mesh = node.Mesh; // Fix for cases where UVs reside on a different layer mesh.UVLayer = (int)uxUVUpDown.Value; var outputFile = GetMirrorFile(file); var outputDir = outputFile.Directory; if (!outputDir.Exists) { outputDir.Create(); } var daeFile = new FileInfo(outputFile.FullName.ToLower().Replace(".fbx", ".dae")); var cgfFile = new FileInfo(daeFile.FullName.Replace(".dae", ".cgf")); var originalTime = cgfFile.LastWriteTime; FbxConverter.ToCollada(mesh, daeFile); var finalFile = ColladaConverter.ToCgf(daeFile); File.Delete(daeFile + ".rcdone"); daeFile.Delete(); if (!finalFile.Exists) { m_worker.ReportProgress(0, "Failed to compile file: " + file.FullName); } else if (originalTime == finalFile.LastWriteTime) { m_worker.ReportProgress(0, "Failed to compile file but a CGF already exists: " + file.FullName); } else { m_worker.ReportProgress(0, "Successfully converted: " + file.FullName); } } }