我的目标是使用python从漂亮的(.nii)格式获得一个.obj文件,目的是在Unity上打开它。我知道“scikit image”包有一个名为“measure”的模块,它实现了Marching cube算法。我将marching cube算法应用于我的数据,得到了我期望的结果:
verts, faces, normals, values = measure.marching_cubes_lewiner(nifty_data, 0)
然后我可以绘制数据:
^{pr2}$我已经找到了将数据(顶点、面法线、值)保存为.obj的函数,但没有找到。因此,我决定自己建造它。在
thefile = open('test.obj', 'w')
for item in verts:
thefile.write("v {0} {1} {2}\n".format(item[0],item[1],item[2]))
for item in normals:
thefile.write("vn {0} {1} {2}\n".format(item[0],item[1],item[2]))
for item in faces:
thefile.write("f {0}//{0} {1}//{1} {2}//{2}\n".format(item[0],item[1],item[2]))
thefile.close()
但当我将数据导入unity时,我得到了以下结果:
所以我的问题是:
谢谢。在
更多示例:
Python:
统一:
解决方案:经过数小时的调试,解决方案非常简单!只需将+1添加到通过应用marching cubes得到的面部数据。问题是Python认为顶点从0开始,unity认为它们从1开始。这就是为什么他们不匹配!欢迎。在
成功!在
相关问题 更多 >
编程相关推荐