9
我需要Python入門(我幾乎一無所知)的幫助,以便對從Rhino生成的3D網格進行體素化。數據輸入將是.OBJ文件,輸出也是如此。這種用法的最終目的是找出建築物內兩點之間的最短距離。但那是爲了以後。至於現在,我需要先體素化3D網格。體素化原語可能只是一個簡單的立方體。在Python中,如何體元化3D網格
到目前爲止,我可以從OBJ文件解析器中讀取,並從解析的obj中讀取V,VT,VN,F前綴,並使用這些座標來查找3D對象的邊界框。什麼應該是正確的方式來體現網格?
import objParser
import math
inputFile = 'test.obj'
vList = []; vtList = []; vnList = []; fList = []
def parseOBJ(inputFile):
list = []
vList, vtList, vnList, fList = objParser.getObj(inputFile)
print 'in parseOBJ'
#print vList, vtList, vnList, fList
return vList, vtList, vnList, fList
def findBBox(vList):
i = 0; j=0; x_min = float('inf'); x_max = float('-inf'); y_min = float('inf');
y_max = float('-inf'); z_min = float('inf'); z_max = float('-inf');
xWidth = 0; yWidth = 0; zWidth =0
print 'in findBBox'
while i < len(vList):
#find min and max x value
if vList[i][j] < x_min:
x_min = float(vList[i][j])
elif vList[i][j] > x_max:
x_max = float(vList[i][j])
#find min and max y value
if vList[i][j + 1] < y_min:
y_min = float(vList[i][j + 1])
elif vList[i][j + 1] > y_max:
y_max = float(vList[i][j + 1])
#find min and max x value
if vList[i][j + 2] < z_min:
z_min = vList[i][j + 2]
elif vList[i][j + 2] > z_max:
z_max = vList[i][j + 2]
#incriment the counter int by 3 to go to the next set of (x, y, z)
i += 3; j=0
xWidth = x_max - x_min
yWidth = y_max - y_min
zWidth = z_max - z_min
length = xWidth, yWidth, zWidth
volume = xWidth* yWidth* zWidth
print 'x_min, y_min, z_min : ', x_min, y_min, z_min
print 'x_max, y_max, z_max : ', x_max, y_max, z_max
print 'xWidth, yWidth, zWidth : ', xWidth, yWidth, zWidth
return length, volume
def init():
list = parseOBJ(inputFile)
findBBox(list[0])
print init()
Binvox已經轉移到[此位置](http://www.patrickmin.com/binvox/) – 2016-09-04 19:27:00
感謝您的信息@A_A,我已更新鏈接。 – kolenda 2018-02-02 10:04:18