gpt4 book ai didi

c++ - 如何使用 openframework 的 ofMesh 正确导出 .obj?

转载 作者:太空宇宙 更新时间:2023-11-03 22:31:44 24 4
gpt4 key购买 nike

我正在使用 ofxFaceTracker 并尝试导出面部网格:

face tracker mesh

image source

我试过这样导出它:

void testApp::exportOBJ(ofMesh m,const string name){
obj.open(ofToDataPath(name),ofFile::WriteOnly);
obj << "vertices:\n";
for(int i = 0 ; i < m.getNumVertices(); i++) {
ofVec3f v = m.getVertex(i);
obj << "v " + ofToString(v.x) + " " + ofToString(v.y) + " " + ofToString(v.z) + "\n";
}
obj << "faces:\n";
for(int i = 0 ; i < m.getNumIndices(); i += 3)
obj << "f " + ofToString(m.getIndex(i)) + " " + ofToString(m.getIndex(i+1)) + " " + ofToString(m.getIndex(i+2)) + "\n";
obj << "\n";
obj.close();
cout << "wrote " << name << endl;
}

但在 osx 上我无法打开网格(尝试使用 meshlab/blender/wings3d)。我设法用犀牛在 window 上打开了同样的网格,它看起来很像一张脸,但是有些顶点确实扭曲了/在错误的位置,所以我的猜测是我对索引做错了,但不确定是什么/如何。

这是一个导出的 .obj 示例:

vertices:
v -20.6022 -5.66773 21.5579
v -19.8261 -0.419152 20.9754
v -18.7688 4.80224 20.5902
v -17.4952 9.82323 18.4562
v -15.6561 14.3357 13.5869
v -12.5987 17.9449 8.00129
v -8.53776 20.5398 3.32444
v -3.94841 22.2104 -0.892325
v 1.02873 22.4121 -4.53705
v 6.18366 21.5766 -0.714729
v 10.605 19.0508 3.50892
v 14.2893 15.6505 8.12131
v 17.009 11.5584 13.606
v 18.5784 6.98063 18.3654
v 19.3276 2.1372 20.5367
v 19.64 -2.84804 20.831
v 19.5423 -7.82872 21.2609
v -17.327 -14.5225 0.123951
v -14.9373 -16.7636 -1.52573
v -11.8495 -17.9108 -2.87878
v -8.56141 -18.0651 -4.1774
v -5.32835 -17.4937 -5.38178
v 2.79548 -17.8005 -5.4358
v 5.63979 -18.6976 -4.14262
v 8.66089 -18.956 -2.80534
v 11.6497 -18.4135 -1.37405
v 14.2054 -16.789 0.341925
v -0.408693 -11.8925 -4.88226
v -0.180875 -8.73332 -7.72351
v 0.0312087 -5.60233 -10.714
v 0.231803 -2.47574 -13.552
v -2.84584 1.30904 -6.47237
v -1.12265 1.67075 -7.31997
v 0.671659 1.72685 -8.1004
v 2.29284 1.47247 -7.20141
v 3.78514 0.901742 -6.43822
v -12.9266 -9.93115 -0.801998
v -11.0504 -11.234 -1.02927
v -8.72255 -11.4499 -1.16927
v -6.69202 -10.4231 -1.045
v -8.72807 -9.76957 -1.15914
v -10.8849 -9.54587 -1.06901
v 4.84169 -11.0086 -0.905979
v 6.64327 -12.2275 -1.11565
v 8.91755 -12.4115 -0.967128
v 10.9016 -11.366 -0.685089
v 8.99931 -10.6743 -0.93854
v 6.88148 -10.6499 -0.986586
v -6.31415 9.57306 -2.88979
v -4.28127 7.70573 -5.03882
v -1.92705 6.22388 -6.66532
v 0.757197 6.1971 -8.35617
v 3.3569 5.91561 -6.45012
v 5.76649 7.07784 -4.82012
v 7.81309 8.75701 -2.65881
v 5.91403 10.1098 -3.89979
v 3.55874 10.8651 -5.05484
v 1.01962 11.0854 -6.49424
v -1.54786 11.1077 -5.23493
v -4.05109 10.6435 -4.02293
v -1.89044 8.35439 -5.36359
v 0.896875 8.06717 -7.44355
v 3.61175 8.07349 -5.06538
v 3.60898 8.43406 -4.47627
v 0.941186 8.54596 -6.41103
v -1.78114 8.73121 -4.70015
faces:
f 20 21 23
f 21 22 23
f 0 1 36
f 15 16 45
f 0 17 36
f 16 26 45
f 17 18 37
f 25 26 44
f 17 36 37
f 26 44 45
f 18 19 38
f 24 25 43
f 18 37 38
f 25 43 44
f 19 20 38
f 23 24 43
f 20 21 39
f 22 23 42
f 20 38 39
f 23 42 43
f 21 22 27
f 21 27 39
f 22 27 42
f 27 28 42
f 27 28 39
f 28 42 47
f 28 39 40
f 1 36 41
f 15 45 46
f 1 2 41
f 14 15 46
f 28 29 40
f 28 29 47
f 2 40 41
f 14 46 47
f 2 29 40
f 14 29 47
f 2 3 29
f 13 14 29
f 29 30 31
f 29 30 35
f 3 29 31
f 13 29 35
f 30 32 33
f 30 33 34
f 30 31 32
f 30 34 35
f 3 4 31
f 12 13 35
f 4 5 48
f 11 12 54
f 5 6 48
f 10 11 54
f 6 48 59
f 10 54 55
f 6 7 59
f 9 10 55
f 7 58 59
f 9 55 56
f 8 57 58
f 8 56 57
f 7 8 58
f 8 9 56
f 4 31 48
f 12 35 54
f 31 48 49
f 35 53 54
f 31 49 50
f 35 52 53
f 31 32 50
f 34 35 52
f 32 33 50
f 33 34 52
f 33 50 51
f 33 51 52
f 48 49 60
f 49 60 50
f 50 60 61
f 50 51 61
f 51 52 61
f 61 62 52
f 52 53 62
f 53 54 62
f 54 55 63
f 55 56 63
f 56 63 64
f 56 57 64
f 64 65 57
f 57 58 65
f 58 59 65
f 48 59 65

关于如何将此网格正确导出为 .obj 的任何提示/技巧?

最佳答案

obj 文件有一个奇怪的面孔索引,从 1 而不是 0 开始。

你必须给你所有的脸指数加1


你也必须评论你的评论:

#vertices:
#faces:

代替

vertices:
faces:

关于c++ - 如何使用 openframework 的 ofMesh 正确导出 .obj?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22708501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com