feat: 心箭图插件结合

master
tongg 5 months ago
parent 115b06abaf
commit 9c7f2838b2
  1. 6
      Language/en_US.xaml
  2. 6
      Language/zh_CN.xaml
  3. 9
      Views/UserControl/Viewport3D.xaml.cs
  4. 58
      Views/UserControl/ViewportData/Helper/RayHelper.cs

@ -218,4 +218,10 @@
<sys:String x:Key="CuttingGrade">CuttingGrade</sys:String>
<sys:String x:Key="SymmetryLevel">SymmetryLevel</sys:String>
<sys:String x:Key="Print">Print</sys:String>
<sys:String x:Key="RayTracingNoPlugin">No rendering plugin found!</sys:String>
<sys:String x:Key="RayTracingGenError">Image generation failed!</sys:String>
<sys:String x:Key="RayTracingFail">Image rendering error:</sys:String>
<sys:String x:Key="RayTracingFormTitle">Simulated Heart and Arrow Preview</sys:String>
<sys:String x:Key="RayTracingFormMessage">The simulated heart and arrow diagram is a rendered simulation. Actual results should be verified with a cut-scope.</sys:String>
</ResourceDictionary>

@ -218,4 +218,10 @@
<sys:String x:Key="CuttingGrade">综合切工等级</sys:String>
<sys:String x:Key="SymmetryLevel">综合对称等级</sys:String>
<sys:String x:Key="Print">打印</sys:String>
<sys:String x:Key="RayTracingNoPlugin">未找到渲染插件!</sys:String>
<sys:String x:Key="RayTracingGenError">图像生成失败!</sys:String>
<sys:String x:Key="RayTracingFail">图像渲染异常:</sys:String>
<sys:String x:Key="RayTracingFormTitle">仿真心箭图预览</sys:String>
<sys:String x:Key="RayTracingFormMessage">仿真心箭图为模拟渲染,实际请以切工镜观测为准。</sys:String>
</ResourceDictionary>

@ -17,6 +17,7 @@ using SharpDX.Direct3D11;
using SharpDX.DXGI;
using MathNet.Numerics;
using System.Windows.Media;
using MessageBox = SparkClient.Views.Dialog.MessageBox;
using ObjExporter = SparkClient.Views.UserControl.ViewportData.Helper.ObjExporter;
@ -220,7 +221,15 @@ public partial class Viewport3D
break;
case "BtnShow3DView":
// ObjExporter.ExportToObj2(ViewportManager.ViewportTriangle, @"D:\id03.obj");
try
{
RayHelper.GenerateRender(ViewportManager.ViewportTriangle.First().TriangleCode, "123");
}
catch (Exception ex)
{
new MessageBox().Show(ex.Message);
}
break;
}

@ -1,3 +1,7 @@
using System.Drawing;
using System.Text;
using SparkClient.Model.Helper;
namespace SparkClient.Views.UserControl.ViewportData.Helper;
using System;
using System.Diagnostics;
@ -46,14 +50,14 @@ public class RayHelper
}
else
{
MessageBox.Show("生成失败,请重试。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new Exception(MultilingualHelper.getString("RayTracingGenError"));
}
}
private static string GenerateSignature(string modelInfo, string diamondCode)
{
// 模拟生成签名逻辑,可以自定义为更复杂的算法
return modelInfo.GetHashCode() + "_" + diamondCode.GetHashCode();
return modelInfo;
}
private static void CleanDirectory(string path)
@ -73,12 +77,12 @@ public class RayHelper
private static void ExecuteUnityRendering(string fileName, int type)
{
string arguments = $@"--model {_obj_path + fileName + ".obj"} --output {_image_path}\{type}.jpg --type {type}";
string exePath = Path.Combine(_unity_path, "raytracing2.exe");
string arguments = $@"--obj {_obj_path + @"\" + fileName + ".obj"} --output {_image_path}{type}.jpg --mode {type}";
string exePath = Path.Combine(_unity_path, "hart.exe");
if (!File.Exists(exePath))
{
throw new FileNotFoundException("渲染插件未找到", exePath);
throw new FileNotFoundException(MultilingualHelper.getString("RayTracingNoPlugin"), exePath);
}
using (Process process = new Process())
@ -87,12 +91,39 @@ public class RayHelper
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
// 使用StringBuilder来捕获输出和错误信息
StringBuilder outputBuilder = new StringBuilder();
StringBuilder errorBuilder = new StringBuilder();
process.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
outputBuilder.AppendLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
errorBuilder.AppendLine(e.Data);
};
process.Start();
// 开始异步读取输出和错误流
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
// 获取完整的输出和错误信息
string outputMsg = outputBuilder.ToString();
string errorMsg = errorBuilder.ToString();
errorMsg = string.IsNullOrWhiteSpace(errorMsg)?outputMsg:errorMsg;
if (process.ExitCode != 0)
{
throw new Exception("渲染进程异常退出。");
throw new Exception($"{MultilingualHelper.getString("RayTracingFail")}{errorMsg}");
}
}
}
@ -110,17 +141,19 @@ public class RayHelper
// 创建一个简单的图片展示窗口
Form form = new Form
{
Text = "心箭图模拟渲染",
Text = MultilingualHelper.getString("RayTracingFormTitle"),
Width = 800,
Height = 600,
Height = 450,
MaximizeBox = false,
MinimizeBox = false,
BackColor = Color.Black,
StartPosition = FormStartPosition.CenterScreen,
};
PictureBox heartBox = new PictureBox
{
ImageLocation = Path.Combine(_image_path, "0.jpg"),
SizeMode = PictureBoxSizeMode.CenterImage,
SizeMode = PictureBoxSizeMode.Zoom,
Dock = DockStyle.Left,
Width = 400
};
@ -128,7 +161,7 @@ public class RayHelper
PictureBox arrowBox = new PictureBox
{
ImageLocation = Path.Combine(_image_path, "1.jpg"),
SizeMode = PictureBoxSizeMode.CenterImage,
SizeMode = PictureBoxSizeMode.Zoom,
Dock = DockStyle.Right,
Width = 400
};
@ -138,10 +171,11 @@ public class RayHelper
Label label = new Label
{
Text = "[预览版]心箭图为模拟渲染,实际请以切工镜观测为准。",
Text = MultilingualHelper.getString("RayTracingFormMessage"),
Dock = DockStyle.Bottom,
Height = 30,
TextAlign = System.Drawing.ContentAlignment.MiddleCenter
TextAlign = System.Drawing.ContentAlignment.MiddleCenter,
ForeColor = Color.WhiteSmoke,
};
form.Controls.Add(label);

Loading…
Cancel
Save