* own error, importer would never load images.
* moved from NMesh to Mesh * added more error checking. * tested with 1660 lightwave models * faster dictionary usage. BPyImage - disallowed recursive searching of '/' or a windows drive letter.
This commit is contained in:
@@ -101,7 +101,6 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
|
|||||||
#if path.endswith('\\') or path.endswith('/'):
|
#if path.endswith('\\') or path.endswith('/'):
|
||||||
# raise 'INVALID PATH'
|
# raise 'INVALID PATH'
|
||||||
try:
|
try:
|
||||||
|
|
||||||
img = Blender.Image.Load(path)
|
img = Blender.Image.Load(path)
|
||||||
if VERBOSE: print '\t\tImage loaded "%s"' % path
|
if VERBOSE: print '\t\tImage loaded "%s"' % path
|
||||||
return img
|
return img
|
||||||
@@ -252,7 +251,10 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr
|
|||||||
if VERBOSE: print '\t\tImage Not Found in any of the dirs, doing a recusrive search'
|
if VERBOSE: print '\t\tImage Not Found in any of the dirs, doing a recusrive search'
|
||||||
for path in paths.iterkeys():
|
for path in paths.iterkeys():
|
||||||
# Were not going to use files
|
# Were not going to use files
|
||||||
|
if path == '/' or len(path) == 3 and path[1:] == ':\\':
|
||||||
|
continue
|
||||||
|
|
||||||
|
# print path , 'ASS'
|
||||||
|
|
||||||
#------------------
|
#------------------
|
||||||
# finds the file starting at the root.
|
# finds the file starting at the root.
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import Blender
|
|||||||
|
|
||||||
# use for comprehensiveImageLoad
|
# use for comprehensiveImageLoad
|
||||||
import BPyImage
|
import BPyImage
|
||||||
|
reload(BPyImage)
|
||||||
|
|
||||||
# Use this ngon function
|
# Use this ngon function
|
||||||
import BPyMesh
|
import BPyMesh
|
||||||
@@ -177,8 +178,8 @@ class dotext:
|
|||||||
|
|
||||||
def pdict(self, pdict, where = _NO):
|
def pdict(self, pdict, where = _NO):
|
||||||
self.pprint ("dict:{", where)
|
self.pprint ("dict:{", where)
|
||||||
for pp in pdict.iterkeys():
|
for pp, pdict_val in pdict.iteritems():
|
||||||
self.pprint ("[%s] -> %s" % (pp, pdict[pp]), where)
|
self.pprint ("[%s] -> %s" % (pp, pdict_val), where)
|
||||||
self.pprint ("}")
|
self.pprint ("}")
|
||||||
# end def pdict
|
# end def pdict
|
||||||
|
|
||||||
@@ -228,7 +229,12 @@ def read(filename):
|
|||||||
editmode = Blender.Window.EditMode() # are we in edit mode? If so ...
|
editmode = Blender.Window.EditMode() # are we in edit mode? If so ...
|
||||||
if editmode: Blender.Window.EditMode(0) # leave edit mode before getting the mesh # === LWO header ===
|
if editmode: Blender.Window.EditMode(0) # leave edit mode before getting the mesh # === LWO header ===
|
||||||
|
|
||||||
|
try:
|
||||||
form_id, form_size, form_type = struct.unpack(">4s1L4s", file.read(12))
|
form_id, form_size, form_type = struct.unpack(">4s1L4s", file.read(12))
|
||||||
|
except:
|
||||||
|
Blender.Draw.PupMenu('Error%t|This is not a lightwave file')
|
||||||
|
return
|
||||||
|
|
||||||
if (form_type == "LWOB"):
|
if (form_type == "LWOB"):
|
||||||
read_lwob(file, filename)
|
read_lwob(file, filename)
|
||||||
elif (form_type == "LWO2"):
|
elif (form_type == "LWO2"):
|
||||||
@@ -479,7 +485,7 @@ def read_lwo2(file, filename, typ="LWO2"):
|
|||||||
elif lwochunk.chunkname == "PTAG": # PTags
|
elif lwochunk.chunkname == "PTAG": # PTags
|
||||||
tobj.pprint("---- PTAG")
|
tobj.pprint("---- PTAG")
|
||||||
polytag_dict = read_ptags(lwochunk, tag_list)
|
polytag_dict = read_ptags(lwochunk, tag_list)
|
||||||
for kk in polytag_dict.iterkeys(): objspec_list[5][kk] = polytag_dict[kk]
|
for kk, polytag_dict_val in polytag_dict.iteritems(): objspec_list[5][kk] = polytag_dict_val
|
||||||
else: # Misc Chunks
|
else: # Misc Chunks
|
||||||
tobj.pprint("---- %s: skipping (definitely!)" % lwochunk.chunkname)
|
tobj.pprint("---- %s: skipping (definitely!)" % lwochunk.chunkname)
|
||||||
lwochunk.skip()
|
lwochunk.skip()
|
||||||
@@ -599,6 +605,7 @@ def read_vmap(uvcoords_dict, maxvertnum, lwochunk):
|
|||||||
tobj.pprint ("TXUV %d %s" % (dimension, name))
|
tobj.pprint ("TXUV %d %s" % (dimension, name))
|
||||||
#note if there is already a VMAD it will be lost
|
#note if there is already a VMAD it will be lost
|
||||||
#it is assumed that VMAD will follow the corresponding VMAP
|
#it is assumed that VMAD will follow the corresponding VMAP
|
||||||
|
Vector = Blender.Mathutils.Vector
|
||||||
try: #if uvcoords_dict.has_key(name):
|
try: #if uvcoords_dict.has_key(name):
|
||||||
my_uv_dict = uvcoords_dict[name] #update existing
|
my_uv_dict = uvcoords_dict[name] #update existing
|
||||||
except: #else:
|
except: #else:
|
||||||
@@ -609,7 +616,7 @@ def read_vmap(uvcoords_dict, maxvertnum, lwochunk):
|
|||||||
if vertnum >= maxvertnum:
|
if vertnum >= maxvertnum:
|
||||||
tobj.pprint ("Hem: more uvmap than vertexes? ignoring uv data for vertex %d" % vertnum)
|
tobj.pprint ("Hem: more uvmap than vertexes? ignoring uv data for vertex %d" % vertnum)
|
||||||
else:
|
else:
|
||||||
my_uv_dict[vertnum] = uv
|
my_uv_dict[vertnum] = Vector(uv)
|
||||||
i += 8 + vnum_size
|
i += 8 + vnum_size
|
||||||
#end loop on uv pairs
|
#end loop on uv pairs
|
||||||
uvcoords_dict[name] = my_uv_dict
|
uvcoords_dict[name] = my_uv_dict
|
||||||
@@ -639,6 +646,7 @@ def read_vmad(uvcoords_dict, facesuv_dict, maxfacenum, maxvertnum, lwochunk):
|
|||||||
my_facesuv_list = []
|
my_facesuv_list = []
|
||||||
newindex = maxvertnum + 10 #why +10? Why not?
|
newindex = maxvertnum + 10 #why +10? Why not?
|
||||||
#end variable initialization
|
#end variable initialization
|
||||||
|
Vector = Blender.Mathutils.Vector
|
||||||
while (i < lwochunk.chunksize - 6): #4+2 header bytes already read
|
while (i < lwochunk.chunksize - 6): #4+2 header bytes already read
|
||||||
vertnum, vnum_size = read_vx(data)
|
vertnum, vnum_size = read_vx(data)
|
||||||
i += vnum_size
|
i += vnum_size
|
||||||
@@ -648,7 +656,7 @@ def read_vmad(uvcoords_dict, facesuv_dict, maxfacenum, maxvertnum, lwochunk):
|
|||||||
if polynum >= maxfacenum or vertnum >= maxvertnum:
|
if polynum >= maxfacenum or vertnum >= maxvertnum:
|
||||||
tobj.pprint ("Hem: more uvmap than vertexes? ignorig uv data for vertex %d" % vertnum)
|
tobj.pprint ("Hem: more uvmap than vertexes? ignorig uv data for vertex %d" % vertnum)
|
||||||
else:
|
else:
|
||||||
my_uv_dict[newindex] = uv
|
my_uv_dict[newindex] = Vector(uv)
|
||||||
my_facesuv_list.append([polynum, vertnum, newindex])
|
my_facesuv_list.append([polynum, vertnum, newindex])
|
||||||
newindex += 1
|
newindex += 1
|
||||||
i += 8
|
i += 8
|
||||||
@@ -708,8 +716,8 @@ def read_ptags(lwochunk, tag_list):
|
|||||||
except: #if not(ptag_dict.has_key(tag_key)):
|
except: #if not(ptag_dict.has_key(tag_key)):
|
||||||
ptag_dict[tag_list[tag_index]] = [poln]
|
ptag_dict[tag_list[tag_index]] = [poln]
|
||||||
|
|
||||||
for i in ptag_dict.iterkeys():
|
for i, ptag_dict_val in ptag_dict.iteritems():
|
||||||
tobj.pprint ("read %d polygons belonging to TAG %s" % (len(ptag_dict[i]), i))
|
tobj.pprint ("read %d polygons belonging to TAG %s" % (len(ptag_dict_val ), i))
|
||||||
return ptag_dict
|
return ptag_dict
|
||||||
|
|
||||||
|
|
||||||
@@ -772,14 +780,12 @@ def read_clip(lwochunk, dir_part):
|
|||||||
except:
|
except:
|
||||||
clip_dict['g_IMG'] = None
|
clip_dict['g_IMG'] = None
|
||||||
return
|
return
|
||||||
|
# print 'test', NAME, BASENAME
|
||||||
img = BPyImage.comprehensiveImageLoad('', NAME)
|
img = BPyImage.comprehensiveImageLoad(NAME, dir_part, PLACE_HOLDER= False, RECURSIVE= True)
|
||||||
if not img:
|
if not img:
|
||||||
tobj.pprint ( "***No image %s found: trying LWO file subdir" % NAME)
|
tobj.pprint ( "***No image %s found: trying LWO file subdir" % NAME)
|
||||||
img = BPyImage.comprehensiveImageLoad(dir_part, BASENAME)
|
img = BPyImage.comprehensiveImageLoad(BASENAME, dir_part, PLACE_HOLDER= False, RECURSIVE= True)
|
||||||
if not img:
|
|
||||||
tobj.pprint ( "***No image %s found: trying alternate Images subdir" % BASENAME)
|
|
||||||
img = BPyImage.comprehensiveImageLoad(dir_part+Blender.sys.sep+".."+Blender.sys.sep+"Images", BASENAME)
|
|
||||||
if not img:
|
if not img:
|
||||||
tobj.pprint ( "***No image %s found: giving up" % BASENAME)
|
tobj.pprint ( "***No image %s found: giving up" % BASENAME)
|
||||||
#lucky we are: we have an image
|
#lucky we are: we have an image
|
||||||
@@ -1165,29 +1171,30 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not
|
|||||||
store_edge = 0
|
store_edge = 0
|
||||||
|
|
||||||
scn= Blender.Scene.GetCurrent()
|
scn= Blender.Scene.GetCurrent()
|
||||||
obj= Blender.Object.New('Mesh', objname)
|
#obj= Blender.Object.New('Mesh', objname)
|
||||||
scn.link(obj) # bad form but object data is created.
|
#scn.link(obj) # bad form but object data is created.
|
||||||
obj.sel= 1
|
#obj.sel= 1
|
||||||
obj.Layers= scn.Layers
|
#obj.Layers= scn.Layers
|
||||||
msh = obj.getData()
|
#msh = obj.getData()
|
||||||
mat_index = len(msh.getMaterials(1))
|
#mat_index = len(msh.getMaterials(1))
|
||||||
|
|
||||||
|
msh = Blender.Mesh.New()
|
||||||
|
obj = scn.objects.new(msh)
|
||||||
|
|
||||||
mat = None
|
mat = None
|
||||||
try:
|
try:
|
||||||
msh.addMaterial(surf['g_MAT'])
|
msh.materials = [surf['g_MAT']]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
msh.mode |= Blender.NMesh.Modes.AUTOSMOOTH #smooth it anyway
|
msh.mode |= Blender.Mesh.Modes.AUTOSMOOTH #smooth it anyway
|
||||||
if surf.has_key('SMAN'):
|
if surf.has_key('SMAN'):
|
||||||
#not allowed mixed mode mesh (all the mesh is smoothed and all with the same angle)
|
#not allowed mixed mode mesh (all the mesh is smoothed and all with the same angle)
|
||||||
#only one smoothing angle will be active! => take the max one
|
#only one smoothing angle will be active! => take the max one
|
||||||
s = int(surf['SMAN']/3.1415926535897932384626433832795*180.0) #lwo in radians - blender in degrees
|
msh.degr = min(80, int(surf['SMAN']/3.1415926535897932384626433832795*180.0)) #lwo in radians - blender in degrees
|
||||||
if msh.getMaxSmoothAngle() < s: msh.setMaxSmoothAngle(s)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ima= lookup_imag(clip_list, surf['g_IMAG'])
|
img= lookup_imag(clip_list, surf['g_IMAG'])['g_IMG']
|
||||||
img= ima['g_IMG'] # If its none then
|
|
||||||
except:
|
except:
|
||||||
img= None
|
img= None
|
||||||
|
|
||||||
@@ -1195,169 +1202,146 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not
|
|||||||
#uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])) and (img != None))
|
#uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])) and (img != None))
|
||||||
uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])))
|
uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])))
|
||||||
|
|
||||||
if uv_flag: #assign uv-data; settings at mesh level
|
|
||||||
msh.hasFaceUV(1)
|
|
||||||
|
|
||||||
msh.update(1) # CAN WE REMOVE THIS???- Cam
|
|
||||||
|
|
||||||
tobj.pprint ("\n#===================================================================#")
|
tobj.pprint ("\n#===================================================================#")
|
||||||
tobj.pprint("Processing Object: %s" % objname)
|
tobj.pprint("Processing Object: %s" % objname)
|
||||||
tobj.pprint ("#===================================================================#")
|
tobj.pprint ("#===================================================================#")
|
||||||
|
|
||||||
jj = 0
|
if uv_flag:
|
||||||
vertlen = len(vertex_map)
|
msh.verts.extend([(0.0,0.0,0.0),])
|
||||||
maxvert = len(complete_vertlist)
|
j = 1
|
||||||
Vert= Blender.NMesh.Vert
|
else:
|
||||||
for i in vertex_map.iterkeys():
|
j = 0
|
||||||
#if not jj%1000 and my_meshtools.show_progress: Blender.Window.DrawProgressBar(float(i)/vertlen, "Generating Verts")
|
|
||||||
if i >= maxvert:
|
def tmp_get_vert(k, i):
|
||||||
tobj.logcon("Non existent vertex addressed: Giving up with this object")
|
vertex_map[k] = i+j # j is the dummy vert
|
||||||
return obj, not_used_faces #return the created object
|
# print complete_vertlist[i]
|
||||||
x, y, z = complete_vertlist[i]
|
return complete_vertlist[k]
|
||||||
msh.verts.append(Vert(x, y, z))
|
|
||||||
vertex_map[i] = jj
|
|
||||||
jj += 1
|
|
||||||
del Vert
|
msh.verts.extend([tmp_get_vert(k, i) for i, k in enumerate(vertex_map.iterkeys())])
|
||||||
|
|
||||||
#end sweep over vertexes
|
#end sweep over vertexes
|
||||||
|
|
||||||
#append faces
|
#append faces
|
||||||
FACE_TEX= Blender.NMesh.FaceModes['TEX']
|
FACE_TEX= Blender.Mesh.FaceModes.TEX
|
||||||
FACE_ALPHA= Blender.NMesh.FaceTranspModes['ALPHA']
|
FACE_ALPHA= Blender.Mesh.FaceTranspModes.ALPHA
|
||||||
EDGE_DRAW_FLAG= Blender.NMesh.EdgeFlags.EDGEDRAW | Blender.NMesh.EdgeFlags.EDGERENDER
|
EDGE_DRAW_FLAG= Blender.Mesh.EdgeFlags.EDGEDRAW | Blender.Mesh.EdgeFlags.EDGERENDER
|
||||||
|
|
||||||
Face= Blender.NMesh.Face
|
|
||||||
jj = 0
|
|
||||||
for i in cur_ptag_faces_indexes:
|
|
||||||
#if not jj%1000 and my_meshtools.show_progress: Blender.Window.DrawProgressBar(float(jj)/len(cur_ptag_faces_indexes), "Generating Faces")
|
|
||||||
cur_face = complete_facelist[i]
|
|
||||||
numfaceverts = len(cur_face)
|
|
||||||
vmad_list = [] #empty VMAD in any case
|
|
||||||
if uv_flag: #settings at original face level
|
|
||||||
if facesuv_dict.has_key(surf['UVNAME']): #yes = has VMAD; no = has VMAP only
|
|
||||||
vmad_list = get_uvface(facesuv_dict[surf['UVNAME']],i) #this for VMAD
|
|
||||||
|
|
||||||
if numfaceverts == 2:
|
edges = []
|
||||||
#This is not a face is an edge
|
face_data = [] # [(indicies, material, uvs, image), ]
|
||||||
store_edge = 1
|
face_uvs = []
|
||||||
if msh.edges == None: #first run
|
edges_fgon = []
|
||||||
msh.addEdgeData()
|
|
||||||
i1 = vertex_map[cur_face[1]]
|
|
||||||
i2 = vertex_map[cur_face[0]]
|
|
||||||
if i1 != i2:
|
|
||||||
ee = msh.addEdge(msh.verts[i1],msh.verts[i2])
|
|
||||||
ee.flag |= EDGE_DRAW_FLAG
|
|
||||||
|
|
||||||
elif numfaceverts == 3:
|
|
||||||
#This face is a triangle skip face reduction
|
|
||||||
face = Face()
|
|
||||||
msh.faces.append(face)
|
|
||||||
# Associate face properties => from create materials
|
|
||||||
if mat != None: face.materialIndex = mat_index
|
|
||||||
#face.smooth = 1 #smooth it anyway
|
|
||||||
|
|
||||||
rev_face= [cur_face[2], cur_face[1], cur_face[0]]
|
|
||||||
|
|
||||||
for vi in rev_face:
|
|
||||||
index= vertex_map[vi]
|
|
||||||
face.v.append(msh.verts[index])
|
|
||||||
|
|
||||||
if uv_flag:
|
if uv_flag:
|
||||||
ni= get_newindex(vmad_list, vi)
|
uvcoords_dict_context = uvcoords_dict[surf['UVNAME']]
|
||||||
if ni > -1:
|
try: current_uvdict = facesuv_dict[surf['UVNAME']]
|
||||||
uv_index= ni
|
except: current_uvdict = None
|
||||||
else: #VMAP - uses the same criteria as face
|
|
||||||
uv_index= vi
|
|
||||||
try: #if uvcoords_dict[surf['UVNAME']].has_key(uv_index):
|
|
||||||
uv_tuple= uvcoords_dict[surf['UVNAME']][uv_index]
|
|
||||||
except: # else:
|
|
||||||
uv_tuple= (0,0)
|
|
||||||
face.uv.append(uv_tuple)
|
|
||||||
|
|
||||||
if uv_flag and img != None:
|
default_uv = Blender.Mathutils.Vector(0,0)
|
||||||
face.mode |= FACE_TEX
|
def tmp_get_face_uvs(cur_face, i):
|
||||||
face.image= img
|
uvs = []
|
||||||
if surf.has_key('TRAN') or (mat and mat.getAlpha()<1.0):
|
if current_uvdict:
|
||||||
face.transp= FACE_ALPHA
|
uvface = get_uvface(current_uvdict,i)
|
||||||
|
for vi in cur_face:
|
||||||
|
ni = get_newindex(uvface, vi)
|
||||||
|
if ni == -1: ni = vi
|
||||||
|
|
||||||
|
try:
|
||||||
|
uvs.append(uvcoords_dict_context[ ni ])
|
||||||
|
except:
|
||||||
|
print '\tWarning, Corrupt UVs'
|
||||||
|
uvs.append(default_uv)
|
||||||
|
else:
|
||||||
|
for vi in cur_face:
|
||||||
|
uvs.append(uvcoords_dict_context[ vi ])
|
||||||
|
|
||||||
|
return uvs
|
||||||
|
|
||||||
|
for i in cur_ptag_faces_indexes:
|
||||||
|
cur_face = complete_facelist[i]
|
||||||
|
numfaceverts = len(cur_face)
|
||||||
|
|
||||||
|
if numfaceverts == 2: edges.append((vertex_map[cur_face[0]], vertex_map[cur_face[1]]))
|
||||||
|
elif numfaceverts == 3:
|
||||||
|
rev_face = (cur_face[2], cur_face[1], cur_face[0])
|
||||||
|
face_data.append( [vertex_map[j] for j in rev_face] )
|
||||||
|
if uv_flag: face_uvs.append(tmp_get_face_uvs(rev_face, i))
|
||||||
|
|
||||||
elif numfaceverts > 3:
|
elif numfaceverts > 3:
|
||||||
#Reduce all the faces with more than 3 vertexes (& test if the quad is concave .....)
|
meta_faces= reduce_face(complete_vertlist, cur_face) # Indices of triangles
|
||||||
|
|
||||||
#meta_faces= reduce_face_old(complete_vertlist, cur_face) # Indices of triangles.
|
|
||||||
meta_faces= reduce_face(complete_vertlist, cur_face) # Indices of triangles.
|
|
||||||
|
|
||||||
if len(meta_faces) > 1:
|
|
||||||
USE_FGON= True
|
|
||||||
edge_face_count = {}
|
edge_face_count = {}
|
||||||
else:
|
|
||||||
USE_FGON= False
|
|
||||||
|
|
||||||
for mf in meta_faces:
|
for mf in meta_faces:
|
||||||
# print meta_faces
|
# print meta_faces
|
||||||
face= Face()
|
|
||||||
msh.faces.append(face)
|
|
||||||
|
|
||||||
if len(mf) == 3: #triangle
|
if len(mf) == 3: #triangle
|
||||||
rev_face= [cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]]
|
mf = cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]
|
||||||
if USE_FGON:
|
face_data.append( [vertex_map[j] for j in mf] )
|
||||||
|
|
||||||
|
if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i))
|
||||||
|
|
||||||
|
#if USE_FGON:
|
||||||
|
if len(meta_faces) > 1:
|
||||||
|
mf = face_data[-1] # reuse mf
|
||||||
for i in xrange(3):
|
for i in xrange(3):
|
||||||
v1= vertex_map[rev_face[i]]
|
v1= mf[i]
|
||||||
v2= vertex_map[rev_face[i-1]]
|
v2= mf[i-1]
|
||||||
if v1!=v2:
|
if v1!=v2:
|
||||||
if v1>v2:
|
if v1>v2:
|
||||||
v2,v1= v1,v2
|
v2,v1= v1,v2
|
||||||
try:
|
try:
|
||||||
edge_face_count[v1,v2]+= 1
|
edge_face_count[v1,v2]+= 1
|
||||||
except:
|
except:
|
||||||
edge_face_count[v1,v2]= 1
|
edge_face_count[v1,v2]= 0
|
||||||
|
|
||||||
|
|
||||||
else: #quads
|
else: #quads
|
||||||
rev_face= [cur_face[mf[3]], cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]]
|
mf= cur_face[mf[3]], cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]
|
||||||
|
face_data.append( [vertex_map[j] for j in mf] )
|
||||||
|
if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i))
|
||||||
|
|
||||||
# Associate face properties => from create materials
|
if edge_face_count:
|
||||||
if mat != None: face.materialIndex = mat_index
|
edges_fgon.extend( [vert_key for vert_key, count in edge_face_count.iteritems() if count] )
|
||||||
#face.smooth = 1 #smooth it anyway
|
|
||||||
|
|
||||||
for vi in rev_face:
|
|
||||||
index = vertex_map[vi]
|
msh.edges.extend(edges)
|
||||||
face.v.append(msh.verts[index])
|
face_mapping_removed = msh.faces.extend(face_data, indexList=True)
|
||||||
|
if surf.has_key('TRAN') or (mat and mat.alpha<1.0): # incase mat is null
|
||||||
|
transp_flag = True
|
||||||
|
else:
|
||||||
|
transp_flag = False
|
||||||
|
|
||||||
if uv_flag:
|
if uv_flag:
|
||||||
ni = get_newindex(vmad_list, vi)
|
msh.faceUV = True
|
||||||
if ni > -1:
|
msh_faces= msh.faces
|
||||||
uv_index = ni
|
for i, uvs in enumerate(face_uvs):
|
||||||
else: #VMAP - uses the same criteria as face
|
i_mapped = face_mapping_removed[i]
|
||||||
uv_index = vi
|
if i_mapped != None:
|
||||||
try: #if uvcoords_dict[surf['UVNAME']].has_key(uv_index):
|
f = msh_faces[i_mapped]
|
||||||
uv_tuple = uvcoords_dict[surf['UVNAME']][uv_index]
|
f.uv = uvs
|
||||||
except: #else:
|
if img:
|
||||||
uv_tuple = (0,0)
|
f.image = img
|
||||||
face.uv.append(uv_tuple)
|
|
||||||
|
|
||||||
if uv_flag and img != None:
|
if transp_flag: f.transp |= FACE_ALPHA
|
||||||
face.mode |= FACE_TEX
|
|
||||||
face.image = img
|
|
||||||
if surf.has_key('TRAN') or (mat and mat.getAlpha()<1.0): # incase mat is null
|
|
||||||
face.transp= FACE_ALPHA
|
|
||||||
|
|
||||||
# Tag edges for FGONS
|
if edges_fgon:
|
||||||
if USE_FGON:
|
msh_edges = msh.edges
|
||||||
for vert_key, count in edge_face_count.iteritems():
|
FGON= Blender.Mesh.EdgeFlags.FGON
|
||||||
if count > 1: # we are used by more then 1 face
|
edges_fgon = msh.findEdges( edges_fgon )
|
||||||
nm_edge= msh.addEdge( msh.verts[vert_key[0]], msh.verts[vert_key[1]] )
|
if type(edges_fgon) != list: edges_fgon = [edges_fgon]
|
||||||
if nm_edge:
|
for ed in edges_fgon:
|
||||||
nm_edge.flag |=Blender.NMesh.EdgeFlags.FGON
|
if ed!=None:
|
||||||
|
msh_edges[ed].flag |= FGON
|
||||||
jj += 1
|
|
||||||
|
|
||||||
if not(uv_flag): #clear eventual UV data
|
if not(uv_flag): #clear eventual UV data
|
||||||
msh.hasFaceUV(0)
|
msh.faceUV = False
|
||||||
msh.update(1,store_edge)
|
|
||||||
obj.sel= 1
|
if uv_flag:
|
||||||
# Cycle editmode to render a nice wire frame.
|
msh.verts.delete([0,])
|
||||||
# Blender.Window.EditMode(1)
|
|
||||||
# Blender.Window.EditMode(0)
|
|
||||||
# Blender.Redraw()
|
|
||||||
return obj, not_used_faces #return the created object
|
return obj, not_used_faces #return the created object
|
||||||
|
|
||||||
|
|
||||||
@@ -1398,10 +1382,10 @@ def create_objects(clip_list, objspec_list, surf_list):
|
|||||||
endchar = ""
|
endchar = ""
|
||||||
if (objspec_list[6] == 1):
|
if (objspec_list[6] == 1):
|
||||||
middlechar = endchar = "#"
|
middlechar = endchar = "#"
|
||||||
for cur_tag in ptag_dict.iterkeys():
|
for cur_tag, ptag_dict_val in ptag_dict.iteritems():
|
||||||
if ptag_dict[cur_tag] != []:
|
if ptag_dict_val != []:
|
||||||
cur_surf = get_surf(surf_list, cur_tag)
|
cur_surf = get_surf(surf_list, cur_tag)
|
||||||
cur_obj, not_used_faces= my_create_mesh(clip_list, cur_surf, objspec_list, ptag_dict[cur_tag], objspec_list[0][:9]+middlechar+cur_tag[:9], not_used_faces)
|
cur_obj, not_used_faces= my_create_mesh(clip_list, cur_surf, objspec_list, ptag_dict_val, objspec_list[0][:9]+middlechar+cur_tag[:9], not_used_faces)
|
||||||
# Works now with new modifiers
|
# Works now with new modifiers
|
||||||
if objspec_list[6] == 1:
|
if objspec_list[6] == 1:
|
||||||
set_subsurf(cur_obj)
|
set_subsurf(cur_obj)
|
||||||
@@ -1680,7 +1664,7 @@ def update_material(clip_list, objspec, surf_list):
|
|||||||
uvcoords_dict = objspec[7]
|
uvcoords_dict = objspec[7]
|
||||||
facesuv_dict = objspec[8]
|
facesuv_dict = objspec[8]
|
||||||
for surf in surf_list:
|
for surf in surf_list:
|
||||||
if (surf and surf['NAME'] in ptag_dict.iterkeys()):
|
if surf and surf['NAME'] in ptag_dict: # in ptag_dict.keys()
|
||||||
tobj.pprint ("#-------------------------------------------------------------------#")
|
tobj.pprint ("#-------------------------------------------------------------------#")
|
||||||
tobj.pprint ("Processing surface (material): %s" % surf['NAME'])
|
tobj.pprint ("Processing surface (material): %s" % surf['NAME'])
|
||||||
tobj.pprint ("#-------------------------------------------------------------------#")
|
tobj.pprint ("#-------------------------------------------------------------------#")
|
||||||
@@ -1785,7 +1769,7 @@ if __name__=='__main__':
|
|||||||
TIME= Blender.sys.time()
|
TIME= Blender.sys.time()
|
||||||
import os
|
import os
|
||||||
print 'Searching for files'
|
print 'Searching for files'
|
||||||
os.system('find /metavr/ -iname "*.lwo" > /tmp/templwo_list')
|
os.system('find /fe/ -iname "*.lwo" > /tmp/templwo_list')
|
||||||
# os.system('find /storage/ -iname "*.lwo" > /tmp/templwo_list')
|
# os.system('find /storage/ -iname "*.lwo" > /tmp/templwo_list')
|
||||||
print '...Done'
|
print '...Done'
|
||||||
file= open('/tmp/templwo_list', 'r')
|
file= open('/tmp/templwo_list', 'r')
|
||||||
@@ -1799,10 +1783,14 @@ def between(v,a,b):
|
|||||||
return False
|
return False
|
||||||
size= 0.0
|
size= 0.0
|
||||||
for i, _lwo in enumerate(lines):
|
for i, _lwo in enumerate(lines):
|
||||||
if i==425: # SCANFILL
|
#if i==425: # SCANFILL
|
||||||
|
#if 1:
|
||||||
#if i==520: # SCANFILL CRASH
|
#if i==520: # SCANFILL CRASH
|
||||||
#if i==47: # SCANFILL CRASH
|
#if i==47: # SCANFILL CRASH
|
||||||
#if between(i, 0, 1800):
|
#if between(i, 525, 550):
|
||||||
|
#if i > 1635:
|
||||||
|
#if i != 1519: # 730
|
||||||
|
if 1:
|
||||||
_lwo= _lwo[:-1]
|
_lwo= _lwo[:-1]
|
||||||
print 'Importing', _lwo, '\nNUMBER', i, 'of', len(lines)
|
print 'Importing', _lwo, '\nNUMBER', i, 'of', len(lines)
|
||||||
_lwo_file= _lwo.split('/')[-1].split('\\')[-1]
|
_lwo_file= _lwo.split('/')[-1].split('\\')[-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user