diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-07-30 06:24:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-07-30 06:24:17 +0400 |
commit | 8b127a9bc1824746d6f70665a792f7d66b09e6fa (patch) | |
tree | 14a6cf783787072a66a8bbd58db86f54bd1ce25b /release | |
parent | 6dcde0b5be6d87981fcdd27c924ec1c9e4965c96 (diff) |
this importer tried to be smart by splitting quads that were not planer. - This is not somthing an importer should do and a user was having problems importing meshes to subsurf from lightwave.
also some other updates, and small cleanup.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/lightwave_import.py | 157 |
1 files changed, 78 insertions, 79 deletions
diff --git a/release/scripts/lightwave_import.py b/release/scripts/lightwave_import.py index 63506a6dc1a..eb2447090fe 100644 --- a/release/scripts/lightwave_import.py +++ b/release/scripts/lightwave_import.py @@ -693,7 +693,7 @@ def read_clip(lwochunk, dir_part): i = i + 6 + subchunklen #end loop on surf chunks ###if DEBUG: print "read image:%s" % clip_dict - if clip_dict.has_key('XREF'): + if 'XREF' in clip_dict: # has_key ###if DEBUG: print "Cross-reference: no image pre-allocated." return clip_dict #look for images @@ -985,7 +985,8 @@ def read_surfs(lwochunk, surf_list, tag_list): if uvname: # != "": my_dict['UVNAME'] = uvname #theoretically there could be a number of them: only one used per surf - if not(my_dict.has_key('g_IMAG')) and (rr.has_key('CHAN')) and (rr.has_key('OPAC')) and (rr.has_key('IMAG')): + # all are dictionaries - so testing keys + if not('g_IMAG' in my_dict) and ('CHAN' in rr) and ('OPAC' in rr) and ('IMAG' in rr): if (rr['CHAN'] == 'COLR') and (rr['OPAC'] == 0): my_dict['g_IMAG'] = rr['IMAG'] #do not set anything, just save image object for later assignment subchunklen = 0 #force ending @@ -1008,11 +1009,15 @@ def read_surfs(lwochunk, surf_list, tag_list): def reduce_face(verts, face): - TriangleArea= Blender.Mathutils.TriangleArea - Vector= Blender.Mathutils.Vector + ####if DEBUG: print len(face), face # wants indicies local to the face len_face= len(face) + + + # Dont do this, its no good - odd quads are ok and used in subsurf modeling + """ + TriangleArea= Blender.Mathutils.TriangleArea if len_face==3: return [face] elif len_face==4: @@ -1031,11 +1036,13 @@ def reduce_face(verts, face): return [[0,1,2], [0,2,3]] else: return [[0,1,3], [1,2,3]] - + """ + + if len(face) <= 4: + return [face] else: # 5+ - ####if DEBUG: print 'SCANFILL...', len(face) - ngons= BPyMesh.ngon(verts, face, PREF_FIX_LOOPS= True) - return ngons + ###if DEBUG: print 'SCANFILL...', len(face) + return BPyMesh.ngon(verts, face, PREF_FIX_LOOPS= True) @@ -1109,7 +1116,7 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not pass msh.mode |= Blender.Mesh.Modes.AUTOSMOOTH #smooth it anyway - if surf.has_key('SMAN'): + if 'SMAN' in surf: # has_key #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 msh.degr = min(80, int(surf['SMAN']/3.1415926535897932384626433832795*180.0)) #lwo in radians - blender in degrees @@ -1119,12 +1126,8 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not except: 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 = (('UVNAME' in surf) and (surf['UVNAME'] in uvcoords_dict)) ###if DEBUG: print "\n#===================================================================#" ###if DEBUG: print "Processing Object: %s" % objname @@ -1186,55 +1189,50 @@ def my_create_mesh(clip_list, surf, objspec_list, current_facelist, objname, not uvs.append(default_uv) return uvs - + cur_face 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]) + elif numfaceverts == 3 or numfaceverts == 4: + rev_face = [__i for __i in reversed(cur_face)] 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 > 4: meta_faces= reduce_face(complete_vertlist, cur_face) # Indices of triangles edge_face_count = {} for mf in meta_faces: - # ###if DEBUG: print meta_faces + # These will always be tri's since they are scanfill faces + mf = cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]] + face_data.append( [vertex_map[j] for j in mf] ) - if len(mf) == 3: #triangle - mf = 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)) - - #if USE_FGON: - if len(meta_faces) > 1: - mf = face_data[-1] # reuse mf - for i in xrange(3): - v1= mf[i] - v2= mf[i-1] - if v1!=v2: - if v1>v2: - v2,v1= v1,v2 - try: - edge_face_count[v1,v2]+= 1 - except: - edge_face_count[v1,v2]= 0 + if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i)) - else: #quads - 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)) + #if USE_FGON: + if len(meta_faces) > 1: + mf = face_data[-1] # reuse mf + for j in xrange(3): + v1= mf[j] + v2= mf[j-1] + if v1!=v2: + if v1>v2: + v2,v1= v1,v2 + try: + edge_face_count[v1,v2]+= 1 + except: + edge_face_count[v1,v2]= 0 + + if edge_face_count: edges_fgon.extend( [vert_key for vert_key, count in edge_face_count.iteritems() if count] ) - - msh.edges.extend(edges) + if edges: + msh.edges.extend(edges) + 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 + if 'TRAN' in surf or (mat and mat.alpha<1.0): # incase mat is null transp_flag = True else: transp_flag = False @@ -1347,7 +1345,7 @@ def create_objects(clip_list, objspec_list, surf_list): def lookup_imag(clip_list, ima_id): for ii in clip_list: if ii and ii['ID'] == ima_id: - if ii.has_key('XREF'): + if 'XREF' in ii: # has_key #cross reference - recursively look for images return lookup_imag(clip_list, ii['XREF']) else: @@ -1415,7 +1413,7 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): #if not blok['ENAB']: # ###if DEBUG: print "***Image is not ENABled! Quitting this block" # break - if not(blok.has_key('IMAG')): + if not('IMAG' in blok): # has_key ###if DEBUG: print "***No IMAGE for this block? Quitting" break #extract out the image index within the clip_list if blok['IMAG'] == 0: blok['IMAG'] = lastimag #experimental .... @@ -1434,13 +1432,13 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): tname += "+" else: tname += "x" #let's signal when should not be enabled - if blok.has_key('CHAN'): + if 'CHAN' in blok: # has_key tname += blok['CHAN'] newtex = bpy.data.textures.new(tname) newtex.setType('Image') # make it anu image texture newtex.image = img #how does it extends beyond borders - if blok.has_key('WRAP'): + if 'WRAP' in blok: # has_key if (blok['WRAP'] == 3) or (blok['WRAP'] == 2): newtex.setExtend('Extend') elif (blok['WRAP'] == 1): @@ -1457,35 +1455,35 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): nega = False mapflag = Blender.Texture.MapTo.COL #default to color maptype = Blender.Texture.Mappings.FLAT - if blok.has_key('CHAN'): - if blok['CHAN'] == 'COLR' and blok.has_key('OPACVAL'): + if 'CHAN' in blok: # has_key + if blok['CHAN'] == 'COLR' and 'OPACVAL' in blok: # has_key colfac = blok['OPACVAL'] # Blender needs this to be clamped colfac = max(0.0, min(1.0, colfac)) ###if DEBUG: print "!!!Set Texture -> MapTo -> Col = %.3f" % colfac if blok['CHAN'] == 'BUMP': mapflag = Blender.Texture.MapTo.NOR - if blok.has_key('OPACVAL'): norfac = blok['OPACVAL'] + if 'OPACVAL' in blok: norfac = blok['OPACVAL'] # has_key ###if DEBUG: print "!!!Set Texture -> MapTo -> Nor = %.3f" % norfac if blok['CHAN'] == 'LUMI': mapflag = Blender.Texture.MapTo.EMIT - if blok.has_key('OPACVAL'): dvar = blok['OPACVAL'] + if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key ###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar if blok['CHAN'] == 'DIFF': mapflag = Blender.Texture.MapTo.REF - if blok.has_key('OPACVAL'): dvar = blok['OPACVAL'] + if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key ###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar if blok['CHAN'] == 'SPEC': mapflag = Blender.Texture.MapTo.SPEC - if blok.has_key('OPACVAL'): dvar = blok['OPACVAL'] + if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key ###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar if blok['CHAN'] == 'TRAN': mapflag = Blender.Texture.MapTo.ALPHA - if blok.has_key('OPACVAL'): dvar = blok['OPACVAL'] + if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key ###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar alphaflag = 1 nega = True - if blok.has_key('NEGA'): + if 'NEGA' in blok: # has_key ###if DEBUG: print "!!!Watch-out: effect of this texture channel must be INVERTED!" nega = not nega @@ -1498,7 +1496,7 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): 'Texture Displacement', 'Additive'] set_blendmode = 7 #default additive - if blok.has_key('OPAC'): + if 'OPAC' in blok: # has_key set_blendmode = blok['OPAC'] if set_blendmode == 5: #transparency newtex.imageFlags |= Blender.Texture.ImageFlags.CALCALPHA @@ -1509,7 +1507,7 @@ def create_blok(surf, mat, clip_list, obj_size, obj_pos): axis = [Blender.Texture.Proj.X, Blender.Texture.Proj.Y, Blender.Texture.Proj.Z] size = [1.0] * 3 ofs = [0.0] * 3 - if blok.has_key('PROJ'): + if 'PROJ' in blok: # has_key if blok['PROJ'] == 0: #0 - Planar ###if DEBUG: print "!!!Flat projection" coordflag = Blender.Texture.TexCo.ORCO @@ -1598,44 +1596,44 @@ def update_material(clip_list, objspec, surf_list): break #mat = Blender.Material.New(surf['NAME']) #surf['g_MAT'] = mat - if surf.has_key('COLR'): + if 'COLR' in surf: # has_key mat.rgbCol = surf['COLR'] - if surf.has_key('LUMI'): + if 'LUMI' in surf: mat.setEmit(surf['LUMI']) - if surf.has_key('GVAL'): + if 'GVAL' in surf: # has_key mat.setAdd(surf['GVAL']) - if surf.has_key('SPEC'): - mat.setSpec(surf['SPEC']) #it should be * 2 but seems to be a bit higher lwo [0.0, 1.0] - blender [0.0, 2.0] - if surf.has_key('DIFF'): - mat.setRef(surf['DIFF']) #lwo [0.0, 1.0] - blender [0.0, 1.0] - if surf.has_key('GLOS'): #lwo [0.0, 1.0] - blender [0, 255] - glo = int(371.67 * surf['GLOS'] - 42.334) #linear mapping - seems to work better than exp mapping - if glo <32: glo = 32 #clamped to 32-255 + if 'SPEC' in surf: # has_key + mat.setSpec(surf['SPEC']) #it should be * 2 but seems to be a bit higher lwo [0.0, 1.0] - blender [0.0, 2.0] + if 'DIFF' in surf: # has_key + mat.setRef(surf['DIFF']) #lwo [0.0, 1.0] - blender [0.0, 1.0] + if 'GLOS' in surf: # has_key #lwo [0.0, 1.0] - blender [0, 255] + glo = int(371.67 * surf['GLOS'] - 42.334) #linear mapping - seems to work better than exp mapping + if glo <32: glo = 32 #clamped to 32-255 if glo >255: glo = 255 mat.setHardness(glo) - if surf.has_key('TRNL'): + if 'TRNL' in surf: # has_key mat.setTranslucency(surf['TRNL']) #NOT SURE ABOUT THIS lwo [0.0, 1.0] - blender [0.0, 1.0] - mm = mat.getMode() + mm = mat.mode mm |= Blender.Material.Modes.TRANSPSHADOW - if surf.has_key('REFL'): + if 'REFL' in surf: # has_key mat.setRayMirr(surf['REFL']) #lwo [0.0, 1.0] - blender [0.0, 1.0] mm |= Blender.Material.Modes.RAYMIRROR - if surf.has_key('TRAN'): + if 'TRAN' in surf: # has_key mat.setAlpha(1.0-surf['TRAN']) #lwo [0.0, 1.0] - blender [1.0, 0.0] mm |= Blender.Material.Modes.RAYTRANSP - if surf.has_key('RIND'): + if 'RIND' in surf: # has_key s = surf['RIND'] if s < 1.0: s = 1.0 if s > 3.0: s = 3.0 mat.setIOR(s) #clipped to blender [1.0, 3.0] mm |= Blender.Material.Modes.RAYTRANSP - if surf.has_key('BLOK') and surf['BLOK'] != []: + if 'BLOK' in surf and surf['BLOK'] != []: #update the material according to texture. alphaflag = create_blok(surf, mat, clip_list, obj_size, obj_pos) if alphaflag: mm |= Blender.Material.Modes.RAYTRANSP - mat.setMode(mm) + mat.mode = mm #finished setting up the material #end if exist SURF #end loop on materials (SURFs) @@ -1676,12 +1674,13 @@ def main(): return Blender.Window.FileSelector(read, "Import LWO", '*.lwo') + if __name__=='__main__': main() -""" -# Cams debugging lwo loader +# Cams debugging lwo loader +""" TIME= Blender.sys.time() import os print 'Searching for files' |