From: ailmanki Date: Sat, 11 Feb 2012 15:45:17 +0000 (+0100) Subject: bobtoolz fixes to patch merging X-Git-Tag: xonotic-v0.6.0~15 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8c8ef16918f87ebc7b8ce48560baf268b36c124b;p=xonotic%2Fnetradiant.git bobtoolz fixes to patch merging --- diff --git a/contrib/bobtoolz/DPatch.cpp b/contrib/bobtoolz/DPatch.cpp index 10dbb4bb..85a95cb0 100644 --- a/contrib/bobtoolz/DPatch.cpp +++ b/contrib/bobtoolz/DPatch.cpp @@ -80,11 +80,11 @@ void DPatch::BuildInRadiant(scene::Node* entity) GlobalPatchCreator().Patch_setShader(patch, texture); GlobalPatchCreator().Patch_resize(patch, height, width); PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch); - for(int x = 0; x < height; x++) + for(int x = 0; x < width; x++) { - for(int y = 0; y < width; y++) + for(int y = 0; y < height; y++) { - PatchControl& p = matrix(y, x); + PatchControl& p = matrix(x, y); p.m_vertex[0] = points[x][y].xyz[0]; p.m_vertex[1] = points[x][y].xyz[1]; p.m_vertex[2] = points[x][y].xyz[2]; @@ -148,11 +148,11 @@ void DPatch::LoadFromPatch(scene::Instance& patch) width = static_cast(matrix.x()); height = static_cast(matrix.y()); - for(int x = 0; x < height; x++) + for(int x = 0; x < width; x++) { - for(int y = 0; y < width; y++) + for(int y = 0; y < height; y++) { - PatchControl& p = matrix(y, x); + PatchControl& p = matrix(x, y); points[x][y].xyz[0] = p.m_vertex[0]; points[x][y].xyz[1] = p.m_vertex[1]; points[x][y].xyz[2] = p.m_vertex[2]; @@ -307,17 +307,13 @@ DPatch* DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2) if(merge_info.pos2 < 0) merge_info.pos2 += 3; } - // int newHeight = p1->height + p2->height - 1; if(newHeight > MAX_PATCH_HEIGHT) return false; -/* int newWidth = p1->width + p2->width - 1; - if(newWidth > MAX_PATCH_WIDTH) - return NULL; -*/ + DPatch* newPatch = new DPatch(); - //switched.. + newPatch->height = newHeight; newPatch->width = p1->width; newPatch->SetTexture(p1->texture); @@ -346,6 +342,45 @@ void DPatch::Invert() } } } +/* +//Was used for debugging, obsolete function +DPatch* DPatch::TransposePatch(DPatch *p1) +{ + globalOutputStream() << "Source patch "; + p1->DebugPrint(); + p1->Transpose(); + globalOutputStream() << "Transposed"; + p1->DebugPrint(); + + DPatch* newPatch = new DPatch(); + newPatch->height = p1->height; + newPatch->width = p1->width; + newPatch->SetTexture(p1->texture); + + for(int x = 0; x < p1->height; x++) + { + for(int y = 0; y < p1->width; y++) + { + newPatch->points[x][y] = p1->points[x][y]; + } + } + return newPatch; +} + +//Function to figure out what is actually going wrong. +void DPatch::DebugPrint() +{ + globalOutputStream() << "width: " << width << "\theight: " << height << "\n"; + for(int x = 0; x < height; x++) + { + for(int y = 0; y < width; y++) + { + globalOutputStream() << "\t(" << points[x][y].xyz[0] << " " << points[x][y].xyz[1] << " " << points[x][y].xyz[2] << ")\t"; + } + globalOutputStream() << "\n"; + } +} + */ void DPatch::Transpose() { @@ -397,7 +432,7 @@ void DPatch::Transpose() Invert(); } -std::list DPatch::SplitRows() +std::list DPatch::SplitCols() { std::list patchList; int i; @@ -410,39 +445,25 @@ std::list DPatch::SplitRows() DPatch p; p.width = width; - p.height = 3; + p.height = MIN_PATCH_HEIGHT; p.SetTexture(texture); - for(x = 0; x < 3; x++) + for(x = 0; x < p.width; x++) { - for(y = 0; y < p.width; y++) + for(y = 0; y < MIN_PATCH_HEIGHT; y++) { - p.points[x][y] = points[(i*2)+x][y]; + p.points[x][y] = points[x][(i*2)+y]; } } patchList.push_back(p); } } else { - //This returns exactly what comes in.. I don't know better :/ - //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros. - DPatch p; - - p.height = height; - p.width = width; - p.SetTexture(texture); - - for(x = 0; x < p.height; x++) - { - for(y = 0; y < p.width; y++) - { - p.points[x][y] = points[x][y]; + //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n"; + patchList.push_back(*this); } - } - patchList.push_back(p); - } return patchList; } -std::list DPatch::SplitCols() +std::list DPatch::SplitRows() { std::list patchList; int i; @@ -454,38 +475,23 @@ std::list DPatch::SplitCols() { DPatch p; - p.width = 3; + p.width = MIN_PATCH_WIDTH; p.height = height; p.SetTexture(texture); - for(x = 0; x < p.height; x++) + for(x = 0; x < MIN_PATCH_WIDTH; x++) { - for(y = 0; y < 3; y++) + for(y = 0; y < p.height; y++) { - p.points[x][y] = points[x][(i*2)+y]; + p.points[x][y] = points[(i*2)+x][y]; } } patchList.push_back(p); } } else { - //This returns exactly what comes in.. I don't know better :/ - //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros. - DPatch p; - - p.height = height; - p.width = width; - p.SetTexture(texture); - - for(x = 0; x < p.height; x++) - { - for(y = 0; y < p.width; y++) - { - p.points[x][y] = points[x][y]; + patchList.push_back(*this); } - } - patchList.push_back(p); - } return patchList; } @@ -497,77 +503,26 @@ std::list DPatch::Split() if(width >= 5) { - for(i = 0; i < (width-1)/2; i++) + std::list patchColList = SplitCols(); + for(std::list::iterator patchesCol = patchColList.begin(); patchesCol != patchColList.end(); patchesCol++) { - DPatch p; - - p.width = 3; - p.height = height; - p.SetTexture(texture); - - for(x = 0; x < p.height; x++) + std::list patchRowList = (*patchesCol).SplitRows(); + for(std::list::iterator patchesRow = patchRowList.begin(); patchesRow != patchRowList.end(); patchesRow++) { - for(y = 0; y < 3; y++) - { - p.points[x][y] = points[x][(i*2)+y]; + patchList.push_front(*patchesRow); } } - patchList.push_back(p); - } - std::list patchList2; - for(std::list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) - { - std::list patchList3 = (*patches).SplitRows(); - for(std::list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) - patchList2.push_front(*patches2); - } - return patchList2; - } else if(height >= 5) { - for(i = 0; i < (height-1)/2; i++) + std::list patchRowList = SplitRows(); + for(std::list::iterator patchesRow = patchRowList.begin(); patchesRow != patchRowList.end(); patchesRow++) { - DPatch p; - - p.width = width; - p.height = 3; - p.SetTexture(texture); - for(x = 0; x < 3; x++) - { - for(y = 0; y < p.width; y++) - { - p.points[x][y] = points[(i*2)+x][y]; + patchList.push_front(*patchesRow); } - } - patchList.push_back(p); - } - std::list patchList2; - for(std::list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) - { - std::list patchList3 = (*patches).SplitCols(); - for(std::list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) - patchList2.push_front(*patches2); - } - return patchList2; - } else { - //This returns exactly what comes in.. I don't know better :/ - //If nothing is returned, the Patch in Radiant is just deleted - I suppose for evil follow up erros. - DPatch p; - - p.height = height; - p.width = width; - p.SetTexture(texture); - - for(x = 0; x < p.height; x++) - { - for(y = 0; y < p.width; y++) - { - p.points[x][y] = points[x][y]; + //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n"; + patchList.push_back(*this); } - } - patchList.push_back(p); - } return patchList; } diff --git a/contrib/bobtoolz/DPatch.h b/contrib/bobtoolz/DPatch.h index a10773d6..63e15eea 100644 --- a/contrib/bobtoolz/DPatch.h +++ b/contrib/bobtoolz/DPatch.h @@ -59,6 +59,8 @@ public: std::list SplitCols(); std::list Split(); void Transpose(); + //DPatch* TransposePatch(DPatch* p1); + //void DebugPrint(); void Invert(); DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2); patch_merge_t IsMergable(DPatch* other);