|
|
@ -7,17 +7,17 @@ using System.Windows.Forms; |
|
|
|
public class RayHelper |
|
|
|
public class RayHelper |
|
|
|
{ |
|
|
|
{ |
|
|
|
//unity渲染结果(运行前清理) |
|
|
|
//unity渲染结果(运行前清理) |
|
|
|
private static string _image_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\image\"; |
|
|
|
private static string _image_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\Image\"; |
|
|
|
//unity渲染模型缓存(运行前清理) |
|
|
|
//unity渲染模型缓存(运行前清理) |
|
|
|
private static string _stl_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\"; |
|
|
|
private static string _obj_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\Obj"; |
|
|
|
//用于存放unity渲染插件(版本发布独立更新) |
|
|
|
//用于存放unity渲染插件(版本发布独立更新) |
|
|
|
private static string _unity_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\core\"; |
|
|
|
private static string _unity_path = AppDomain.CurrentDomain.BaseDirectory + @"Ray\Core\"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void GenerateRender(string modelInfo, string diamondCode) |
|
|
|
public static void GenerateRender(string modelInfo, string diamondCode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string fileName = GenerateSignature(modelInfo, diamondCode); |
|
|
|
string fileName = GenerateSignature(modelInfo, diamondCode); |
|
|
|
string fullStlPath = Path.Combine(_stl_path, fileName); |
|
|
|
string fullStlPath = Path.Combine(_obj_path, fileName); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 检查STL文件是否存在 |
|
|
|
// 1. 检查STL文件是否存在 |
|
|
|
if (File.Exists(fullStlPath)) |
|
|
|
if (File.Exists(fullStlPath)) |
|
|
@ -31,7 +31,7 @@ public class RayHelper |
|
|
|
|
|
|
|
|
|
|
|
// 2. 清理Unity相关目录 |
|
|
|
// 2. 清理Unity相关目录 |
|
|
|
CleanDirectory(_image_path); |
|
|
|
CleanDirectory(_image_path); |
|
|
|
CleanDirectory(_stl_path); |
|
|
|
CleanDirectory(_obj_path); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 导出模型为STL |
|
|
|
// 3. 导出模型为STL |
|
|
|
ObjExporter.ExportToObj2(ViewportManager.ViewportTriangle, fullStlPath + ".obj"); |
|
|
|
ObjExporter.ExportToObj2(ViewportManager.ViewportTriangle, fullStlPath + ".obj"); |
|
|
@ -73,12 +73,12 @@ public class RayHelper |
|
|
|
|
|
|
|
|
|
|
|
private static void ExecuteUnityRendering(string fileName, int type) |
|
|
|
private static void ExecuteUnityRendering(string fileName, int type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string arguments = $"--model={_stl_path + fileName} --output={_image_path} --type={type}"; |
|
|
|
string arguments = $@"--model {_obj_path + fileName + ".obj"} --output {_image_path}\{type}.jpg --type {type}"; |
|
|
|
string exePath = Path.Combine(_unity_path, "RayTracing.exe"); |
|
|
|
string exePath = Path.Combine(_unity_path, "raytracing2.exe"); |
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(exePath)) |
|
|
|
if (!File.Exists(exePath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new FileNotFoundException("Unity渲染插件未找到", exePath); |
|
|
|
throw new FileNotFoundException("渲染插件未找到", exePath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using (Process process = new Process()) |
|
|
|
using (Process process = new Process()) |
|
|
@ -92,15 +92,15 @@ public class RayHelper |
|
|
|
|
|
|
|
|
|
|
|
if (process.ExitCode != 0) |
|
|
|
if (process.ExitCode != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new Exception("Unity渲染进程异常退出。"); |
|
|
|
throw new Exception("渲染进程异常退出。"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static bool ValidateImages() |
|
|
|
private static bool ValidateImages() |
|
|
|
{ |
|
|
|
{ |
|
|
|
string heartImage = Path.Combine(_image_path, "0.png"); |
|
|
|
string heartImage = Path.Combine(_image_path, "0.jpg"); |
|
|
|
string arrowImage = Path.Combine(_image_path, "1.png"); |
|
|
|
string arrowImage = Path.Combine(_image_path, "1.jpg"); |
|
|
|
|
|
|
|
|
|
|
|
return File.Exists(heartImage) && File.Exists(arrowImage); |
|
|
|
return File.Exists(heartImage) && File.Exists(arrowImage); |
|
|
|
} |
|
|
|
} |
|
|
@ -119,7 +119,7 @@ public class RayHelper |
|
|
|
|
|
|
|
|
|
|
|
PictureBox heartBox = new PictureBox |
|
|
|
PictureBox heartBox = new PictureBox |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImageLocation = Path.Combine(_image_path, "0.png"), |
|
|
|
ImageLocation = Path.Combine(_image_path, "0.jpg"), |
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage, |
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage, |
|
|
|
Dock = DockStyle.Left, |
|
|
|
Dock = DockStyle.Left, |
|
|
|
Width = 400 |
|
|
|
Width = 400 |
|
|
@ -127,7 +127,7 @@ public class RayHelper |
|
|
|
|
|
|
|
|
|
|
|
PictureBox arrowBox = new PictureBox |
|
|
|
PictureBox arrowBox = new PictureBox |
|
|
|
{ |
|
|
|
{ |
|
|
|
ImageLocation = Path.Combine(_image_path, "1.png"), |
|
|
|
ImageLocation = Path.Combine(_image_path, "1.jpg"), |
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage, |
|
|
|
SizeMode = PictureBoxSizeMode.CenterImage, |
|
|
|
Dock = DockStyle.Right, |
|
|
|
Dock = DockStyle.Right, |
|
|
|
Width = 400 |
|
|
|
Width = 400 |
|
|
|