diff --git a/Language/en_US.xaml b/Language/en_US.xaml
index 007d15a..1ccc0c2 100644
--- a/Language/en_US.xaml
+++ b/Language/en_US.xaml
@@ -218,4 +218,10 @@
CuttingGrade
SymmetryLevel
Print
+
+ No rendering plugin found!
+ Image generation failed!
+ Image rendering error:
+ Simulated Heart and Arrow Preview
+ The simulated heart and arrow diagram is a rendered simulation. Actual results should be verified with a cut-scope.
diff --git a/Language/zh_CN.xaml b/Language/zh_CN.xaml
index ee8ee18..46432fb 100644
--- a/Language/zh_CN.xaml
+++ b/Language/zh_CN.xaml
@@ -218,4 +218,10 @@
综合切工等级
综合对称等级
打印
+
+ 未找到渲染插件!
+ 图像生成失败!
+ 图像渲染异常:
+ 仿真心箭图预览
+ 仿真心箭图为模拟渲染,实际请以切工镜观测为准。
\ No newline at end of file
diff --git a/Views/UserControl/Viewport3D.xaml.cs b/Views/UserControl/Viewport3D.xaml.cs
index 65141f2..44d9a92 100644
--- a/Views/UserControl/Viewport3D.xaml.cs
+++ b/Views/UserControl/Viewport3D.xaml.cs
@@ -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");
- RayHelper.GenerateRender(ViewportManager.ViewportTriangle.First().TriangleCode, "123");
+ try
+ {
+ RayHelper.GenerateRender(ViewportManager.ViewportTriangle.First().TriangleCode, "123");
+ }
+ catch (Exception ex)
+ {
+ new MessageBox().Show(ex.Message);
+ }
+
break;
}
diff --git a/Views/UserControl/ViewportData/Helper/RayHelper.cs b/Views/UserControl/ViewportData/Helper/RayHelper.cs
index 20a522d..c933a53 100644
--- a/Views/UserControl/ViewportData/Helper/RayHelper.cs
+++ b/Views/UserControl/ViewportData/Helper/RayHelper.cs
@@ -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);