[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1979] trunk/py/scripts/addons/ io_scene_map: ported to blender 2.5x and add addon info, generally works ok now.

Campbell Barton ideasman42 at gmail.com
Fri May 27 20:05:19 CEST 2011


Revision: 1979
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1979
Author:   campbellbarton
Date:     2011-05-27 18:05:19 +0000 (Fri, 27 May 2011)
Log Message:
-----------
ported to blender 2.5x and add addon info, generally works ok now.
still need to add some operator options

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

Added Paths:
-----------
    trunk/py/scripts/addons/io_scene_map/__init__.py

Added: trunk/py/scripts/addons/io_scene_map/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_map/__init__.py	                        (rev 0)
+++ trunk/py/scripts/addons/io_scene_map/__init__.py	2011-05-27 18:05:19 UTC (rev 1979)
@@ -0,0 +1,94 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+bl_info = {
+    "name": "Quake MAP format",
+    "author": "Campbell Barton",
+    "blender": (2, 5, 7),
+    "api": 35622,
+    "location": "File > Export",
+    "description": "Export MAP brushes, nurbs surfaces, lamps and empties as map nodes",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+        "Scripts/Import-Export/Quake_MAP",
+    "tracker_url": "",
+    "support": 'OFFICIAL',
+    "category": "Import-Export"}
+
+# To support reload properly, try to access a package var, if it's there, reload everything
+if "bpy" in locals():
+    import imp
+    if "export_map" in locals():
+        imp.reload(export_map)
+
+
+import bpy
+from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
+from bpy_extras.io_utils import ExportHelper, axis_conversion
+
+
+class ExportMAP(bpy.types.Operator, ExportHelper):
+    '''Export selection to a quake map'''
+    bl_idname = "export_scene.quake_map"
+    bl_label = "Export MAP"
+    bl_options = {'PRESET'}
+
+    filename_ext = ".map"
+    filter_glob = StringProperty(default="*.map", options={'HIDDEN'})
+
+    def execute(self, context):
+        import math
+        from mathutils import Matrix
+        if not self.filepath:
+            raise Exception("filepath not set")
+
+        '''
+        global_matrix = Matrix()
+        global_matrix[0][0] = global_matrix[1][1] = global_matrix[2][2] = self.global_scale
+        global_matrix = global_matrix * axis_conversion(to_forward=self.axis_forward, to_up=self.axis_up).to_4x4()
+
+        keywords = self.as_keywords(ignore=("axis_forward", "axis_up", "global_scale", "check_existing", "filter_glob"))
+        keywords["global_matrix"] = global_matrix
+        '''
+        
+        keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
+
+        from . import export_map
+        return export_map.save(self, context, **keywords)
+        
+
+
+def menu_func(self, context):
+    self.layout.operator(ExportMAP.bl_idname, text="Quake MAP (.map)")
+
+
+def register():
+    bpy.utils.register_module(__name__)
+
+    bpy.types.INFO_MT_file_export.append(menu_func)
+
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+
+    bpy.types.INFO_MT_file_export.remove(menu_func)
+
+if __name__ == "__main__":
+    register()

Modified: trunk/py/scripts/addons/io_scene_map/export_map.py
===================================================================
--- trunk/py/scripts/addons/io_scene_map/export_map.py	2011-05-27 17:07:49 UTC (rev 1978)
+++ trunk/py/scripts/addons/io_scene_map/export_map.py	2011-05-27 18:05:19 UTC (rev 1979)
@@ -1,68 +1,61 @@
-#!BPY
-
-"""
-Name: 'Quake 3 (.map)'
-Blender: 249
-Group: 'Export'
-Tooltip: 'Export to Quake map format'
-"""
-
-__author__ = 'Campbell Barton'
-__version__ = '0.1a'
-__email__ = "ideasman42 at gmail.com"
-__bpydoc__ = """\
-This script Exports a Quake 3 map format.
-
- Supports meshes, lights and nurbs patch surfaces
-"""
-
-# ***** BEGIN GPL LICENSE BLOCK *****
+# ##### BEGIN GPL LICENSE BLOCK #####
 #
-# Script copyright (C): Campbell Barton
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-# ***** END GPL LICENCE BLOCK *****
-# --------------------------------------------------------------------------
+# ##### END GPL LICENSE BLOCK #####
 
-from Blender import *
-import BPyMesh
+# <pep8 compliant>
 
