Base: support of SoFaceSet in InventorLoader
This commit is contained in:
@@ -991,6 +991,24 @@ std::vector<Vector3f> InventorLoader::convert(const std::vector<float>& data) co
|
||||
return points;
|
||||
}
|
||||
|
||||
std::vector<InventorLoader::Face> InventorLoader::convert(const std::vector<int32_t>& data) const
|
||||
{
|
||||
std::vector<Face> faces;
|
||||
faces.reserve(data.size());
|
||||
int32_t coordIndex = 0;
|
||||
for (const auto it : data) {
|
||||
if (it == 3) {
|
||||
faces.emplace_back(coordIndex, coordIndex+1, coordIndex+2);
|
||||
}
|
||||
else if (it == 4) {
|
||||
faces.emplace_back(coordIndex, coordIndex+1, coordIndex+2);
|
||||
faces.emplace_back(coordIndex, coordIndex+2, coordIndex+3);
|
||||
}
|
||||
coordIndex += it;
|
||||
}
|
||||
return faces;
|
||||
}
|
||||
|
||||
std::vector<std::vector<int32_t>> InventorLoader::split(const std::vector<int32_t>& data)
|
||||
{
|
||||
std::vector<std::vector<int32_t>> splitdata;
|
||||
@@ -1005,9 +1023,8 @@ std::vector<std::vector<int32_t>> InventorLoader::split(const std::vector<int32_
|
||||
return splitdata;
|
||||
}
|
||||
|
||||
std::vector<InventorLoader::Face> InventorLoader::convert(const std::vector<int32_t>& data) const
|
||||
std::vector<InventorLoader::Face> InventorLoader::convert(const std::vector<std::vector<int32_t>>& coordIndex) const
|
||||
{
|
||||
std::vector<std::vector<int32_t>> coordIndex = split(data);
|
||||
std::vector<Face> faces;
|
||||
faces.reserve(coordIndex.size());
|
||||
for (const auto it : coordIndex) {
|
||||
@@ -1034,10 +1051,17 @@ void InventorLoader::readCoords()
|
||||
points = convert(data);
|
||||
}
|
||||
|
||||
void InventorLoader::readFaceSet()
|
||||
void InventorLoader::readIndexedFaceSet()
|
||||
{
|
||||
auto data = readData<int32_t>("coordIndex");
|
||||
faces = convert(split(data));
|
||||
}
|
||||
|
||||
void InventorLoader::readFaceSet()
|
||||
{
|
||||
auto data = readData<int32_t>("numVertices");
|
||||
faces = convert(data);
|
||||
isnonindexed = true;
|
||||
}
|
||||
|
||||
bool InventorLoader::read()
|
||||
@@ -1061,6 +1085,10 @@ bool InventorLoader::read()
|
||||
readCoords();
|
||||
}
|
||||
else if (line.find("IndexedFaceSet {") != std::string::npos) {
|
||||
readIndexedFaceSet();
|
||||
break;
|
||||
}
|
||||
else if (line.find("FaceSet {") != std::string::npos) {
|
||||
readFaceSet();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -362,6 +362,12 @@ public:
|
||||
/// Checks if the loaded data are valid
|
||||
bool isValid() const;
|
||||
|
||||
/// Returns true if the data come from a non-indexed node as SoFaceSet.
|
||||
/// This means that the read points contain duplicates.
|
||||
bool isNonIndexed() const {
|
||||
return isnonindexed;
|
||||
}
|
||||
|
||||
/// Return the vectors of an SoNormal node
|
||||
const std::vector<Vector3f>& getVector() {
|
||||
return vector;
|
||||
@@ -380,14 +386,17 @@ public:
|
||||
private:
|
||||
void readNormals();
|
||||
void readCoords();
|
||||
void readIndexedFaceSet();
|
||||
void readFaceSet();
|
||||
template<typename T>
|
||||
std::vector<T> readData(const char*) const;
|
||||
std::vector<Vector3f> convert(const std::vector<float>&) const;
|
||||
std::vector<Face> convert(const std::vector<int32_t>&) const;
|
||||
std::vector<Face> convert(const std::vector<std::vector<int32_t>>&) const;
|
||||
static std::vector<std::vector<int32_t>> split(const std::vector<int32_t>&);
|
||||
|
||||
private:
|
||||
bool isnonindexed = false;
|
||||
std::vector<Vector3f> vector;
|
||||
std::vector<Vector3f> points;
|
||||
std::vector<Face> faces;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "MeshIO.h"
|
||||
#include "Algorithm.h"
|
||||
#include "Builder.h"
|
||||
#include "Degeneration.h"
|
||||
|
||||
#include <Base/Builder3D.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -1517,6 +1518,12 @@ bool MeshInput::LoadInventor (std::istream &inp)
|
||||
meshAdj.SetFacetNeighbourhood();
|
||||
this->_rclMesh.Adopt(meshPoints, meshFacets);
|
||||
|
||||
if (loader.isNonIndexed()) {
|
||||
if (!MeshEvalDuplicatePoints(this->_rclMesh).Evaluate()) {
|
||||
MeshFixDuplicatePoints(this->_rclMesh).Fixup();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user