Skip to content

Commit

Permalink
Вывел Viewer в поток СДК, убрал спам смуз группами у статик объектов
Browse files Browse the repository at this point in the history
  • Loading branch information
VaIeroK committed Aug 5, 2022
1 parent d86e4e4 commit 347a263
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 42 deletions.
85 changes: 56 additions & 29 deletions Source/App/ObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public Surface()
public Thread SdkThread = null;
public bool NORMALS_DEFAULT = true;
System.Diagnostics.Process EditorProcess = null;
System.Diagnostics.Process ViewerProcess = null;
public bool ViewerWorking = false;
public bool EditorWorking = false;
public bool EditorKilled = false;
public double dLastTime = 0.0;
Expand All @@ -146,6 +148,8 @@ public Object_Editor()
EditorProcess.OutputDataReceived += SortOutputHandler;
EditorProcess.StartInfo.UseShellExecute = false;

ViewerProcess = new System.Diagnostics.Process();

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

SaveSklDialog = new FolderSelectDialog();
Expand Down Expand Up @@ -1911,14 +1915,30 @@ private void FastSaveObject(string filename)

private void ClosingForm(object sender, FormClosingEventArgs e)
{
if (Directory.Exists(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) + "\\temp"))
Directory.Delete(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) + "\\temp", true);

if (EditorWorking)
try
{
EditorKilled = true;
EditorProcess.Kill();
if (SdkThread != null && SdkThread.ThreadState != System.Threading.ThreadState.Stopped)
SdkThread.Abort();

if (ViewerWorking)
{
ViewerProcess.Kill();
ViewerProcess.Close();
}

if (EditorWorking)
{
EditorKilled = true;
EditorProcess.Kill();
EditorProcess.Close();
}

Thread.Sleep(100);

if (Directory.Exists(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) + "\\temp"))
Directory.Delete(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) + "\\temp", true);
}
catch (Exception) { }
}

private void CheckTempFileExist()
Expand Down Expand Up @@ -2225,6 +2245,7 @@ private void EditorKeyDown(object sender, KeyEventArgs e)
{
EditorKilled = true;
EditorProcess.Kill();
EditorProcess.Close();
EditorWorking = false;
AutoClosingMessageBox.Show("Process Closed!", "", 1000, MessageBoxIcon.Information);
}
Expand Down Expand Up @@ -2799,7 +2820,7 @@ private void modelExportToolStripMenuItem_Click(object sender, EventArgs e)
"3. Optimize surfaces - îáúåäèíÿåò ìåøè ñ îäèíàêîâûìè òåêñòóðàìè è øåéäåðàìè â îäèí.\n" +
"4. HQ Geometry+ - êîìïèëÿòîð íå áóäåò óäàëÿòü ïîõîæèå vertex'û è face'û, ïîääåðæêà áîëåå ïëîòíîé ñåòêè ïîëèãîíîâ.\n" +
"5. SoC bone export - ïðè ýêñïîðòå äèíàìè÷åñêîãî OGF, íà ïîëèãîí áóäóò âëèÿòü ìàêñèìóì 2 êîñòè. Ïðè îòêëþ÷åíèè áóäåò âêëþ÷åíî CoP âëèÿíèå â 4 êîñòè (íå ïîääåðæèâàåòñÿ â SoC).\n" +
"6. Smooth Type îïðåäåëÿåò òèï ñãëàæèâàíèÿ ïðè ýêñïîðòå ìîäåëåé.\n1) SoC: #1\n2) CS\\CoP: #2\n3) Normals: èñïîëüçóåò îðèãèíàëüíûå Split íîðìàëè.\n4) Auto: ïðîãðàììà áóäåò àâòîìàòè÷åñêè îïðåäåëÿòü òèï ñãëàæèâàíèÿ, ïåðâûìè â ïðèîðèòåòå ñòîÿò íîðìàëè. Åñëè èõ íåò òî íà÷íåòñÿ âûáîð òèïà ñãëàæèâàíèÿ.\nÐàáîòàåò ñ 99% ìîäåëåé."
"6. Smooth Type îïðåäåëÿåò òèï ñãëàæèâàíèÿ ïðè ýêñïîðòå ìîäåëåé.\n1) SoC: #1\n2) CS\\CoP: #2\n3) Normals: èñïîëüçóåò îðèãèíàëüíûå Split íîðìàëè.\n4) Auto: ïðîãðàììà áóäåò àâòîìàòè÷åñêè îïðåäåëÿòü òèï ñãëàæèâàíèÿ, ïåðâûìè â ïðèîðèòåòå ñòîÿò íîðìàëè. Åñëè èõ íåò òî íà÷íåòñÿ âûáîð òèïà ñãëàæèâàíèÿ.\nÏðàâèëüíî îïðåäåëÿåò 95% ìîäåëåé, ÷àùå âñåãî íåïðàâèëüíî îïðåäåëÿåò õàéïîëè ìîäåëè."
, "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Expand Down Expand Up @@ -2909,6 +2930,8 @@ private void viewToolStripMenuItem1_Click(object sender, EventArgs e)

