diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-12-31 18:48:50 +0100 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-12-31 19:17:37 +0100 |
commit | 0c1aec42f4c23dc3a0671fe95089f27047284d79 (patch) | |
tree | 27c05b971cd2074f20a719048d0c3191f165aff6 /io_scene_hl1map/__init__.py | |
parent | 64f9fbff414c6f17c2256dcd6c932b5d0c3f1380 (diff) | |
download | blender-export-hl1map-0c1aec42f4c23dc3a0671fe95089f27047284d79.tar.gz blender-export-hl1map-0c1aec42f4c23dc3a0671fe95089f27047284d79.tar.bz2 blender-export-hl1map-0c1aec42f4c23dc3a0671fe95089f27047284d79.zip |
First export plugin version
Diffstat (limited to 'io_scene_hl1map/__init__.py')
-rwxr-xr-x | io_scene_hl1map/__init__.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/io_scene_hl1map/__init__.py b/io_scene_hl1map/__init__.py new file mode 100755 index 0000000..cfe9cd2 --- /dev/null +++ b/io_scene_hl1map/__init__.py @@ -0,0 +1,128 @@ +# ##### 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 ##### + +bl_info = { + "name": "Export Half-Life 1 Tools Format (.map)", + "author": "Ludovic Pouzenc", + "version": (0, 2, 0), + "blender": (2, 79, 0), + "location": "File > Export > Half-Life 1 tools (.map)", + "description": "Export mesh to Half-Life 1 tools (.map)", + "warning": "", + #"wiki_url": "http://to.do", + "category": "Import-Export"} + +""" +Related links: +https://developer.valvesoftware.com/wiki/MAP_file_format + +Usage Notes: +Map file could be opened in Valve Hammer 3.4 editor (prefered bit windows only) +or passed to orignal's or ZLHT's compiler tools (use wine to run them on linux) + +MAP format defines solids (brushes) as a set of intersecting planes. +Planes a defined by 3 points in space (could be different from face's vertices) + +This is (very) unusual. This cannot reprents things such as : +* Concave meshes +* Non-planar faces +Existing tools that use this .map format probably don't cope with : +* ngons with n > 32 + +For now this script do : +* For each mesh in current scene +** Simplify it (remove doubles in vertices, fill holes, connect vertices to not have concave faces nor non planar faces) +** Recalc face normals to have them pointing to this outside of the mesh +* For each object in current scene that is type 'MESH' +** Take the mesh and local to world matrix +** Make a .map brush for each mesh's blender face (world coords, scaled by blender_to_map_scale_factor) +** Put AAATRIGGER texture stupidly +** Output it as part of worldspawn entity in .map + +Line termination aren't well specified, this plugin will use system default (CRLF on Win, LF on Lin...) +""" + +if "bpy" in locals(): + import importlib + if "export_hl1map" in locals(): + importlib.reload(export_hl1map) + +import bpy +from bpy.props import ( + BoolProperty, + CollectionProperty, + FloatProperty, + StringProperty, + ) +from bpy_extras.io_utils import ( + ExportHelper, + ) + +class ExportHL1MAP(bpy.types.Operator, ExportHelper): + """Export Half-Life 1 Tools Format (.map)""" + bl_idname = 'export_scene.hl1_map' + bl_label = 'Export HL1 .map' + + filename_ext = '.map' + + filter_glob = StringProperty(default='*'+filename_ext, options={'HIDDEN'}) + + use_selection = BoolProperty( + name='Selection Only', + description='Export selected objects only', + default=False, + ) + + blender_to_map_scale_factor = FloatProperty( + name='Upscaling factor', + description='Scale from blender world coordinates to map brush coordinates', + default=100, + ) + + worldspawn_props = { + 'classname': 'worldspawn', + 'sounds': 1, + 'MaxRange': 4096, + 'mapversion': 220, + 'wad': '\\half-life\\valve\\xeno.wad;\\half-life\\valve\\decals.wad;\\half-life\\valve\\halflife.wad;\\half-life\\valve\\liquids.wad' + } + + def execute(self, context): + from . import export_hl1map + keywords = self.as_keywords(ignore=('filter_glob','check_existing')) + keywords['worldspawn_props'] = self.worldspawn_props + print('export_hl1map.save(self, context, ', keywords, ')') + return export_hl1map.save(self, context, **keywords) + + + +# Add to a menu +def menu_func_export(self, context): + self.layout.operator(ExportHL1MAP.bl_idname, text="Half-Life 1 tools (.map)") + +def register(): + bpy.utils.register_module(__name__) + bpy.types.INFO_MT_file_export.append(menu_func_export) + + +def unregister(): + bpy.utils.unregister_module(__name__) + bpy.types.INFO_MT_file_export.remove(menu_func_export) + +if __name__ == "__main__": + register() |