#!BPY """ Name: 'ASCII Scene (.ase) v0.13' Blender: 244 Group: 'Import' Tooltip: 'Import from ASCII Scene Export file format (.ase)' """ __author__ = "Goofos" __version__ = "0.13" # goofos # # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** import time, sys import Blender from Blender import Scene, Object, Mesh ''' Some Options ''' # Scale Factor (float) OPT_SCALE = 0.1 # Add EdgeSplit Modifier when importing sharp edges (bool) OPT_MOD_EDGESPLIT = True # Enable the fileselector (bool) OPT_FILESELECTOR = True # If the fileselector is disabled, specify a static filename (string) OPT_STATIC_FILENAME = 'E:\ASE Files\garage.ASE' # Enable Progressbar (bool) OPT_PROGRESSBAR = False # File buffer. After testing with big files i think there is no real difference. # -1 = system default, 0 = unbuffered, 1 = line buffered, >1 = buffer size OPT_FILE_BUFFER = -1 ''' Import Options ''' # Import Meshes scaled, defined by the scale factor of OPT_SCALE (bool) # Note: Object location data looses some precision, .. i think! IMP_SCALED = True # Import Vertex Colors (bool) IMP_VCOLOR = True # Import UV Coords and UV layers (bool) IMP_UV = True # Import NGons as Blender FGons (bool) # Note: Include quads, too. IMP_FGONS = False # Try to find possible quads and convert the two tris to a quad (bool) # Note: Very slow!! ablsolutely doesn't work accurate :/ # i don't know wether this is a script problem or a blender problem! IMP_QUADS = False # Surround UV islands with seams (bool) IMP_SEAMS = False # Surround smooth groups with sharp edges (bool) IMP_SMOOTHGROUPS = True # Try to find the lowest autosmooth angle in vertex normals (bool) # Note: i dont know if this is correct :> IMP_AUTOSMOOTH = False class Ase_group: def __init__(self): self.name = 'Name' self.ase_type = 'GROUP' self.ase_helper = None self.ase_objects = [] class Ase_object: def __init__(self, ase_object_type, name=''): #if ase_object_type not in ['GEOM','HELPER','SHAPE','LIGHT','CAMERA']: return if ase_object_type not in ['geom','helper','shape','light','camera']: return self.name = name self.ase_type = ase_object_type #GEOM, HELPER, SHAPE, LIGHT, CAMERA self.row0 = None self.row1 = None self.row2 = None self.row3 = None self.parent = None #new_ase_data = None if ase_object_type == 'geom': new_ase_data = Ase_mesh(self) self.ase_data = new_ase_data class Ase_mesh: def __init__(self, ase_obj=None): self.name = 'Name' self.num = {'VERTS':0,'FACES':0,'CVERTEX':0,'CVFACES':0} self.ase_verts = {} self.vertseq = [] self.ase_edges = {} self.ase_faces = {} self.faceseq = [] self.ase_uv_channels = {} self.active_uv = None self.ase_vertcolors = {} self.ase_cfaces = {} self.autosmooth = 0 self.hasUV = 0 self.hasVC = 0 def sort_edgekeys(self,vi0,vi1,vi2): ''' Returns sorted edge keys of the given triangle vert indicies. ''' if vi0 > vi1: ed_k0 = vi1,vi0 else: ed_k0 = vi0,vi1 if vi1 > vi2: ed_k1 = vi2,vi1 else: ed_k1 = vi1,vi2 if vi0 > vi2: ed_k2 = vi2,vi0 else: ed_k2 = vi0,vi2 return ed_k0,ed_k1,ed_k2 def append_vert(self, ase_vert_index, x, y, z): ''' Create a new Vertex for this Mesh. ''' ase_v = Ase_vert(ase_vert_index, x, y, z) self.ase_verts[ase_vert_index] = ase_v #self.vertseq.insert(ase_vert_index, (ase_v.co.x,ase_v.co.y,ase_v.co.z)) self.vertseq.insert(ase_vert_index, ase_v.co) def append_face(self, index, vi0, vi1, vi2, AB=1, BC=1, CA=1, smooth_groups=[0], mat_indices=0): ''' Uhm ... work in progress! ''' # create a new Ase_face ase_f = Ase_face(index, vi0, vi1, vi2, smooth_groups, mat_indices) ed_keys = self.sort_edgekeys(vi0,vi1,vi2) #ed_keys = [vi0,vi1].sort(),[vi1,vi2].sort(),[vi0,vi2].sort() ase_f.edge_keys = ed_keys ase_f.vis_sum = AB+BC+CA if ase_f.vis_sum == 2: if not AB: ase_f.tri_edge = ed_keys[0] elif not BC: ase_f.tri_edge = ed_keys[1] elif not CA: ase_f.tri_edge = ed_keys[2] # set visibility (fgon) and sharp for edges # and look if the two face users might form a quad # or create a new Ase_edge for k,vis in zip(ed_keys,[AB,BC,CA]): # Ase_edge already exist or create a new one if not self.ase_edges.has_key(k): ase_ed = Ase_edge(k) ase_ed.fusers.append(ase_f.index) ase_ed.visible = vis self.ase_edges[k] = ase_ed continue else: ase_ed = self.ase_edges[k] ase_ed.fusers.append(ase_f.index) if ase_f.vis_sum == 2 and not ase_ed.visible: ase_f.tri_edge = k fusers = [i for i in ase_ed.fusers if i != ase_f.index] if not fusers: continue for i in fusers: ase_f2 = self.ase_faces[i] # if this edge is invisible and both tris only have # this invisible edge, than the two tris could form a quad # easy done with a sum of all vis variables of the edges if k == ase_f.tri_edge: if ase_f.tri_edge == ase_f2.tri_edge: ase_f.quad_team = ase_f2.index ase_f2.quad_team = ase_f.index # look if this edge is sharp # if not both faces share at least one smoothgroup var # than this edge is sharp #if ase_ed.sharp: continue for sg in smooth_groups: if sg not in ase_f2.smooth_groups: ase_ed.sharp = True self.ase_faces[ase_f.index] = ase_f self.faceseq.insert(ase_f.index, (ase_f.v0, ase_f.v1, ase_f.v2)) def append_uv_channel(self, layer_index=1): ''' Create a new UV Layer and set it active. ''' self.ase_uv_channels[layer_index] = Ase_uv_channel(layer_index) self.active_uv = self.ase_uv_channels[layer_index] def append_tvert(self, ase_uv_index, u, v, w=0): ''' Create a new UV Vector in the active! UV Channel. ''' if not self.active_uv: return #self.active_uv.ase_tverts[ase_uv_index] = Ase_tvert(ase_uv_index,u,v,w) self.active_uv.ase_tverts[ase_uv_index] = (u,v) def append_tface(self, ase_face_index, uvi0, uvi1, uvi2, opt_check_seams=False): ''' Create a new Face UV with indicies to UV Vectors in the active UV Layer. Optional check for Seams and store into the UV Channel. ''' if not self.active_uv: return self.active_uv.ase_tfaces[ase_face_index] = [uvi0, uvi1, uvi2] # look if this face has seams # might useless because it makes no sense to import seams for all UV layers # that's why those edge keys are separately written to each ase UV layer if opt_check_seams: edge_keys = self.ase_faces[ase_face_index].edge_keys for ed_key,uvs in zip(edge_keys,[[uvi0,uvi1],[uvi1,uvi2],[uvi0,uvi2]]): uvs.sort() ase_ed,active_uv = self.ase_edges[ed_key],self.active_uv if not active_uv.ase_tedges.has_key(ed_key): active_uv.ase_tedges[ed_key] = uvs continue elif active_uv.ase_tedges[ed_key] != uvs: active_uv.seams.append(ed_key) def append_vertcol(self, ase_color_index, r, g, b): #new = Ase_vertcolor(ase_color_index, r, g, b) #self.ase_vertcolors[ase_color_index] = new self.ase_vertcolors[ase_color_index] = (r,g,b) def append_cface(self, ase_face_index, ci0, ci1, ci2): ase_f = self.ase_faces[ase_face_index] #f.c0, f.c1, f.c2 = ci0, ci1, ci2 self.ase_cfaces[ase_face_index] = (ci0, ci1, ci2) def append_normal(self, ase_face_index, x, y, z): self.ase_faces[ase_face_index].normal = Blender.Mathutils.Vector(x,y,z) def append_vnormal(self, ase_face_index, ase_vert_index, x, y, z, opt_check_smooth=False): ase_f = self.ase_faces[ase_face_index] self.ase_verts[ase_vert_index].normals[ase_face_index] = Blender.Mathutils.Vector(x,y,z) if opt_check_smooth and ase_f.smooth_groups: ase_edges = [self.ase_edges[key] for key in ase_f.edge_keys] for ed_key,ase_ed in zip(ase_f.edge_keys,ase_edges): if ase_ed.sharp or len(ase_ed.fusers) < 2: continue for vi in ed_key: if not self.ase_verts.has_key(vi): continue vnormals = self.ase_verts[vi].normals fi0, fi1 = ase_ed.fusers[0:2] if vnormals.has_key(fi0) and vnormals.has_key(fi1): vnor0, vnor1 = vnormals[fi0],vnormals[fi1] if vnor0 == vnor1: continue else: angle = round(Blender.Mathutils.AngleBetweenVecs(vnor0, vnor1)) if not self.autosmooth: self.autosmooth = angle elif angle and self.autosmooth > angle: print angle self.autosmooth = angle class Ase_vert: def __init__(self, index, x, y, z): self.index = index #self.co = Blender.Mathutils.Vector(x,y,z) self.co = (x,y,z) self.normals = {} class Ase_edge: def __init__(self, key): self.key = key self.fusers = [] self.uvs = None self.visible = 1 self.sharp = False class Ase_face: def __init__(self, ase_face_index, v0, v1, v2, smooth_groups=0, mat_indices=0): self.index = ase_face_index self.v0 = v0 self.v1 = v1 self.v2 = v2 self.edge_keys = None self.c0 = None self.c1 = None self.c2 = None self.normal = None #self.vert_normals = {} self.mat_indices = mat_indices self.smooth_groups = smooth_groups # 0 = solid face self.vis_sum = 3 self.quad_team = None self.tri_edge = None class Ase_uv_channel: def __init__(self, index=1): self.index = index self.num = {'TVERTEX':0,'TVFACES':0} self.uv_layer_name = 'UVTex#' + str(self.index) self.ase_tverts = {} self.ase_tfaces = {} self.ase_tedges = {} self.seams = [] class Ase_tvert: def __init__(self,index, u, v, w=0): self.index = index #self.vec = Blender.Mathutils.Vector(u,v) self.vec = (u,v) class Ase_tface: def __init__(self, index, uvi0, uvi1, uvi2): self.index = index self.uv = {0:uvi0, 1:uvi1, 2:uvi2} class Ase_vertcolor: def __init__(self, index, r, g, b): self.index = 0 self.r = round(r*256) self.g = round(g*256) self.b = round(b*256) self.a = 255.0 def spawn(ase_objects): PB_index = 0.0 PB_num = float(len(ase_objects)) print 'Import Objects...' if OPT_PROGRESSBAR: Blender.Window.DrawProgressBar(0.0, "Importing Objects...") scene = Blender.Scene.GetCurrent() for ase_ob in ase_objects: if OPT_PROGRESSBAR and not (PB_index % PB_num): Blender.Window.DrawProgressBar(PB_index / PB_num, "Importing Objects...") if ase_ob.ase_type == 'geom': spawn_mesh(scene,ase_ob) PB_index += 1.0 def spawn_mesh(scene,ase_ob): ase_me = ase_ob.ase_data #normal_flag = 1 row0 = ase_ob.row0 row1 = ase_ob.row1 row2 = ase_ob.row2 row3 = ase_ob.row3 matrix = Blender.Mathutils.Matrix(row0, row1, row2, row3) matrix.resize4x4() # create new Blender Object and link to scene ob = Blender.Object.New('Mesh', ase_ob.name) ob.setMatrix(matrix) scene.objects.link(ob) # get Mesh data from Object me = ob.getData(0,1) me.vertexColors = me.faceUV = False # create Verts and Faces # seems like extend() is limited to a length of 64000? # this is a problem when importing big meshes. div = divmod(ase_me.num['VERTEX'], 64000) if div[1]: div = div[0]+1 else: div = div[0] start = 0 for i in range(div): end = start+64000 me.verts.extend(ase_me.vertseq[start:end]) start = end div = divmod(ase_me.num['FACES'], 64000) face_index_list = [] if div[1]: div = div[0]+1 else: div = div[0] start = 0 for i in range(div): end = start+64000 me.faces.extend(ase_me.faceseq[start:end]) start = end # import Vertex Colors, Solid/Smooth to faces if IMP_VCOLOR: me.vertexColors = ase_me.hasVC ase_vcolors = ase_me.ase_vertcolors for i,ase_f in ase_me.ase_faces.iteritems(): try:f = me.faces[i] except: # dont know what's the problem with this print 'array index out of range:', i continue if me.vertexColors: cface = ase_me.ase_cfaces[i] c0,c1,c2 = ase_vcolors[cface[0]],ase_vcolors[cface[1]],ase_vcolors[cface[2]] fc0,fc1,fc2 = f.col[:] fc0.r,fc0.g,fc0.b = int(c0[0]*255),int(c0[1]*255),int(c0[2]*255) fc1.r,fc1.g,fc1.b = int(c1[0]*255),int(c1[1]*255),int(c1[2]*255) fc2.r,fc2.g,fc2.b = int(c2[0]*255),int(c2[1]*255),int(c2[2]*255) if ase_f.smooth_groups: f.smooth = 1 # import UV layer's if IMP_UV and ase_me.hasUV: for uv_chan in ase_me.ase_uv_channels.itervalues(): me.addUVLayer(uv_chan.uv_layer_name) me.activeUVLayer = uv_chan.uv_layer_name tverts = uv_chan.ase_tverts for fi,uvis in uv_chan.ase_tfaces.iteritems(): try:f = me.faces[fi] except: continue uv1,uv2,uv3 = tverts[uvis[0]],tverts[uvis[1]],tverts[uvis[2]] f.uv = [Blender.Mathutils.Vector(uv1), Blender.Mathutils.Vector(uv2), Blender.Mathutils.Vector(uv3)] me.activeUVLayer = ase_me.ase_uv_channels[1].uv_layer_name # EXPERIMENTAL! # convert tris to quads # this is currently the easiest way i found without destroying uvs or vcolors # but don't work like expected...:/ if IMP_QUADS: #quad_teams = set([i for i,ase_f in ase_me.ase_faces.iteritems() if ase_f.quad_team != None]) quad_teams = [] for i,ase_f in ase_me.ase_faces.iteritems(): if ase_f.quad_team != None: if ase_f.index < ase_f.quad_team: qt = ase_f.index,ase_f.quad_team elif ase_f.index > ase_f.quad_team: qt = ase_f.quad_team,ase_f.index if qt not in quad_teams: quad_teams.append(qt) faces = me.faces # first deselect all faces for f in faces: f.sel = 0 for t0,t1 in quad_teams: ase_f0 = ase_me.ase_faces[t0] ase_f1 = ase_me.ase_faces[t1] try: f0,f1 = me.faces[ase_f0.index], me.faces[ase_f1.index] except: continue f0.sel = 1 f1.sel = 1 me.triangleToQuad() for i in faces.selected(): faces[i].sel = 0 # apply the matrix to mesh (and optional fit the ob and me to blender) if IMP_SCALED: # seems this isn't accurate because of precision of the location vector scale = Blender.Mathutils.ScaleMatrix(OPT_SCALE,4) inv_matrix = ob.getMatrix().copy().invert() * scale ob.setLocation(ob.getMatrix().translationPart() * scale) else: inv_matrix = ob.getMatrix().copy().invert() me.transform(inv_matrix, 1) me.calcNormals() # apply sharp, seam and fgon flags to edges. add_EDGESPLIT = False if IMP_FGONS or IMP_SEAMS or IMP_SMOOTHGROUPS: SHARP = Mesh.EdgeFlags.SHARP SEAM = Mesh.EdgeFlags.SEAM FGON = Mesh.EdgeFlags.FGON seam_keys = [] if ase_me.hasUV: seam_keys = ase_me.ase_uv_channels[1].seams for k,ase_ed in ase_me.ase_edges.iteritems(): if ase_ed.sharp or not ase_ed.visible or k in seam_keys: edi = me.findEdges(k[0],k[1]) if edi: ed = me.edges[edi] if ase_me.hasUV and k in seam_keys and IMP_SEAMS: ed.flag |= SEAM if not ase_ed.visible and IMP_FGONS: ed.flag |= FGON if ase_ed.sharp and IMP_SMOOTHGROUPS: ed.flag |= SHARP add_EDGESPLIT = True # add EdgeSplit Modiefier when the mesh has sharp edges # autosmooth is EXPERIMENTAL! because i dont know if this is correct! if add_EDGESPLIT and OPT_MOD_EDGESPLIT: mod = ob.modifiers.append(Blender.Modifier.Types.EDGESPLIT) if not ase_me.autosmooth: mod[Blender.Modifier.Settings.EDGESPLIT_FROM_ANGLE] = 0 else: mod[Blender.Modifier.Settings.EDGESPLIT_ANGLE] = ase_me.autosmooth mod[Blender.Modifier.Settings.EDGESPLIT_FROM_SHARP] = 1 ob.makeDisplayList() # Needed to apply the modifier elif not add_EDGESPLIT and ase_me.autosmooth: AUTOSMOOTH = Mesh.Modes.AUTOSMOOTH me.modes |= AUTOSMOOTH me.degr = ase_me.autosmooth me.update() counts['verts'] += ase_me.num['VERTEX'] counts['tris'] += ase_me.num['FACES'] counts['faces'] += len(me.faces) print 'Imported Mesh-Object: ', ob.name #def oj_the_object_jockey(file): def read_file(file): ''' Read an .ase file and return a list of ase_objects ''' lines= file.readlines() print 'Read file...' PB_index = 0.0 PB_num = float(len(lines)) if OPT_PROGRESSBAR: Blender.Window.DrawProgressBar(0.0, "Read File...") # it is needed to read UV if Seams should be imported even when importing UV is disabled READ_UV = False if IMP_UV or IMP_SEAMS: READ_UV = True #if IMP_AUTOSMOOTH and not IMP_SMOOTHGROUPS: IMP_AUTOSMOOTH = False ase_objects = [] ase_ob = False for line in lines: if OPT_PROGRESSBAR and not (PB_index % 10000): Blender.Window.DrawProgressBar(PB_index / PB_num, "Read File...") PB_index += 1 words = line.split() if not words: continue word0 = words[0] if word0 == '*GEOMOBJECT': #if ase_ob: ase_objects.append(ase_ob) ase_ob_type = word0.lower()[1:-6] #get rid of '*' and 'OBJECT' ase_ob = Ase_object(ase_ob_type) ase_objects.append(ase_ob) continue elif word0 in ['*HELPEROBJECT','*SHAPEOBJECT','*LIGHTOBJECT','*CAMERAOBJECT','*GROUP']: # Not supported objects! # because these objects too use a TM_NODE, # ase_ob should be set back to False to prevent errors. ase_ob = False continue elif word0 == '*NODE_NAME' and ase_ob: name = words[1][1:-1] #get rid of '"' if ase_ob and ase_ob.name != '': ase_ob.ase_data.name = name elif ase_ob: ase_ob.name = name continue elif word0 == '*NODE_PARENT' and ase_ob: ase_ob.parent = words[1][1:-1] #get rid of '"' continue elif word0 == '*TM_ROW0' and ase_ob: ase_ob.row0 = float(words[1]), float(words[2]), float(words[3]) continue elif word0 == '*TM_ROW1' and ase_ob: ase_ob.row1 = float(words[1]), float(words[2]), float(words[3]) continue elif word0 == '*TM_ROW2' and ase_ob: ase_ob.row2 = float(words[1]), float(words[2]), float(words[3]) continue elif word0 == '*TM_ROW3' and ase_ob: ase_ob.row3 = float(words[1]), float(words[2]), float(words[3]) continue elif word0 == '*MESH': ase_me = ase_ob.ase_data continue elif word0 == '*MESH_NUMVERTEX': ase_me.num['VERTEX'] = int(words[1]) continue elif word0 == '*MESH_NUMFACES': ase_me.num['FACES'] = int(words[1]) continue elif word0 == '*MESH_VERTEX': #vert_index, x, y, z ase_me.append_vert(int(words[1]),float(words[2]),float(words[3]),float(words[4])) continue elif word0 == '*MESH_FACE': #ase_face_index, vi0, vi1, vi2, AB, BC, CA, smooth_groups, mat_indicies #smooth = mat = False ase_face_index = words[1] if ase_face_index.endswith(':'): ase_face_index = ase_face_index[:-1] smooth_groups = mat_indices = [] for i,w in enumerate(words): if w == '*MESH_SMOOTHING' and IMP_SMOOTHGROUPS: try: if words[i+1] != '*MESH_MTLID': smooth_groups = [int(i) for i in words[i+1].split(',')] except: smooth_groups = 0 elif w == '*MESH_MTLID' and IMP_SMOOTHGROUPS: try: mat_indices = [int(i) for i in words[i+1].split(',')] except: mat_indices = 0 ase_me.append_face(int(ase_face_index),int(words[3]),int(words[5]),int(words[7]),int(words[9]),int(words[11]),int(words[13]),smooth_groups,mat_indices) continue elif READ_UV: if word0 == '*MESH_NUMTVERTEX': if not ase_me.ase_uv_channels: ase_me.append_uv_channel() ase_me.active_uv.num['TVERTEX'] = int(words[1]) ase_me.hasUV = True continue elif word0 == '*MESH_MAPPINGCHANNEL': # uv_channel_index ase_me.append_uv_channel(int(words[1])) continue elif word0 == '*MESH_TVERT': #uv_index, u, v, w ase_me.append_tvert(int(words[1]),float(words[2]),float(words[3]),float(words[4])) continue elif word0 == '*MESH_NUMTVFACES': ase_me.active_uv.num['TVFACES'] = int(words[1]) continue elif word0 == '*MESH_TFACE': #ase_face_index, uv0, uv1, uv2, opt_IMP_SEAMS ase_face_index = words[1] if ase_face_index.endswith(':'): ase_face_index = ase_face_index[:-1] ase_me.append_tface(int(ase_face_index),int(words[2]),int(words[3]),int(words[4]),IMP_SEAMS) continue elif IMP_VCOLOR: if word0 == '*MESH_NUMCVERTEX': ase_me.num['CVERTEX'] = int(words[1]) if ase_me.num['CVERTEX']: ase_me.hasVC = True continue elif word0 == '*MESH_VERTCOL': #color_index, r, g, b ase_me.append_vertcol(int(words[1]),float(words[2]),float(words[3]),float(words[4])) continue elif word0 == '*MESH_NUMCVFACES': ase_me.num['CVFACES'] = words[1] continue elif word0 == '*MESH_CFACE': #ase_face_index, ci0, ci1, ci2 ase_face_index = words[1] if ase_face_index.endswith(':'): ase_face_index = ase_face_index[:-1] ase_me.append_cface(int(ase_face_index),int(words[2]),int(words[3]),int(words[4])) continue #elif word0 == '*MESH_NORMALS': elif IMP_AUTOSMOOTH: if word0 == '*MESH_FACENORMAL': # ase_face_index, x, y, z ase_face_index = int(words[1]) ase_me.append_normal(ase_face_index,float(words[2]),float(words[3]),float(words[4])) continue elif word0 == '*MESH_VERTEXNORMAL': # ase_face_index, ase_vert_index, x, y, z ase_me.append_vnormal(ase_face_index,int(words[1]),float(words[2]),float(words[3]),float(words[4]),IMP_AUTOSMOOTH) continue else: continue return ase_objects def print_boxed(text): #Copy/Paste from meshtools, only to remove the beep :) lines = text.splitlines() maxlinelen = max(map(len, lines)) if sys.platform[:3] == "win": print chr(218)+chr(196) + chr(196)*maxlinelen + chr(196)+chr(191) for line in lines: print chr(179) + ' ' + line.ljust(maxlinelen) + ' ' + chr(179) print chr(192)+chr(196) + chr(196)*maxlinelen + chr(196)+chr(217) else: print '+-' + '-'*maxlinelen + '-+' for line in lines: print '| ' + line.ljust(maxlinelen) + ' |' print '+-' + '-'*maxlinelen + '-+' def read(filename): global counts counts = {'verts':0,'tris':0,'faces':0} start = time.clock() print_boxed("----------ASCII Scene Import----------") print 'Import File: ', filename mode = Blender.Window.EditMode() # are we in edit mode? If so ... if mode: Blender.Window.EditMode(0) # leave edit mode before getting the mesh file = open(filename,'r', OPT_FILE_BUFFER) ase_objects = read_file(file) file.close() spawn(ase_objects) Blender.Redraw() if OPT_PROGRESSBAR: Blender.Window.DrawProgressBar(1.0, '') # clear progressbar # Blender.Window.EditMode(mode) end = time.clock() seconds = " in %.2f %s" % (end-start, "seconds") #totals = "Imported Verts: %i Faces: %i Tris: %i " % (counts['verts'],counts['tris'],counts['faces']) #print_boxed(totals) message = "Successfully imported " + Blender.sys.basename(filename) + seconds print_boxed(message) def read_ui(filename): global IMPORT_SC, IMPORT_VC, IMP_UV, IMPORT_GO, IMPORT_SE, IMPORT_SM global IMP_SCALED,IMP_SMOOTHGROUPS,IMP_VCOLOR,IMP_UV,IMP_FGONS,IMP_QUADS,IMP_SEAMS,IMP_SMOOTHGROUPS,IMP_AUTOSMOOTH IMPORT_SC = Blender.Draw.Create(IMP_SCALED) IMPORT_VC = Blender.Draw.Create(IMP_VCOLOR) IMP_UV = Blender.Draw.Create(IMP_UV) IMPORT_SE = Blender.Draw.Create(IMP_SEAMS) IMPORT_SM = Blender.Draw.Create(IMP_SMOOTHGROUPS) # Get USER Options pup_block = [('Import Options'),('Scale Meshes', IMPORT_SC, 'Scale the Objects so that they better fit into Blender\'s grid size'),('Vertex Colors', IMPORT_VC, 'Import Vertex Colors if existing'),('UV (Layer)', IMP_UV, 'Import UV and UV layer\'s if existing'),('Smoothing', IMPORT_SM, 'Surround Smoothgroups with sharp edges'),('Seams', IMPORT_SE, 'Try to import Seams from UV islands (from the first UV layer!)')] if not Blender.Draw.PupBlock('Import ASCII Scene...', pup_block): return Blender.Window.WaitCursor(1) IMP_SCALED = IMPORT_SC.val IMP_VCOLOR = IMPORT_VC.val IMP_UV = IMP_UV.val IMP_SEAMS = IMPORT_SE.val IMP_SMOOTHGROUPS = IMPORT_SM.val read(filename) Blender.Window.WaitCursor(0) Blender.Redraw() if __name__ == '__main__' and OPT_FILESELECTOR: Blender.Window.FileSelector(read_ui, 'Import ASCII Scene', ('.ase')) elif __name__ == '__main__': read_ui(OPT_STATIC_FILENAME)