From 433cf0262430945a3f77b4d0cba6700468a348a1 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 2 Sep 2012 14:10:12 +0200 Subject: [PATCH] Added: #1440 Initial code for shape export --HG-- branch : build_pipeline_v3 --- code/nel/include/nel/misc/tool_logger.h | 23 +- .../nel_export/nel_export_export.cpp | 13 + .../nel_export/nel_export_script.cpp | 73 ++++ .../3d/plugin_max/nel_mesh_lib/calc_lm.cpp | 8 + .../3d/plugin_max/nel_mesh_lib/export_nel.h | 3 + .../plugin_max/nel_mesh_lib/export_script.cpp | 5 + .../plugin_max/scripts/export_footer.ms | 32 ++ .../plugin_max/scripts/export_header.ms | 134 ++++++++ .../pipeline/plugin_max/scripts/shape.ms | 322 ++++++++++++++++++ 9 files changed, 600 insertions(+), 13 deletions(-) create mode 100644 code/nel/tools/pipeline/plugin_max/scripts/export_footer.ms create mode 100644 code/nel/tools/pipeline/plugin_max/scripts/export_header.ms create mode 100644 code/nel/tools/pipeline/plugin_max/scripts/shape.ms diff --git a/code/nel/include/nel/misc/tool_logger.h b/code/nel/include/nel/misc/tool_logger.h index be9b704fa..12ac28c2d 100644 --- a/code/nel/include/nel/misc/tool_logger.h +++ b/code/nel/include/nel/misc/tool_logger.h @@ -5,6 +5,7 @@ * \author Jan Boon (Kaetemi) * Tool logger is fully implemented in header so small tools do not * need to link to this library unnecessarily. + * NOTE: Needs to be changed not to use time_nl and string_common. */ /* @@ -43,8 +44,6 @@ namespace PIPELINE { -namespace { - #ifdef ERROR #undef ERROR #endif @@ -78,17 +77,17 @@ private: FILE *m_DependLog; public: - CToolLogger() + inline CToolLogger() { } - virtual ~CToolLogger() + inline ~CToolLogger() { release(); } - void initError(const std::string &errorLog) + inline void initError(const std::string &errorLog) { releaseError(); @@ -99,7 +98,7 @@ public: } - void initDepend(const std::string &dependLog) + inline void initDepend(const std::string &dependLog) { releaseDepend(); @@ -109,7 +108,7 @@ public: // fflush(m_DependLog); } - void writeError(TError type, const std::string &path, const std::string &error) + inline void writeError(TError type, const std::string &path, const std::string &error) { if (m_ErrorLog) { @@ -138,7 +137,7 @@ public: } /// inputFile can only be file. [? May be not-yet-existing file for expected input for future build runs. ?] Directories are handled on process level. [? You should call this before calling writeError on inputFile, so the error is also linked from the outputFile. ?] - void writeDepend(TDepend type, const std::string &outputFile, const std::string &inputFile) + inline void writeDepend(TDepend type, const std::string &outputFile, const std::string &inputFile) { if (m_DependLog) { @@ -163,7 +162,7 @@ public: } } - void releaseError() + inline void releaseError() { if (m_ErrorLog) { @@ -173,7 +172,7 @@ public: } } - void releaseDepend() + inline void releaseDepend() { if (m_DependLog) { @@ -183,15 +182,13 @@ public: } } - void release() + inline void release() { releaseError(); releaseDepend(); } }; /* class CToolLogger */ -} /* anonymous namespace */ - } /* namespace PIPELINE */ #endif /* #ifndef PIPELINE_TOOL_LOGGER_H */ diff --git a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp index fbca1f037..adfeec57a 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp @@ -43,10 +43,16 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) { DWORD dwRetVal = GetTempPathA(MAX_PATH, tempPathBuffer); if (dwRetVal > MAX_PATH || (dwRetVal == 0)) + { + ToolLogger.writeError(PIPELINE::ERROR, "*", "GetTempPath failed"); nlerror("GetTempPath failed"); + } UINT uRetVal = GetTempFileNameA(tempPathBuffer, TEXT("_nel_export_mesh_"), 0, tempFileName); if (uRetVal == 0) + { + ToolLogger.writeError(PIPELINE::ERROR, "*", "GetTempFileName failed"); nlerror("GetTempFileName failed"); + } // Eval the object a time ObjectState os = node.EvalWorldState(time); @@ -118,6 +124,7 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) catch (...) { nlwarning("Shape serialization failed!"); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Shape serialization failed"); try { file.close(); @@ -132,6 +139,7 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) else { nlwarning("Failed to create file %s", tempFileName); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Failed to create temporary shape file"); if (_TerminateOnFileOpenIssues) nelExportTerminateProcess(); } @@ -148,6 +156,7 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) catch (...) { nlwarning("Failed to delete pShape pointer! Something might be wrong."); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Failed to delete pShape pointer"); remove(tempFileName); bRet = false; } @@ -174,6 +183,7 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) else { nlwarning("Failed to open file: %s", tempFileName); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Failed to open temp shape file"); if (_TerminateOnFileOpenIssues) nelExportTerminateProcess(); } @@ -181,6 +191,7 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) catch (...) { nlwarning("Failed to verify shape. Must crash now."); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Failed to verify shape"); remove(tempFileName); bRet = false; } @@ -191,11 +202,13 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time) catch (...) { nlwarning("Fatal exception at CNelExport::exportMesh."); + ToolLogger.writeError(PIPELINE::ERROR, "*", "Fatal exception at CNelExport::exportMesh"); bRet = false; } if (bRet) { + ToolLogger.writeDepend(PIPELINE::BUILD, sPath, "*"); try { remove(sPath); diff --git a/code/nel/tools/3d/plugin_max/nel_export/nel_export_script.cpp b/code/nel/tools/3d/plugin_max/nel_export/nel_export_script.cpp index 7bc128706..e3d8a4a12 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/nel_export_script.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/nel_export_script.cpp @@ -63,6 +63,13 @@ def_visible_primitive ( set_file_modification_date, "NeLSetFileModificationDate def_visible_primitive ( force_quit_on_msg_displayer, "NelForceQuitOnMsgDisplayer"); def_visible_primitive ( force_quit_right_now, "NelForceQuitRightNow"); +def_visible_primitive(tool_logger_init_error, "NelToolLoggerInitError"); +def_visible_primitive(tool_logger_init_depend, "NelToolLoggerInitDepend"); +def_visible_primitive(tool_logger_write_error, "NelToolLoggerWriteError"); +def_visible_primitive(tool_logger_write_depend, "NelToolLoggerWriteDepend"); +def_visible_primitive(tool_logger_release_error, "NelToolLoggerReleaseError"); +def_visible_primitive(tool_logger_release_depend, "NelToolLoggerReleaseDepend"); + char *sExportShapeErrorMsg = "NeLExportShape [Object] [Filename.shape]"; char *sExportShapeExErrorMsg = "NeLExportShapeEx [Object] [Filename.shape] [bShadow] [bExportLighting] [sLightmapPath] [nLightingLimit] [fLumelSize] [nOverSampling] [bExcludeNonSelected] [bShowLumel]"; char *sExportAnimationErrorMsg = "NelExportAnimation [node array] [Filename.anim] [bool_scene_animation]"; @@ -114,10 +121,12 @@ Value* export_shape_cf (Value** arg_list, int count) } catch (Exception &e) { + ToolLogger.writeError(PIPELINE::ERROR, "*", e.what()); nlwarning ("ERROR (NelExportShape) %s", e.what()); } catch (...) { + ToolLogger.writeError(PIPELINE::ERROR, "*", "Exception"); nlwarning ("ERROR (NelExportShape) catch (...)"); } nlinfo("ret"); @@ -189,10 +198,12 @@ Value* export_shape_ex_cf (Value** arg_list, int count) } catch (Exception &e) { + ToolLogger.writeError(PIPELINE::ERROR, "*", e.what()); nlwarning ("ERROR (NelExportShapeEx) %s", e.what()); } catch (...) { + ToolLogger.writeError(PIPELINE::ERROR, "*", "Exception"); nlwarning ("ERROR (NelExportShapeEx) catch (...)"); } nlinfo("ret"); @@ -986,6 +997,68 @@ Value* force_quit_right_now_cf(Value** arg_list, int count) return &true_value; } +Value* tool_logger_init_error_cf(Value** arg_list, int count) +{ + check_arg_count(NelToolLoggerInitError, 1, count); + type_check(arg_list[0], String, ""); + + ToolLogger.initError(arg_list[0]->to_string()); + + return &true_value; +} + +Value* tool_logger_init_depend_cf(Value** arg_list, int count) +{ + check_arg_count(NelToolLoggerInitDepend, 1, count); + type_check(arg_list[0], String, ""); + + ToolLogger.initDepend(arg_list[0]->to_string()); + + return &true_value; +} + +Value* tool_logger_write_error_cf(Value** arg_list, int count) +{ + check_arg_count(NelToolLoggerWriteError, 3, count); + type_check(arg_list[0], String, ""); + type_check(arg_list[1], String, ""); + type_check(arg_list[2], String, ""); + + // TYPE, PATH, MESSAGE + std::string type = arg_list[0]->to_string(); + ToolLogger.writeError(type == "MESSAGE" ? PIPELINE::MESSAGE : type == "WARNING" ? PIPELINE::WARNING : PIPELINE::ERROR, arg_list[1]->to_string(), arg_list[2]->to_string()); + + return &true_value; +} + +Value* tool_logger_write_depend_cf(Value** arg_list, int count) +{ + check_arg_count(NelToolLoggerWriteDepend, 3, count); + type_check(arg_list[0], String, ""); + type_check(arg_list[1], String, ""); + type_check(arg_list[2], String, ""); + + // TYPE, OUTPUT, INPUT + std::string type = arg_list[0]->to_string(); + ToolLogger.writeDepend(type == "RUNTIME" ? PIPELINE::RUNTIME : type == "DIRECTORY" ? PIPELINE::DIRECTORY : PIPELINE::BUILD, arg_list[1]->to_string(), arg_list[2]->to_string()); + + return &true_value; +} + +Value* tool_logger_release_error_cf(Value** arg_list, int count) +{ + ToolLogger.releaseError(); + + return &true_value; +} + +Value* tool_logger_release_depend_cf(Value** arg_list, int count) +{ + ToolLogger.releaseDepend(); + + return &true_value; +} + /*===========================================================================*\ | MAXScript Plugin Initialization \*===========================================================================*/ diff --git a/code/nel/tools/3d/plugin_max/nel_mesh_lib/calc_lm.cpp b/code/nel/tools/3d/plugin_max/nel_mesh_lib/calc_lm.cpp index 0f08dd163..15e8e68ba 100644 --- a/code/nel/tools/3d/plugin_max/nel_mesh_lib/calc_lm.cpp +++ b/code/nel/tools/3d/plugin_max/nel_mesh_lib/calc_lm.cpp @@ -2012,6 +2012,7 @@ void CExportNel::deleteLM(INode& ZeNode) if (!CFile::deleteFile(sSaveName)) { nlwarning("Failed to delete file %s.", sSaveName.c_str()); + ToolLogger.writeError(PIPELINE::ERROR, sSaveName.c_str(), "Failed to delete previously built lightmap"); } } } @@ -2272,6 +2273,7 @@ bool CExportNel::calculateLM( CMesh::CMeshBuild *pZeMeshBuild, CMeshBase::CMeshB thetext = "Warning "; thetext += ZeNode.GetName(); thetext = "have all faces NOT mapped (UV2)"; + ToolLogger.writeError(PIPELINE::ERROR, "*", thetext); if (gOptions.FeedBack != NULL) { gOptions.FeedBack->setLine (11, thetext); @@ -2322,6 +2324,8 @@ bool CExportNel::calculateLM( CMesh::CMeshBuild *pZeMeshBuild, CMeshBase::CMeshB sTmp += ZeNode.GetName(); sTmp += " has mapping problem"; + ToolLogger.writeError(PIPELINE::ERROR, "*", sTmp); + // Script trace mprintf ((sTmp+"\n").c_str()); @@ -2590,6 +2594,7 @@ bool CExportNel::calculateLM( CMesh::CMeshBuild *pZeMeshBuild, CMeshBase::CMeshB nlinfo("DELETE %s", sLMName.c_str()); if (!CFile::deleteFile(sLMName)) { + ToolLogger.writeError(PIPELINE::ERROR, sLMName, "Failed to delete previously built lightmap"); nlwarning("Failed to delete file %s", sLMName.c_str()); } } @@ -2606,6 +2611,8 @@ bool CExportNel::calculateLM( CMesh::CMeshBuild *pZeMeshBuild, CMeshBase::CMeshB // cust copy to 32 bits LightMap.copyColToBitmap32 (pLightMap, j); + ToolLogger.writeDepend(PIPELINE::BUILD, sSaveName, "*"); + COFile f( sSaveName ); try { @@ -2624,6 +2631,7 @@ bool CExportNel::calculateLM( CMesh::CMeshBuild *pZeMeshBuild, CMeshBase::CMeshB } catch(Exception &e) { + ToolLogger.writeError(PIPELINE::ERROR, sSaveName, "Cannot write the lightmap file"); if (gOptions.FeedBack != NULL) { char message[512]; diff --git a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_nel.h b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_nel.h index d9383fea2..2f73f4463 100644 --- a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_nel.h +++ b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_nel.h @@ -28,6 +28,9 @@ #include "nel/3d/animation_time.h" #include "nel/3d/animation_time.h" #include "nel/../../src/pacs/collision_mesh_build.h" +#include "nel/misc/tool_logger.h" + +extern PIPELINE::CToolLogger ToolLogger; #define UVGEN_MISSING (-1) #define UVGEN_REFLEXION (-2) diff --git a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_script.cpp b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_script.cpp index a0971d587..42c967858 100644 --- a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_script.cpp +++ b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_script.cpp @@ -25,6 +25,11 @@ #endif #include "export_nel.h" #include "export_appdata.h" +#include + +// *************************************************************************** + +PIPELINE::CToolLogger ToolLogger; // *************************************************************************** diff --git a/code/nel/tools/pipeline/plugin_max/scripts/export_footer.ms b/code/nel/tools/pipeline/plugin_max/scripts/export_footer.ms new file mode 100644 index 000000000..3fab52b1d --- /dev/null +++ b/code/nel/tools/pipeline/plugin_max/scripts/export_footer.ms @@ -0,0 +1,32 @@ + +try +( + undo off + ( + NelToolLoggerInitError %LogErrorFile% + NelToolLoggerInitDepend %LogDependFiles% + + -- Unhide, unselect + unhidecategory() + max unhide all + max select none + + -- Setup + lowercasenodes() + dependxref undefined + + -- Go! + runNelMaxExport() + + NelToolLoggerReleaseError + NelToolLoggerReleaseDepend + + gc() + ) +) +catch +( + -- Error + nlerror("Fatal error occured") + NelForceQuitRightNow() +) diff --git a/code/nel/tools/pipeline/plugin_max/scripts/export_header.ms b/code/nel/tools/pipeline/plugin_max/scripts/export_header.ms new file mode 100644 index 000000000..2e22c755a --- /dev/null +++ b/code/nel/tools/pipeline/plugin_max/scripts/export_header.ms @@ -0,0 +1,134 @@ + + +-- ################################################################# +-- ## %PreGenWarning% +-- ################################################################# + + +-- Allocate 20 Me for the script +heapSize += 15000000 + +-- In case of error just abort the app and don't show nel report window +NelForceQuitOnMsgDisplayer() + +-- Global definitions +NEL3D_APPDATA_LOD_NAME_COUNT_MAX = 10 +NEL3D_APPDATA_LOD = 1423062537 +NEL3D_APPDATA_LOD_NAME_COUNT = NEL3D_APPDATA_LOD +NEL3D_APPDATA_LOD_NAME = NEL3D_APPDATA_LOD_NAME_COUNT+1 +NEL3D_APPDATA_LOD_BLEND_IN = NEL3D_APPDATA_LOD_NAME+NEL3D_APPDATA_LOD_NAME_COUNT_MAX +NEL3D_APPDATA_LOD_BLEND_OUT = NEL3D_APPDATA_LOD_BLEND_IN+1 +NEL3D_APPDATA_LOD_COARSE_MESH = NEL3D_APPDATA_LOD_BLEND_OUT+1 + +fn lowercase instring = +( + local upper, lower, outstring + upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" + lower="abcdefghijklmnopqrstuvwxyz" + + outstring = copy instring + + for iii = 1 to outstring.count do + ( + jjj = findString upper outstring[iii] + if (jjj != undefined) then + outstring[iii] = lower[jjj] + else + outstring[iii] = instring[iii] + ) + return outstring -- value of outstring will be returned as function result +) + +fn uppercase instring = +( + local upper, lower, outstring + upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" + lower="abcdefghijklmnopqrstuvwxyz" + + outstring = copy instring + + for iii = 1 to outstring.count do + ( + jjj = findString upper outstring[iii] + if (jjj != undefined) then + outstring[iii] = upper[jjj] + else + outstring[iii] = instring[iii] + ) + return outstring -- value of outstring will be returned as function result +) + +-- Add xrefs as dependencies +fn dependxref root = +( + sceneName = maxFilePath + maxFileName + + for i = 1 to xrefs.getXRefFileCount(root) do + ( + curxref = xrefs.getXRefFile i root + NelToolLoggerWriteDepend "BUILD" "*" curxref.filename -- not sure if full filepath... + dependxref curxref + ) +) + +-- Lowercase node names etc, temporary until another full conversion run over the max files is done +fn lowercasenodes = +( + allNodes = $* + + for node in allNodes do + ( + -- Lowercase the node name + node.name = lowercase(node.name) + + -- Lowercase all LOD node name references + lodCount = getAppData node NEL3D_APPDATA_LOD_NAME_COUNT + if (lodCount != undefined) then + ( + lodCountNum = nodeCount as Integer + for lod = 1 to lodCountNum do + ( + lod = getAppData node (NEL3D_APPDATA_LOD_NAME + lod - 1) + if (lod != undefined) then + ( + setAppData node (NEL3D_APPDATA_LOD_NAME + lod - 1) lowercase(lod) + ) + ) + ) + ) +) + +-- Unhide category +fn unhidecategory = +( + if (geometry.count > 0) then + ( + unhide geometry[1] + if (geometry[1].ishidden == true) then + max hide object toggle + ) + if (shapes.count > 0) then + ( + unhide shapes[1] + if (shapes[1].ishidden == true) then + max hide shape toggle + ) + if (lights.count > 0) then + ( + unhide lights[1] + if (lights[1].ishidden == true) then + max hide light toggle + ) + if (cameras.count > 0) then + ( + unhide cameras[1] + if (cameras[1].ishidden == true) then + max hide camera toggle + ) + if (helpers.count > 0) then + ( + unhide helpers[1] + if (helpers[1].ishidden == true) then + max hide helper toggle + ) +) diff --git a/code/nel/tools/pipeline/plugin_max/scripts/shape.ms b/code/nel/tools/pipeline/plugin_max/scripts/shape.ms new file mode 100644 index 000000000..1b6099dcb --- /dev/null +++ b/code/nel/tools/pipeline/plugin_max/scripts/shape.ms @@ -0,0 +1,322 @@ + + +-- Some globals + +NEL3D_APPDATA_ACCEL = 1423062561 -- type of accelerator : "32" = is not an accelerator and IS clusterized + -- "0" = is not an accelerator and IS NOT clusterized (always visible) + -- "1" = is an accelerator type PORTAL + -- "2" = is an accelerator type CLUSTER + -- "6" = is an accelerator type CLUSTER FATHER-VISIBLE + -- "10" = is an accelerator type CLUSTER VISIBLE-FROM-FATHER + -- "14" = is an accelerator type CLUSTER FATHER-VISIBLE and VISIBLE-FROM-FATHER + -- "17" = is an accelerator type PORTAL DYNAMIC + +NEL3D_APPDATA_DONOTEXPORT = 1423062565 -- do not export me : "undefined" = export me + -- "0" = export me + -- "1" = DONT export me + +NEL3D_APPDATA_COLLISION = 1423062613 +NEL3D_APPDATA_COLLISION_EXTERIOR = 1423062614 +NEL3D_APPDATA_AUTOMATIC_ANIMATION = 1423062617 + +-- This node is n accelerator ? +fn isAccelerator node = +( + accel = getappdata node NEL3D_APPDATA_ACCEL + if (accel != undefined) then + ( + if (accel == "0") or (accel == "32") then + return false + else + return true + ) + return false +) + +-- Must export this node ? +fn isToBeExported node = +( + if (isAccelerator node) == true then + return false + + if ((classof node) == RklPatch) then + return false + + if ((classof node) == nel_ps) then + return false + + if ((classof node) == nel_pacs_cylinder) then + return false + + if ((classof node) == nel_pacs_box) then + return false + + doNotExport = getappdata node NEL3D_APPDATA_DONOTEXPORT + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + doNotExport = getappdata node NEL3D_APPDATA_COLLISION + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + doNotExport = getappdata node NEL3D_APPDATA_COLLISION_EXTERIOR + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + return true +) + +-- Must export this node ? +fn isAnimToBeExported node = +( + automaticAnimation = getappdata node NEL3D_APPDATA_AUTOMATIC_ANIMATION + if (automaticAnimation == undefined) then + return false + if (automaticAnimation == "0") then + return false + + if (isAccelerator node) == true then + return false + + if ((classof node) == nel_pacs_cylinder) then + return false + + if ((classof node) == nel_pacs_box) then + return false + + doNotExport = getappdata node NEL3D_APPDATA_DONOTEXPORT + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + doNotExport = getappdata node NEL3D_APPDATA_COLLISION + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + doNotExport = getappdata node NEL3D_APPDATA_COLLISION_EXTERIOR + if (doNotExport != undefined) then + ( + if (doNotExport == "1") then + return false + ) + + return true +) + +-- Cast shadow ? +fn isCastShadow node = +( + if (classof node == nel_ps) then + return false + + if (isAccelerator node) == true then + ( + return false + ) + else + ( + return true + ) +) + +-- List the lod +lod_array = #() + +-- is a lod ? +fn isLod node = +( + for i = 1 to lod_array.count do + ( + if (lod_array[i] == node) then + return true + ) + return false +) + +-- have a coarse mesh ? +fn haveCoarseMesh node = +( + -- Get lod count + nodeCount = getappdata node NEL3D_APPDATA_LOD_NAME_COUNT + if (nodeCount != undefined) then + ( + -- For each lod + nodeCountNum = nodeCount as Integer + for lod = 1 to nodeCountNum do + ( + -- Get the lod + lod = getappdata node (NEL3D_APPDATA_LOD_NAME+lod-1) + + -- Exist ? + if (lod != undefined) then + ( + -- Select a node + nd = execute ("$'"+lod+"'") + + -- Node exist ? + if (nd != undefined) then + ( + -- Is a coarse mesh ? + if (getappdata nd NEL3D_APPDATA_LOD_COARSE_MESH == "1") then + return true + ) + ) + ) + ) + return false +) + +fn runNelMaxExportSub = +( + sceneName = maxFilePath + maxFileName + + -- Exported object count + exported = 0 + + -- Add the lod + for node in geometry do + ( + -- Get lod count + nodeCount = getappdata node NEL3D_APPDATA_LOD_NAME_COUNT + if (nodeCount != undefined) then + ( + -- For each lod + nodeCountNum = nodeCount as Integer + for lod = 1 to nodeCountNum do + ( + -- Get the lod + lod = getappdata node (NEL3D_APPDATA_LOD_NAME+lod-1) + + -- Exist ? + if (lod != undefined) then + ( + -- Select a node + try + ( + nd = execute("$'"+lod+"'") + ) + catch + ( + NelToolLoggerWriteError "ERROR" "*" ("Error in Execute $'"+lod+"' from node "+node.name) + nd = undefined + ) + + -- Node exist ? + if (nd != undefined) then + ( + append lod_array nd + ) + ) + ) + ) + ) + + -- Select objects for shadows + for node in geometry do + ( + if (node.parent == undefined) then + ( + -- Cast shadow ? + if (isCastShadow node == true) then + ( + -- Select this node + selectmore node + ) + ) + ) + + -- Tag this file ? + tagThisFile = true + + -- Array of node to export + array_node = #() + + -- Add geometry + for node in geometry do + append array_node node + + -- Add shapes + for node in shapes do + append array_node node + + -- For each node + for node in array_node do + ( + -- It is root ? + if (node.parent == undefined) then + ( + -- Is not a skeleton ? + if (node.name != "Bip01") then + ( + -- Can be exported ? + if (isToBeExported node == true) then + ( + -- Not a lod ? + if ((isLod node) == false) then + ( + -- Output directory + if (haveCoarseMesh node) == true then + output = ("%OutputDirectoryWithCoarseMesh%/" + (node.name) + ".shape") + else + output = ("%OutputDirectoryWithoutCoarseMesh%/" + (node.name) + ".shape") + + try + ( + -- Export the shape + if (NelExportShapeEx node output %ShapeExportOptShadow% %ShapeExportOptExportLighting% "%OutputDirectoryLightmap%" %ShapeExportOptLightingLimit% %ShapeExportOptLumelSize% %ShapeExportOptOversampling% true false %ShapeExportOptLightmapLog%) == true then + ( + exported = exported + 1 + ) + else + ( + NelToolLoggerWriteError "ERROR" "*" "Failed exporting shape " + node.name + ".shape" + ) + ) + catch + ( + NelToolLoggerWriteError "ERROR" "*" "Fatal error exporting shape " + node.name + ".shape" + ) + ) + ) + ) + ) + ) + + -- Export default animations + for node in objects do + ( + -- Can export it ? + if (isAnimToBeExported node) == true then + ( + -- Anim output directory + output = ("%OutputDirectoryAnim%/" + (node.name) + ".anim") + + -- Export the animation + if (NelExportAnimation #(node) output false) == false then + ( + NelToolLoggerWriteError "ERROR" "*" "Exporting animation " + node.name + ".anim" + ) + ) + ) + + -- Nothing exported + if exported == 0 then + ( + -- Warning + NelToolLoggerWriteError "WARNING" "*" "No shape exported" + ) +)