[Bf-extensions-cvs] [3b7cc4a] master: Re-Add Quake/Doom3 map exporter.
Bastien Montagne
noreply at git.blender.org
Sun Jul 19 18:23:41 CEST 2015
Commit: 3b7cc4a11dfa085c2da2008a8e4a85452a17ebdd
Author: Bastien Montagne
Date: Sun Jul 19 17:31:25 2015 +0200
Branches: master
https://developer.blender.org/rBAC3b7cc4a11dfa085c2da2008a8e4a85452a17ebdd
Re-Add Quake/Doom3 map exporter.
History of this code is rather fuzzy, quake part is from Campbell and scorpion81 I think,
doom part is from me.
Simpler to keep this here, since it seems there is still some interest to those stuff...
===================================================================
A io_scene_map/__init__.py
A io_scene_map/export_map.py
===================================================================
diff --git a/io_scene_map/__init__.py b/io_scene_map/__init__.py
new file mode 100644
index 0000000..b0019ce
--- /dev/null
+++ b/io_scene_map/__init__.py
@@ -0,0 +1,127 @@
+# ##### 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/Doom3 MAP format",
+ "author": "Campbell Barton, scorpion81, Bastien Montagne",
+ "version": (2, 0, 0),
+ "blender": (2, 6, 9),
+ "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.6/Py/"
+ "Scripts/Import-Export/Quake_MAP",
+ "tracker_url": "",
+ "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, FloatProperty, BoolProperty
+from bpy_extras.io_utils import ExportHelper
+
+
+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'})
+
+ doom3_format = BoolProperty(
+ name="Doom 3 Format",
+ description="Export to Doom3 MAP Format",
+ default=True)
+
+ face_thickness = FloatProperty(
+ name="Face Thickness",
+ description=("Thickness given to geometry which can't be "
+ "converted into a brush"),
+ min=0.0001, max=10.0,
+ default=0.1,
+ )
+ global_scale = FloatProperty(
+ name="Scale",
+ description="Scale everything by this value",
+ min=0.01, max=1000.0,
+ default=100.0,
+ )
+ grid_snap = BoolProperty(
+ name="Grid Snap",
+ description="Round to whole numbers",
+ default=False,
+ )
+ texture_null = StringProperty(
+ name="Tex Null",
+ description="Texture used when none is assigned",
+ default="NULL",
+ )
+ texture_opts = StringProperty(
+ name="Tex Opts",
+ description="Brush texture options",
+ default='0 0 0 1 1 0 0 0',
+ )
+
+ 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/Doom3 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()
diff --git a/io_scene_map/export_map.py b/io_scene_map/export_map.py
new file mode 100644
index 0000000..5c868d8
--- /dev/null
+++ b/io_scene_map/export_map.py
@@ -0,0 +1,620 @@
+# ##### 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 #####
+
+#http://www.pasteall.org/47943/python
+
+# <pep8-80 compliant>
+
+import bpy
+import os
+import mathutils
+from mathutils import Vector
+
+# TODO, make options
+PREF_SCALE = 1
+PREF_FACE_THICK = 0.1
+PREF_GRID_SNAP = False
+# Quake 1/2?
+# Quake 3+?
+PREF_DEF_TEX_OPTS = '0 0 0 1 1 0 0 0' # not user settable yet
+
+PREF_NULL_TEX = 'NULL' # not user settable yet
+PREF_INVIS_TEX = 'common/caulk'
+PREF_DOOM3_FORMAT = True
+
+
+def face_uv_image_get(me, face):
+ uv_faces = me.uv_textures.active
+ if uv_faces:
+ return uv_faces.data[face.index].image
+ else:
+ return None
+
+
+def face_uv_coords_get(me, face):
+ tf_uv_faces = me.tessface_uv_textures.active
+ if tf_uv_faces:
+ return tf_uv_faces.data[face.index].uv_raw[:]
+ else:
+ return None
+
+
+def face_material_get(me, face):
+ idx = face.material_index
+ return me.materials[idx] if idx < len(me.materials) else None
+
+
+def poly_to_doom(me, p, radius):
+ """
+ Convert a face into Doom3 representation (infinite plane defined by its normal
+ and distance from origin along that normal).
+ """
+ # Compute the distance to the mesh from the origin to the plane.
+ # Line from origin in the direction of the face normal.
+ origin = Vector((0, 0, 0))
+ target = Vector(p.normal) * radius
+ # Find the target point.
+ intersect = mathutils.geometry.intersect_line_plane(origin, target, Vector(p.center), Vector(p.normal))
+ # We have to handle cases where intersection with face happens on the "negative" part of the vector!
+ length = intersect.length
+ nor = p.normal.copy()
+ if (nor.dot(intersect.normalized()) > 0):
+ length *= -1
+ nor.resize_4d()
+ nor.w = length
+ return nor
+
+
+def doom_are_same_planes(p1, p2):
+ """
+ To avoid writing two planes that are nearly the same!
+ """
+ # XXX Is sign of the normal/length important in Doom for plane definition??? For now, assume that no!
+ if p1.w < 0:
+ p1 = p1 * -1.0
+ if p2.w < 0:
+ p2 = p2 * -1.0
+
+ threshold = 0.0001
+
+ if abs(p1.w - p2.w) > threshold:
+ return False
+
+ # Distances are the same, check orientations!
+ if p1.xyz.normalized().dot(p2.xyz.normalized()) < (1 - threshold):
+ return False
+
+ # Same plane!
+ return True
+
+
+def doom_check_plane(done_planes, plane):
+ """
+ Check if plane as already been handled, or is similar enough to an already handled one.
+ Return True if it has already been handled somehow.
+ done_planes is expected to be a dict {written_plane: {written_plane, similar_plane_1, similar_plane_2, ...}, ...}.
+ """
+ p_key = tuple(plane)
+ if p_key in done_planes:
+ return True
+ for p, dp in done_planes.items():
+ if p_key in dp:
+ return True
+ elif doom_are_same_planes(Vector(p), plane):
+ done_planes[p].add(p_key)
+ return True
+ done_planes[p_key] = {p_key}
+ return False
+
+
+def ob_to_radius(ob):
+ radius = max(Vector(pt).length for pt in ob.bound_box)
+
+ # Make the ray casts, go just outside the bounding sphere.
+ return radius * 1.1
+
+
+def is_cube_facegroup(faces):
+ """
+ Returns a bool, true if the faces make up a cube
+ """
+ # cube must have 6 faces
+ if len(faces) != 6:
+ # print('1')
+ return False
+
+ # Check for quads and that there are 6 unique verts
+ verts = {}
+ for f in faces:
+ f_v = f.vertices[:]
+ if len(f_v) != 4:
+ return False
+
+ for v in f_v:
+ verts[v] = 0
+
+ if len(verts) != 8:
+ return False
+
+ # Now check that each vert has 3 face users
+ for f in faces:
+ f_v = f.vertices[:]
+ for v in f_v:
+ verts[v] += 1
+
+ for v in verts.values():
+ 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
+ Returns a bool, true if the faces make an extruded tri solid
+ """
+
+ # tricyl must have 5 faces
+ if len(faces) != 5:
+ # print('1')
+ return False
+
+ # Check for quads and that there are 6 unique verts
+ verts = {}
+ tottri = 0
+ for f in faces:
+ if len(f.vertices) == 3:
+ tottri += 1
+
+ for vi in f.vertices:
+ verts[vi] = 0
+
+ if len(verts) != 6 or tottri != 2:
+ return False
+
+ # Now check that each vert has 3 face users
+ for f in faces:
+ for vi in f.vertices:
+ verts[vi] += 1
+
+ for v in verts.values():
+ if v != 3: # vert has 3 u
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list