Revision: 20635 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20635 Author: migius Date: 2009-06-04 21:49:19 +0200 (Thu, 04 Jun 2009)
Log Message: ----------- bugfix and updates for DXF-Importer/Exporter scripts DXF-Library log: v1.31 - 2009.06.02 by migius - modif _Entity class: added paperspace,elevation v1.30 - 2009.05.28 by migius - bugfix 3dPOLYLINE/POLYFACE: VERTEX needs x,y,z coordinates, index starts with 1 not 0 DXF-Importer: minor changes DXF-Exporter log: v1.34 - 2009.06.02 by migius - support XYmirrored 2d-curves to POLYLINEs: works correct only for rotX,rotY==0.0 - support thickness and elevation for curve-objects - fix extrusion 210-code (3d orientation vector) - fix POLYFACE export, synchronized with dxfLibrary.py - changed to the new 2.49 method Vector.cross() - output style manager (first try) v1.33 - 2009.05.25 by migius - bugfix flipping normals in mirrored mesh-objects - added UI-Button for future Shadow Generator - support curve objects in projection-2d mode - UI stuff: camera selector/manager Modified Paths: -------------- trunk/blender/release/scripts/bpymodules/dxfLibrary.py trunk/blender/release/scripts/export_dxf.py trunk/blender/release/scripts/import_dxf.py Modified: trunk/blender/release/scripts/bpymodules/dxfLibrary.py =================================================================== --- trunk/blender/release/scripts/bpymodules/dxfLibrary.py 2009-06-04 19:35:03 UTC (rev 20634) +++ trunk/blender/release/scripts/bpymodules/dxfLibrary.py 2009-06-04 19:49:19 UTC (rev 20635) @@ -1,6 +1,6 @@ #dxfLibrary.py : provides functions for generating DXF files # -------------------------------------------------------------------------- -__version__ = "v1.30 - 2009.05.28" +__version__ = "v1.31 - 2009.06.02" __author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -18,28 +18,30 @@ - TODO: -- add support for DXFr14 (new file header) -- add support for SPLINEs, although it is DXFr14 object +- add support for DXFr14 (needs extended file header) +- add support for SPLINEs (possible first in DXFr14 version) History +v1.31 - 2009.06.02 by migius + - modif _Entity class: added paperspace,elevation v1.30 - 2009.05.28 by migius -- bugfix 3dPOLYLINE/POLYFACE: VERTEX needs x,y,z coordinates, index starts with 1 not 0 + - bugfix 3dPOLYLINE/POLYFACE: VERTEX needs x,y,z coordinates, index starts with 1 not 0 v1.29 - 2008.12.28 by Yorik -- modif POLYLINE to support bulge segments + - modif POLYLINE to support bulge segments v1.28 - 2008.12.13 by Steeve/BlenderArtists -- bugfix for EXTMIN/EXTMAX to suit Cycas-CAD + - bugfix for EXTMIN/EXTMAX to suit Cycas-CAD v1.27 - 2008.10.07 by migius -- beautifying output code: keys whitespace prefix -- refactoring DXF-strings format: NewLine moved to the end of + - beautifying output code: keys whitespace prefix + - refactoring DXF-strings format: NewLine moved to the end of v1.26 - 2008.10.05 by migius -- modif POLYLINE to support POLYFACE + - modif POLYLINE to support POLYFACE v1.25 - 2008.09.28 by migius -- modif FACE class for r12 + - modif FACE class for r12 v1.24 - 2008.09.27 by migius -- modif POLYLINE class for r12 -- changing output format from r9 to r12(AC1009) + - modif POLYLINE class for r12 + - changing output format from r9 to r12(AC1009) v1.1 (20/6/2005) by www.stani.be/python/sdxf -- Python library to generate dxf drawings + - Python library to generate dxf drawings ______________________________________________________________ """ % (__author__,__version__,__license__,__url__) @@ -106,17 +108,21 @@ #------------------------------------------------------- class _Entity(_Call): """Base class for _common group codes for entities.""" - def __init__(self,color=None,extrusion=None,layer='0', + def __init__(self,paperspace=None,color=None,layer='0', lineType=None,lineTypeScale=None,lineWeight=None, - thickness=None,parent=None): + extrusion=None,elevation=None,thickness=None, + parent=None): """None values will be omitted.""" + self.paperspace = paperspace self.color = color - self.extrusion = extrusion self.layer = layer self.lineType = lineType self.lineTypeScale = lineTypeScale self.lineWeight = lineWeight + self.extrusion = extrusion + self.elevation = elevation self.thickness = thickness + #self.visible = visible self.parent = parent def _common(self): @@ -124,13 +130,16 @@ if self.parent:parent=self.parent else:parent=self result ='' + if parent.paperspace==1: result+=' 67\n1\n' if parent.layer!=None: result+=' 8\n%s\n'%parent.layer if parent.color!=None: result+=' 62\n%s\n'%parent.color - if parent.extrusion!=None: result+='%s\n'%_point(parent.extrusion,200) if parent.lineType!=None: result+=' 6\n%s\n'%parent.lineType #TODO: if parent.lineWeight!=None: result+='370\n%s\n'%parent.lineWeight + #TODO: if parent.visible!=None: result+='60\n%s\n'%parent.visible if parent.lineTypeScale!=None: result+=' 48\n%s\n'%parent.lineTypeScale + if parent.elevation!=None: result+=' 38\n%s\n'%parent.elevation if parent.thickness!=None: result+=' 39\n%s\n'%parent.thickness + if parent.extrusion!=None: result+='%s\n'%_point(parent.extrusion,200) return result #-------------------------- Modified: trunk/blender/release/scripts/export_dxf.py =================================================================== --- trunk/blender/release/scripts/export_dxf.py 2009-06-04 19:35:03 UTC (rev 20634) +++ trunk/blender/release/scripts/export_dxf.py 2009-06-04 19:49:19 UTC (rev 20635) @@ -7,7 +7,7 @@ Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).' """ -__version__ = "1.34 - 2009.05.28" +__version__ = "1.34 - 2009.06.02" __author__ = "Remigiusz Fiedler (AKA migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -28,25 +28,27 @@ url: %s IDEAs: -- correct normals for POLYLINE-POLYFACE via proper vertex-order - HPGL output, especially usefull for correct scaled printing of 2d drawings TODO: -- export dupligroups and dupliverts as blocks ( option for the user to decide ) +- export dupligroups and dupliverts as blocks (option for the user to decide) - optimize POLYFACE routine: remove double-vertices -- optimize POLYFACE routine: remove unused vertices +- optimize POLYFACE routine: remove loose vertices +- support any-oriented mirrored curves(to POLYLINEs): fix blender negative-matrix.invert() - support hierarchies: groups, instances, parented structures -- support 210-code (3d orientation vector) - write drawing extends for automatic view positioning in CAD -- support mapping: materials to DXF-styles +- mapping materials to DXF-styles History -v1.34 - 2009.05.28 by migius -- bugfix POLYFACE export, synchronized with dxfLibrary.py +v1.34 - 2009.06.02 by migius +- support XYmirrored 2d-curves to POLYLINEs: works correct only for rotX,rotY==0.0 +- support thickness and elevation for curve-objects +- fix extrusion 210-code (3d orientation vector) +- fix POLYFACE export, synchronized with dxfLibrary.py - changed to the new 2.49 method Vector.cross() - output style manager (first try) v1.33 - 2009.05.25 by migius -- bugfix flipping normals in mirrored objects +- bugfix flipping normals in mirrored mesh-objects - added UI-Button for future Shadow Generator - support curve objects in projection-2d mode - UI stuff: camera selector/manager @@ -122,7 +124,7 @@ import Blender from Blender import Mathutils, Window, Scene, Draw, Camera, BezTriple -from Blender import Registry, Object, Mesh +from Blender import Registry, Object, Mesh, Curve import os import subprocess @@ -132,10 +134,11 @@ #from dxfLibrary import * import math -from math import atan, log10 +from math import atan, atan2, log10, sin, cos #pi = math.pi #pi = 3.14159265359 +r2d = 180.0 / math.pi d2r = math.pi / 180.0 #note: d2r * angle == math.radians(angle) @@ -392,29 +395,75 @@ #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!') + def M_CrossVecs(v1,v2): + return v1.cross(v2) #for up2.49 + def M_DotVecs(v1,v2): + return v1.dot(v2) #for up2.49 +else: + def M_CrossVecs(v1,v2): + return Mathutils.CrossVecs(v1,v2) #for pre2.49 + def M_DotVecs(v1,v2): + return Mathutils.DotVecs(v1,v2) #for pre2.49 + #----------------------------------------------------- def getExtrusion(matrix): - - print 'deb:getExtrusion() matrix=\n', matrix #--------- - ma = matrix.copy().normalize() - AZaxis = ma[2] # = ArbitraryZvector - ArbitraryZaxis = [AZaxis[0],AZaxis[1],AZaxis[2]] - threshold = 1.0 / 64.0 - if abs(Zaxis[0]) < threshold or abs(Zaxis[1]) < threshold: - #AXaxis = Mathutils.CrossVecs(WORLDY,AZaxis) #for<2.49 - AXaxis = WORLDY.cross(AZaxis) + #print 'deb:getExtrusion() given matrix=\n', matrix #--------- + 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 else: - #AXaxis = Mathutils.CrossVecs(WORLDZ,AZaxis) #for<2.49 - AXaxis = WORLDZ.cross(AZaxis) - - Rotation = Mathutils.AngleBetweenVecs(WORLDX,AXaxis) #output in degrees - Elevation = 1.0 - - return ArbitraryZaxis, Rotation, Elevation + threshold = 1.0 / 64.0 + if abs(AZaxis[0]) < threshold or 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() #----------------------------------------------------- +def getZRotation(AXaxis, rot_matrix_invert): + #ZRotation = Mathutils.AngleBetweenVecs(WORLDX,AXaxis) #output in degrees + + # this works: Xaxis is the obj.matrix Xaxis vector + #Xaxis = matrix[0].copy().resize3D() # = ArbitraryXvector + ##Xaxis.normalize() # = ArbitraryXvector + #ZRotation = - d2r * Mathutils.AngleBetweenVecs(Xaxis,AXaxis) #output in degrees + + # this works too, maybe 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 #--------- + ZRotation = - atan2(vec[1],vec[0]) #output in radians + + #print 'deb:ZRotation() ZRotation=', ZRotation*r2d #--------- + return ZRotation + + +#------------------------------------------ +def normalizeMat(matrix): + mat12 = matrix.copy() + mat12 = [Mathutils.Vector(v).normalize() for v in mat12] + if len(mat12)>3: + matr12 = Mathutils.Matrix(mat12[0],mat12[1],mat12[2],mat12[3]) + else: + matr12 = Mathutils.Matrix(mat12[0],mat12[1],mat12[2]) + return matr12 + + +#----------------------------------------------------- def projected_co(verts, mx): # converts world coordinates of points to screen coordinates temp_verts = [] @@ -422,12 +471,12 @@ #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 if GUI_A['Z_force_on'].val: locZ = GUI_A['Z_elev'].val else: locZ = 0.0 - for v in temp_verts: - v.co *= mx @@ 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