From 370a5f5e84783ad02d10ad31a0daa13846456e6b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 9 Dec 2014 23:10:27 +0100 Subject: [PATCH] Merge --- .../3d/driver/opengl/driver_opengl_window.cpp | 18 +- code/nel/tools/3d/ligo/plugin_max/script.cpp | 33 ++-- .../3d/plugin_max/nel_patch_paint/paint.cpp | 4 +- .../3d/plugin_max/scripts/nel_zone_namer.ms | 68 ++++++++ .../plugin_max/scripts/nel_zone_snapshot.ms | 162 ++++++++++++++++++ 5 files changed, 266 insertions(+), 19 deletions(-) create mode 100644 code/nel/tools/3d/plugin_max/scripts/nel_zone_namer.ms create mode 100644 code/nel/tools/3d/plugin_max/scripts/nel_zone_snapshot.ms diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index 9df2a53f9..8307f885e 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -627,9 +627,11 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re // Offscreen mode ? if (_CurrentMode.OffScreen) { -#if 0 if (!createWindow(mode)) return false; + HWND tmpHWND = _win; + int width = mode.Width; + int height = mode.Height; // resize the window RECT rc; @@ -908,7 +910,6 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re _hDC = NULL; return false; } -#endif } else { @@ -1437,8 +1438,17 @@ bool CDriverGL::createWindow(const GfxMode &mode) #ifdef NL_OS_WINDOWS // create the OpenGL window - window = CreateWindowW(L"NLClass", L"NeL Window", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, - CW_USEDEFAULT, CW_USEDEFAULT, mode.Width, mode.Height, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL); + DWORD dwStyle = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS; + int pos = CW_USEDEFAULT; + HWND hwndParent = HWND_DESKTOP; + if (mode.OffScreen) + { + dwStyle &= ~WS_VISIBLE; + pos = 0; + hwndParent = NULL; + } + window = CreateWindowW(L"NLClass", L"NeL Window", dwStyle, + pos, pos, mode.Width, mode.Height, hwndParent, NULL, GetModuleHandle(NULL), NULL); if (window == EmptyWindow) { diff --git a/code/nel/tools/3d/ligo/plugin_max/script.cpp b/code/nel/tools/3d/ligo/plugin_max/script.cpp index 41740bcbe..8a88136c5 100644 --- a/code/nel/tools/3d/ligo/plugin_max/script.cpp +++ b/code/nel/tools/3d/ligo/plugin_max/script.cpp @@ -1739,14 +1739,14 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c float posY = config.CellSize * (float)ymin; // Use NELU - if (CNELU::init (oversampledWidth, oversampledHeight, CViewport(), 32, true, NULL, true)) + if (CNELU::init (oversampledWidth, oversampledHeight, CViewport(), 32, true, NULL, false, true)) // FIXME: OpenGL not working correctly, offscreen not available in Direct3D { // Setup the camera CNELU::Camera->setTransformMode (ITransformable::DirectMatrix); CMatrix view; view.setPos (CVector (width/2 + posX, height/2 + posY, width)); view.setRot (CVector::I, -CVector::K, CVector::J); - CNELU::Camera->setFrustum (width, height, 0.1f, 1000.f, false); + CNELU::Camera->setFrustum (width, height, 0.1f, 10000.f, false); CNELU::Camera->setMatrix (view); // Create a Landscape. @@ -1766,12 +1766,17 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c theLand->enableAdditive (true); theLand->Landscape.setRefineMode (true); + // theLand->Landscape.setupStaticLight(CRGBA(255, 255, 255), CRGBA(0, 0, 0), 1.0f); + // theLand->Landscape.setThreshold(0.0005); + // Enbable automatique lighting #ifndef NL_DEBUG - theLand->Landscape.enableAutomaticLighting (true); - theLand->Landscape.setupAutomaticLightDir (CVector (0, 0, -1)); + // theLand->Landscape.enableAutomaticLighting (true); + // theLand->Landscape.setupAutomaticLightDir (CVector (0, 0, -1)); #endif // NL_DEBUG + // theLand->Landscape.updateLightingAll(); + // Clear the backbuffer and the alpha CNELU::clearBuffers(CRGBA(255,0,255,0)); @@ -1851,7 +1856,7 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c Value* make_snapshot_cf (Value** arg_list, int count) { // Make sure we have the correct number of arguments (7) - check_arg_count(check_zone_with_template, 7, count); + check_arg_count(NeLLigoMakeSnapShot, 7, count); // Check to see if the arguments match up to what we expect char *message = "NeLLigoMakeSnapShot [Object] [Snapshot filename] [xMin] [xMax] [yMin] [yMax] [Error in dialog]"; @@ -1903,11 +1908,11 @@ Value* make_snapshot_cf (Value** arg_list, int count) else { // Build a filename - char drive[512]; - char path[512]; - char name[512]; - char ext[512]; - _splitpath (fileName.c_str(), drive, path, name, ext); + char drivetga[512]; + char pathtga[512]; + char nametga[512]; + char exttga[512]; + _splitpath (fileName.c_str(), drivetga, pathtga, nametga, exttga); // Build the zone CZone zone; @@ -1970,7 +1975,7 @@ Value* make_snapshot_cf (Value** arg_list, int count) { // Build the snap shot filename char outputFilenameSnapShot[512]; - _makepath (outputFilenameSnapShot, drive, path, name, ".tga"); + _makepath (outputFilenameSnapShot, drivetga, pathtga, nametga, ".tga"); // Output the snap shot COFile outputSnapShot; @@ -2011,10 +2016,10 @@ Value* make_snapshot_cf (Value** arg_list, int count) // Write the zone COFile outputLigoZone; - _makepath (outputFilenameSnapShot, drive, path, name, ".ligozone"); + _makepath (outputFilenameSnapShot, drivetga, pathtga, nametga, ".ligozone"); // Catch exception - try + /*try { // Open the selected zone file if (outputLigoZone.open (outputFilenameSnapShot)) @@ -2043,7 +2048,7 @@ Value* make_snapshot_cf (Value** arg_list, int count) char tmp[512]; smprintf (tmp, 512, "Error while loading the file %s : %s", fileName, e.what()); CMaxToLigo::errorMessage (tmp, "NeL Ligo export zone", *MAXScript_interface, errorInDialog); - } + }*/ } else { diff --git a/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp b/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp index fb99978da..73bb142b1 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_paint/paint.cpp @@ -3043,7 +3043,7 @@ private: // Callback on mouse events virtual void operator ()(const CEvent& event) { - if (event==EventDestroyWindowId) + if (event==EventDestroyWindowId || event==EventCloseWindowId) { WindowActive=false; } @@ -4287,6 +4287,7 @@ DWORD WINAPI myThread (LPVOID vData) CNELU::EventServer.addListener (EventMouseUpId, &listener); CNELU::EventServer.addListener (EventMouseDblClkId, &listener); CNELU::EventServer.addListener (EventDestroyWindowId, &listener); + CNELU::EventServer.addListener (EventCloseWindowId, &listener); CNELU::EventServer.addListener (EventKeyDownId, &listener); // Camera position @@ -4356,6 +4357,7 @@ DWORD WINAPI myThread (LPVOID vData) CNELU::EventServer.removeListener (EventMouseDblClkId, &listener); CNELU::EventServer.removeListener (EventKeyDownId, &listener); CNELU::EventServer.removeListener (EventDestroyWindowId, &listener); + CNELU::EventServer.removeListener (EventCloseWindowId, &listener); // End. //======== diff --git a/code/nel/tools/3d/plugin_max/scripts/nel_zone_namer.ms b/code/nel/tools/3d/plugin_max/scripts/nel_zone_namer.ms new file mode 100644 index 000000000..e651dd76a --- /dev/null +++ b/code/nel/tools/3d/plugin_max/scripts/nel_zone_namer.ms @@ -0,0 +1,68 @@ +-- This script sets proper centered zone positions and generates their names +-- Use after cutting the zone into 160m by 160m pieces + +cell_size = 160.0 +offset_x = 7680 / 2 +offset_y = -(20480 + (5120 / 2)) + +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +-- http://proofofprogress.blogspot.be/2011/03/solution-align-pivot-to-world-without.html +Function alignPivotToWorld &theObject = ( + --VLM = Visible Local Matrix. + --The matrix/pivot you see when selecting object and "Local" axis is selected as viewable. + VLM = theObject.Transform; + IP_LocalRot = theObject.objectOffsetRot; --Rotation to be used later. + IP_LOCAL = theObject.objectOffsetPos; --Invisible Pivot Local coordinates + --In relation to VLM matrix. + IP_WORLD = IP_LOCAL * VLM; --World Coordinates of Invisible Pivot. [Local To World Transform] + VLM_0 = matrix3 1; --Reset Visible Local matrix coordinates. + + NEW_IP_LOCAL = IP_WORLD * inverse(VLM_0); --[World To local Transform] + + theObject.Transform = VLM_0; + theObject.objectOffsetPos = NEW_IP_LOCAL; + + --Now Handle Rotation: + --Since rotation of visible local matrix has been zeroed out, + --You must add that loss to the invisible pivot rotation. + GeomWorldRot = VLM.RotationPart + IP_LocalRot; + theObject.objectOffsetRot = GeomWorldRot; +) + +-- Convert a coordinate in a name +-- name = coordToName #(x, y) +fn coordToName coord = +( + up = floor(coord[1] / 26) + 1 + down = floor(coord[1] - ((up-1) * 26)) + 1 + return (((-coord[2] + 1) as integer) as string) + "_" + alphabet[up] + alphabet[down] +) + +fn realCoordToName coord = +( + return coordToName(#(((coord[1] + offset_x) / cell_size) + 0.5, ((coord[2] + offset_y) / cell_size) + 0.5)) +) + +fn roundedCoord coord = +( + return #(ceil(coord[1] / cell_size) * cell_size - (cell_size / 2), ceil(coord[2] / cell_size) * cell_size - (cell_size / 2)) +) + +max select none +clearselection() + +for node in geometry do +( + if (classof node) == RklPatch or (classof node) == Editable_Patch then + ( + newcoords = roundedCoord(#(node.center.x, node.center.y)) + newname = realCoordToName(newcoords) + node.name = newname + alignPivotToWorld &node + node.pivot.x = newcoords[1] + node.pivot.y = newcoords[2] + resetxform node + maxOps.CollapseNode node off + ) +) diff --git a/code/nel/tools/3d/plugin_max/scripts/nel_zone_snapshot.ms b/code/nel/tools/3d/plugin_max/scripts/nel_zone_snapshot.ms new file mode 100644 index 000000000..edab4f35d --- /dev/null +++ b/code/nel/tools/3d/plugin_max/scripts/nel_zone_snapshot.ms @@ -0,0 +1,162 @@ +-- Use to take the snapshots of a large manually created zone + +from_x = 160 +size_x = 7680-320 +from_y = -25600+160 +size_y = 5120-320 + +targetdir = "W:/database/landscape/ligo/asteroids/max" +snapshotdir = "W:/database/landscape/ligo/asteroids/zonebitmaps" +zonename = "anne" +resumeonly = true + +cell_size = 160.0 + +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +fn lowercase instring = -- beginning of function definition +( + local upper, lower, outstring -- declare variables as local + upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" -- set variables to literals + lower="abcdefghijklmnopqrstuvwxyz" + outstring=copy instring + for i=1 to outstring.count do + ( + j=findString upper outstring[i] + if (j != undefined) do outstring[i]=lower[j] + ) + return outstring -- value of outstring will be returned as function result +) + +fn existFile fname = (getfiles fname).count != 0 + +-- Convert a coordinate in a name +-- name = coordToName #(x, y) +fn coordToName coord = +( + up = floor(coord[1] / 26) + 1 + down = floor(coord[1] - ((up-1) * 26)) + 1 + return (((-coord[2] + 1) as integer) as string) + "_" + alphabet[up] + alphabet[down] +) + +fn roundedCoord coord = +( + return #(ceil(coord[1] / cell_size) * cell_size - (cell_size / 2), ceil(coord[2] / cell_size) * cell_size - (cell_size / 2)) +) + +fn coordId coord = +( + coordr = (roundedCoord coord) + return #(((coordr[1]) / cell_size) + 0.5, ((coordr[2]) / cell_size) + 0.5) +) + +from_coord = (coordId #(from_x, from_y)) +to_coord = (coordId #(from_x + size_x, from_y + size_y)) + +print from_coord +print to_coord + +print (coordToName from_coord) + +undo off +( + for x=from_coord[1] to to_coord[1] do + ( + for y=from_coord[2] to to_coord[2] do + ( + ny=y+1 + sy=y-1 + ex=x+1 + wx=x-1 + zc = coordToName #(x, y) + zn = coordToName #(x, ny) + zne = coordToName #(ex, ny) + ze = coordToName #(ex, y) + zse = coordToName #(ex, sy) + zs = coordToName #(x, sy) + zsw = coordToName #(wx, sy) + zw = coordToName #(wx, y) + znw = coordToName #(wx, ny) + maxc = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zc) + ".max" + csnapfile = snapshotdir + "/" + zonename + "-" + (lowercase zc) + ".tga" + if existFile maxc and (not resumeonly or not (existFile csnapfile)) then + ( + print zc + resetMAXFile #noprompt + gc() + mergeMAXFile maxc #(zc) + ccenter = getnodebyname zc + maxn = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zn) + ".max" + if existFile maxn then + ( + mergeMAXFile maxn #(zn) + cnode = getnodebyname zn + cnode.position.y = cnode.position.y + 160 + NeLAttachPatchMesh cnode ccenter + ) + maxne = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zne) + ".max" + if existFile maxne then + ( + mergeMAXFile maxne #(zne) + cnode = getnodebyname zne + cnode.position.x = cnode.position.x + 160 + cnode.position.y = cnode.position.y + 160 + NeLAttachPatchMesh cnode ccenter + ) + maxe = targetdir + "/zonematerial-" + zonename + "-" + (lowercase ze) + ".max" + if existFile maxe then + ( + mergeMAXFile maxe #(ze) + cnode = getnodebyname ze + cnode.position.x = cnode.position.x + 160 + NeLAttachPatchMesh cnode ccenter + ) + maxse = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zse) + ".max" + if existFile maxse then + ( + mergeMAXFile maxse #(zse) + cnode = getnodebyname zse + cnode.position.x = cnode.position.x + 160 + cnode.position.y = cnode.position.y - 160 + NeLAttachPatchMesh cnode ccenter + ) + maxs = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zs) + ".max" + if existFile maxs then + ( + mergeMAXFile maxs #(zs) + cnode = getnodebyname zs + cnode.position.y = cnode.position.y - 160 + NeLAttachPatchMesh cnode ccenter + ) + maxsw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zsw) + ".max" + if existFile maxsw then + ( + mergeMAXFile maxsw #(zsw) + cnode = getnodebyname zsw + cnode.position.x = cnode.position.x - 160 + cnode.position.y = cnode.position.y - 160 + --NeLAttachPatchMesh cnode ccenter + ) + maxw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zw) + ".max" + if existFile maxw then + ( + mergeMAXFile maxw #(zw) + cnode = getnodebyname zw + cnode.position.x = cnode.position.x - 160 + NeLAttachPatchMesh cnode ccenter + ) + maxnw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase znw) + ".max" + if existFile maxnw then + ( + mergeMAXFile maxnw #(znw) + cnode = getnodebyname znw + cnode.position.x = cnode.position.x - 160 + cnode.position.y = cnode.position.y + 160 + NeLAttachPatchMesh cnode ccenter + ) + NeLWeldPatchMesh ccenter 1.0 + NeLLigoMakeSnapShot ccenter csnapfile 0 1 0 1 false + ) + ) + ) +)