[英]Assimp C++ NULL mesh face data
我遇到這個問題已經有一段時間了,我確信我有一些根本性的錯誤。 Assimp 是從最近提交的 github 的源代碼構建的,但我也嘗試過 v5.0.0/1/2。
我可以在 Assimp 中幾乎完成導入 fbx 文件(轉換后所有網格都由三角形組成),但是當從網格訪問面數據時,面是 null(或指向無效內存)。
整個代碼:
void recursive_explorer(aiNode *n, const aiScene *s) {
if (n) {
if (n->mNumChildren != 0) {
for (unsigned i = 0; i < n->mNumChildren; i++) {
recursive_explorer(n->mChildren[i], s);
}
} else {
printf("%d\n", n->mNumMeshes);
for (unsigned j = 0; j < n->mNumMeshes; j++) {
const struct aiMesh *m = s->mMeshes[n->mMeshes[j]];
printf("\t%d\n", m->mNumFaces);
if (m->HasFaces()) {
for (unsigned k = 0; k < m->mNumFaces; k++) {
printf("\t\t%p\n", &m->mFaces[k]);
}
}
}
}
}
}
int main() {
Assimp::Importer importer;
std::fstream f("../maps/de_dust2.fbx");
const aiScene *s = importer.ReadFile("../maps/de_dust2.fbx",
aiProcess_SortByPType | aiProcess_JoinIdenticalVertices |
aiProcess_Triangulate);
printf("Root has %d children\n", s->mRootNode->mNumChildren);
for (unsigned i = 0; i < s->mRootNode->mNumChildren; i++) {
printf("[%u] %s\n", i, s->mRootNode->mChildren[i]->mName.C_Str());
recursive_explorer(s->mRootNode->mChildren[i], s);
}
return 0;
}
結果是:
Root has 3 children
[0] CINEMA_4D_Editor
0
[1] Sky
0
0
0
0
0
[2] de_dust2
2
4
0x1b1b1b1b1b1b1b1b
0x1b1b1b1b1b1b1b2b
0x1b1b1b1b1b1b1b3b
...
如果我嘗試訪問人臉(以獲取 mNumIndices 或 mIndices),則會出現段錯誤。
盡管我還沒有找到正確的組合,但我已經嘗試了不同的預處理選項。
我知道這個可以工作,因為我之前已經設法讓這個特定的 map 工作,但我確信我錯過了一些非常明顯的東西。 提前致謝!
我發現根據我當前的環境,assimp build v5.1.0.rc1 可以工作:
我測試過的東西可以讓 v5.1.5 工作:
也許這特別是一個 MacOS 問題,盡管我在網上看到了一些其他類似問題的帖子,希望這會有所幫助。 謝謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.