-PREF_SCALE = Draw.Create(100)
-PREF_FACE_THICK = Draw.Create(0.1)
-PREF_GRID_SNAP = Draw.Create(0)
+import bpy
+
+# TODO, make options
+PREF_SCALE = 100
+PREF_FACE_THICK = 0.1
+PREF_GRID_SNAP = False
 # Quake 1/2?
 # 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 = ' 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 = 'NULL'  # not user settable yet
+PREF_INVIS_TEX = 'common/caulk'
 
 
+def face_uv_get(face):
+    """ Workaround 2.5x change.
+    """
+    me = face.id_data
+    uv_faces = me.uv_textures.active
+    if uv_faces:
+        return uv_faces.data[face.index]
+    else:
+        return None
+
+
 def write_cube2brush(file, faces):
     '''
     Takes 6 faces and writes a brush,
     these faces can be from 1 mesh, 1 cube within a mesh of larger cubes
     Faces could even come from different meshes or be contrived.
     '''
+    import os
     # comment only
-    # file.write('// brush "%s", "%s"\n' % (ob.name, ob.getData(name_only=1)))
+    # file.write('// brush "%s", "%s"\n' % (ob.name, ob.data.name))
     file.write('// brush from cube\n{\n')
 
-    if PREF_GRID_SNAP.val:
+    if PREF_GRID_SNAP:
         format_vec = '( %d %d %d ) '
     else:
         format_vec = '( %.8f %.8f %.8f ) '
@@ -70,34 +63,29 @@
     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 % v.co[:])
+        me = f.id_data  #XXX25
+        for v in f.vertices[:][2::-1]:
+            file.write(format_vec % me.vertices[v].co[:])
 
-        try:
-            mode = f.mode
-        except:
-            mode = 0
+        uf = face_uv_get(f)
 
-        if mode & Mesh.FaceModes.INVISIBLE:
-            file.write(PREF_INVIS_TEX.val)
+        if uf and uf.hide:
+            file.write(PREF_INVIS_TEX)
         else:
-            try:
-                image = f.image
-            except:
-                image = None
+            image = uf.image if uf else None
 
             if image:
-                file.write(sys.splitext(sys.basename(image.filename))[0])
+                file.write(os.path.splitext(os.path.basename(image.filename))[0])
             else:
-                file.write(PREF_NULL_TEX.val)
+                file.write(PREF_NULL_TEX)
 
         # Texture stuff ignored for now
-        file.write(PREF_DEF_TEX_OPTS.val)
+        file.write(PREF_DEF_TEX_OPTS)
     file.write('}\n')
 
 
 def round_vec(v):
-    if PREF_GRID_SNAP.val:
+    if PREF_GRID_SNAP:
         return v.to_tuple(0)
     else:
         return v[:]
@@ -109,34 +97,34 @@
     each face is a cube/brush
     '''
 
-    if PREF_GRID_SNAP.val:
+    if PREF_GRID_SNAP:
         format_vec = '( %d %d %d ) '
     else:
         format_vec = '( %.8f %.8f %.8f ) '
 
-    image_text = PREF_NULL_TEX.val
+    image_text = PREF_NULL_TEX
 
-    try:
-        mode = face.mode
-    except:
-        mode = 0
+    uf = face_uv_get(face)
 
-    if mode & Mesh.FaceModes.INVISIBLE:
-        image_text = PREF_INVIS_TEX.val
+    if uf and uf.hide:
+        image_text = PREF_INVIS_TEX
     else:
-        try:
-            image = face.image
-        except:
-            image = None
+        image = uf.image if uf else None
+
         if image:
-            image_text = sys.splitext(sys.basename(image.filename))[0]
+            image_text = os.path.splitext(os.path.basename(image.filename))[0]
 
+    # reuse face vertices
+    _v = face.id_data.vertices  #XXX25
+    f_vertices = [_v[vi] for vi in face.vertices]
+    del _v  #XXX25
+
     # original verts as tuples for writing
-    orig_vco = [v.co[:] for v in face]
+    orig_vco = [v.co[:] for v in f_vertices]
 
     # 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]
+    dist = PREF_SCALE * PREF_FACE_THICK
+    new_vco = [round_vec(v.co - (v.normal * dist)) for v in f_vertices]
     #new_vco = [round_vec(v.co - (face.no * dist)) for v in face]
 
     file.write('// brush from face\n{\n')
@@ -145,17 +133,17 @@
         file.write(format_vec % co)
     file.write(image_text)
     # Texture stuff ignored for now
-    file.write(PREF_DEF_TEX_OPTS.val)
+    file.write(PREF_DEF_TEX_OPTS)
 
     for co in new_vco[:3]:
         file.write(format_vec % co)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list