- Scripts:

small update of ideasman's obj import/export scripts (added support for smooth faces)
This commit is contained in:
Jiri Hnidek
2004-06-21 20:32:07 +00:00
parent 59433aa42e
commit ee07502a04
2 changed files with 27 additions and 2 deletions

View File

@@ -151,6 +151,8 @@ def save_obj(filename):
# Dosent work properly, # Dosent work properly,
matrix = getWorldMat(ob) matrix = getWorldMat(ob)
smooth = 0
# Vert # Vert
for v in m.verts: for v in m.verts:
# Transform the vert # Transform the vert
@@ -211,6 +213,16 @@ def save_obj(filename):
currentImgName = NULL_IMG currentImgName = NULL_IMG
file.write( 'usemat ' + stripPath(currentImgName) +'\n') # Set a new image for all following faces file.write( 'usemat ' + stripPath(currentImgName) +'\n') # Set a new image for all following faces
if f.smooth == 1:
if smooth == 0:
smooth = 1
file.write('s 1\n')
if f.smooth == 0:
if smooth == 1:
smooth = 0
file.write('s off\n')
file.write('f ') file.write('f ')
for v in f.v: for v in f.v:
file.write( str(m.verts.index(v) +1) + '/') # Vert IDX file.write( str(m.verts.index(v) +1) + '/') # Vert IDX

View File

@@ -217,6 +217,8 @@ def load_obj(file):
currentMat = nullMat # Use this mat. currentMat = nullMat # Use this mat.
currentImg = NULL_IMG # Null image is a string, otherwise this should be set to an image object. currentImg = NULL_IMG # Null image is a string, otherwise this should be set to an image object.
smooth = 0
# Main loop # Main loop
lIdx = 0 lIdx = 0
while lIdx < len(fileLines): while lIdx < len(fileLines):
@@ -271,6 +273,8 @@ def load_obj(file):
f.v.append(mesh.verts[vIdxLs[1]]) f.v.append(mesh.verts[vIdxLs[1]])
f.v.append(mesh.verts[vIdxLs[2]]) f.v.append(mesh.verts[vIdxLs[2]])
f.v.append(mesh.verts[vIdxLs[3]]) f.v.append(mesh.verts[vIdxLs[3]])
# SMOTH FACE
f.smooth = smooth
# UV MAPPING # UV MAPPING
if uvMapList: if uvMapList:
if vtIdxLs[0] < len(uvMapList): if vtIdxLs[0] < len(uvMapList):
@@ -294,6 +298,8 @@ def load_obj(file):
f.v.append(mesh.verts[vIdxLs[0]]) f.v.append(mesh.verts[vIdxLs[0]])
f.v.append(mesh.verts[vIdxLs[i+1]]) f.v.append(mesh.verts[vIdxLs[i+1]])
f.v.append(mesh.verts[vIdxLs[i+2]]) f.v.append(mesh.verts[vIdxLs[i+2]])
# SMOTH FACE
f.smooth = smooth
# UV MAPPING # UV MAPPING
if uvMapList: if uvMapList:
if vtIdxLs[0] < len(uvMapList): if vtIdxLs[0] < len(uvMapList):
@@ -328,6 +334,13 @@ def load_obj(file):
# New texture list # New texture list
uvMapList = [] uvMapList = []
# setting smooth surface on or off
elif l[0] == 's':
if l[1] == 'off':
smooth = 0
else:
smooth = 1
elif l[0] == 'usemtl': elif l[0] == 'usemtl':
if l[1] == '(null)': if l[1] == '(null)':
currentMat = getMat(NULL_MAT) currentMat = getMat(NULL_MAT)