private void ViewtoolStripMenuItem_Click(object sender, EventArgs e)
{
if (!CheckThread()) return;

string exe_path = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf('\\')) + "\\OBJ Viewer.exe";
if (File.Exists(exe_path))
{
Expand Down Expand Up @@ -2936,32 +2959,36 @@ private void ViewtoolStripMenuItem_Click(object sender, EventArgs e)
string ObjName = Path.ChangeExtension(TEMP_FILE_NAME, ".obj");
string MtlName = TEMP_FILE_NAME.Substring(0, TEMP_FILE_NAME.LastIndexOf('\\')) + "\\" + Path.ChangeExtension(GetCorrectString(Path.GetFileName(TEMP_FILE_NAME)), ".mtl");

StartEditor(false, EditorMode.ExportOBJOptimized, TEMP_FILE_NAME, ObjName, -1, 1.0f, pTextures.ToArray());

bool ModelExist = File.Exists(ObjName);

System.Diagnostics.Process Viewer = new System.Diagnostics.Process();
if (ModelExist)
SdkThread = new Thread(() =>
{
Viewer.StartInfo.FileName = exe_path;
Viewer.StartInfo.UseShellExecute = false;
Viewer.StartInfo.Arguments = $"\"{ObjName}\"";
Viewer.Start();
Viewer.WaitForExit();
}
else
AutoClosingMessageBox.Show("Failed to compile model.", "", GetErrorTime(), MessageBoxIcon.Error);
StartEditor(true, EditorMode.ExportOBJOptimized, TEMP_FILE_NAME, ObjName, -1, 1.0f, pTextures.ToArray());

bool ModelExist = File.Exists(ObjName);

if (File.Exists(ObjName))
File.Delete(ObjName);
if (File.Exists(MtlName))
File.Delete(MtlName);
if (ModelExist)
{
ViewerProcess.StartInfo.FileName = exe_path;
ViewerProcess.StartInfo.UseShellExecute = false;
ViewerProcess.StartInfo.Arguments = $"\"{ObjName}\"";
ViewerWorking = true;
ViewerProcess.Start();
ViewerProcess.WaitForExit();
ViewerProcess.Close();
ViewerWorking = false;
}
else
AutoClosingMessageBox.Show("Failed to compile model.", "", GetErrorTime(), MessageBoxIcon.Error);

string[] _files = Directory.GetFiles(TEMP_FILE_NAME.Substring(0, TEMP_FILE_NAME.LastIndexOf('\\')), "*.tga");
foreach (string fl in _files)
File.Delete(fl);
if (File.Exists(ObjName))
File.Delete(ObjName);
if (File.Exists(MtlName))
File.Delete(MtlName);

Viewer.Close();
string[] _files = Directory.GetFiles(TEMP_FILE_NAME.Substring(0, TEMP_FILE_NAME.LastIndexOf('\\')), "*.tga");
foreach (string fl in _files)
File.Delete(fl);
});
SdkThread.Start();
}
else
MessageBox.Show("Can't find OBJ Viewer.exe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down
8 changes: 5 additions & 3 deletions Source/Editors/XrECore/Editor/EditMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void CEditableMesh::GenerateFNormals()
m_Vertices[m_Faces[k].pv[2].pindex]);
}

