[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1978] trunk/py/scripts/addons/ io_scene_map/export_map.py: python3 & pep8 edits

Campbell Barton ideasman42 at gmail.com
Fri May 27 19:07:49 CEST 2011


Revision: 1978
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1978
Author:   campbellbarton
Date:     2011-05-27 17:07:49 +0000 (Fri, 27 May 2011)
Log Message:
-----------
python3 & pep8 edits

Modified Paths:
--------------
    trunk/py/scripts/addons/io_scene_map/export_map.py

Modified: trunk/py/scripts/addons/io_scene_map/export_map.py
===================================================================
--- trunk/py/scripts/addons/io_scene_map/export_map.py	2011-05-27 16:40:25 UTC (rev 1977)
+++ trunk/py/scripts/addons/io_scene_map/export_map.py	2011-05-27 17:07:49 UTC (rev 1978)
@@ -37,23 +37,21 @@
 # ***** END GPL LICENCE BLOCK *****
 # --------------------------------------------------------------------------
 
-
-
-
 from Blender import *
 import BPyMesh
 
-PREF_SCALE= Draw.Create(100)
-PREF_FACE_THICK= Draw.Create(0.1)
-PREF_GRID_SNAP= Draw.Create(0)
+PREF_SCALE = Draw.Create(100)
+PREF_FACE_THICK = Draw.Create(0.1)
+PREF_GRID_SNAP = Draw.Create(0)
 # Quake 1/2?
-# PREF_DEF_TEX_OPTS= Draw.Create(' 0 0 0 1 1\n') # not user settable yet
+# PREF_DEF_TEX_OPTS = Draw.Create(' 0 0 0 1 1\n') # not user settable yet
 # Quake 3+?
-PREF_DEF_TEX_OPTS= Draw.Create(' 0 0 0 1 1 0 0 0\n') # not user settable yet
+PREF_DEF_TEX_OPTS = Draw.Create(' 0 0 0 1 1 0 0 0\n')  # not user settable yet
 
-PREF_NULL_TEX= Draw.Create('NULL') # not user settable yet
-PREF_INVIS_TEX= Draw.Create('common/caulk')
+PREF_NULL_TEX = Draw.Create('NULL')  # not user settable yet
+PREF_INVIS_TEX = Draw.Create('common/caulk')
 
