@ -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 --typ e {type}" ;
string exePath = Path . Combine ( _ unity_path , "raytracing2 .exe" ) ;
string arguments = $@"--obj {_obj_path + @" \ " + fileName + " . obj "} --output {_image_path}{type}.jpg --mod e {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 = 8 0 0 ,
Height = 6 0 0 ,
Height = 4 5 0 ,
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 = 4 0 0
} ;
@ -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 = 4 0 0
} ;
@ -138,10 +171,11 @@ public class RayHelper
Label label = new Label
{
Text = "[预览版]心箭图为模拟渲染,实际请以切工镜观测为准。" ,
Text = MultilingualHelper . getString ( "RayTracingFormMessage" ) ,
Dock = DockStyle . Bottom ,
Height = 3 0 ,
TextAlign = System . Drawing . ContentAlignment . MiddleCenter
TextAlign = System . Drawing . ContentAlignment . MiddleCenter ,
ForeColor = Color . WhiteSmoke ,
} ;
form . Controls . Add ( label ) ;