void CEditableMesh::GenerateVNormals(bool force, bool silent)
void CEditableMesh::GenerateVNormals(bool force, bool silent, bool only_one_msg)
{
m_VNormalsRefs++;
if ((m_VertexNormals || (m_Normals && m_Parent->m_objectFlags.is(CEditableObject::eoNormals))) && !force) return;
Expand All @@ -132,8 +132,9 @@ void CEditableMesh::GenerateVNormals(bool force, bool silent)

if (!m_Parent->m_objectFlags.is(CEditableObject::eoSoCSmooth)) // cop
{
if (!silent)
if (!silent && (!only_one_msg || !m_Parent->m_SmoothMsgSended))
{
m_Parent->m_SmoothMsgSended = true;
WriteLog("..Generate CoP Smooth groups");
Msg("..Generate CoP Smooth groups");
}
Expand Down Expand Up @@ -171,8 +172,9 @@ void CEditableMesh::GenerateVNormals(bool force, bool silent)
}
else // soc
{
if (!silent)
if (!silent && (!only_one_msg || !m_Parent->m_SmoothMsgSended))
{
m_Parent->m_SmoothMsgSended = true;
WriteLog("..Generate SoC Smooth groups");
Msg("..Generate SoC Smooth groups");
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Editors/XrECore/Editor/EditMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ECORE_API CEditableMesh {
public:
static BOOL m_bDraftMeshMode;
void GenerateFNormals ();
void GenerateVNormals (bool force = false, bool silent = false);
void GenerateVNormals (bool force = false, bool silent = false, bool only_one_msg = false);
void GenerateSVertices (u32 influence);
void GenerateSVerticesFast(u32 influence);
void GenerateAdjacency ();
Expand Down
2 changes: 2 additions & 0 deletions Source/Editors/XrECore/Editor/EditObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ CEditableObject::CEditableObject(LPCSTR name):
m_ModifName = "unknown";
m_ModifTime = 0;
m_EditorScript = "";
m_SmoothMsgSended = false;
m_SmoothExportMsgSended = false;
}

CEditableObject::~CEditableObject()
Expand Down
4 changes: 4 additions & 0 deletions Source/Editors/XrECore/Editor/EditObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public CPhysicsShellHolderEditorBase
SMotionVec m_SMotions;
CSMotion* m_ActiveSMotion;
Fmatrix* m_object_xform;

public:
BPVec m_BoneParts;
SurfaceVec m_Surfaces;
Expand All @@ -187,6 +188,9 @@ public CPhysicsShellHolderEditorBase
shared_str m_TempPath;

virtual void InitScript();

bool m_SmoothMsgSended;
bool m_SmoothExportMsgSended;
public:
// options
Flags32 m_objectFlags;
Expand Down
25 changes: 16 additions & 9 deletions Source/Editors/XrECore/Editor/ExportObjectOGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,21 @@ bool CExportObjectOGF::PrepareMESH(CEditableMesh* MESH)
{
// // generate normals
bool bResult = true;
MESH->GenerateVNormals();
MESH->GenerateVNormals(false, false, true);

if(MESH->m_Normals && m_Source->m_objectFlags.is(CEditableObject::eoNormals))
if (!m_Source->m_SmoothExportMsgSended)
{
Log("..Export custom normals");
WriteLog("..Export custom normals");
}
else
{
Log("..Export smooth groups");
WriteLog("..Export smooth groups");
m_Source->m_SmoothExportMsgSended = true;
if (MESH->m_Normals && m_Source->m_objectFlags.is(CEditableObject::eoNormals))
{
Log("..Export custom normals");
WriteLog("..Export custom normals");
}
else
{
Log("..Export smooth groups");
WriteLog("..Export smooth groups");
}
}

u16 surf_counter = 0;
Expand Down Expand Up @@ -626,6 +630,9 @@ void CExportObjectOGF::DetectSmoothType(CEditableMesh* mesh, xr_vector<CEditable

m_Source->m_objectFlags.set(CEditableObject::eoNormals, !!Normals);
m_Source->m_objectFlags.set(CEditableObject::eoSoCSmooth, !!(!bCoP));

if (!Normals)
WriteLog("..SoC\\CoP verts: [%d\\%d]", SoCverts, CoPverts);
WriteLog("..Smooth type detected: %s", Normals ? "Normals" : (bCoP ? "CoP" : "SoC"));
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Editors/XrECore/Editor/ExportSkeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,8 @@ void CExportSkeleton::DetectSmoothType()

m_Source->m_objectFlags.set(CEditableObject::eoNormals, !!Normals);
m_Source->m_objectFlags.set(CEditableObject::eoSoCSmooth, !!(!bCoP));
if (!Normals)
WriteLog("..SoC\\CoP verts: [%d\\%d]", SoCverts, CoPverts);
WriteLog("..Smooth type detected: %s", Normals ? "Normals" : (bCoP ? "CoP" : "SoC"));
}

Expand Down

0 comments on commit 347a263

Please sign in to comment.