diff --git a/tools/io_qfmap/__init__.py b/tools/io_qfmap/__init__.py index 95dd526d6..2e2fbf6db 100644 --- a/tools/io_qfmap/__init__.py +++ b/tools/io_qfmap/__init__.py @@ -52,6 +52,7 @@ from bpy_extras.io_utils import ExportHelper, ImportHelper, path_reference_mode, from bpy.app.handlers import persistent from .entityclass import EntityClassDict +from . import entity from . import import_map #from . import export_map @@ -66,6 +67,8 @@ def ecm_draw(self, context): icon = 'MESH_DATA' op = layout.operator("object.add_entity", text=item[0], icon=icon) op.entclass=item[1] + if ec.comment: + pass else: layout.menu(item[1].bl_idname) @@ -121,12 +124,14 @@ def ec_script_update(self, context): self.script_update(context) class AddEntity(bpy.types.Operator): + '''Add an entity''' bl_idname = "object.add_entity" bl_label = "Entity" entclass = StringProperty(name = "entclass") def execute(self, context): - return {'FINISHED'} + keywords = self.as_keywords() + return entity.add_entity(self, context, **keywords) class QFEntityClasses(bpy.types.PropertyGroup): wadpath = StringProperty( @@ -221,7 +226,7 @@ def menu_func_export(self, context): self.layout.operator(ExportMap.bl_idname, text="Quake map (.map)") def menu_func_add(self, context): - self.layout.menu(context.scene.qfmap.ecm.bl_idname) + self.layout.menu(context.scene.qfmap.ecm.bl_idname, icon='PLUGIN') def register(): bpy.utils.register_module(__name__) diff --git a/tools/io_qfmap/entity.py b/tools/io_qfmap/entity.py new file mode 100644 index 000000000..ce5682adf --- /dev/null +++ b/tools/io_qfmap/entity.py @@ -0,0 +1,67 @@ +# vim:ts=4:et +# ##### 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 ##### + +# + +import bpy + +def entity_box(entityclass): + name = entityclass.name + size = entityclass.size + color = entityclass.color + if name in bpy.data.meshes: + return bpy.data.meshes[name] + verts = [(size[0][0], size[0][1], size[0][2]), + (size[0][0], size[0][1], size[1][2]), + (size[0][0], size[1][1], size[0][2]), + (size[0][0], size[1][1], size[1][2]), + (size[1][0], size[0][1], size[0][2]), + (size[1][0], size[0][1], size[1][2]), + (size[1][0], size[1][1], size[0][2]), + (size[1][0], size[1][1], size[1][2])] + faces = [(0, 1, 3, 2), + (0, 2, 6, 4), + (0, 4, 5, 1), + (4, 6, 7, 5), + (6, 2, 3, 7), + (1, 5, 7, 3)] + mesh = bpy.data.meshes.new(name) + mesh.from_pydata(verts, [], faces) + mat = bpy.data.materials.new(name) + mat.diffuse_color = color + mat.use_raytrace = False + mesh.materials.append(mat) + return mesh + +def add_entity(self, context, entclass): + entity_class = context.scene.qfmap.entity_classes.entity_classes[entclass] + context.user_preferences.edit.use_global_undo = False + for obj in bpy.data.objects: + obj.select = False + if entity_class.size: + mesh = entity_box(entity_class) + else: + mesh = None + obj = bpy.data.objects.new(entity_class.name, mesh) + obj.location = context.scene.cursor_location + obj.select = True + context.scene.objects.link(obj) + bpy.context.scene.objects.active=obj + context.user_preferences.edit.use_global_undo = True + return {'FINISHED'} diff --git a/tools/io_qfmap/import_map.py b/tools/io_qfmap/import_map.py index ae7675c49..ba6a0f4b0 100644 --- a/tools/io_qfmap/import_map.py +++ b/tools/io_qfmap/import_map.py @@ -28,6 +28,7 @@ from mathutils import Vector,Matrix from .map import parse_map, MapError from .quakepal import palette from .wad import WadFile +from .entity import entity_box def parse_vector(vstr): v = vstr.split() @@ -35,34 +36,6 @@ def parse_vector(vstr): v[i] = float(v[i]) return Vector(v) -def entity_box(entityclass): - name = entityclass.name - size = entityclass.size - color = entityclass.color - if name in bpy.data.meshes: - return bpy.data.meshes[name] - verts = [(size[0][0], size[0][1], size[0][2]), - (size[0][0], size[0][1], size[1][2]), - (size[0][0], size[1][1], size[0][2]), - (size[0][0], size[1][1], size[1][2]), - (size[1][0], size[0][1], size[0][2]), - (size[1][0], size[0][1], size[1][2]), - (size[1][0], size[1][1], size[0][2]), - (size[1][0], size[1][1], size[1][2])] - faces = [(0, 1, 3, 2), - (0, 2, 6, 4), - (0, 4, 5, 1), - (4, 6, 7, 5), - (6, 2, 3, 7), - (1, 5, 7, 3)] - mesh = bpy.data.meshes.new(name) - mesh.from_pydata(verts, [], faces) - mat = bpy.data.materials.new(name) - mat.diffuse_color = color - mat.use_raytrace = False - mesh.materials.append(mat) - return mesh - def load_image(tx): if tx.name in bpy.data.images: return bpy.data.images[tx.name]