|
|
|
@ -15,7 +15,7 @@
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
#include "zone_utility.h"
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
#include "nel/misc/types_nl.h"
|
|
|
|
|
#include "nel/misc/path.h"
|
|
|
|
|
#include "nel/misc/file.h"
|
|
|
|
@ -54,7 +54,7 @@ struct CPatchVertexInfo
|
|
|
|
|
uint patchIndex,
|
|
|
|
|
uint patchVertex,
|
|
|
|
|
const CVector &pos
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
: ZoneIndex(zoneIndex),
|
|
|
|
|
PatchIndex(patchIndex),
|
|
|
|
|
PatchVertex(patchVertex),
|
|
|
|
@ -95,7 +95,7 @@ static CZone *LoadZone(uint16 xPos, uint16 yPos, std::string zoneExt)
|
|
|
|
|
{
|
|
|
|
|
std::string zoneName;
|
|
|
|
|
::getZoneNameByCoord(xPos, yPos, zoneName);
|
|
|
|
|
std::auto_ptr<CZone> zone(new CZone);
|
|
|
|
|
std::auto_ptr<CZone> zone(new CZone);
|
|
|
|
|
std::string lookedUpZoneName = CPath::lookup(zoneName + zoneExt, false, false, false);
|
|
|
|
|
if (lookedUpZoneName.empty()) return NULL;
|
|
|
|
|
CIFile iF;
|
|
|
|
@ -128,7 +128,7 @@ static void GetCandidateVertices(const CVector &pos,
|
|
|
|
|
float weldThreshold
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
dest.clear();
|
|
|
|
|
dest.clear();
|
|
|
|
|
CVector half(weldThreshold, weldThreshold, weldThreshold);
|
|
|
|
|
qg.select(pos - half, pos + half);
|
|
|
|
|
for (TPVQuadGrid::CIterator it = qg.begin(); it != qg.end(); ++it)
|
|
|
|
@ -146,8 +146,8 @@ static void GetCandidateVertices(const CVector &pos,
|
|
|
|
|
//===========================================================================================================================
|
|
|
|
|
/** Search a vertex of a patch that can be welded with the given vertex
|
|
|
|
|
* return -1 if none
|
|
|
|
|
*/
|
|
|
|
|
static sint GetWeldableVertex(const CBezierPatch &bp, const CVector &pos, float weldThreshold)
|
|
|
|
|
*/
|
|
|
|
|
static sint GetWeldableVertex(const CBezierPatch &bp, const CVector &pos, float weldThreshold)
|
|
|
|
|
{
|
|
|
|
|
for (uint k = 0; k < 4; ++k)
|
|
|
|
|
{
|
|
|
|
@ -166,7 +166,7 @@ static sint GetWeldableVertex(const CBezierPatch &bp, const CVector &pos, float
|
|
|
|
|
static uint CheckZone(std::string middleZoneFile, float weldThreshold, float middleEdgeWeldThreshold)
|
|
|
|
|
{
|
|
|
|
|
uint numErrors = 0;
|
|
|
|
|
uint k, l, m, n, p, q; // some loop counters
|
|
|
|
|
uint k, l, m, n, p, q; // some loop counters
|
|
|
|
|
// This avoid reporting errors twice (for readability)
|
|
|
|
|
std::set<CPatchIdentPair> errorPairs;
|
|
|
|
|
|
|
|
|
@ -176,7 +176,7 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
|
|
|
|
|
std::auto_ptr<CZone> zones[9];
|
|
|
|
|
std::string zoneNames[9];
|
|
|
|
|
CZoneInfo zoneInfos[9];
|
|
|
|
|
CZoneInfo zoneInfos[9];
|
|
|
|
|
uint16 xPos, yPos;
|
|
|
|
|
const sint16 posOffs[][2] = { {0, 0}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1} };
|
|
|
|
|
|
|
|
|
@ -201,16 +201,16 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
nlinfo("Zones loading failed : %d", e.what());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
|
// retrieve datas from zones //
|
|
|
|
|
///////////////////////////////
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < 9; ++k)
|
|
|
|
|
{
|
|
|
|
|
::getZoneNameByCoord(xPos + posOffs[k][0], yPos + posOffs[k][1], zoneNames[k]);
|
|
|
|
|
::getZoneNameByCoord(xPos + posOffs[k][0], yPos + posOffs[k][1], zoneNames[k]);
|
|
|
|
|
if (zones[k].get() != NULL) zones[k]->retrieve(zoneInfos[k]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fill the quad grid
|
|
|
|
|
CAABBox zoneBBox = zones[0]->getZoneBB().getAABBox();
|
|
|
|
@ -222,7 +222,7 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
|
|
|
|
|
// insert vertices in quadgrid
|
|
|
|
|
for (k = 0; k < 9; ++k)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
for (l = 0; l < zoneInfos[k].Patchs.size(); ++l)
|
|
|
|
|
{
|
|
|
|
|
CPatchInfo &patch = zoneInfos[k].Patchs[l];
|
|
|
|
@ -236,7 +236,7 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
CVector half(weldThreshold, weldThreshold, weldThreshold);
|
|
|
|
|
// yes, insert it in the tree
|
|
|
|
|
qg.insert(pos - half, pos + half, CPatchVertexInfo(k, l, m, pos));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -246,11 +246,11 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
for (l = 0; l < zoneInfos[0].Patchs.size(); ++l)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
CPatchInfo &patch = zoneInfos[0].Patchs[l];
|
|
|
|
|
// deals with each border
|
|
|
|
|
for (m = 0; m < 4; ++m)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
// if this border is said to be bound, no need to test..
|
|
|
|
|
if (patch.BindEdges[m].NPatchs == 0)
|
|
|
|
|
{
|
|
|
|
@ -271,10 +271,10 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
::GetCandidateVertices(patch.Patch.Vertices[vIndex[q]], qg, verts[q], l, 0, weldThreshold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
// 1 - 1 connectivity ? //
|
|
|
|
|
///////////////////////////
|
|
|
|
|
///////////////////////////
|
|
|
|
|
// If there is a patch that is present in the 2 lists, then this is a 1-1 error
|
|
|
|
|
for (n = 0; n < verts[0].size() && !errorFound; ++n)
|
|
|
|
|
{
|
|
|
|
@ -288,9 +288,9 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
CPatchIdentPair errPair = std::make_pair(pi1, pi2);
|
|
|
|
|
//
|
|
|
|
|
if (std::find(errorPairs.begin(), errorPairs.end(), errPair) == errorPairs.end()) // error already displayed ?
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
nlinfo("**** Patch %d of zone %s has 1 - 1 connectivity error, try binding it with patch %d of zone %s",
|
|
|
|
|
l + 1, middleZoneName.c_str(), verts[0][n]->PatchIndex + 1, zoneNames[verts[0][n]->ZoneIndex].c_str());
|
|
|
|
|
l + 1, middleZoneName.c_str(), verts[0][n]->PatchIndex + 1, zoneNames[verts[0][n]->ZoneIndex].c_str());
|
|
|
|
|
errorPairs.insert(std::make_pair(pi2, pi1));
|
|
|
|
|
++numErrors;
|
|
|
|
|
}
|
|
|
|
@ -303,10 +303,10 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
//////////////////////////
|
|
|
|
|
// 1 - 2 connectivity ? //
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get the position at the middle of that border
|
|
|
|
|
CVector middlePos = patch.Patch.eval( 0.5f * (indexToST[vIndex[0]][0] + indexToST[vIndex[1]][0]),
|
|
|
|
|
0.5f * (indexToST[vIndex[0]][1] + indexToST[vIndex[1]][1]) );
|
|
|
|
|
0.5f * (indexToST[vIndex[0]][1] + indexToST[vIndex[1]][1]) );
|
|
|
|
|
|
|
|
|
|
// for each vertex of this border
|
|
|
|
|
for (q = 0; q < 2 && !errorFound; ++q)
|
|
|
|
@ -330,24 +330,24 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
CPatchIdentPair errPair = std::make_pair(pi1, pi2);
|
|
|
|
|
//
|
|
|
|
|
if (std::find(errorPairs.begin(), errorPairs.end(), errPair) == errorPairs.end()) // error already displayed ?
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
nlinfo("**** Patch %d of zone %s has 1 - 2 connectivity error, try binding it with patch %d of zone %s",
|
|
|
|
|
l + 1, middleZoneName.c_str(), pv.PatchIndex + 1, zoneNames[pv.ZoneIndex].c_str());
|
|
|
|
|
l + 1, middleZoneName.c_str(), pv.PatchIndex + 1, zoneNames[pv.ZoneIndex].c_str());
|
|
|
|
|
errorPairs.insert(std::make_pair(pi2, pi1));
|
|
|
|
|
++numErrors;
|
|
|
|
|
++numErrors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errorFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (errorFound) continue;
|
|
|
|
|
|
|
|
|
|
if (errorFound) continue;
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
|
// 1 - 4 connectivity ? //
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// compute points along the border.
|
|
|
|
|
CVector borderPos[5];
|
|
|
|
|
float lambda = 0.f;
|
|
|
|
@ -356,12 +356,12 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
borderPos[n] = patch.Patch.eval((1.f - lambda) * indexToST[vIndex[0]][0] + lambda * indexToST[vIndex[1]][0],
|
|
|
|
|
(1.f - lambda) * indexToST[vIndex[0]][1] + lambda * indexToST[vIndex[1]][1]);
|
|
|
|
|
lambda += 0.25f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to find a patch that shares 2 consecutives vertices
|
|
|
|
|
for (k = 0; k < 4 && !errorFound; ++k)
|
|
|
|
|
{
|
|
|
|
|
::GetCandidateVertices(borderPos[k], qg, verts[0], l, 0, middleEdgeWeldThreshold);
|
|
|
|
|
::GetCandidateVertices(borderPos[k], qg, verts[0], l, 0, middleEdgeWeldThreshold);
|
|
|
|
|
for (p = 0; p < verts[0].size() && !errorFound; ++p)
|
|
|
|
|
{
|
|
|
|
|
const CPatchVertexInfo &pv = *(verts[0][p]);
|
|
|
|
@ -382,16 +382,16 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
CPatchIdentPair errPair = std::make_pair(pi1, pi2);
|
|
|
|
|
//
|
|
|
|
|
if (std::find(errorPairs.begin(), errorPairs.end(), errPair) == errorPairs.end()) // error already displayed ?
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
nlinfo("**** Patch %d of zone %s has 1 - 4 connectivity error, try binding it with patch %d of zone %s",
|
|
|
|
|
l + 1, middleZoneName.c_str(), pv.PatchIndex + 1, zoneNames[pv.ZoneIndex].c_str());
|
|
|
|
|
l + 1, middleZoneName.c_str(), pv.PatchIndex + 1, zoneNames[pv.ZoneIndex].c_str());
|
|
|
|
|
++numErrors;
|
|
|
|
|
errorPairs.insert(std::make_pair(pi2, pi1));
|
|
|
|
|
}
|
|
|
|
|
errorFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -406,14 +406,14 @@ static uint CheckZone(std::string middleZoneFile, float weldThreshold, float mid
|
|
|
|
|
|
|
|
|
|
//=========================================================================================================================
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
NLMISC::createDebug();
|
|
|
|
|
InfoLog->addNegativeFilter("adding the path");
|
|
|
|
|
|
|
|
|
|
if (argc < 4)
|
|
|
|
|
{
|
|
|
|
|
std::string appName = CFile::getFilename(std::string(argv[0]));
|
|
|
|
|
nlinfo("usage : %s <zonesDirectory><weldTheshold><middleEdgeWeldTheshold>\n", appName.empty() ? "zone_check_bind" : appName.c_str());
|
|
|
|
|
nlinfo("usage : %s <zonesDirectory><weldTheshold><middleEdgeWeldTheshold>\n", appName.empty() ? "zone_check_bind" : appName.c_str());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -442,10 +442,10 @@ int main(int argc, char* argv[])
|
|
|
|
|
|
|
|
|
|
// Filter addSearchPath
|
|
|
|
|
CPath::addSearchPath(zonePaths);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Contains all the zone in the directory
|
|
|
|
|
std::vector<std::string> zoneNames;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CPath::getPathContent(zonePaths, true, false, true, zoneNames);
|
|
|
|
|
|
|
|
|
|
uint numErrors = 0;
|
|
|
|
@ -461,4 +461,4 @@ int main(int argc, char* argv[])
|
|
|
|
|
nlinfo("%d errors were found", numErrors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|