Scripts: Campbell (ideasman) updated his obj wavefront scripts.

This commit is contained in:
2004-06-08 04:43:40 +00:00
parent 61bb158291
commit a15b430d71
2 changed files with 71 additions and 89 deletions

View File

@@ -1,7 +1,7 @@
#!BPY
"""
Name: 'OBJ Wavefront'
Name: 'Wavefront (*.obj)'
Blender: 232
Group: 'Import'
Tooltip: 'Load a Wavefront OBJ File'
@@ -150,12 +150,12 @@ def load_obj(file):
# This is a new vert, make a new mesh
mesh.verts.append( NMesh.Vert(eval(l[1]), eval(l[2]), eval(l[3]) ) )
elif l[0] == 'vn':
pass
elif l[0] == 'vn':
pass
elif l[0] == 'vt':
# This is a new vert, make a new mesh
uvMapList.append( (eval(l[1]), eval(l[2])) )
elif l[0] == 'vt':
# This is a new vert, make a new mesh
uvMapList.append( (eval(l[1]), eval(l[2])) )
elif l[0] == 'f':
@@ -165,75 +165,75 @@ def load_obj(file):
# Set up vIdxLs : Verts
# Set up vtIdxLs : UV
vIdxLs = []
vtIdxLs = []
vIdxLs = []
vtIdxLs = []
for v in l[1:]:
objVert = split( v, ['/'] )
objVert = split( v, ['/'] )
# VERT INDEX
vIdxLs.append(eval(objVert[0]) -1)
# UV
if len(objVert) == 1:
vtIdxLs.append(eval(objVert[0]) -1) # Sticky UV coords
else:
vtIdxLs.append(eval(objVert[1]) -1) # Seperate UV coords
# VERT INDEX
vIdxLs.append(eval(objVert[0]) -1)
# UV
if len(objVert) == 1:
vtIdxLs.append(eval(objVert[0]) -1) # Sticky UV coords
else:
vtIdxLs.append(eval(objVert[1]) -1) # Seperate UV coords
# Quads only, we could import quads using the method below but it polite to import a quad as a quad.f
if len(vIdxLs) == 4:
f.v.append(mesh.verts[vIdxLs[0]])
f.v.append(mesh.verts[vIdxLs[1]])
f.v.append(mesh.verts[vIdxLs[2]])
f.v.append(mesh.verts[vIdxLs[3]])
# UV MAPPING
if uvMapList:
if vtIdxLs[0] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[0] ] )
if vtIdxLs[1] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[1] ] )
if vtIdxLs[2] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[2] ] )
if vtIdxLs[3] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[3] ] )
mesh.faces.append(f) # move the face onto the mesh
if len(vIdxLs) == 4:
f.v.append(mesh.verts[vIdxLs[0]])
f.v.append(mesh.verts[vIdxLs[1]])
f.v.append(mesh.verts[vIdxLs[2]])
f.v.append(mesh.verts[vIdxLs[3]])
# UV MAPPING
if uvMapList:
if vtIdxLs[0] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[0] ] )
if vtIdxLs[1] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[1] ] )
if vtIdxLs[2] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[2] ] )
if vtIdxLs[3] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[3] ] )
mesh.faces.append(f) # move the face onto the mesh
elif len(vIdxLs) >= 3: # This handles tri's and fans
for i in range(len(vIdxLs)-2):
f = NMesh.Face()
mesh, f = applyMat(mesh, f, currentMat)
f.v.append(mesh.verts[vIdxLs[0]])
f.v.append(mesh.verts[vIdxLs[i+1]])
f.v.append(mesh.verts[vIdxLs[i+2]])
# UV MAPPING
if uvMapList:
if vtIdxLs[0] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[0] ] )
if vtIdxLs[1] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[i+1] ] )
if vtIdxLs[2] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[i+2] ] )
elif len(vIdxLs) >= 3: # This handles tri's and fans
for i in range(len(vIdxLs)-2):
f = NMesh.Face()
mesh, f = applyMat(mesh, f, currentMat)
f.v.append(mesh.verts[vIdxLs[0]])
f.v.append(mesh.verts[vIdxLs[i+1]])
f.v.append(mesh.verts[vIdxLs[i+2]])
# UV MAPPING
if uvMapList:
if vtIdxLs[0] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[0] ] )
if vtIdxLs[1] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[i+1] ] )
if vtIdxLs[2] < len(uvMapList):
f.uv.append( uvMapList[ vtIdxLs[i+2] ] )
mesh.faces.append(f) # move the face onto the mesh
mesh.faces.append(f) # move the face onto the mesh
# is o the only vert/face delimeter?
# if not we could be screwed.
elif l[0] == 'o':
# Make sure the objects is worth puttong
if len(mesh.verts) > 0:
NMesh.PutRaw(mesh, fileName + '_' + objectName)
# Make new mesh
mesh = NMesh.GetRaw()
# is o the only vert/face delimeter?
# if not we could be screwed.
elif l[0] == 'o':
# Make sure the objects is worth puttong
if len(mesh.verts) > 0:
NMesh.PutRaw(mesh, fileName + '_' + objectName)
# Make new mesh
mesh = NMesh.GetRaw()
# New mesh name
objectName = join(l[1:]) # Use join in case of spaces
# New mesh name
objectName = join(l[1:]) # Use join in case of spaces
# New texture list
uvMapList = []
uvMapList = []
elif l[0] == 'usemtl':
if l[1] == '(null)':
currentMat = NULL_MAT
else:
currentMat = getMat(join(l[1:])) # Use join in case of spaces
elif l[0] == 'usemtl':
if l[1] == '(null)':
currentMat = getMat(NULL_MAT)
else:
currentMat = getMat(join(l[1:])) # Use join in case of spaces
lIdx+=1