diff options
19 files changed, 864 insertions, 587 deletions
diff --git a/release/scripts/import_dxf.py b/release/scripts/import_dxf.py index 88b42e3e564..ce7df610d98 100644 --- a/release/scripts/import_dxf.py +++ b/release/scripts/import_dxf.py @@ -1,5 +1,5 @@ #!BPY -# coding: utf-8 + """ Name: 'Autodesk DXF (.dxf)' Blender: 244 @@ -7,14 +7,15 @@ Group: 'Import' Tooltip: 'Import for DXF geometry data (Drawing eXchange Format).' """ __author__ = 'Kitsu(Ed Blake) & migius(Remigiusz Fiedler)' -__version__ = '1.0.12 - 2008.02.08 by migius' +__version__ = '1.0.12 - 2008.06.05 by migius' __url__ = ["http://blenderartists.org/forum/showthread.php?t=84319", "http://wiki.blender.org/index.php/Scripts/Manual/Import/DXF-3D"] __email__ = ["Kitsune_e(at)yahoo.com", "migius(at)4d-vectors.de"] __bpydoc__ = """\ This script imports objects from DXF (2d/3d) into Blender. -This script imports 2d and 3d geometery from DXFr12 format files. +This script imports 2d and 3d geometery from DXF files. +Supported DXF format versions: from (r2.5) r12 up to 2008. Enhanced features are: - configurable object filtering and geometry manipulation, - configurable material pre-processing, @@ -40,22 +41,23 @@ XREF (External Reference). Supported DXF>r12 objects: ELLIPSE, -(wip v1.0.12 partly supported) LWPOLYLINE (LightWeight), -(wip v1.0.12) MLINE, -(wip v1.0.12) MTEXT +LWPOLYLINE (LightWeight Polylines), +(wip v1.0.12) SPLINE, +(wip v1.0.13) MLINE, +(wip v1.0.13) MTEXT -Unsupported Objects: +Unsupported objects: DXF r12: DIMENSION. -DXF>r12: SPLINE, GROUP, RAY/XLINE, LEADER, 3DSOLID, BODY, REGION, dynamic BLOCK +DXF>r12: GROUP, RAY/XLINE, LEADER, 3DSOLID, BODY, REGION, dynamic BLOCK -Supported Geometry: 2d and 3d DXF-objects. -Curves imported as curves or meshes optionally. +Supported geometry: 2d and 3d DXF-objects. +Curves imported as Blender curves or meshes optionally. Supported layout modes: "model space" is default, "paper space" as option (= "layout views") -Scene definitions produced with AVE_RENDER: +Supported scene definition objescts produced with AVE_RENDER: scene: selection of lights assigned to the camera, lights: DIRECT, OVERHEAD, SH_SPOT, (wip v1.0.13 import of AVE_RENDER material definitions) @@ -77,14 +79,10 @@ It is recommended to use DXF-object properties for assign Blender materials. Notes: - Recommend that you run 'RemoveDoubles' on each imported mesh after using this script - Blocks are created on layer 19 then referenced at each insert point. -- Big DXF-files (over 1500 objects) decrease import performance. +- support for DXF-files up to 160MB on systems with 1GB RAM +- DXF-files with over 1500 objects decrease import performance. The problem is not the inefficiency of python-scripting but Blenders performance -in creating new objects in his database - probably a database management problem. - -TODO: -- the new style object visibility -- support for real 3d-solids (ACIS) -- (to see more, search for "--todo--" in script code) +in creating new objects in scene database - probably a database management problem. """ @@ -92,6 +90,7 @@ TODO: History: v1.0 - 2008.01. by migius planned tasks: + -- (to see more, search for "--todo--" in script code) -- command-line-mode/batch-mode -- in-place-editing for dupliGroups -- support for MLINE (is exported to r12 as BLOCK*Unnamed with LINEs) @@ -102,17 +101,23 @@ History: -- added f_layerFilter -- to-check: obj/mat/group/_mapping-idea from ideasman42: -- curves: added "fill/non-fill" option for closed curves: CIRCLEs,ELLIPSEs,POLYLINEs - -- bug:? object = Object.Get(obname) -> = SCENE.getChildren(obname) -- "normalize Z" option to correct non-planar figures -- LINEs need "width" in 3d-space incl vGroups -- support width_force for LINEs/ELLIPSEs = "solidify" -- add better support for color_index BYLAYER=256, BYBLOCK=0 - -- bug: "oneMesh" produces sometimes errors + -- bug: "oneMesh" produces irregularly errors -- bug: Registry recall from hd_cache ?? only win32 bug?? - - v1.0.12: 2008.02.08 by migius -- support DXF-definitions of scene, lights and cameras -- support ortho mode for VIEWs and VPORTs as cameras + -- add support for SPLINEs + + v1.0.12: 2008.06.05 by migius + b3 bugfix: ob.name conflict with existing meshes (different ob.name/mesh.name) + v1.0.12: 2008.05.24 by migius + b2 added support for LWPOLYLINEs + b2 added support for ProE in readerDXF.py + v1.0.12: 2008.02.08 by migius + b1 update: object = Object.Get(obname) -> f_getSceChild().getChildren() a9 bugfix by non-existing tables views, vports, layers (Kai reported) v1.0.12: 2008.01.17 by migius a8 lately used INI-dir/filename persistently stored in Registry @@ -279,9 +284,9 @@ History: # -------------------------------------------------------------------------- import Blender -#import bpy from Blender import * #from Blender.Mathutils import Vector, Matrix +import bpy #import BPyMessages from dxfReader import readDXF @@ -313,6 +318,8 @@ WORLDX = Mathutils.Vector((1,0,0)) WORLDY = Mathutils.Vector((1,1,0)) WORLDZ = Mathutils.Vector((0,0,1)) +oblist = [] #to be sure, it is an empty list + G_SCALE = 1.0 #(0.0001-1000) global scaling factor for all dxf data G_ORIGIN_X = 0.0 #global translation-vector (x,y,z) in DXF units G_ORIGIN_Y = 0.0 @@ -330,6 +337,10 @@ ELEVATION = 0.0 #standard elevation = coordinate Z TARGET_LAYER = 3 #target blender_layer GROUP_BYLAYER = 0 #(0/1) all entities from same layer import into one blender-group +cur_COUNTER = 0 #counter for progress_bar +M_OBJ = False +BYBLOCK = 0 +BYLAYER = 256 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) @@ -342,75 +353,6 @@ AUTO = BezTriple.HandleTypes.AUTO FREE = BezTriple.HandleTypes.FREE VECT = BezTriple.HandleTypes.VECT ALIGN = BezTriple.HandleTypes.ALIGN -cur_COUNTER = 0 #counter for progress_bar - - -"""This module provides wrapper objects for dxf entities. - - The wrappers expect a "dxf object" as input. The dxf object is - an object with a type and a data attribute. Type is a lowercase - string matching the 0 code of a dxf entity. Data is a list containing - dxf objects or lists of [code, data] pairs. - - This module is not general, and is only for dxf import. -""" - -# from Stani's dxf writer v1.1 (c)www.stani.be (GPL) -#---color values -BYBLOCK = 0 -BYLAYER = 256 - -#---block-type flags (bit coded values, may be combined): -ANONYMOUS =1 # This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application -NON_CONSTANT_ATTRIBUTES =2 # This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all) -XREF =4 # This block is an external reference (xref) -XREF_OVERLAY =8 # This block is an xref overlay -EXTERNAL =16 # This block is externally dependent -RESOLVED =32 # This is a resolved external reference, or dependent of an external reference (ignored on input) -REFERENCED =64 # This definition is a referenced external reference (ignored on input) - -#---polyline flags -CLOSED =1 # This is a closed polyline (or a polygon mesh closed in the M direction) -CURVE_FIT =2 # Curve-fit vertices have been added -SPLINE_FIT =4 # Spline-fit vertices have been added -POLYLINE_3D =8 # This is a 3D polyline -POLYGON_MESH =16 # This is a 3D polygon mesh -CLOSED_N =32 # The polygon mesh is closed in the N direction -POLYFACE_MESH =64 # The polyline is a polyface mesh -CONTINOUS_LINETYPE_PATTERN =128 # The linetype pattern is generated continuously around the vertices of this polyline - -#---text flags -#horizontal -LEFT = 0 -CENTER = 1 -RIGHT = 2 -ALIGNED = 3 #if vertical alignment = 0 -MIDDLE = 4 #if vertical alignment = 0 -FIT = 5 #if vertical alignment = 0 -#vertical -BASELINE = 0 -BOTTOM = 1 -MIDDLE = 2 -TOP = 3 - -#---mtext flags -#attachment point -TOP_LEFT = 1 -TOP_CENTER = 2 -TOP_RIGHT = 3 -MIDDLE_LEFT = 4 -MIDDLE_CENTER = 5 -MIDDLE_RIGHT = 6 -BOTTOM_LEFT = 7 -BOTTOM_CENTER = 8 -BOTTOM_RIGHT = 9 -#drawing direction -LEFT_RIGHT = 1 -TOP_BOTTOM = 3 -BY_STYLE = 5 #the flow direction is inherited from the associated text style -#line spacing style (optional): -AT_LEAST = 1 #taller characters will override -EXACT = 2 #taller characters will not override class View: #----------------------------------------------------------------- @@ -652,6 +594,14 @@ def get_extrusion(data): #------------------------------------------------- return vec +#------------------------------------------ +def getSceneChild(name): + dudu = [i for i in SCENE.objects if i.name==name] +# dudu = [i for i in SCENE.getChildren() if i.name==name] + #print 'deb:getSceneChild %s -result: %s:' %(name,dudu) #----------------- + if dudu!=[]: return dudu[0] + return None + class Solid: #----------------------------------------------------------------- """Class for objects representing dxf SOLID or TRACE. @@ -754,16 +704,16 @@ class Solid: #----------------------------------------------------------------- if l == 4: faces = [[0,1,3,2]] elif l == 3: faces = [[0,1,2]] elif l == 2: edges = [[0,1]] - - - - me = Mesh.New(obname) # create a new mesh + + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object me.verts.extend(points) # add vertices to mesh if faces: me.faces.extend(faces) # add faces to the mesh if edges: me.edges.extend(edges) # add faces to the mesh - ob = SCENE.objects.new(me) # create a new mesh_object - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # each MeshSide becomes vertexGroup for easier material assignment --------------------- replace = Blender.Mesh.AssignModes.ADD #or .AssignModes.ADD/REPLACE if vg_left: me.addVertGroup('side.left') ; me.assignVertsToGroup('side.left', vg_left, 1.0, replace) @@ -777,9 +727,6 @@ class Solid: #----------------------------------------------------------------- return ob - - - class Line: #----------------------------------------------------------------- """Class for objects representing dxf LINEs. """ @@ -838,7 +785,7 @@ class Line: #----------------------------------------------------------------- elif settings.var['lines_as'] == 3: # as thin cylinder cyl_rad = 0.5 * settings.var['width_min'] - if settings.var['lines_as'] == 5: # LINE curve representation------------------------- + elif settings.var['lines_as'] == 5: # LINE curve representation------------------------- obname = 'li_%s' %self.layer # create object name from layer name obname = obname[:MAX_NAMELENGTH] @@ -872,20 +819,23 @@ class Line: #----------------------------------------------------------------- global activObjectName #print 'deb:draw:line.ob IN activObjectName: ', activObjectName #--------------------- - if activObjectLayer == self.layer and settings.var['one_mesh_on']: - obname = activObjectName - #print 'deb:line.draw obname from activObjectName: ', obname #--------------------- - ob = Object.Get(obname) # open an existing mesh_object - #ob = SCENE.getChildren(obname) # open an existing mesh_object - me = Mesh.Get(ob.name) # open objects mesh data - else: - obname = 'li_%s' %self.layer # create object name from layer name - obname = obname[:MAX_NAMELENGTH] - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object - activObjectName = ob.name - activObjectLayer = self.layer - #print ('deb:line.draw new line.ob+mesh:"%s" created!' %ob.name) #--------------------- + if M_OBJ: obname, me, ob = makeNewObject() + else: + if activObjectLayer == self.layer and settings.var['one_mesh_on']: + obname = activObjectName + #print 'deb:line.draw obname from activObjectName: ', obname #--------------------- + ob = getSceneChild(obname) # open an existing mesh_object + #ob = SCENE.getChildren(obname) # open an existing mesh_object + #me = Mesh.Get(ob.name) # open objects mesh data + me = ob.getData(name_only=False, mesh=True) + else: + obname = 'li_%s' %self.layer # create object name from layer name + obname = obname[:MAX_NAMELENGTH] + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object + activObjectName = ob.name + activObjectLayer = self.layer + #print ('deb:line.draw new line.ob+mesh:"%s" created!' %ob.name) #--------------------- faces, edges = [], [] n = len(me.verts) @@ -904,7 +854,7 @@ class Line: #----------------------------------------------------------------- if faces: me.faces.extend(faces) # add faces to the mesh if edges: me.edges.extend(edges) # add faces to the mesh - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # entities with the same color build one vertexGroup for easier material assignment ---- ob.link(me) # link mesh to that object vG_name = 'color_%s' %self.color_index @@ -988,155 +938,23 @@ class Point: #----------------------------------------------------------------- global activObjectLayer global activObjectName #print 'deb:draw:point.ob IN activObjectName: ', activObjectName #--------------------- - if activObjectLayer == self.layer and settings.var['one_mesh_on']: - obname = activObjectName - #print 'deb:draw:point.ob obname from activObjectName: ', obname #--------------------- - ob = Object.Get(obname) # open an existing mesh_object - #ob = SCENE.getChildren(obname) # open an existing mesh_object - me = Mesh.Get(ob.name) # open objects mesh data - else: - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object - activObjectName = ob.name - activObjectLayer = self.layer - #print ('deb:draw:point new point.ob+mesh:"%s" created!' %ob.name) #--------------------- - me.verts.extend(points) # add vertices to mesh - - return ob - - - -class LWpolyline: #----------------------------------------------------------------- - """Class for objects representing dxf LWPOLYLINEs. - """ - def __init__(self, obj): - """Expects an entity object of type lwpolyline as input. - """ - #print 'deb:LWpolyline.START:----------------' #------------------------ - if not obj.type == 'lwpolyline': - raise TypeError, "Wrong type %s for polyline object!" %obj.type - self.type = obj.type - self.data = obj.data[:] - - # required data - self.num_points = obj.get_type(90)[0] - - # optional data (with defaults) - self.space = getit(obj, 67, 0) - - self.color_index = getit(obj, 62, BYLAYER) - - self.elevation = getit(obj, 30, 0) - self.thic = getit(obj, 39, 0) - self.flags = getit(obj, 70, 0) - - self.closed = self.flags&1 # byte coded, 1 = closed, 128 = plinegen - - self.layer = getit(obj.data, 8, None) - self.points = self.get_points(obj.data) - self.extrusion = get_extrusion(obj.data) - - #print 'deb:LWpolyline.obj.data:\n', obj.data #------------------------ - #print 'deb:LWpolyline.ENDinit:----------------' #------------------------ - - - def get_points(self, data): - """Gets points for a polyline type object. - - LW-Polylines have no fixed number of verts, and - each vert can have a number of properties. - Verts should be coded as - 10:xvalue - 20:yvalue - 40:startwidth or 0 - 41:endwidth or 0 - 42:bulge or 0 - for each vert - """ - num = self.num_points - point = None - points = [] - for item in data: - if item[0] == 10: # 10 = x - if point: - points.append(point) - point = Vertex() - point.x = item[1] - elif item[0] == 20: # 20 = y - point.y = item[1] - elif item[0] == 40: # 40 = start width - point.swidth = item[1] - elif item[0] == 41: # 41 = end width - point.ewidth = item[1] - elif item[0] == 42: # 42 = bulge - point.bulge = item[1] - points.append(point) - return points - - - - def __repr__(self): - return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points) - - - def draw(self, settings): - """for LWPOLYLINE: generate Blender_geometry. - """ - #print 'deb:LWpolyline.draw.START:----------------' #------------------------ - points = [] - obname = 'lw_%s' %self.layer # create object name from layer name - obname = obname[:MAX_NAMELENGTH] - #settings.var['curves_on'] == True - #print 'deb:index_len: ', len(self.points) #------------------ - for i, point in enumerate(self.points): - #print 'deb:index: ', i #------------------ - if not point.bulge: - points.append(point.loc) - elif point.bulge and not self.closed and i == len(self.points)-1: - points.append(point.loc) - elif point.bulge: # - if i == len(self.points)-1: - point2 = self.points[0] + if M_OBJ: obname, me, ob = makeNewObject() + else: + if activObjectLayer == self.layer and settings.var['one_mesh_on']: + obname = activObjectName + #print 'deb:draw:point.ob obname from activObjectName: ', obname #--------------------- + ob = getSceneChild(obname) # open an existing mesh_object + #ob = SCENE.getChildren(obname) # open an existing mesh_object + me = ob.getData(name_only=False, mesh=True) + #me = Mesh.Get(ob.name) # open objects mesh data else: - point2 = self.points[i+1] - arc_res = settings.var['arc_res']/sqrt(settings.var['arc_rad']) - verts, center = calcBulge(point, point2, arc_res) -# if i == len(self.points)-1: -# if self.closed: -# verts.pop() #remove last(=first) vertex -# else: -# verts.pop() #remove last vertex, because this point will be writen as the next vertex - points.extend(verts) - - thic = self.thic - if settings.var['thick_force'] and thic == 0: thic = settings.var['thick_min'] - if settings.var['thick_on'] and thic != 0: - len1 = len(points) - points.extend([[point[0], point[1], point[2]+thic] for point in points]) - faces = [] - #print 'deb:len1:', len1 #----------------------- - faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)] - if self.closed: - faces.append([len1-1, 0, len1, 2*len1-1]) - #print 'deb:faces_list:\n', faces #----------------------- - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object - me.verts.extend(points) # add vertices to mesh - me.faces.extend(faces) # add faces to the mesh - else: - edges = [[num, num+1] for num in xrange(len(points)-1)] - if self.closed: - edges.append([len(points)-1, 0]) - #print 'deb:edges_list:\n', edges #----------------------- - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object + activObjectName = ob.name + activObjectLayer = self.layer + #print ('deb:draw:point new point.ob+mesh:"%s" created!' %ob.name) #--------------------- me.verts.extend(points) # add vertices to mesh - me.edges.extend(edges) # add edges to the mesh - ob.LocZ = self.elevation - transform(self.extrusion, 0, ob) - - #print 'deb:LWpolyline.draw.END:----------------' #------------------------ return ob @@ -1172,10 +990,10 @@ class Polyline: #-------------------------------------------------------------- self.plface = self.flags & 64 # 3D-polyface mesh self.contin = self.flags & 128 # the linetype pattern is generated continuously - if self.poly3d or self.plface or self.plmesh: - self.poly2d = False # its not a 2D-polyline - else: - self.poly2d = True # it is a 2D-polyline + self.pltype='poly2d' # default is a 2D-polyline + if self.poly3d: self.pltype='poly3d' + elif self.plface: self.pltype='plface' + elif self.plmesh: self.pltype='plmesh' self.swidth = getit(obj, 40, 0) # default start width self.ewidth = getit(obj, 41, 0) # default end width @@ -1213,19 +1031,19 @@ class Polyline: #-------------------------------------------------------------- """ ob = [] #---- 3dPolyFace - mesh with free topology - if self.plface and settings.drawTypes['plmesh']: + if self.pltype=='plface' and settings.drawTypes['plmesh']: ob = self.drawPlFace(settings) #---- 3dPolyMesh - mesh with ortogonal topology - elif self.plmesh and settings.drawTypes['plmesh']: + elif self.pltype=='plmesh' and settings.drawTypes['plmesh']: ob = self.drawPlMesh(settings) #---- 2dPolyline - plane polyline with arc/wide/thic segments - elif (self.poly2d and settings.drawTypes['polyline']): + elif self.pltype=='poly2d' and settings.drawTypes['polyline']: if settings.var['plines_as'] == 5: # and self.spline: ob = self.drawPolyCurve(settings) else: ob = self.drawPoly2d(settings) #---- 3dPolyline - non-plane polyline (thin segments = without arc/wide/thic) - elif (self.poly3d and settings.drawTypes['pline3']): + elif self.pltype=='poly3d' and settings.drawTypes['pline3']: if settings.var['plines3_as'] == 5: # and self.spline: ob = self.drawPolyCurve(settings) else: @@ -1355,21 +1173,7 @@ class Polyline: #-------------------------------------------------------------- pline = Curve.New(obname) # create new curve data #pline.setResolu(24) #--todo----- - if False: #self.spline: # NURBSplines-----FAKE(with Bezier)----- - #print 'deb:polyline2dCurve.draw self.spline!' #--------------- - curve = pline.appendNurb(BezTriple.New(d_points[0])) - for p in d_points[1:]: - curve.append(BezTriple.New(p)) - for point in curve: - point.handleTypes = [AUTO, AUTO] - if self.closed: - curve.flagU = 1 # Set curve cyclic=close - else: - curve.flagU = 0 # Set curve not cyclic=open - curve[0].handleTypes = [FREE, ALIGN] #remi--todo----- - curve[-1].handleTypes = [ALIGN, FREE] #remi--todo----- - - elif self.spline: # NURBSplines-----OK----- + if self.spline: # NURBSplines-----OK----- #print 'deb:polyline2dCurve.draw self.spline!' #--------------- weight1 = 0.5 weight2 = 1.0 @@ -1562,6 +1366,7 @@ class Polyline: #-------------------------------------------------------------- ewidths = [] swidth_default = self.swidth #default start width of POLYLINEs segments ewidth_default = self.ewidth #default end width of POLYLINEs segments + #print 'deb:drawPoly2d self.swidth=', self.swidth #------------------------ thic = set_thick(self.thic, settings) if self.spline: pline_typ = 'ps' elif self.curved: pline_typ = 'pc' @@ -1633,9 +1438,11 @@ class Polyline: #-------------------------------------------------------------- swidth = point1.swidth ewidth = point1.ewidth + #print 'deb:drawPoly2d point1.swidth=', swidth #------------------------ if swidth == None: swidth = swidth_default if ewidth == None: ewidth = ewidth_default if swidth != 0.0 or ewidth != 0.0: wide_segment_exist = True + #print 'deb:drawPoly2d vertex_swidth=', swidth #------------------------ if settings.var['width_force']: # force minimal width for thin segments width_min = settings.var['width_min'] @@ -1819,14 +1626,14 @@ class Polyline: #-------------------------------------------------------------- left_angle = False limit_dist = settings.var['dist_min'] if left_angle: # if left turning angle - print 'deb:drawPoly2d it is left turning angle' #------------- + #print 'deb:drawPoly2d it is left turning angle' #------------- # to avoid triangelface/doubleVertex delta1 = (cornerpointL - vecL1).normalize() * limit_dist delta4 = (cornerpointL - vecL4).normalize() * limit_dist pointsLc.extend((cornerpointL - delta1, cornerpointL - delta4)) pointsRc.extend((pointsRe[i],pointsRs[i+1])) else: # if right turning angle - print 'deb:drawPoly2d right turning angle' #------------- + #print 'deb:drawPoly2d right turning angle' #------------- delta1 = (cornerpointR - vecR1).normalize() * limit_dist delta4 = (cornerpointR - vecR4).normalize() * limit_dist pointsRc.extend((cornerpointR - delta1, cornerpointR - delta4)) @@ -1917,8 +1724,10 @@ class Polyline: #-------------------------------------------------------------- #faces = f_bottom + f_top #faces = f_left + f_right + f_start + f_end #print 'deb:faces_list:\n', faces #----------------------- - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object me.verts.extend(pointsW) # add vertices to mesh me.faces.extend(faces) # add faces to the mesh @@ -1926,7 +1735,7 @@ class Polyline: #-------------------------------------------------------------- # The mesh must first be linked to an object so the method knows which object to update. # This is because vertex groups in Blender are stored in the object -- not in the mesh, # which may be linked to more than one object. - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # each MeshSide becomes vertexGroup for easier material assignment --------------------- replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD vg_left, vg_right, vg_top, vg_bottom = [], [], [], [] @@ -1956,8 +1765,10 @@ class Polyline: #-------------------------------------------------------------- faces = [[num, len1+num, len1+num+1, num+1] for num in xrange(len1 - 1)] if self.closed: faces.append([len1, 0, len1-1, len1+len1-1]) - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object me.verts.extend(pointsW) # add vertices to mesh me.faces.extend(faces) # add faces to the mesh @@ -1976,8 +1787,10 @@ class Polyline: #-------------------------------------------------------------- faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)] if self.closed: faces.append([len1-1, 0, len1, 2*len1-1]) - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object me.verts.extend(points) # add vertices to mesh me.faces.extend(faces) # add faces to the mesh @@ -1993,8 +1806,10 @@ class Polyline: #-------------------------------------------------------------- edges = [[num, num+1] for num in xrange(len(points)-1)] if self.closed: edges.append([len(points)-1, 0]) - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object me.verts.extend(points) # add vertices to mesh me.edges.extend(edges) # add edges to the mesh @@ -2006,7 +1821,8 @@ class Polyline: #-------------------------------------------------------------- class Vertex(object): #----------------------------------------------------------------- - """Generic vertex object used by POLYLINEs (and maybe others). + """Generic vertex object used by POLYLINEs, (and maybe others). + also used by class_LWPOLYLINEs but without obj-parameter """ def __init__(self, obj=None): @@ -2017,8 +1833,8 @@ class Vertex(object): #-------------------------------------------------------- #print 'deb:Vertex.init.START:----------------' #----------------------- self.loc = [0,0,0] self.face = [] - self.swidth = 0 - self.ewidth = 0 + self.swidth = None #0 + self.ewidth = None #0 self.bulge = 0 if obj is not None: if not obj.type == 'vertex': @@ -2058,14 +1874,14 @@ class Vertex(object): #-------------------------------------------------------- self.curv_tangent = getit(data, 50, None) # curve_tangent if self.plface and not self.plmesh: - v1 = getit(data, 71, 0) # polyface:Face.vertex 1. - v2 = getit(data, 72, 0) # polyface:Face.vertex 2. - v3 = getit(data, 73, 0) # polyface:Face.vertex 3. - v4 = getit(data, 74, None) # polyface:Face.vertex 4. - self.face = [abs(v1)-1,abs(v2)-1,abs(v3)-1] - if v4 != None: - if abs(v4) != abs(v1): - self.face.append(abs(v4)-1) + v1 = getit(data, 71, 0) # polyface:Face.vertex 1. + v2 = getit(data, 72, 0) # polyface:Face.vertex 2. + v3 = getit(data, 73, 0) # polyface:Face.vertex 3. + v4 = getit(data, 74, None) # polyface:Face.vertex 4. + self.face = [abs(v1)-1,abs(v2)-1,abs(v3)-1] + if v4 != None: + if abs(v4) != abs(v1): + self.face.append(abs(v4)-1) else: #--parameter for polyline2d self.swidth = getit(data, 40, None) # start width self.ewidth = getit(data, 41, None) # end width @@ -2119,6 +1935,304 @@ class Vertex(object): #-------------------------------------------------------- +class Spline(Polyline): #----------------------------------------------------------------- + """Class for objects representing dxf SPLINEs. + """ + def __init__(self, obj): + """Expects an entity object of type spline as input. +100 - Subclass marker (AcDbSpline) +210,220, 230 - Normal vector (omitted if the spline is nonplanar) X,Y,Z values of normal vector +70 - Spline flag (bit coded): + 1 = Closed spline + 2 = Periodic spline + 4 = Rational spline + 8 = Planar + 16 = Linear (planar bit is also set) +71 - Degree of the spline curve +72 - Number of knots +73 - Number of control points +74 - Number of fit points (if any) +42 - Knot tolerance (default = 0.0000001) +43 - Control-point tolerance (default = 0.0000001) +44 - Fit tolerance (default = 0.0000000001) +12,22,32 - Start tangent--may be omitted (in WCS). X,Y,Z values of start tangent--may be omitted (in WCS). +13,23, 33 - End tangent--may be omitted (in WCS). X,Y,Z values of end tangent--may be omitted (in WCS) +40 - Knot value (one entry per knot) +41 - Weight (if not 1); with multiple group pairs, are present if all are not 1 +10,20, 30 - Control points (in WCS) one entry per control point. +DXF: X value; APP: 3D point, Y and Z values of control points (in WCS) (one entry per control point) +11,21, 31 - Fit points (in WCS) one entry per fit point. + X,Y,Z values of fit points (in WCS) (one entry per fit point) + """ + #print 'deb:Spline.START:----------------' #------------------------ + if not obj.type == 'spline': + raise TypeError, "Wrong type %s for spline object!" %obj.type + self.type = obj.type + self.data = obj.data[:] + + # required data + self.num_points = obj.get_type(73)[0] + + # optional data (with defaults) + self.space = getit(obj, 67, 0) + + self.color_index = getit(obj, 62, BYLAYER) + + #self.elevation = getit(obj, 30, 0) + self.thic = 0 # getit(obj, 39, 0) + + width = 0 + self.swidth = width # default start width + self.ewidth = width # default end width + + self.flags = getit(obj, 70, 0) + self.closed = self.flags & 1 # closed spline + self.period = self.flags & 2 # Periodic spline + self.ration = self.flags & 4 # Rational spline + self.planar = self.flags & 8 # Planar + self.linear = self.flags & 16 # Linear (and Planar) + + self.degree = getit(obj, 71, 0) # Degree of the spline curve + self.curvNormal = False + self.curvQBspline = False + self.curvCBspline = False + self.curvBezier = False + if self.degree == 0: self.curvNormal = True + elif self.degree == 1: self.curvQBspline = True + elif self.degree == 2: self.curvCBspline = True + #elif self.degree == 3: self.curvBezier = True + elif self.degree == 3: self.spline = True + + self.num_knots = getit(obj, 72, 0) # Number of knots + self.num_contr = getit(obj, 73, 0) # Number of control points + self.num_fitpk = getit(obj, 74, 0) # Number of fit points (if any) + + self.layer = getit(obj.data, 8, None) + self.extrusion = get_extrusion(obj.data) + + self.points = self.get_points(obj.data) + + if self.planar: self.pltype = 'poly2d' + else: self.pltype = 'poly3d' + self.curved = False + #self.curved = False + + #print 'deb:Spline obj.data:\n', obj.data #------------------------ + #print 'deb:Spline self.points:\n', self.points #------------------------ + #print 'deb:Spline.ENDinit:----------------' #------------------------ + + + def get_points(self, data): + """Gets points for a spline type object. + + Splines have fixed number of verts, and + each vert can have a number of properties. + Verts should be coded as + 10:xvalue + 20:yvalue + for each vert + """ + num = self.num_contr + point = None + points = [] + #point = Vertex() + for item in data: + #print 'deb:Spline item:', item #------------------------ + if item[0] == 10: # control point + if point: points.append(point) + point = Vertex() + point.curved = True + point.x = item[1] + elif item[0] == 20: # 20 = y + point.y = item[1] + elif item[0] == 30: # 30 = z + point.z = item[1] + + elif item[0] == 11: # fit point + if point: points.append(point) + point = Vertex() + point.curved = True + point.x = item[1] + elif item[0] == 21: # 20 = y + point.y = item[1] + elif item[0] == 31: # 30 = z + point.z = item[1] + + elif item[0] == 12: # start tangent + if point: points.append(point) + point = Vertex() + point.curved = True + point.x = item[1] + elif item[0] == 22: # = y + point.y = item[1] + elif item[0] == 32: # = z + point.z = item[1] + + elif item[0] == 13: # end tangent + if point: points.append(point) + point = Vertex() + point.curved = True + point.x = item[1] + elif item[0] == 23: # 20 = y + point.y = item[1] + elif item[0] == 33: # 30 = z + point.z = item[1] + points.append(point) + #print 'deb:Spline points:\n', points #------------------------ + return points + + + + def __repr__(self): + return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points) + + + + +class LWpolyline(Polyline): #------------------------------------------------------------- + """Class for objects representing dxf LWPOLYLINEs. + """ + def __init__(self, obj): + """Expects an entity object of type lwpolyline as input. + """ + #print 'deb:LWpolyline.START:----------------' #------------------------ + if not obj.type == 'lwpolyline': + raise TypeError, "Wrong type %s for polyline object!" %obj.type + self.type = obj.type + self.data = obj.data[:] + + # required data + self.num_points = obj.get_type(90)[0] + + # optional data (with defaults) + self.space = getit(obj, 67, 0) + self.elevation = getit(obj, 38, 0) + self.thic = getit(obj, 39, 0) + self.color_index = getit(obj, 62, BYLAYER) + width = getit(obj, 43, 0) + self.swidth = width # default start width + self.ewidth = width # default end width + #print 'deb:LWpolyline width=', width #------------------------ + #print 'deb:LWpolyline elevation=', self.elevation #------------------------ + + self.flags = getit(obj, 70, 0) + self.closed = self.flags&1 # byte coded, 1 = closed, 128 = plinegen + + self.layer = getit(obj.data, 8, None) + self.extrusion = get_extrusion(obj.data) + + self.points = self.get_points(obj.data) + + self.pltype = 'poly2d' # LW-polyline is a 2D-polyline + self.spline = False + self.curved = False + + + #print 'deb:LWpolyline.obj.data:\n', obj.data #------------------------ + #print 'deb:LWpolyline.ENDinit:----------------' #------------------------ + + + def get_points(self, data): + """Gets points for a polyline type object. + + LW-Polylines have no fixed number of verts, and + each vert can have a number of properties. + Verts should be coded as + 10:xvalue + 20:yvalue + 40:startwidth or 0 + 41:endwidth or 0 + 42:bulge or 0 + for each vert + """ + num = self.num_points + point = None + points = [] + for item in data: + if item[0] == 10: # 10 = x + if point: + points.append(point) + point = Vertex() + point.x = item[1] + point.z = self.elevation + elif item[0] == 20: # 20 = y + point.y = item[1] + elif item[0] == 40: # 40 = start width + point.swidth = item[1] + elif item[0] == 41: # 41 = end width + point.ewidth = item[1] + elif item[0] == 42: # 42 = bulge + point.bulge = item[1] + points.append(point) + return points + + + + def __repr__(self): + return "%s: layer - %s, points - %s" %(self.__class__.__name__, self.layer, self.points) + + + def draw_old(self, settings): + """for LWPOLYLINE: generate Blender_geometry. + """ + #print 'deb:LWpolyline.draw.START:----------------' #------------------------ + points = [] + obname = 'lw_%s' %self.layer # create object name from layer name + obname = obname[:MAX_NAMELENGTH] + #settings.var['curves_on'] == True + #print 'deb:index_len: ', len(self.points) #------------------ + for i, point in enumerate(self.points): + #print 'deb:index: ', i #------------------ + if not point.bulge: + points.append(point.loc) + elif point.bulge and not self.closed and i == len(self.points)-1: + points.append(point.loc) + elif point.bulge: # + if i == len(self.points)-1: + point2 = self.points[0] + else: + point2 = self.points[i+1] + arc_res = settings.var['arc_res']/sqrt(settings.var['arc_rad']) + verts, center = calcBulge(point, point2, arc_res) +# if i == len(self.points)-1: +# if self.closed: +# verts.pop() #remove last(=first) vertex +# else: +# verts.pop() #remove last vertex, because this point will be writen as the next vertex + points.extend(verts) + + thic = self.thic + if settings.var['thick_force'] and thic == 0: thic = settings.var['thick_min'] + if settings.var['thick_on'] and thic != 0: + len1 = len(points) + points.extend([[point[0], point[1], point[2]+thic] for point in points]) + faces = [] + #print 'deb:len1:', len1 #----------------------- + faces = [[num, num+1, num+len1+1, num+len1] for num in xrange(len1 - 1)] + if self.closed: + faces.append([len1-1, 0, len1, 2*len1-1]) + #print 'deb:faces_list:\n', faces #----------------------- + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object + me.verts.extend(points) # add vertices to mesh + me.faces.extend(faces) # add faces to the mesh + else: + edges = [[num, num+1] for num in xrange(len(points)-1)] + if self.closed: + edges.append([len(points)-1, 0]) + #print 'deb:edges_list:\n', edges #----------------------- + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object + me.verts.extend(points) # add vertices to mesh + me.edges.extend(edges) # add edges to the mesh + + ob.LocZ = self.elevation + transform(self.extrusion, 0, ob) + + #print 'deb:LWpolyline.draw.END:----------------' #------------------------ + return ob + + class Text: #----------------------------------------------------------------- """Class for objects representing dxf TEXT. """ @@ -2363,8 +2477,6 @@ class Mtext: #----------------------------------------------------------------- return ob - - class Circle: #----------------------------------------------------------------- """Class for objects representing dxf CIRCLEs. """ @@ -2494,8 +2606,10 @@ class Circle: #---------------------------------------------------------------- return ob else: # draw CIRCLE as mesh ----------------------------------------------- - cir = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(cir) # create a new circle_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object # set a number of segments in entire circle arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad']) start, end = 0.0 , 360.0 @@ -2534,24 +2648,24 @@ class Circle: #---------------------------------------------------------------- #print 'deb:circleDraw:verts:', verts #--------------- faces = f_band + f_bottom + f_top #print 'deb:circleDraw:faces:', faces #--------------- - cir.verts.extend(verts) # add vertices to mesh - cir.faces.extend(faces) # add faces to the mesh + me.verts.extend(verts) # add vertices to mesh + me.faces.extend(faces) # add faces to the mesh if settings.var['meshSmooth_on']: # left and right side become smooth ---------------------- for i in xrange(smooth_len): - cir.faces[i].smooth = True + me.faces[i].smooth = True # each MeshSide becomes vertexGroup for easier material assignment --------------------- - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # each MeshSide becomes vertexGroup for easier material assignment --------------------- replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD vg_band, vg_top, vg_bottom = [], [], [] for v in f_band: vg_band.extend(v) - cir.addVertGroup('side.band') ; cir.assignVertsToGroup('side.band', list(set(vg_band)), 1.0, replace) + me.addVertGroup('side.band') ; me.assignVertsToGroup('side.band', list(set(vg_band)), 1.0, replace) if settings.var['fill_on']: for v in f_top: vg_top.extend(v) for v in f_bottom: vg_bottom.extend(v) - cir.addVertGroup('side.top') ; cir.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace) - cir.addVertGroup('side.bottom'); cir.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace) + me.addVertGroup('side.top') ; me.assignVertsToGroup('side.top', list(set(vg_top)), 1.0, replace) + me.addVertGroup('side.bottom'); me.assignVertsToGroup('side.bottom',list(set(vg_bottom)), 1.0, replace) else: # if thic == 0 if settings.var['fill_on']: @@ -2563,20 +2677,18 @@ class Circle: #---------------------------------------------------------------- faces.append([len1-1, 0, center1]) #print 'deb:circleDraw:verts:', verts #--------------- #print 'deb:circleDraw:faces:', faces #--------------- - cir.verts.extend(verts) # add vertices to mesh - cir.faces.extend(faces) # add faces to the mesh + me.verts.extend(verts) # add vertices to mesh + me.faces.extend(faces) # add faces to the mesh else: - cir.verts.extend(verts) # add vertices to mesh + me.verts.extend(verts) # add vertices to mesh edges = [[num, num+1] for num in xrange(len(verts))] edges[-1][1] = 0 # it points the "new" last edge to the first vertex - cir.edges.extend(edges) # add edges to the mesh + me.edges.extend(edges) # add edges to the mesh ob.loc = tuple(self.loc) transform(self.extrusion, 0, ob) return ob - - class Arc: #----------------------------------------------------------------- """Class for objects representing dxf ARCs. @@ -2670,8 +2782,10 @@ class Arc: #----------------------------------------------------------------- return ob else: # draw ARC as mesh -------------------- - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object # set a number of segments in entire circle arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad']) @@ -2719,7 +2833,7 @@ class Arc: #----------------------------------------------------------------- for i in xrange(smooth_len): me.faces[i].smooth = True # each MeshSide becomes vertexGroup for easier material assignment --------------------- - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # each MeshSide becomes vertexGroup for easier material assignment --------------------- replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD vg_left, vg_right, vg_top, vg_bottom = [], [], [], [] @@ -2792,8 +2906,8 @@ class BlockRecord: #----------------------------------------------------------- # optional data (with defaults) self.insertion_units = getit(obj, 70, None) self.insert_units = getit(obj, 1070, None) - """code 1070 Einfügeeinheiten: - 0 = Keine Einheiten; 1 = Zoll; 2 = Fuß; 3 = Meilen; 4 = Millimeter; + """code 1070 Einfuegeeinheiten: + 0 = Keine Einheiten; 1 = Zoll; 2 = Fuss; 3 = Meilen; 4 = Millimeter; 5 = Zentimeter; 6 = Meter; 7 = Kilometer; 8 = Mikrozoll; 9 = Mils; 10 = Yard; 11 = Angstrom; 12 = Nanometer; 13 = Mikrons; 14 = Dezimeter; 15 = Dekameter; @@ -3048,7 +3162,7 @@ class Insert: #---------------------------------------------------------------- return ob elif settings.drawTypes['insert']: #if insert_drawType activated - print 'deb:draw. settings.blocknamesmap:', settings.blocknamesmap #-------------------- + #print 'deb:draw. settings.blocknamesmap:', settings.blocknamesmap #-------------------- obname = settings.blocknamesmap[self.name] obname = 'in_%s' %obname # create object name from block name #obname = obname[:MAX_NAMELENGTH] @@ -3193,10 +3307,10 @@ class Ellipse: #--------------------------------------------------------------- if settings.var['lines_as'] == 4: # as thin_box thic = settings.var['thick_min'] width = settings.var['width_min'] - if settings.var['lines_as'] == 3: # as thin cylinder + elif settings.var['lines_as'] == 3: # as thin cylinder cyl_rad = 0.5 * settings.var['width_min'] - if settings.var['lines_as'] == 5: # draw ELLIPSE as curve ------------- + elif settings.var['lines_as'] == 5: # draw ELLIPSE as curve ------------- arc_res = settings.var['curve_arc'] triples = True VectorTriples = calcArc(None, radius, start, end, arc_res, triples) @@ -3236,12 +3350,13 @@ class Ellipse: #--------------------------------------------------------------- else: # draw ELLIPSE as mesh -------------------------------------- - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object + if M_OBJ: obname, me, ob = makeNewObject() + else: + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object # set a number of segments in entire circle arc_res = settings.var['arc_res'] * sqrt(radius) / sqrt(settings.var['arc_rad']) - verts = calcArc(None, radius, start, end, arc_res, False) #verts = [list(point) for point in verts] if False: #--todo--: if ellipse_closed: @@ -3287,8 +3402,7 @@ class Ellipse: #--------------------------------------------------------------- smooth_len = len(f_left) + len(f_right) for i in xrange(smooth_len): me.faces[i].smooth = True - - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # each MeshSide becomes vertexGroup for easier material assignment --------------------- replace = Blender.Mesh.AssignModes.REPLACE #or .AssignModes.ADD vg_left, vg_right, vg_top, vg_bottom = [], [], [], [] @@ -3408,21 +3522,24 @@ class Face: #----------------------------------------------------------------- global activObjectName #print 'deb:draw:face.ob IN activObjectName: ', activObjectName #--------------------- - if activObjectLayer == self.layer and settings.var['one_mesh_on']: - obname = activObjectName - #print 'deb:face.draw obname from activObjectName: ', obname #--------------------- - ob = Object.Get(obname) # open an existing mesh_object - #ob = SCENE.getChildren(obname) # open an existing mesh_object - else: - obname = 'fa_%s' %self.layer # create object name from layer name - obname = obname[:MAX_NAMELENGTH] - me = Mesh.New(obname) # create a new mesh - ob = SCENE.objects.new(me) # create a new mesh_object - activObjectName = ob.name - activObjectLayer = self.layer - #print ('deb:except. new face.ob+mesh:"%s" created!' %ob.name) #--------------------- - - me = Mesh.Get(ob.name) # open objects mesh data + if M_OBJ: obname, me, ob = makeNewObject() + else: + if activObjectLayer == self.layer and settings.var['one_mesh_on']: + obname = activObjectName + #print 'deb:face.draw obname from activObjectName: ', obname #--------------------- + ob = getSceneChild(obname) # open an existing mesh_object + #ob = SCENE.getChildren(obname) # open an existing mesh_object + me = ob.getData(name_only=False, mesh=True) + else: + obname = 'fa_%s' %self.layer # create object name from layer name + obname = obname[:MAX_NAMELENGTH] + me = Mesh.New(obname) # create a new mesh + ob = SCENE.objects.new(me) # create a new mesh_object + activObjectName = ob.name + activObjectLayer = self.layer + #print ('deb:except. new face.ob+mesh:"%s" created!' %ob.name) #--------------------- + + #me = Mesh.Get(ob.name) # open objects mesh data faces, edges = [], [] n = len(me.verts) if len(self.points) == 4: @@ -3435,7 +3552,7 @@ class Face: #----------------------------------------------------------------- me.verts.extend(points) # add vertices to mesh if faces: me.faces.extend(faces) # add faces to the mesh if edges: me.edges.extend(edges) # add faces to the mesh - if settings.var['vGroup_on']: + if settings.var['vGroup_on'] and not M_OBJ: # entities with the same color build one vertexGroup for easier material assignment --------------------- ob.link(me) # link mesh to that object vG_name = 'color_%s' %self.color_index @@ -3468,6 +3585,7 @@ type_map = { # 'mline':MLine, 'polyline':Polyline, 'lwpolyline':LWpolyline, + 'spline':Spline, # 'region':Region, 'trace':Solid, 'solid':Solid, @@ -3738,7 +3856,11 @@ class Blocks: #---------------------------------------------------------------- global oblist oblist.append((ob, insertFlag, blockFlag)) else: + if M_OBJ: + car_end() + car_start() drawEntities(block.entities, self.settings, block_def) + if M_OBJ: car_end() self.settings.write("Drawing block:\'%s\' done!" %name) self.blocks[name] = blender_group @@ -3809,7 +3931,8 @@ class Settings: #-------------------------------------------------------------- """Given the drawing, build dictionaries of Layers, Colors and Blocks. """ - #de: paßt die distance parameter an globalScale + global oblist + #adjust the distance parameter to globalScale if self.var['g_scale'] != 1.0: self.var['dist_min'] = self.var['dist_min'] / self.var['g_scale'] self.var['thick_min'] = self.var['thick_min'] / self.var['g_scale'] @@ -3859,7 +3982,6 @@ class Settings: #-------------------------------------------------------------- if views: #---------------------------------- if self.var['views_on']: - global oblist for item in views.data: if type(item) != list and item.type == 'view': #print 'deb:settings_valid views dir(item)=', dir(item) #------------- @@ -3876,7 +3998,6 @@ class Settings: #-------------------------------------------------------------- if vports: #---------------------------------- if self.var['views_on']: - global oblist for item in vports.data: if type(item) != list and item.type == 'vport': #print 'deb:settings_valid views dir(item)=', dir(item) #------------- @@ -3901,7 +4022,8 @@ class Settings: #-------------------------------------------------------------- # Read the block definitions and build our block object if self.drawTypes['insert']: #if support for entity type 'Insert' is activated #Build a dictionary of blockname:block_data pairs - blocksmap, self.obj_number = getBlocksmap(drawing, layersmap, self.var['layFrozen_on']) + blocksmap, obj_number = getBlocksmap(drawing, layersmap, self.var['layFrozen_on']) + self.obj_number += obj_number self.blocknamesmap = getBlocknamesmap(blocksmap) self.blocks = Blocks(blocksmap, self) # initiates container for blocks_data self.usedBlocks = blocksmap.keys() @@ -3916,9 +4038,7 @@ class Settings: #-------------------------------------------------------------- # The section:entities if 'entities' in sections.keys(): self.write("found section:entities") - self.obj_number += len(drawing.entities.data) - #print 'deb:settings_valid self.obj_number', self.obj_number #---------- self.obj_number = 1.0 / self.obj_number @@ -4152,6 +4272,7 @@ def analyzeDXF(dxfFile): #--------------------------------------- def main(dxfFile): #---------------#############################----------- #print 'deb:filename:', filename #-------------- global SCENE + global oblist editmode = Window.EditMode() # are we in edit mode? If so ... if editmode: Window.EditMode(0) # leave edit mode before @@ -4206,7 +4327,6 @@ def main(dxfFile): #---------------#############################----------- return None # Draw all the know entity types in the current scene - global oblist oblist = [] # a list of all created AND linked objects for final f_globalScale time2 = Blender.sys.time() #time marker2 @@ -4218,9 +4338,12 @@ def main(dxfFile): #---------------#############################----------- global activObjectLayer, activObjectName activObjectLayer, activObjectName = None, None + if M_OBJ: car_init() + drawEntities(drawing.entities, settings) #print 'deb:drawEntities after: oblist:', oblist #----------------------- + if M_OBJ: car_end() if oblist: # and settings.var['g_scale'] != 1: globalScale(oblist, settings.var['g_scale']) @@ -4357,7 +4480,7 @@ def getBlocksmap(drawing, layersmap, layFrozen_on=False): #-------------------- try: usedblocks[item.name] = [used, childList] except KeyError: print 'Cannot map "%s" - "%s" as Block!' %(item.name, item) #print 'deb:getBlocksmap: usedblocks=' , usedblocks #------------- - print 'deb:getBlocksmap: layersmap=' , layersmap #------------- + #print 'deb:getBlocksmap: layersmap=' , layersmap #------------- for item in drawing.entities.data: if type(item) != list and item.type == 'insert': @@ -4527,19 +4650,27 @@ def drawer(_type, entities, settings, block_def): #---------------------------- insertFlag = False alt_obname = activObjectName ob = entity.draw(settings) - if ob and ob.name != alt_obname: - if block_def: - blockFlag = True - bl_loc = block_def[1] - ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]] - else: blockFlag = False - setObjectProperties(ob, group, entity, settings, block_def) - if settings.var['optimization'] <= settings.MIN: - #if settings.var['g_origin_on'] and not block_def: ob.loc = Mathutils.Vector(ob.loc) + settings.g_origin - if settings.var['g_scale_on']: globalScaleOne(ob, insertFlag, blockFlag, settings.var['g_scale']) - settings.redraw() - else: oblist.append((ob, insertFlag, blockFlag)) - + if ob: + if M_OBJ and ob.type=='Mesh': #'Curve', 'Text' + if block_def: + blockFlag = True + bl_loc = block_def[1] + ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]] + car_nr() + + elif ob.name != alt_obname: + if block_def: + blockFlag = True + bl_loc = block_def[1] + ob.loc = [ob.loc[0]-bl_loc[0],ob.loc[1]-bl_loc[1],ob.loc[2]-bl_loc[2]] + else: blockFlag = False + setObjectProperties(ob, group, entity, settings, block_def) + if settings.var['optimization'] <= settings.MIN: + #if settings.var['g_origin_on'] and not block_def: ob.loc = Mathutils.Vector(ob.loc) + settings.g_origin + if settings.var['g_scale_on']: globalScaleOne(ob, insertFlag, blockFlag, settings.var['g_scale']) + settings.redraw() + else: oblist.append((ob, insertFlag, blockFlag)) + #print 'deb:Finished drawing:', entities[0].type #------------------------ message = "\nDrawing dxf\'%ss\' done!" % _type settings.write(message, True) @@ -4569,7 +4700,8 @@ def globalScaleOne(ob, insertFlag, blockFlag, SCALE): #------------------------ ob.loc = Mathutils.Vector(ob.loc) * SCALE_MAT else: # entire scaling for all other imported objects ------------ if ob.type == 'Mesh': - me = Mesh.Get(ob.name) + me = ob.getData(name_only=False, mesh=True) + #me = Mesh.Get(ob.name) # set centers of all objects in (0,0,0) #me.transform(ob.matrixWorld*SCALE_MAT) #ob.loc = Mathutils.Vector([0,0,0]) @@ -4990,6 +5122,7 @@ points_as_menu = "convert to: %t|empty %x1|mesh.vertex %x2|thin sphere %x3|thin lines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|thin box %x4|curve %x5" mlines_as_menu = "convert to: %t|*edge %x1|*mesh %x2|*thin cylinder %x3|*thin box %x|*curve %x5" plines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|curve %x5" +splines_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|curve %x5" plines3_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|curve %x5" plmesh_as_menu = "convert to: %t|*edge %x1|mesh %x2" solids_as_menu = "convert to: %t|*edge %x1|mesh %x2" @@ -5072,6 +5205,7 @@ keywords_org = { 'lines_as' : 2, 'mlines_as' : 2, 'plines_as' : 2, + 'splines_as' : 2, 'plines3_as': 2, 'plmesh_as' : 2, 'solids_as' : 2, @@ -5087,6 +5221,7 @@ drawTypes_org = { 'ellipse': 1, 'mline' : 0, 'polyline': 1, + 'spline': 0, 'plmesh': 1, 'pline3': 1, 'lwpolyline': 1, @@ -5272,12 +5407,14 @@ def presetConfig_curv(): #----------------------------------------------- GUI_A['lines_as'].val = 5 GUI_A['mlines_as'].val = 5 GUI_A['plines_as'].val = 5 + GUI_A['splines_as'].val = 5 GUI_A['plines3_as'].val = 5 else: GUI_A['points_as'].val = 2 GUI_A['lines_as'].val = 2 GUI_A['mlines_as'].val = 2 GUI_A['plines_as'].val = 2 + GUI_A['splines_as'].val = 2 GUI_A['plines3_as'].val = 2 @@ -5315,6 +5452,7 @@ def resetDefaultConfig_2D(): #----------------------------------------------- 'ellipse': 1, 'mline' : 0, 'polyline': 1, + 'spline': 0, 'plmesh': 0, 'pline3': 0, 'lwpolyline': 1, @@ -5361,6 +5499,7 @@ def resetDefaultConfig_3D(): #----------------------------------------------- 'ellipse': 1, 'mline' : 0, 'polyline': 1, + 'spline': 0, 'plmesh': 1, 'pline3': 1, 'lwpolyline': 1, @@ -5429,7 +5568,7 @@ def draw_UI(): #--------------------------------------------------------------- menu_w = (3 * butt_margin) + but_0c + but_1c + but_2c + but_3c #menu width simple_menu_h = 80 - extend_menu_h = 350 + extend_menu_h = 370 y = simple_menu_h # y is menu upper.y if config_UI.val: y += extend_menu_h x = 20 #menu left.x @@ -5450,8 +5589,9 @@ def draw_UI(): #--------------------------------------------------------------- if config_UI.val: b0, b0_ = but0c, but_0c + butt_margin b1, b1_ = but1c, but_1c - y -= 10 + y_top = y + y -= 10 y -= 20 Draw.BeginAlign() GUI_B['point'] = Draw.Toggle('POINT', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['point'].val, "support dxf-POINT on/off") @@ -5476,7 +5616,14 @@ def draw_UI(): #--------------------------------------------------------------- y -= 20 Draw.BeginAlign() - GUI_B['polyline'] = Draw.Toggle('2D-PLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['polyline'].val, "support dxf-2D-POLYLINE on/off") + GUI_B['spline'] = Draw.Toggle('SPLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['spline'].val, "support dxf-SPLINE on/off") + if GUI_B['spline'].val: + GUI_A['splines_as'] = Draw.Menu(splines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['splines_as'].val, "select target Blender-object") + Draw.EndAlign() + + y -= 20 + Draw.BeginAlign() + GUI_B['polyline'] = Draw.Toggle('2D/LWPLINE', EVENT_REDRAW, b0, y, b0_, 20, GUI_B['polyline'].val, "support dxf-2D-POLYLINE on/off") if GUI_B['polyline'].val: GUI_A['plines_as'] = Draw.Menu(plines_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plines_as'].val, "select target Blender-object") Draw.EndAlign() @@ -5488,6 +5635,64 @@ def draw_UI(): #--------------------------------------------------------------- GUI_A['plines3_as'] = Draw.Menu(plines3_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plines3_as'].val, "select target Blender-object") Draw.EndAlign() + y_down = y + # ----------------------------------------------- + + y = y_top + b0, b0_ = but2c, but_2c + butt_margin + b1, b1_ = but3c, but_3c + + y -= 10 + y -= 20 + Draw.BeginAlign() + GUI_B['plmesh'] = Draw.Toggle('POLY-MESH/FACE', EVENT_NONE, b0, y, b0_+b1_, 20, GUI_B['plmesh'].val, "support dxf-POLYMESH/POLYFACE on/off") +# GUI_A['plmesh_as'] = Draw.Menu(plmesh_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plmesh_as'].val, "select target Blender-object") + Draw.EndAlign() + + y -= 20 + Draw.BeginAlign() + GUI_B['solid'] = Draw.Toggle('SOLID', EVENT_NONE, b0, y, b0_, 20, GUI_B['solid'].val, "support dxf-SOLID and TRACE on/off") + GUI_B['face'] = Draw.Toggle('3DFACE', EVENT_NONE, b1, y, b1_, 20, GUI_B['face'].val, "support dxf-3DFACE on/off") +# GUI_A['solids_as'] = Draw.Menu(solids_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['solids_as'].val, "select target Blender-object") + Draw.EndAlign() + #print 'deb:support solid, trace', GUI_B['trace'].val, GUI_B['solid'].val # ------------ + + + y -= 20 + Draw.BeginAlign() + GUI_B['text'] = Draw.Toggle('TEXT', EVENT_NONE, b0, y, b0_, 20, GUI_B['text'].val, "support dxf-TEXT on/off") + GUI_B['mtext'] = Draw.Toggle('*MTEXT', EVENT_NONE, b1, y, b1_, 20, GUI_B['mtext'].val, "(*wip)support dxf-MTEXT on/off") +# GUI_A['texts_as'] = Draw.Menu(texts_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['texts_as'].val, "select target Blender-object") + Draw.EndAlign() + + y -= 20 + Draw.BeginAlign() + GUI_B['block'] = Draw.Toggle('BLOCK', EVENT_REDRAW, b0, y, b0_-30, 20, GUI_B['block'].val, "support dxf-BLOCK and ARRAY on/off") + GUI_B['insert'].val = GUI_B['block'].val + if GUI_B['block'].val: + GUI_A['block_nn'] = Draw.Toggle('n', EVENT_NONE, b1-30, y, 15, 20, GUI_A['block_nn'].val, "support hatch/noname BLOCKs *X... on/off") + GUI_A['blockFilter_on'] = Draw.Toggle('F', EVENT_NONE, b1-15, y, 15, 20, GUI_A['blockFilter_on'].val, "(*wip) support name filtering of BLOCKs on/off") + GUI_A['xref_on'] = Draw.Toggle('Xref', EVENT_NONE, b1, y, 20, 20, GUI_A['xref_on'].val, "support place holder for XREF-BLOCKs on/off") + GUI_A['blocks_as'] = Draw.Menu(blocks_as_menu, EVENT_NONE, b1+20, y, b1_-20, 20, GUI_A['blocks_as'].val, "select target representation for imported BLOCKs") + Draw.EndAlign() + + + y -= 20 + Draw.BeginAlign() + GUI_A['views_on'] = Draw.Toggle('views', EVENT_NONE, b0, y, b0_-25, 20, GUI_A['views_on'].val, "imports VIEWs and VIEWPORTs as cameras on/off") + GUI_A['cams_on'] = Draw.Toggle('*cams', EVENT_NONE, b1-25, y, b1_-25, 20, GUI_A['cams_on'].val, "(*wip) support ASHADE cameras on/off") + GUI_A['lights_on'] = Draw.Toggle('*lights', EVENT_NONE, b1+25, y, b1_-25, 20, GUI_A['lights_on'].val, "(*wip) support AVE_RENDER lights on/off") + Draw.EndAlign() + + + if y < y_down: y_down = y + # -----end supported objects-------------------------------------- + + b0, b0_ = but0c, but_0c + butt_margin + b1, b1_ = but1c, but_1c + + y_top = y_down + y = y_top y -= 10 y -= 20 Draw.BeginAlign() @@ -5534,6 +5739,14 @@ def draw_UI(): #--------------------------------------------------------------- Draw.Label(scale_str, b1+45, y, 200, 20) Draw.EndAlign() + y_down = y + # -----end material,translate,scale------------------------------------------ + + b0, b0_ = but0c, but_0c + butt_margin + b1, b1_ = but1c, but_1c + + y_top = y_down + y = y_top y -= 10 y -= 20 Draw.BeginAlign() @@ -5571,56 +5784,11 @@ def draw_UI(): #--------------------------------------------------------------- y_down = y # ----------------------------------------------- - y = simple_menu_h + extend_menu_h +20 + b0, b0_ = but2c, but_2c + butt_margin b1, b1_ = but3c, but_3c - y -= 20 - Draw.BeginAlign() - GUI_B['plmesh'] = Draw.Toggle('POLY-MESH/FACE', EVENT_NONE, b0, y, b0_+b1_, 20, GUI_B['plmesh'].val, "support dxf-POLYMESH/POLYFACE on/off") -# GUI_A['plmesh_as'] = Draw.Menu(plmesh_as_menu, EVENT_NONE, but1c, y, but_1c, 20, GUI_A['plmesh_as'].val, "select target Blender-object") - Draw.EndAlign() - - y -= 20 - Draw.BeginAlign() - GUI_B['solid'] = Draw.Toggle('SOLID', EVENT_NONE, b0, y, b0_, 20, GUI_B['solid'].val, "support dxf-SOLID and TRACE on/off") - GUI_B['face'] = Draw.Toggle('3DFACE', EVENT_NONE, b1, y, b1_, 20, GUI_B['face'].val, "support dxf-3DFACE on/off") -# GUI_A['solids_as'] = Draw.Menu(solids_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['solids_as'].val, "select target Blender-object") - Draw.EndAlign() - #print 'deb:support solid, trace', GUI_B['trace'].val, GUI_B['solid'].val # ------------ - - - y -= 20 - Draw.BeginAlign() - GUI_B['text'] = Draw.Toggle('TEXT', EVENT_NONE, b0, y, b0_, 20, GUI_B['text'].val, "support dxf-TEXT on/off") - GUI_B['mtext'] = Draw.Toggle('*MTEXT', EVENT_NONE, b1, y, b1_, 20, GUI_B['mtext'].val, "(*wip)support dxf-MTEXT on/off") -# GUI_A['texts_as'] = Draw.Menu(texts_as_menu, EVENT_NONE, but3c, y, but_3c, 20, GUI_A['texts_as'].val, "select target Blender-object") - Draw.EndAlign() - - y -= 20 - Draw.BeginAlign() - GUI_B['block'] = Draw.Toggle('BLOCK', EVENT_REDRAW, b0, y, b0_-30, 20, GUI_B['block'].val, "support dxf-BLOCK and ARRAY on/off") - GUI_B['insert'].val = GUI_B['block'].val - if GUI_B['block'].val: - GUI_A['block_nn'] = Draw.Toggle('n', EVENT_NONE, b1-30, y, 15, 20, GUI_A['block_nn'].val, "support hatch/noname BLOCKs *X... on/off") - GUI_A['blockFilter_on'] = Draw.Toggle('F', EVENT_NONE, b1-15, y, 15, 20, GUI_A['blockFilter_on'].val, "(*wip) support name filtering of BLOCKs on/off") - GUI_A['xref_on'] = Draw.Toggle('Xref', EVENT_NONE, b1, y, 20, 20, GUI_A['xref_on'].val, "support place holder for XREF-BLOCKs on/off") - GUI_A['blocks_as'] = Draw.Menu(blocks_as_menu, EVENT_NONE, b1+20, y, b1_-20, 20, GUI_A['blocks_as'].val, "select target representation for imported BLOCKs") - Draw.EndAlign() - - - y -= 20 - Draw.BeginAlign() - GUI_A['views_on'] = Draw.Toggle('views', EVENT_NONE, b0, y, b0_-25, 20, GUI_A['views_on'].val, "imports VIEWs and VIEWPORTs as cameras on/off") - GUI_A['cams_on'] = Draw.Toggle('*cams', EVENT_NONE, b1-25, y, b1_-25, 20, GUI_A['cams_on'].val, "(*wip) support ASHADE cameras on/off") - GUI_A['lights_on'] = Draw.Toggle('*lights', EVENT_NONE, b1+25, y, b1_-25, 20, GUI_A['lights_on'].val, "(*wip) support AVE_RENDER lights on/off") - Draw.EndAlign() - - y -= 10 - y -= 20 - y -= 20 - y -= 20 - + y = y_top y -= 10 y -= 20 Draw.BeginAlign() @@ -5656,8 +5824,13 @@ def draw_UI(): #--------------------------------------------------------------- GUI_A['newScene_on'] = Draw.Toggle('newScene', EVENT_NONE, b0, y, b0_, 20, GUI_A['newScene_on'].val, "creates new Blender-Scene for each import on/off") GUI_A['target_layer'] = Draw.Number('layer', EVENT_NONE, b1, y, b1_, 20, GUI_A['target_layer'].val, 1, 18, "imports into this Blender-layer (<19> reserved for block_definitions)") + if y < y_down: y_down = y + # -----end options -------------------------------------- + + #-------------------------------------- - if y > y_down: y = y_down + y_top = y_down + y = y_top #GUI_A['dummy_on'] = Draw.Toggle(' - ', EVENT_NONE, but0c, y, but_0c, 20, GUI_A['dummy_on'].val, "reserved") y -= 30 Draw.BeginAlign() @@ -5891,6 +6064,7 @@ def multi_import(DIR): +UI_MODE = True if __name__ == "__main__": UI_MODE = True @@ -5942,5 +6116,4 @@ if 1: main(_dxf) print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME) -""" - +"""
\ No newline at end of file diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 62289d227c7..980604cb5b6 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -95,6 +95,7 @@ typedef struct Global { int totobj, totlamp, totobjsel, totcurve, totmesh; int totbone, totbonesel; int totvert, totedge, totface, totvertsel, totedgesel, totfacesel; + int tottri; /* APRICOT HACK */ short afbreek, moving; short qual, background; @@ -259,6 +260,8 @@ typedef struct Global { /* Memory is allocated where? blender.c */ extern Global G; +#define TOTTRI_INC(isquad) G.tottri += (isquad ? 2:1) + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index fc9a8132aaf..7f41ca033d3 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -683,7 +683,8 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap collpair->distance = distance; collpair->flag = 0; - } + collpair++; + }/* else { float w1, w2, w3, u1, u2, u3; @@ -716,9 +717,9 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap { // check for collision in the future collpair->flag |= COLLISION_IN_FUTURE; + collpair++; } - } - collpair++; + }*/ } return collpair; } @@ -1398,7 +1399,7 @@ int cloth_bvh_objcollision ( ClothModifierData * clmd, float step, float dt ) Cloth *cloth=NULL; Object *coll_ob=NULL; BVHTree *cloth_bvh=NULL; - long i=0, j = 0, k = 0, numfaces = 0, numverts = 0; + long i=0, j = 0, k = 0, l = 0, numfaces = 0, numverts = 0; int result = 0, rounds = 0; // result counts applied collisions; ic is for debug output; ClothVertex *verts = NULL; int ret = 0, ret2 = 0; @@ -1498,88 +1499,91 @@ int cloth_bvh_objcollision ( ClothModifierData * clmd, float step, float dt ) //////////////////////////////////////////////////////////// if ( clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) { - // TODO: add coll quality rounds again - BVHTreeOverlap *overlap = NULL; - - collisions = 1; - verts = cloth->verts; // needed for openMP - - numfaces = clmd->clothObject->numfaces; - numverts = clmd->clothObject->numverts; - - verts = cloth->verts; - - if ( cloth->bvhselftree ) + for(l = 0; l < clmd->coll_parms->self_loop_count; l++) { - // search for overlapping collision pairs - overlap = BLI_bvhtree_overlap ( cloth->bvhselftree, cloth->bvhselftree, &result ); - -// #pragma omp parallel for private(k, i, j) schedule(static) - for ( k = 0; k < result; k++ ) + // TODO: add coll quality rounds again + BVHTreeOverlap *overlap = NULL; + + collisions = 1; + verts = cloth->verts; // needed for openMP + + numfaces = clmd->clothObject->numfaces; + numverts = clmd->clothObject->numverts; + + verts = cloth->verts; + + if ( cloth->bvhselftree ) { - float temp[3]; - float length = 0; - float mindistance; - - i = overlap[k].indexA; - j = overlap[k].indexB; - - mindistance = clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len + cloth->verts[j].avg_spring_len ); - - if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) + // search for overlapping collision pairs + overlap = BLI_bvhtree_overlap ( cloth->bvhselftree, cloth->bvhselftree, &result ); + + // #pragma omp parallel for private(k, i, j) schedule(static) + for ( k = 0; k < result; k++ ) { - if ( ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) - && ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) ) + float temp[3]; + float length = 0; + float mindistance; + + i = overlap[k].indexA; + j = overlap[k].indexB; + + mindistance = clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len + cloth->verts[j].avg_spring_len ); + + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) { - continue; + if ( ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) + && ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) ) + { + continue; + } } - } - - VECSUB ( temp, verts[i].tx, verts[j].tx ); - - if ( ( ABS ( temp[0] ) > mindistance ) || ( ABS ( temp[1] ) > mindistance ) || ( ABS ( temp[2] ) > mindistance ) ) continue; - - // check for adjacent points (i must be smaller j) - if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) - { - continue; - } - - length = Normalize ( temp ); - - if ( length < mindistance ) - { - float correction = mindistance - length; - - if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) + + VECSUB ( temp, verts[i].tx, verts[j].tx ); + + if ( ( ABS ( temp[0] ) > mindistance ) || ( ABS ( temp[1] ) > mindistance ) || ( ABS ( temp[2] ) > mindistance ) ) continue; + + // check for adjacent points (i must be smaller j) + if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) { - VecMulf ( temp, -correction ); - VECADD ( verts[j].tx, verts[j].tx, temp ); + continue; } - else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) + + length = Normalize ( temp ); + + if ( length < mindistance ) { - VecMulf ( temp, correction ); - VECADD ( verts[i].tx, verts[i].tx, temp ); + float correction = mindistance - length; + + if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) + { + VecMulf ( temp, -correction ); + VECADD ( verts[j].tx, verts[j].tx, temp ); + } + else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) + { + VecMulf ( temp, correction ); + VECADD ( verts[i].tx, verts[i].tx, temp ); + } + else + { + VecMulf ( temp, -correction*0.5 ); + VECADD ( verts[j].tx, verts[j].tx, temp ); + + VECSUB ( verts[i].tx, verts[i].tx, temp ); + } + ret = 1; + ret2 += ret; } else { - VecMulf ( temp, -correction*0.5 ); - VECADD ( verts[j].tx, verts[j].tx, temp ); - - VECSUB ( verts[i].tx, verts[i].tx, temp ); + // check for approximated time collisions } - ret = 1; - ret2 += ret; - } - else - { - // check for approximated time collisions } + + if ( overlap ) + MEM_freeN ( overlap ); + } - - if ( overlap ) - MEM_freeN ( overlap ); - } //////////////////////////////////////////////////////////// diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 7b727528b3d..57ecffbb796 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -185,8 +185,8 @@ static int ptcache_path(PTCacheID *pid, char *filename) file[i-6] = '\0'; sprintf(filename, "//"PTCACHE_PATH"%s", file); /* add blend file name to pointcache dir */ - BLI_add_slash(filename); BLI_convertstringcode(filename, blendfilename); + BLI_add_slash(filename); return strlen(filename); } diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 9c4238431dc..a85883f6572 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -240,17 +240,16 @@ void sort_along_axis(BVHTree *tree, int start, int end, int axis) //after a call to this function you can expect one of: // every node to left of a[n] are smaller or equal to it // every node to the right of a[n] are greater or equal to it -int partition_nth_element(BVHNode **a, int _begin, int _end, int n, int axis){ - int begin = _begin, end = _end, cut; - int i; - while(end-begin > 3) - { - cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, (begin+end)/2, end-1, axis), axis ); - if(cut <= n) - begin = cut; - else - end = cut; - } +int partition_nth_element(BVHNode **a, int _begin, int _end, int n, int axis){ + int begin = _begin, end = _end, cut; + while(end-begin > 3) + { + cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, (begin+end)/2, end-1, axis), axis ); + if(cut <= n) + begin = cut; + else + end = cut; + } bvh_insertionsort(a, begin, end, axis); return n; @@ -415,7 +414,7 @@ static void refit_kdop_hull(BVHTree *tree, BVHNode *node, int start, int end) for (j = start; j < end; j++) { - // for all Axes. +// for all Axes. for (i = tree->start_axis; i < tree->stop_axis; i++) { newmin = tree->nodes[j]->bv[(2 * i)]; @@ -696,7 +695,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result) } #pragma omp parallel for private(j) schedule(static) - for(j = 0; j < tree1->tree_type; j++) + for(j = 0; j < MIN2(tree1->tree_type, tree1->nodes[tree1->totleaf]->totnode); j++) { traverse(data[j], tree1->nodes[tree1->totleaf]->children[j], tree2->nodes[tree2->totleaf]); } diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 3610813f2da..848e45ccb1b 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -865,11 +865,8 @@ int BLI_strcaseeq(char *a, char *b) { void BLI_cleanup_dir(const char *relabase, char *dir) { BLI_cleanup_file(relabase, dir); -#ifdef WIN32 - strcat(dir, "\\"); -#else - strcat(dir, "/"); -#endif + BLI_add_slash(dir); + } void BLI_cleanup_file(const char *relabase, char *dir) @@ -878,6 +875,13 @@ void BLI_cleanup_file(const char *relabase, char *dir) char *start, *eind; if (relabase) { BLI_convertstringcode(dir, relabase); + } else { + if (dir[0]=='/' && dir[1]=='/') { + if (dir[2]== '\0') { + return; /* path is "//" - cant clean it */ + } + dir = dir+2; /* skip the first // */ + } } #ifdef WIN32 if(dir[0]=='.') { /* happens for example in FILE_MAIN */ @@ -1150,24 +1154,32 @@ int BLI_convertstringcode(char *path, const char *basepath) BLI_char_switch(tmp, '\\', '/'); BLI_char_switch(base, '\\', '/'); + /* Paths starting with // will get the blend file as their base, + * this isnt standard in any os but is uesed in blender all over the place */ if (tmp[0] == '/' && tmp[1] == '/') { - char *filepart= BLI_strdup(tmp+2); /* skip code */ char *lslash= BLI_last_slash(base); - if (lslash) { int baselen= (int) (lslash-base) + 1; - + /* use path for for temp storage here, we copy back over it right away */ + BLI_strncpy(path, tmp+2, FILE_MAX); + memcpy(tmp, base, baselen); - strcpy(tmp+baselen, filepart); + strcpy(tmp+baselen, path); + strcpy(path, tmp); } else { - strcpy(tmp, filepart); + strcpy(path, tmp+2); } - - MEM_freeN(filepart); + } else { + strcpy(path, tmp); } - BLI_cleanup_file(NULL, tmp); - strcpy(path, tmp); + if (path[0]!='\0') { + if ( path[strlen(path)-1]=='/') { + BLI_cleanup_dir(NULL, path); + } else { + BLI_cleanup_file(NULL, path); + } + } #ifdef WIN32 /* skip first two chars, which in case of diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index dec9dbd7286..72050b0809e 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -274,7 +274,7 @@ typedef struct RenderData { /* Bake Render options */ short bake_osa, bake_filter, bake_mode, bake_flag; - short bake_normal_space, bpad; + short bake_normal_space, bake_quad_split; float bake_maxdist, bake_biasdist, bake_pad; /* yafray: global panel params. TODO: move elsewhere */ diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index b0de4bb9ba5..7db2c7a01ec 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -1181,7 +1181,7 @@ static int bpy_pydriver_create_dict(void) { PyObject *d, *mod; - if (bpy_pydriver_Dict || (G.f&G_DOSCRIPTLINKS)==0) return -1; + if (bpy_pydriver_Dict) return -1; d = PyDict_New(); if (!d) return -1; @@ -1218,15 +1218,16 @@ static int bpy_pydriver_create_dict(void) /* If there's a Blender text called pydrivers.py, import it. * Users can add their own functions to this module. */ - mod = importText("pydrivers"); /* can also use PyImport_Import() */ - if (mod) { - PyDict_SetItemString(d, "pydrivers", mod); - PyDict_SetItemString(d, "p", mod); - Py_DECREF(mod); + if (G.f&G_DOSCRIPTLINKS) { + mod = importText("pydrivers"); /* can also use PyImport_Import() */ + if (mod) { + PyDict_SetItemString(d, "pydrivers", mod); + PyDict_SetItemString(d, "p", mod); + Py_DECREF(mod); + } else { + PyErr_Clear(); + } } - else - PyErr_Clear(); - /* short aliases for some Get() functions: */ /* ob(obname) == Blender.Object.Get(obname) */ diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index 6fce0864189..6b2e00f27de 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -952,7 +952,7 @@ static PyObject *Blender_GetPaths( PyObject * self, PyObject *args, PyObject *ke if (absolute) { BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded ); } else { - BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded ); + BLI_bpathIterator_getPath( &bpi, filepath_expanded ); } st = PyString_FromString(filepath_expanded); diff --git a/source/blender/python/api2_2x/Sys.c b/source/blender/python/api2_2x/Sys.c index 3863cc12227..baae2220143 100644 --- a/source/blender/python/api2_2x/Sys.c +++ b/source/blender/python/api2_2x/Sys.c @@ -406,11 +406,12 @@ static PyObject *M_sys_cleanpath( PyObject * self, PyObject * value ) { char *path = PyString_AsString(value); char cleaned[FILE_MAXDIR + FILE_MAXFILE]; - int trailing_slash = 0; + int trailing_slash = 0, last; if (!path) return EXPP_ReturnPyObjError( PyExc_TypeError, "expected string argument" ); - if (strstr(path, "/") || strstr(path, "\\")) { + last = strlen(path)-1; + if ((last >= 0) && ((path[last]=='/') || (path[last]=='\\'))) { trailing_slash = 1; } BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE); diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c index bfad069f943..b446af7efd4 100644 --- a/source/blender/python/api2_2x/sceneRender.c +++ b/source/blender/python/api2_2x/sceneRender.c @@ -2048,7 +2048,7 @@ static int RenderData_setIValueAttrClamp( BPy_RenderData *self, PyObject *value, break; case EXPP_RENDER_ATTR_BAKEMODE: min = RE_BAKE_LIGHT; - max = RE_BAKE_DISPLACEMENT; + max = RE_BAKE_SHADOW; size = 'h'; param = &self->renderContext->bake_mode; break; @@ -3781,6 +3781,7 @@ static PyObject *M_Render_BakeModesDict( void ) PyConstant_Insert( d, "NORMALS", PyInt_FromLong( RE_BAKE_NORMALS ) ); PyConstant_Insert( d, "TEXTURE", PyInt_FromLong( RE_BAKE_TEXTURE ) ); PyConstant_Insert( d, "DISPLACEMENT", PyInt_FromLong( RE_BAKE_DISPLACEMENT ) ); + PyConstant_Insert( d, "SHADOW", PyInt_FromLong( RE_BAKE_SHADOW ) ); } return M; } diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index 66dc1dd5fef..64cf7fcb37b 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -220,6 +220,8 @@ void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize, #define RE_BAKE_NORMALS 3 #define RE_BAKE_TEXTURE 4 #define RE_BAKE_DISPLACEMENT 5 +#define RE_BAKE_SHADOW 6 + void RE_Database_Baking(struct Render *re, struct Scene *scene, int type, struct Object *actob); void RE_DataBase_GetView(struct Render *re, float mat[][4]); diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index d7e71b3e531..8414b6aefe3 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -499,6 +499,7 @@ typedef struct LampRen { #define R_NEED_TANGENT 32 #define R_SKIP_MULTIRES 64 #define R_BAKE_TRACE 128 +#define R_BAKING 256 /* vlakren->flag (vlak = face in dutch) char!!! */ #define R_SMOOTH 1 diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index dbade68ba1d..afe4c47a9a4 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -3935,7 +3935,7 @@ static void set_fullsample_flag(Render *re, ObjectRen *obr) } } -static void check_non_flat_quads(ObjectRen *obr) +static void check_non_flat_quads(ObjectRen *obr, int quad_flip) { VlakRen *vlr, *vlr1; VertRen *v1, *v2, *v3, *v4; @@ -3997,20 +3997,27 @@ static void check_non_flat_quads(ObjectRen *obr) xn= nor[0]*vlr->n[0] + nor[1]*vlr->n[1] + nor[2]*vlr->n[2]; if(ABS(xn) < 0.999995 ) { // checked on noisy fractal grid + float d1, d2; vlr1= RE_vlakren_copy(obr, vlr); vlr1->flag |= R_FACE_SPLIT; - /* split direction based on vnorms */ - CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, nor); - d1= nor[0]*vlr->v1->n[0] + nor[1]*vlr->v1->n[1] + nor[2]*vlr->v1->n[2]; + if (quad_flip==0) { /* nonzero quad_flip is used to force dividing one way */ + /* split direction based on vnorms */ + CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, nor); + d1= nor[0]*vlr->v1->n[0] + nor[1]*vlr->v1->n[1] + nor[2]*vlr->v1->n[2]; - CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, nor); - d2= nor[0]*vlr->v2->n[0] + nor[1]*vlr->v2->n[1] + nor[2]*vlr->v2->n[2]; + CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, nor); + d2= nor[0]*vlr->v2->n[0] + nor[1]*vlr->v2->n[1] + nor[2]*vlr->v2->n[2]; - if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; - else vlr->flag &= ~R_DIVIDE_24; + if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; + else vlr->flag &= ~R_DIVIDE_24; + } else if (quad_flip==1) { + vlr->flag &= ~R_DIVIDE_24; + } else { /* quad_flip == 3 */ + vlr->flag |= R_DIVIDE_24; + } /* new vertex pointers */ if (vlr->flag & R_DIVIDE_24) { @@ -4064,8 +4071,14 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) ob->smoothresh= 0.0; if((re->r.mode & R_RAYTRACE) && (re->r.mode & R_SHADOW)) set_phong_threshold(obr); - - check_non_flat_quads(obr); + + if (re->flag & R_BAKING) { + /* Baking lets us define a quad split order */ + check_non_flat_quads(obr, re->r.bake_quad_split); + } else { + check_non_flat_quads(obr, 0); + } + set_fullsample_flag(re, obr); /* compute bounding boxes for clipping */ @@ -5406,6 +5419,7 @@ void RE_Database_FromScene_Vectors(Render *re, Scene *sce) RE_BAKE_AO: for baking, no lamps, but all objects RE_BAKE_TEXTURE:for baking, no lamps, only selected objects RE_BAKE_DISPLACEMENT:for baking, no lamps, only selected objects + RE_BAKE_SHADOW: for baking, only shadows, but all objects */ void RE_Database_Baking(Render *re, Scene *scene, int type, Object *actob) { @@ -5421,6 +5435,7 @@ void RE_Database_Baking(Render *re, Scene *scene, int type, Object *actob) RE_init_threadcount(re); re->flag |= R_GLOB_NOPUNOFLIP; + re->flag |= R_BAKING; re->excludeob= actob; if(type == RE_BAKE_LIGHT) re->flag |= R_SKIP_MULTIRES; @@ -5435,6 +5450,10 @@ void RE_Database_Baking(Render *re, Scene *scene, int type, Object *actob) re->r.mode &= ~R_RAYTRACE; } + if(!actob && (type==RE_BAKE_SHADOW)) { + re->r.mode |= R_SHADOW; + } + /* setup render stuff */ re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE); @@ -5472,7 +5491,7 @@ void RE_Database_Baking(Render *re, Scene *scene, int type, Object *actob) set_node_shader_lamp_loop(shade_material_loop); /* MAKE RENDER DATA */ - nolamps= !ELEM(type, RE_BAKE_LIGHT, RE_BAKE_ALL); + nolamps= !ELEM3(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW); onlyselected= ELEM3(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT); database_init_objects(re, lay, nolamps, onlyselected, actob, 0); diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index ff31ba8a6ee..dae7b0dcd88 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2017,9 +2017,12 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int quad, int ambient_occlusion_to_diffuse(shi, shr.combined); } else { + if (bs->type==RE_BAKE_SHADOW) /* Why do shadows set the color anyhow?, ignore material color for baking */ + shi->r = shi->g = shi->b = 1.0f; + shade_input_set_shade_texco(shi); - if(!ELEM(bs->type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE)) + if(!ELEM3(bs->type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_SHADOW)) shade_samples_do_AO(ssamp); if(shi->mat->nodetree && shi->mat->use_nodes) { @@ -2070,6 +2073,10 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int quad, int shr.combined[2]= shi->b; shr.alpha = shi->alpha; } + else if(bs->type==RE_BAKE_SHADOW) { + VECCOPY(shr.combined, shr.shad); + shr.alpha = shi->alpha; + } } if(bs->rect_float) { @@ -2505,7 +2512,12 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob) memset(&handles[a], 0, sizeof(BakeShade)); handles[a].ssamp.shi[0].lay= re->scene->lay; - handles[a].ssamp.shi[0].passflag= SCE_PASS_COMBINED; + + if (type==RE_BAKE_SHADOW) { + handles[a].ssamp.shi[0].passflag= SCE_PASS_SHADOW; + } else { + handles[a].ssamp.shi[0].passflag= SCE_PASS_COMBINED; + } handles[a].ssamp.shi[0].combinedflag= ~(SCE_PASS_SPEC); handles[a].ssamp.shi[0].thread= a; handles[a].ssamp.tot= 1; diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c index b98a8c58102..3797a92f16f 100644 --- a/source/blender/src/buttons_scene.c +++ b/source/blender/src/buttons_scene.c @@ -2150,6 +2150,10 @@ static void render_panel_bake(void) "Normalized displacement value to fit the 'Dist' range" ); } + + uiDefButS(block, MENU, B_NOP, "Quad Split Order%t|Quad Split Auto%x0|Quad Split A (0,1,2) (0,2,3)%x1|Quad Split B (1,2,3) (1,3,0)%x2", + 10,10,190,20, &G.scene->r.bake_quad_split, 0, 0, 0, 0, "Method to divide quads (use A or B for external applications that use a fixed order)"); + #if 0 uiBlockBeginAlign(block); uiDefButBitS(block, TOG, R_BAKE_OSA, B_DIFF, "OSA", 10,120,190,20, &G.scene->r.bake_flag, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)"); @@ -2161,14 +2165,15 @@ static void render_panel_bake(void) uiBlockBeginAlign(block); uiDefButS(block, ROW,B_REDR,"Full Render", 210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, ""); uiDefButS(block, ROW,B_REDR,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, ""); - uiDefButS(block, ROW,B_REDR,"Normals", 210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, ""); - uiDefButS(block, ROW,B_REDR,"Textures", 210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, ""); - uiDefButS(block, ROW,B_REDR,"Displacement", 210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, ""); + uiDefButS(block, ROW,B_REDR,"Shadow", 210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_SHADOW, 0, 0, ""); + uiDefButS(block, ROW,B_REDR,"Normals", 210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, ""); + uiDefButS(block, ROW,B_REDR,"Textures", 210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, ""); + uiDefButS(block, ROW,B_REDR,"Displacement", 210,70,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, ""); uiBlockEndAlign(block); - uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear", 210,60,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking"); + uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear", 210,40,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking"); - uiDefButS(block, NUM, B_DIFF,"Margin:", 210,30,120,20,&G.scene->r.bake_filter, 0.0, 32.0, 0, 0, "Amount of pixels to extend the baked result with, as post process filter"); + uiDefButS(block, NUM, B_DIFF,"Margin:", 210,10,120,20,&G.scene->r.bake_filter, 0.0, 32.0, 0, 0, "Amount of pixels to extend the baked result with, as post process filter"); } static void render_panel_simplify(void) diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index 08cc552e709..30fcaf3ce67 100644 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -135,24 +135,23 @@ static void helpline(TransInfo *t, float *vec) getmouseco_areawin(mval); projectFloatView(t, vecrot, cent); // no overflow in extreme cases - if(cent[0]!=IS_CLIPPED) { - persp(PERSP_WIN); - - glDrawBuffer(GL_FRONT); - - BIF_ThemeColor(TH_WIRE); - - setlinestyle(3); - glBegin(GL_LINE_STRIP); - glVertex2sv(mval); - glVertex2fv(cent); - glEnd(); - setlinestyle(0); - - persp(PERSP_VIEW); - bglFlush(); // flush display for frontbuffer - glDrawBuffer(GL_BACK); - } + + persp(PERSP_WIN); + + glDrawBuffer(GL_FRONT); + + BIF_ThemeColor(TH_WIRE); + + setlinestyle(3); + glBegin(GL_LINE_STRIP); + glVertex2sv(mval); + glVertex2fv(cent); + glEnd(); + setlinestyle(0); + + persp(PERSP_VIEW); + bglFlush(); // flush display for frontbuffer + glDrawBuffer(GL_BACK); } @@ -354,8 +353,9 @@ void convertViewVec(TransInfo *t, float *vec, short dx, short dy) void projectIntView(TransInfo *t, float *vec, int *adr) { - if (t->spacetype==SPACE_VIEW3D) - project_int(vec, adr); + if (t->spacetype==SPACE_VIEW3D) { + project_int_noclip(vec, adr); + } else if(t->spacetype==SPACE_IMAGE) { float aspx, aspy, v[2]; @@ -376,8 +376,9 @@ void projectIntView(TransInfo *t, float *vec, int *adr) void projectFloatView(TransInfo *t, float *vec, float *adr) { - if (t->spacetype==SPACE_VIEW3D) - project_float(vec, adr); + if (t->spacetype==SPACE_VIEW3D) { + project_float_noclip(vec, adr); + } else if(t->spacetype==SPACE_IMAGE) { int a[2]; diff --git a/source/blender/src/view.c b/source/blender/src/view.c index c8fce0e8ea5..d63b4b366da 100644 --- a/source/blender/src/view.c +++ b/source/blender/src/view.c @@ -270,6 +270,29 @@ void project_int(float *vec, int *adr) } } +void project_int_noclip(float *vec, int *adr) +{ + float fx, fy, vec4[4]; + + VECCOPY(vec4, vec); + vec4[3]= 1.0; + + Mat4MulVec4fl(G.vd->persmat, vec4); + + if( fabs(vec4[3]) > BL_NEAR_CLIP ) { + fx = (curarea->winx/2)*(1 + vec4[0]/vec4[3]); + fy = (curarea->winy/2)*(1 + vec4[1]/vec4[3]); + + adr[0] = floor(fx); + adr[1] = floor(fy); + } + else + { + adr[0] = curarea->winx / 2; + adr[1] = curarea->winy / 2; + } +} + void project_short_noclip(float *vec, short *adr) { float fx, fy, vec4[4]; @@ -306,8 +329,28 @@ void project_float(float *vec, float *adr) Mat4MulVec4fl(G.vd->persmat, vec4); if( vec4[3]>BL_NEAR_CLIP ) { - adr[0]= (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3]; - adr[1]= (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3]; + adr[0] = (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3]; + adr[1] = (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3]; + } +} + +void project_float_noclip(float *vec, float *adr) +{ + float vec4[4]; + + VECCOPY(vec4, vec); + vec4[3]= 1.0; + + Mat4MulVec4fl(G.vd->persmat, vec4); + + if( fabs(vec4[3]) > BL_NEAR_CLIP ) { + adr[0] = (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3]; + adr[1] = (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3]; + } + else + { + adr[0] = curarea->winx / 2.0f; + adr[1] = curarea->winy / 2.0f; } } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h index a18ed038f35..3e24ee204a1 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h @@ -53,9 +53,9 @@ #elif defined(__APPLE__) # include "mac_compat_glext.h" # include <OpenGL/glext.h> -# else +#else # include <GL/glext.h> -# endif +#endif #endif #ifdef __sgi |