Revision: 20712 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20712 Author: migius Date: 2009-06-07 16:57:50 +0200 (Sun, 07 Jun 2009)
Log Message: ----------- DXF-Exporter script update v1.34 - 2009.06.07 by migius - cleaning code for release - fix nasty bug in getExtrusion() - support text-objects, also in ortho/persp-projection - support XYmirrored 2d-curves to 2dPOLYLINEs Modified Paths: -------------- trunk/blender/release/scripts/export_dxf.py Modified: trunk/blender/release/scripts/export_dxf.py =================================================================== --- trunk/blender/release/scripts/export_dxf.py 2009-06-07 14:53:08 UTC (rev 20711) +++ trunk/blender/release/scripts/export_dxf.py 2009-06-07 14:57:50 UTC (rev 20712) @@ -7,7 +7,7 @@ Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).' """ -__version__ = "1.34 - 2009.06.02" +__version__ = "1.34 - 2009.06.07" __author__ = "Remigiusz Fiedler (AKA migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -34,14 +34,19 @@ - export dupligroups and dupliverts as blocks (option for the user to decide) - optimize POLYFACE routine: remove double-vertices - optimize POLYFACE routine: remove loose vertices -- support any-oriented mirrored curves(to POLYLINEs): fix blender negative-matrix.invert() +- stable support X,Y-rotated curves(to POLYLINEs): fix blender negative-matrix.invert() - support hierarchies: groups, instances, parented structures - write drawing extends for automatic view positioning in CAD - mapping materials to DXF-styles +- wip: corrected text-objects in persp-projection +- wip: fix filter out objects from inactive(off) layers History -v1.34 - 2009.06.02 by migius -- support XYmirrored 2d-curves to POLYLINEs: works correct only for rotX,rotY==0.0 +v1.34 - 2009.06.07 by migius +- cleaning code +- fix nasty bug in getExtrusion() +- support text-objects, also in ortho/persp-projection +- support XYmirrored 2d-curves to 2dPOLYLINEs - support thickness and elevation for curve-objects - fix extrusion 210-code (3d orientation vector) - fix POLYFACE export, synchronized with dxfLibrary.py @@ -186,7 +191,7 @@ M_OBJ = 0 FILENAME_MAX = 180 #max length of path+file_name string (FILE_MAXDIR + FILE_MAXFILE) -MAX_NAMELENGTH = 17 #max_effective_obnamelength in blender =21=17+(.001) +NAMELENGTH_MAX = 80 #max_obnamelength in DXF, (limited to 256? ) INIFILE_DEFAULT_NAME = 'exportDXF' INIFILE_EXTENSION = '.ini' INIFILE_HEADER = '#ExportDXF.py ver.1.0 config data' @@ -194,7 +199,6 @@ SCENE = None WORLDX = Mathutils.Vector((1,0,0)) -#TODO: a bug? WORLDY = Mathutils.Vector((1,1,0)) WORLDY = Mathutils.Vector((0,1,0)) WORLDZ = Mathutils.Vector((0,0,1)) @@ -267,7 +271,7 @@ #---------------------------------------------- def gotoCAMERA(): cam = Object.Get(CAMERAS[CAMERA-1]) - print 'deb: CAMERA, cam',CAMERA, cam + #print 'deb: CAMERA, cam',CAMERA, cam if cam.getType() != 'Camera': sure = Draw.PupMenu("Info: %t| It is not a Camera Object.") else: @@ -278,7 +282,7 @@ updateMenuCAMERA() -#------- Duplicats support ---------------------------------------------- +#------- Duplicates support ---------------------------------------------- def dupTest(object): """ Checks objects for duplicates enabled (any type) @@ -296,8 +300,8 @@ """ Return a list of real objects and duplicates and optionally their matrices oblist: List of Blender Objects - MATRICES: Boolean - Check to also get the objects matrices default=False - HACK: Boolean - See note default=False + MATRICES: Boolean - Check to also get the objects matrices, default=False + HACK: Boolean - See note, default=False Returns: List of objects or List of tuples of the form:(ob,matrix) if MATRICES is set to True NOTE: There is an ugly hack here that excludes all objects whose name @@ -334,7 +338,7 @@ #----------------------------------------------------- def hidden_status(faces, mx, mx_n): # sort out back-faces = with normals pointed away from camera - print 'HIDDEN_LINES: caution! not full implemented yet' + #print 'HIDDEN_LINES: caution! not full implemented yet' front_faces = [] front_edges = [] for f in faces: @@ -376,25 +380,6 @@ return front_faces, front_edges -#--------not used------------------------------------- -def projected_co0(vec, mw): - # convert the world coordinates of vector to screen coordinates - #co = vec.co.copy().resize4D() - co = vec.copy().resize4D() - co[3] = 1.0 - sc = co * mw - #print 'deb: viewprojection=', sc #--------- - return [sc[0],sc[1],0.0] - - -#--------not used--------------------------------------------- -def flatten(points, mw): - for i,v in enumerate(points): - v = projected_co(v, mw) - points[i]=v - #print 'deb: flatten points=', points #--------- - return points - #---- migration to 2.49------------------------------------------------- if 'cross' in dir(Mathutils.Vector()): #Draw.PupMenu('DXF exporter: Abort%t|This script version works for Blender up 2.49 only!') @@ -411,41 +396,45 @@ #----------------------------------------------------- def getExtrusion(matrix): - #print 'deb:getExtrusion() given matrix=\n', matrix #--------- + """calculates DXF-Extrusion = Arbitrary Xaxis and Zaxis vectors + + """ AZaxis = matrix[2].copy().resize3D().normalize() # = ArbitraryZvector Extrusion = [AZaxis[0],AZaxis[1],AZaxis[2]] if AZaxis[2]==1.0: Extrusion = None - AXaxis = matrix[0].copy().resize3D() # = ArbitraryZvector + AXaxis = matrix[0].copy().resize3D() # = ArbitraryXvector else: threshold = 1.0 / 64.0 - if abs(AZaxis[0]) < threshold or abs(AZaxis[1]) < threshold: + if abs(AZaxis[0]) < threshold and abs(AZaxis[1]) < threshold: # AXaxis is the intersection WorldPlane and ExtrusionPlane AXaxis = M_CrossVecs(WORLDY,AZaxis) else: AXaxis = M_CrossVecs(WORLDZ,AZaxis) - #print 'deb:\n' #------------- #print 'deb:getExtrusion() Extrusion=', Extrusion #--------- - return Extrusion, AXaxis.normalize() + return Extrusion, AXaxis.normalize() + #----------------------------------------------------- def getZRotation(AXaxis, rot_matrix_invert): - #ZRotation = Mathutils.AngleBetweenVecs(WORLDX,AXaxis) #output in degrees - - # this works: Xaxis is the obj.matrix Xaxis vector + """calculates ZRotation = angle between ArbitraryXvector and obj.matrix.Xaxis + + """ + # this works: Xaxis is the obj.matrix-Xaxis vector + # but not correct for all orientations #Xaxis = matrix[0].copy().resize3D() # = ArbitraryXvector ##Xaxis.normalize() # = ArbitraryXvector - #ZRotation = - d2r * Mathutils.AngleBetweenVecs(Xaxis,AXaxis) #output in degrees + #ZRotation = - Mathutils.AngleBetweenVecs(Xaxis,AXaxis) #output in radians - # this works too, maybe faster + # this works for all orientations, maybe a bit faster # transform AXaxis into OCS:Object-Coord-System #rot_matrix = normalizeMat(matrix.rotationPart()) #rot_matrix_invert = rot_matrix.invert() vec = AXaxis * rot_matrix_invert ##vec = AXaxis * matrix.copy().invert() ##vec.normalize() # not needed for atan2() - ##print '\ndeb:getExtrusion() vec=', vec #--------- + #print '\ndeb:getExtrusion() vec=', vec #--------- ZRotation = - atan2(vec[1],vec[0]) #output in radians #print 'deb:ZRotation() ZRotation=', ZRotation*r2d #--------- @@ -464,15 +453,15 @@ #----------------------------------------------------- -def projected_co(verts, mx): - # converts world coordinates of points to screen coordinates - temp_verts = [] - for v in verts: - #temp_verts.append(Blender.Mesh.MVert(v.co)) - temp_verts.append(Mesh.MVert(v)) - #print 'deb: temp_verts=', temp_verts #--------- - for v in temp_verts: - v.co *= mx +def projected_co(verts, matrix): + """ converts coordinates of points from OCS to WCS->ScreenCS + needs matrix: a projection matrix + needs verts: a list of vectors[x,y,z] + returns a list of [x,y,z] + """ + #print 'deb:projected_co() verts=', verts #--------- + temp_verts = [Mathutils.Vector(v)*matrix for v in verts] + #print 'deb:projected_co() temp_verts=', temp_verts #--------- if GUI_A['Z_force_on'].val: locZ = GUI_A['Z_elev'].val else: locZ = 0.0 @@ -481,13 +470,14 @@ if PERSPECTIVE: clipStart = 10.0 for v in temp_verts: - coef = - clipStart / v.co[2] - v.co[0] *= coef - v.co[1] *= coef - v.co[2] = locZ + coef = - clipStart / v[2] + v[0] *= coef + v[1] *= coef + v[2] = locZ for v in temp_verts: - v.co[2] = locZ - temp_verts = [v.co[:3] for v in temp_verts] + v[2] = locZ + temp_verts = [v[:3] for v in temp_verts] + #print 'deb:projected_co() out_verts=', temp_verts #--------- return temp_verts @@ -503,10 +493,11 @@ #----------------------------------------------------- def exportMesh(ob, mx, mx_n, me=None, **common): - global APPLY_MODIFIERS + """converts Mesh-Object to desired projection and representation(DXF-Entity type) + """ entities = [] #print 'deb:exportMesh() common=', common #--------- - if me is None: # me means mesh + if me==None: me = ob.getData(mesh=1) else: me.getFromObject(ob) @@ -519,14 +510,14 @@ #print 'deb:exportMesh() started' #--------- allpoints = [v.co for v in me.verts] allpoints = projected_co(allpoints, mx) - if GUI_A['g_origin_on'].val: #TODO: scale and object orientation + if GUI_A['g_origin_on'].val: for p in allpoints: p[0] += G_ORIGIN[0] p[1] += G_ORIGIN[1] p[2] += G_ORIGIN[2] faces=[] edges=[] - if me.faces and HIDDEN_LINES: + if me.faces and PROJECTION and HIDDEN_LINES: if DEBUG: print 'deb:exportMesh HIDDEN_LINES mode' #--------- faces, edges = hidden_status(me.faces, mx, mx_n) faces = [[v.index for v in me.faces[f_nr].verts] for f_nr in faces] @@ -562,9 +553,24 @@ if allpoints: #TODO: purge allpoints: left only vertices used by faces if DEBUG: mesh_drawBlender(allpoints, None, faces) #deb: draw to scene - faces = [[v+1 for v in f] for f in faces] +# faces = [[v+1 for v in f] for f in faces] + + verts_state= [0]*len(allpoints) + for f in faces: + for v in f: + verts_state[v]=1 + if 0: # in verts_state: # if dirty state + i,new_position,newverts=0,[],[] + for used_i,used in enumerate(verts_state): + if used: + newverts.append(allpoints[used_i]) + new_position.append(i) + i+=1 + allpoints = newverts + faces = [[new_position[v]+1 for v in f] for f in faces] + else: + faces = [[v+1 for v in f] for f in faces] dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag=64, **common) - #dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag=64) #print '\n deb: dxfPOLYFACE=',dxfPOLYFACE #------------- entities.append(dxfPOLYFACE) elif '3DFACEs'==c: @@ -638,8 +644,10 @@ #----------------------------------------------------- def exportEmpty(ob, mx, mw, **common): @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs