wip
This commit is contained in:
parent
3068be1a74
commit
304f804705
|
|
@ -39,45 +39,31 @@ std::vector<qvec3f> qvecsToGlm(std::vector<qvec3f> qvecs) {
|
|||
return res;
|
||||
}
|
||||
|
||||
mesh_t buildMesh(const vector<vector<qvec3f>> &faces)
|
||||
{
|
||||
class vertex_uniquer {
|
||||
private:
|
||||
// FIXME: this is ugly
|
||||
using pos_t = tuple<float, float, float>;
|
||||
|
||||
int nextVert = 0;
|
||||
int nextVert;
|
||||
map<pos_t, int> posToVertIndex;
|
||||
|
||||
vector<qplane3f> faceplanes;
|
||||
vector<vector<int>> facesWithIndices;
|
||||
for (const auto &face : faces) {
|
||||
vector<int> vertIndices;
|
||||
|
||||
// compute face plane
|
||||
const auto glmvecs = qvecsToGlm(face);
|
||||
qvec4f gp = GLM_PolyPlane(glmvecs);
|
||||
qplane3f qp(qvec3f(gp[0], gp[1], gp[2]), gp[3]);
|
||||
faceplanes.push_back(qp);
|
||||
|
||||
for (const auto &vert : face) {
|
||||
float distOff = qp.distAbove(vert);
|
||||
Q_assert(fabs(distOff) < 0.001);
|
||||
public:
|
||||
vertex_uniquer() : nextVert(0), posToVertIndex() {}
|
||||
|
||||
int addExactPoint(const qvec3f &point) {
|
||||
const pos_t pos = make_tuple(vert[0], vert[1], vert[2]);
|
||||
const auto it = posToVertIndex.find(pos);
|
||||
|
||||
if (it == posToVertIndex.end()) {
|
||||
posToVertIndex[pos] = nextVert;
|
||||
vertIndices.push_back(nextVert);
|
||||
nextVert++;
|
||||
return nextVert++;
|
||||
} else {
|
||||
int vertIndex = it->second;
|
||||
vertIndices.push_back(vertIndex);
|
||||
return vertIndex;
|
||||
}
|
||||
}
|
||||
|
||||
facesWithIndices.push_back(vertIndices);
|
||||
}
|
||||
|
||||
vector<qvec3f> getVerts() const {
|
||||
// convert posToVertIndex to a vector
|
||||
vector<qvec3f> vertsVec;
|
||||
vertsVec.resize(posToVertIndex.size());
|
||||
|
|
@ -85,14 +71,59 @@ mesh_t buildMesh(const vector<vector<qvec3f>> &faces)
|
|||
const pos_t &pos = posIndex.first;
|
||||
vertsVec.at(posIndex.second) = qvec3f(std::get<0>(pos), std::get<1>(pos), std::get<2>(pos));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mesh_t buildMeshWithNormals(const std::vector<std::vector<qvec3f>> &faces,
|
||||
const std::vector<std::vector<qvec3f>> *faceVertNormals=nullptr)
|
||||
{
|
||||
vertex_uniquer uniquer;
|
||||
|
||||
vector<qplane3f> faceplanes;
|
||||
vector<vector<int>> facesWithIndices;
|
||||
vector<vector<qvec3f>> facesWithNormals;
|
||||
|
||||
for (const auto &face : faces) {
|
||||
vector<int> vertIndices;
|
||||
vector<qvec3f> vertNormals;
|
||||
|
||||
// compute face plane
|
||||
const auto glmvecs = qvecsToGlm(face);
|
||||
qvec4f gp = GLM_PolyPlane(glmvecs);
|
||||
qplane3f qp(qvec3f(gp[0], gp[1], gp[2]), gp[3]);
|
||||
faceplanes.push_back(qp);
|
||||
|
||||
for (const qvec3f &vert : face) {
|
||||
const qvec3f &vert = vertNormalPair.first;
|
||||
const qvec3f &normal = vertNormalPair.second;
|
||||
|
||||
float distOff = qp.distAbove(vert);
|
||||
Q_assert(fabs(distOff) < 0.001);
|
||||
|
||||
int vertIndex = uniquer.addExactPoint(vert)
|
||||
vertIndices.push_back(vertIndex);
|
||||
vertNormals.push_back(normal);
|
||||
}
|
||||
|
||||
facesWithIndices.push_back(vertIndices);
|
||||
facesWithNormals.push_back(vertNormals);
|
||||
}
|
||||
|
||||
mesh_t res;
|
||||
res.verts = vertsVec;
|
||||
res.faces = facesWithIndices;
|
||||
res.faceplanes = faceplanes;
|
||||
res.facevertnormals = facesWithNormals;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// wrapper around buildMesh
|
||||
mesh_t buildMesh(const vector<vector<qvec3f>> &faces)
|
||||
{
|
||||
std::vector<std::vector<std::pair<qvec3f, qvec3f>>>
|
||||
}
|
||||
|
||||
mesh_t buildMeshFromBSP(const bsp2_t *bsp)
|
||||
{
|
||||
mesh_t res;
|
||||
|
|
@ -255,6 +286,7 @@ void cleanupMesh(mesh_t &mesh)
|
|||
|
||||
// sample point positioning
|
||||
|
||||
#if 0
|
||||
class position_t {
|
||||
public:
|
||||
bool m_unoccluded;
|
||||
|
|
@ -426,3 +458,4 @@ sample_position_t positionSample(const mesh_t &mesh, facenum_t startingFace, con
|
|||
// call the recursive version
|
||||
return positionSample_r(mesh, startingFace, startingPos, 0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -34,14 +34,17 @@ using meshface_t = std::vector<vertnum_t>;
|
|||
class mesh_t {
|
||||
public:
|
||||
std::vector<qvec3f> verts;
|
||||
std::vector<meshface_t> faces;
|
||||
std::vector<meshface_t> faceverts;
|
||||
std::vector<std::vector<qvec3f>> facevertnormals;
|
||||
|
||||
// this is redundant data with the verts, but we know the planes in advance
|
||||
// and this saves having to estimate them from the verts
|
||||
std::vector<qplane3f> faceplanes;
|
||||
};
|
||||
|
||||
// Welds vertices at exactly the same position
|
||||
mesh_t buildMesh(const std::vector<std::vector<qvec3f>> &faces);
|
||||
mesh_t buildMeshWithNormals(const std::vector<std::vector<qvec3f>> &faces,
|
||||
const std::vector<std::vector<qvec3f>> *faceVertNormals=nullptr);
|
||||
mesh_t buildMeshFromBSP(const bsp2_t *bsp);
|
||||
|
||||
std::vector<std::vector<qvec3f>> meshToFaces(const mesh_t &mesh);
|
||||
|
|
@ -74,6 +77,12 @@ public:
|
|||
m_interpolatedNormal(interpolatedNormal) {};
|
||||
};
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* "Corrects" a point so it's on the front side of the
|
||||
* mesh
|
||||
*/
|
||||
sample_position_t positionSample(const mesh_t &mesh, facenum_t startingFace, const qvec3f &startingPos);
|
||||
#endif
|
||||
|
||||
#endif /* __COMMON_MESH_HH__ */
|
||||
|
|
|
|||
Loading…
Reference in New Issue