+
 def write_cube2brush(file, faces):
     '''
     Takes 6 faces and writes a brush,
@@ -64,26 +62,34 @@
     # file.write('// brush "%s", "%s"\n' % (ob.name, ob.getData(name_only=1)))
     file.write('// brush from cube\n{\n')
 
-    if PREF_GRID_SNAP.val:      format_vec= '( %d %d %d ) '
-    else:                       format_vec= '( %.8f %.8f %.8f ) '
+    if PREF_GRID_SNAP.val:
+        format_vec = '( %d %d %d ) '
+    else:
+        format_vec = '( %.8f %.8f %.8f ) '
 
     for f in faces:
         # from 4 verts this gets them in reversed order and only 3 of them
         # 0,1,2,3 -> 2,1,0
         for v in f.v[2::-1]:
-            file.write(format_vec % tuple(v.co) )
+            file.write(format_vec % v.co[:])
 
-        try:    mode= f.mode
-        except: mode= 0
+        try:
+            mode = f.mode
+        except:
+            mode = 0
 
         if mode & Mesh.FaceModes.INVISIBLE:
             file.write(PREF_INVIS_TEX.val)
         else:
-            try:    image= f.image
-            except: image= None
+            try:
+                image = f.image
+            except:
+                image = None
 
-            if image:   file.write(sys.splitext(sys.basename(image.filename))[0])
-            else:       file.write(PREF_NULL_TEX.val)
+            if image:
+                file.write(sys.splitext(sys.basename(image.filename))[0])
+            else:
+                file.write(PREF_NULL_TEX.val)
 
         # Texture stuff ignored for now
         file.write(PREF_DEF_TEX_OPTS.val)
@@ -92,51 +98,57 @@
 
 def round_vec(v):
     if PREF_GRID_SNAP.val:
-        return round(v.x), round(v.y), round(v.z)
+        return v.to_tuple(0)
     else:
-        return tuple(v)
+        return v[:]
 
+
 def write_face2brush(file, face):
     '''
     takes a face and writes it as a brush
     each face is a cube/brush
     '''
 
-    if PREF_GRID_SNAP.val:      format_vec= '( %d %d %d ) '
-    else:                       format_vec= '( %.8f %.8f %.8f ) '
+    if PREF_GRID_SNAP.val:
+        format_vec = '( %d %d %d ) '
+    else:
+        format_vec = '( %.8f %.8f %.8f ) '
 
+    image_text = PREF_NULL_TEX.val
 
-    image_text= PREF_NULL_TEX.val
+    try:
+        mode = face.mode
+    except:
+        mode = 0
 
-    try:    mode= face.mode
-    except: mode= 0
-
     if mode & Mesh.FaceModes.INVISIBLE:
-        image_text= PREF_INVIS_TEX.val
+        image_text = PREF_INVIS_TEX.val
     else:
-        try:    image= face.image
-        except: image= None
-        if image:   image_text = sys.splitext(sys.basename(image.filename))[0]
+        try:
+            image = face.image
+        except:
+            image = None
+        if image:
+            image_text = sys.splitext(sys.basename(image.filename))[0]
 
     # original verts as tuples for writing
-    orig_vco= [tuple(v.co) for v in face]
+    orig_vco = [v.co[:] for v in face]
 
     # new verts that give the face a thickness
-    dist= PREF_SCALE.val * PREF_FACE_THICK.val
-    new_vco= [round_vec(v.co - (v.no * dist)) for v in face]
-    #new_vco= [round_vec(v.co - (face.no * dist)) for v in face]
+    dist = PREF_SCALE.val * PREF_FACE_THICK.val
+    new_vco = [round_vec(v.co - (v.no * dist)) for v in face]
+    #new_vco = [round_vec(v.co - (face.no * dist)) for v in face]
 
     file.write('// brush from face\n{\n')
     # front
     for co in orig_vco[2::-1]:
-        file.write(format_vec % co )
+        file.write(format_vec % co)
     file.write(image_text)
     # Texture stuff ignored for now
     file.write(PREF_DEF_TEX_OPTS.val)
 
-
     for co in new_vco[:3]:
-        file.write(format_vec % co )
+        file.write(format_vec % co)
     if mode & Mesh.FaceModes.TWOSIDE:
         file.write(image_text)
     else:
@@ -146,36 +158,37 @@
     file.write(PREF_DEF_TEX_OPTS.val)
 
     # sides.
-    if len(orig_vco)==3: # Tri, it seemms tri brushes are supported.
-        index_pairs= ((0,1), (1,2), (2,0))
+    if len(orig_vco) == 3:  # Tri, it seemms tri brushes are supported.
+        index_pairs = ((0, 1), (1, 2), (2, 0))
     else:
-        index_pairs= ((0,1), (1,2), (2,3), (3,0))
+        index_pairs = ((0, 1), (1, 2), (2, 3), (3, 0))
 
     for i1, i2 in index_pairs:
         for co in orig_vco[i1], orig_vco[i2], new_vco[i2]:
-            file.write( format_vec %  co )
+            file.write(format_vec % co)
         file.write(PREF_INVIS_TEX.val)
         file.write(PREF_DEF_TEX_OPTS.val)
 
     file.write('}\n')
 
+
 def is_cube_facegroup(faces):
     '''
     Returens a bool, true if the faces make up a cube
     '''
     # cube must have 6 faces
     if len(faces) != 6:
-        print '1'
+        # print('1')
         return False
 
     # Check for quads and that there are 6 unique verts
-    verts= {}
+    verts = {}
     for f in faces:
-        if len(f)!= 4:
+        if len(f) != 4:
             return False
 
         for v in f:
-            verts[v.index]= 0
+            verts[v.index] = 0
 
     if len(verts) != 8:
         return False
@@ -186,12 +199,13 @@
             verts[v.index] += 1
 
     for v in verts.itervalues():
-        if v != 3: # vert has 3 users?
+        if v != 3:  # vert has 3 users?
             return False
 
     # Could we check for 12 unique edges??, probably not needed.
     return True
 
+
 def is_tricyl_facegroup(faces):
     '''
     is the face group a tri cylinder
@@ -200,18 +214,18 @@
 
     # cube must have 5 faces
     if len(faces) != 5:
-        print '1'
+        #  print('1')
         return False
 
     # Check for quads and that there are 6 unique verts
-    verts= {}
-    tottri= 0
+    verts = {}
+    tottri = 0
     for f in faces:
