+ fix reading of meshes with textures when vertexes are isolated
This commit is contained in:
parent
8cfabdb579
commit
d51ea4c96b
|
@ -344,9 +344,13 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
|
|
||||||
this->_rclMesh.Clear(); // remove all data before
|
this->_rclMesh.Clear(); // remove all data before
|
||||||
|
|
||||||
MeshKernel tmp;
|
MeshCleanup meshCleanup(meshPoints,meshFacets);
|
||||||
tmp.Adopt(meshPoints,meshFacets);
|
if (_material)
|
||||||
this->_rclMesh.Merge(tmp);
|
meshCleanup.SetMaterial(_material);
|
||||||
|
meshCleanup.RemoveInvalids();
|
||||||
|
MeshPointFacetAdjacency meshAdj(meshPoints.size(),meshFacets);
|
||||||
|
meshAdj.SetFacetNeighbourhood();
|
||||||
|
this->_rclMesh.Adopt(meshPoints,meshFacets);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -486,29 +490,14 @@ bool MeshInput::LoadOFF (std::istream &rstrIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
this->_rclMesh.Clear(); // remove all data before
|
this->_rclMesh.Clear(); // remove all data before
|
||||||
// Don't use Assign() because Merge() checks which points are really needed.
|
|
||||||
// This method sets already the correct neighbourhood
|
|
||||||
unsigned long ct = meshPoints.size();
|
|
||||||
std::list<unsigned long> removeFaces;
|
|
||||||
for (MeshFacetArray::_TConstIterator it = meshFacets.begin(); it != meshFacets.end(); ++it) {
|
|
||||||
bool ok = true;
|
|
||||||
for (int i=0;i<3;i++) {
|
|
||||||
if (it->_aulPoints[i] >= ct) {
|
|
||||||
Base::Console().Warning("Face index %lu out of range\n", it->_aulPoints[i]);
|
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok)
|
MeshCleanup meshCleanup(meshPoints,meshFacets);
|
||||||
removeFaces.push_front(it-meshFacets.begin());
|
if (_material)
|
||||||
}
|
meshCleanup.SetMaterial(_material);
|
||||||
|
meshCleanup.RemoveInvalids();
|
||||||
for (std::list<unsigned long>::iterator it = removeFaces.begin(); it != removeFaces.end(); ++it)
|
MeshPointFacetAdjacency meshAdj(meshPoints.size(),meshFacets);
|
||||||
meshFacets.erase(meshFacets.begin() + *it);
|
meshAdj.SetFacetNeighbourhood();
|
||||||
|
this->_rclMesh.Adopt(meshPoints,meshFacets);
|
||||||
MeshKernel tmp;
|
|
||||||
tmp.Adopt(meshPoints,meshFacets);
|
|
||||||
this->_rclMesh.Merge(tmp);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -978,16 +967,15 @@ bool MeshInput::LoadPLY (std::istream &inp)
|
||||||
}
|
}
|
||||||
|
|
||||||
this->_rclMesh.Clear(); // remove all data before
|
this->_rclMesh.Clear(); // remove all data before
|
||||||
#if 1
|
|
||||||
MeshCleanup(meshPoints,meshFacets).RemoveInvalids();
|
MeshCleanup meshCleanup(meshPoints,meshFacets);
|
||||||
|
if (_material)
|
||||||
|
meshCleanup.SetMaterial(_material);
|
||||||
|
meshCleanup.RemoveInvalids();
|
||||||
MeshPointFacetAdjacency meshAdj(meshPoints.size(),meshFacets);
|
MeshPointFacetAdjacency meshAdj(meshPoints.size(),meshFacets);
|
||||||
meshAdj.SetFacetNeighbourhood();
|
meshAdj.SetFacetNeighbourhood();
|
||||||
this->_rclMesh.Adopt(meshPoints,meshFacets);
|
this->_rclMesh.Adopt(meshPoints,meshFacets);
|
||||||
#else
|
|
||||||
MeshKernel tmp;
|
|
||||||
tmp.Adopt(meshPoints,meshFacets);
|
|
||||||
this->_rclMesh.Merge(tmp);
|
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1036,11 +1024,12 @@ bool MeshInput::LoadMeshNode (std::istream &rstrIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
this->_rclMesh.Clear(); // remove all data before
|
this->_rclMesh.Clear(); // remove all data before
|
||||||
// Don't use Assign() because Merge() checks which points are really needed.
|
|
||||||
// This method sets already the correct neighbourhood
|
MeshCleanup meshCleanup(meshPoints,meshFacets);
|
||||||
MeshKernel tmp;
|
meshCleanup.RemoveInvalids();
|
||||||
tmp.Adopt(meshPoints,meshFacets);
|
MeshPointFacetAdjacency meshAdj(meshPoints.size(),meshFacets);
|
||||||
this->_rclMesh.Merge(tmp);
|
meshAdj.SetFacetNeighbourhood();
|
||||||
|
this->_rclMesh.Adopt(meshPoints,meshFacets);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2519,6 +2508,7 @@ bool MeshOutput::SaveVRML (std::ostream &rstrOut) const
|
||||||
MeshCleanup::MeshCleanup(MeshPointArray& p, MeshFacetArray& f)
|
MeshCleanup::MeshCleanup(MeshPointArray& p, MeshFacetArray& f)
|
||||||
: pointArray(p)
|
: pointArray(p)
|
||||||
, facetArray(f)
|
, facetArray(f)
|
||||||
|
, materialArray(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2526,6 +2516,11 @@ MeshCleanup::~MeshCleanup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshCleanup::SetMaterial(Material* mat)
|
||||||
|
{
|
||||||
|
materialArray = mat;
|
||||||
|
}
|
||||||
|
|
||||||
void MeshCleanup::RemoveInvalids()
|
void MeshCleanup::RemoveInvalids()
|
||||||
{
|
{
|
||||||
// first mark all points as invalid
|
// first mark all points as invalid
|
||||||
|
@ -2562,6 +2557,21 @@ void MeshCleanup::RemoveInvalidFacets()
|
||||||
std::size_t countInvalidFacets = std::count_if(facetArray.begin(), facetArray.end(),
|
std::size_t countInvalidFacets = std::count_if(facetArray.begin(), facetArray.end(),
|
||||||
std::bind2nd(MeshIsFlag<MeshFacet>(), MeshFacet::INVALID));
|
std::bind2nd(MeshIsFlag<MeshFacet>(), MeshFacet::INVALID));
|
||||||
if (countInvalidFacets > 0) {
|
if (countInvalidFacets > 0) {
|
||||||
|
|
||||||
|
// adjust the material array if needed
|
||||||
|
if (materialArray && materialArray->binding == MeshIO::PER_FACE &&
|
||||||
|
materialArray->diffuseColor.size() == facetArray.size()) {
|
||||||
|
std::vector<App::Color> colors;
|
||||||
|
colors.reserve(facetArray.size() - countInvalidFacets);
|
||||||
|
for (std::size_t index = 0; index < facetArray.size(); index++) {
|
||||||
|
if (facetArray[index].IsValid()) {
|
||||||
|
colors.push_back(materialArray->diffuseColor[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
materialArray->diffuseColor.swap(colors);
|
||||||
|
}
|
||||||
|
|
||||||
MeshFacetArray copy_facets(facetArray.size() - countInvalidFacets);
|
MeshFacetArray copy_facets(facetArray.size() - countInvalidFacets);
|
||||||
// copy all valid facets to the new array
|
// copy all valid facets to the new array
|
||||||
std::remove_copy_if(facetArray.begin(), facetArray.end(), copy_facets.begin(),
|
std::remove_copy_if(facetArray.begin(), facetArray.end(), copy_facets.begin(),
|
||||||
|
@ -2598,6 +2608,21 @@ void MeshCleanup::RemoveInvalidPoints()
|
||||||
|
|
||||||
// delete point, number of valid points
|
// delete point, number of valid points
|
||||||
std::size_t validPoints = pointArray.size() - countInvalidPoints;
|
std::size_t validPoints = pointArray.size() - countInvalidPoints;
|
||||||
|
|
||||||
|
// adjust the material array if needed
|
||||||
|
if (materialArray && materialArray->binding == MeshIO::PER_VERTEX &&
|
||||||
|
materialArray->diffuseColor.size() == pointArray.size()) {
|
||||||
|
std::vector<App::Color> colors;
|
||||||
|
colors.reserve(validPoints);
|
||||||
|
for (std::size_t index = 0; index < pointArray.size(); index++) {
|
||||||
|
if (pointArray[index].IsValid()) {
|
||||||
|
colors.push_back(materialArray->diffuseColor[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
materialArray->diffuseColor.swap(colors);
|
||||||
|
}
|
||||||
|
|
||||||
MeshPointArray copy_points(validPoints);
|
MeshPointArray copy_points(validPoints);
|
||||||
// copy all valid facets to the new array
|
// copy all valid facets to the new array
|
||||||
std::remove_copy_if(pointArray.begin(), pointArray.end(), copy_points.begin(),
|
std::remove_copy_if(pointArray.begin(), pointArray.end(), copy_points.begin(),
|
||||||
|
|
|
@ -191,6 +191,14 @@ public:
|
||||||
MeshCleanup(MeshPointArray& p, MeshFacetArray& f);
|
MeshCleanup(MeshPointArray& p, MeshFacetArray& f);
|
||||||
~MeshCleanup();
|
~MeshCleanup();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Set the material array.
|
||||||
|
In case the material array sets the colors per vertex and
|
||||||
|
\ref RemoveInvalids() removes points from the array the
|
||||||
|
material array will be adjusted.
|
||||||
|
*/
|
||||||
|
void SetMaterial(Material* mat);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Remove unreferenced and invalid facets.
|
\brief Remove unreferenced and invalid facets.
|
||||||
*/
|
*/
|
||||||
|
@ -209,6 +217,7 @@ private:
|
||||||
private:
|
private:
|
||||||
MeshPointArray& pointArray;
|
MeshPointArray& pointArray;
|
||||||
MeshFacetArray& facetArray;
|
MeshFacetArray& facetArray;
|
||||||
|
Material* materialArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user