openMe sh - перебирая грани для экспорта me sh в векторы - PullRequest
0 голосов
/ 16 января 2020

Я пытаюсь создать тестовый пример, который бы учитывал рабочий процесс: assimp> openMe sh> assimp / список векторов / нормалей / uvs / indices.

Пока что простой тест выглядит так: follow:

typedef OpenMesh::PolyMesh_ArrayKernelT<> MyMesh;

void openTest(aiMesh *meshPtr) { // assimp mesh
MyMesh mesh;

mesh.request_vertex_normals(); // add normals channel

/// populate vertex/handles and normals
MyMesh::VertexHandle vertexHandle;
for (int x = 0; x < meshPtr->mNumVertices; ++x) {
    auto vertex = meshPtr->mVertices[x];
    vertexHandle = mesh.add_vertex(MyMesh::Point(vertex.x, vertex.y, vertex.z));
    auto normal = meshPtr->mNormals[x];
    mesh.set_normal(vertexHandle, OpenMesh::Vec3f(normal.x, normal.y, normal.z));
    vhandle[x] = vertexHandle;
}

/// create faces with early made vertexes.
std::vector<MyMesh::VertexHandle> face_vhandles;
for (int x = 0; x < meshPtr->mNumFaces; ++x) {
    auto face = meshPtr->mFaces[x];
    face_vhandles.resize(face.mNumIndices);
    for (int c = 0; c < face.mNumIndices; ++c) {
        face_vhandles[c] = vhandle[face.mIndices[c]];
    }
    mesh.add_face(face_vhandles);
}


/// Get data back... 


/// the below data is wrong... so test failed.
QVector<QVector3D> newVertex(mesh.n_vertices());
QVector<QVector3D> newNormal(mesh.n_vertices());
int index = 0;
for (auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it) {
    OpenMesh::Vec3f &point = mesh.point(*v_it);
    newVertex[index] = QVector3D(point[0], point[1], point[2]);

    auto &normal = mesh.normal(*v_it);
    newVertex[index] = QVector3D(normal[0], normal[1], normal[2]);

    index++;
}


/// another test here + indices but also failed.

/// count indices count
for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) {
    for (auto fv_it = mesh.fv_ccwiter(*f_it); fv_it.is_valid(); ++fv_it) {
        index++; // couint indices count
    }
}
QVector<unsigned int> newIndices(index);
index = 0;
for (auto f_it = mesh.faces_begin(); f_it != mesh.faces_end(); ++f_it) {
    for (auto fv_it = mesh.fv_ccwiter(*f_it); fv_it.is_valid(); ++fv_it) {
        int id = fv_it->idx();
        auto point = mesh.point(vhandle[id]);
        newVertex[id] = QVector3D(point[0], point[1], point[2]);

        auto &normal = mesh.normal(vhandle[id]);
        newVertex[id] = QVector3D(normal[0], normal[1], normal[2]);

        newIndices[index] = id;
        index++;
    }
}

///bad vertex/etc.

}

Изначально я пытался просто получить список вершин / нормалей и создать для него индексы. Даже когда я пытаюсь получить индексы, они всегда кажутся правильными и совпадают с тем, что я изначально отправляю. Но вершины / нормали никогда не выдаются должным образом.

Я не уверен, какая команда вернет vertexCount для лица. Или если мне нужно l oop поверх него с помощью fv_ccwriter () или одного другого циклического / итератора ...

Я пытаюсь получить список индексов вершин / нормалей +, чтобы начать с Я могу отображать данные в моем окне просмотра openGl.

Насколько я могу судить, я должен l oop над гранями, а затем l oop над гранями граней, а затем сохранять вершины + индексы для этой вершины. & нормальный / ультрафиолетовый / et c для него. Но я не уверен, какие команды мне нужны для этого.

Любая помощь будет отличной.

...