-        if len(f)== 3:
-            tottri+=1
+        if len(f) == 3:
+            tottri += 1
 
         for v in f:
-            verts[v.index]= 0
+            verts[v.index] = 0
 
     if len(verts) != 6 or tottri != 2:
         return False
@@ -222,24 +236,25 @@
             verts[v.index] += 1
 
     for v in verts.itervalues():
-        if v != 3: # vert has 3 users?
+        if v != 3:  # vert has 3 users?
             return False
 
     # Could we check for 12 unique edges??, probably not needed.
     return True
 
+
 def write_node_map(file, ob):
     '''
     Writes the properties of an object (empty in this case)
     as a MAP node as long as it has the property name - classname
     returns True/False based on weather a node was written
     '''
-    props= [(p.name, p.data) for p in ob.game_properties]
+    props = [(p.name, p.data) for p in ob.game_properties]
 
-    IS_MAP_NODE= False
+    IS_MAP_NODE = False
     for name, value in props:
-        if name=='classname':
-            IS_MAP_NODE= True
+        if name == "classname":
+            IS_MAP_NODE = True
             break
 
     if not IS_MAP_NODE:
@@ -250,15 +265,20 @@
     for name_value in props:
         file.write('"%s" "%s"\n' % name_value)
     if PREF_GRID_SNAP.val:
-        file.write('"origin" "%d %d %d"\n' % tuple([round(axis*PREF_SCALE.val) for axis in ob.getLocation('worldspace')]) )
+        file.write('"origin" "%d %d %d"\n' %
+                   tuple([round(axis * PREF_SCALE.val)
+                          for axis in ob.getLocation('worldspace')]))
     else:
-        file.write('"origin" "%.6f %.6f %.6f"\n' % tuple([axis*PREF_SCALE.val for axis in ob.getLocation('worldspace')]) )
+        file.write('"origin" "%.6f %.6f %.6f"\n' %
+                   tuple([axis * PREF_SCALE.val
+                          for axis in ob.getLocation('worldspace')]))
+
     file.write('}\n')
     return True
 
 
 def export_map(filepath):
-
+    """
     pup_block = [\
     ('Scale:', PREF_SCALE, 1, 1000, 'Scale the blender scene by this value.'),\
     ('Face Width:', PREF_FACE_THICK, 0.01, 10, 'Thickness of faces exported as brushes.'),\
@@ -271,31 +291,35 @@
 
     if not Draw.PupBlock('map export', pup_block):
         return
+    """
 
     Window.WaitCursor(1)
-    time= sys.time()
-    print 'Map Exporter 0.0'
-    file= open(filepath, 'w')
+    time = sys.time()
+    print("Map Exporter 0.0")
+    file = open(filepath, 'w')
 
+    obs_mesh = []
+    obs_lamp = []
+    obs_surf = []
+    obs_empty = []
 
-    obs_mesh= []
-    obs_lamp= []
-    obs_surf= []
-    obs_empty= []
+    SCALE_MAT = Mathutils.Matrix()
+    SCALE_MAT[0][0] = SCALE_MAT[1][1] = SCALE_MAT[2][2] = PREF_SCALE.val
 
-    SCALE_MAT= Mathutils.Matrix()
-    SCALE_MAT[0][0]= SCALE_MAT[1][1]= SCALE_MAT[2][2]= PREF_SCALE.val
+    dummy_mesh = Mesh.New()
 
-    dummy_mesh= Mesh.New()
+    TOTBRUSH = TOTLAMP = TOTNODE = 0
 
-    TOTBRUSH= TOTLAMP= TOTNODE= 0
-
     for ob in Object.GetSelected():
-        type= ob.type
-        if type == 'Mesh':      obs_mesh.append(ob)
-        elif type == 'Surf':    obs_surf.append(ob)
-        elif type == 'Lamp':    obs_lamp.append(ob)
-        elif type == 'Empty':   obs_empty.append(ob)
+        type = ob.type
+        if type == 'Mesh':
+            obs_mesh.append(ob)
+        elif type == 'Surf':
+            obs_surf.append(ob)
+        elif type == 'Lamp':
+            obs_lamp.append(ob)
+        elif type == 'Empty':
+            obs_empty.append(ob)
 
     if obs_mesh or obs_surf:
         # brushes and surf's must be under worldspan
@@ -303,22 +327,19 @@
         file.write('{\n')

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list