-- Quake 1 BSP Importer for Blender --
by Andrew Palmer 2013.06 (Quake was released in 1996.06, so I'm a bit late)
email andyp.123 -at- gmail.com for help or whatever.

Thanks to Ian Cunningham (aka Slight) for his work on 0.0.5 and Blender Artists
forum member Eppo for spotting a fix when the addon broke in a later version of 
Blender. Thanks to their work, the addon work in Blender 2.75.

Usage -------------------------------------------------------------------------
1. Extract to blender scripts/addons/
2. In user settings go to addons and enable 'Import-Export: Import Quake BSP format'
3. from the File menu, select import>Quake BSP (.bsp)
4. Choose a valid Quake 1 .bsp file
5. Assuming everything worked, your scene should contain all the models in the bsp,
   though you may need to move/rotate the camera to see them.

There are several options available when importing:
+ Scale - scale down the level on import (default 0.05)
	Quake units are 64units ~ 2m (assuming Quake guy is short and stocky)
+ Create materials - enable/disable creation of materials (default on)
+ Worldspawn only - when enabled, only the first model (the worldspawn entity,
	or main level geometry) is loaded. (default off)
+ Use Cycles - Creates diffuse shader nodes for materials and sets emmision
	strength for lamps
+ Create Lamps - Creates lamps based on light in the entities list in the level. In
	cycles the brightness may require setting the Film Exposure to 5 or 6.
+ Create Spawn - Creates a camera at the info_player_start location in the entities
	list and sets the camera as the active camera.

Tips --------------------------------------------------------------------------
You might not be able to see textures, even if the viewport is in textured mode.
To fix this, press 'n' with the cursor in the viewport to open an options panel
on the right. In here, expand the display options and set shading to 'GLSL'. In
Cycles, use the 'Material' viewport shading to see textures.

It's easier to view the level with backface culling enabled. To do this, open
the display options (see above description) and check 'Backface Culling'.

Everything might be black if there is no Lamp object in the scene. To fix this,
either set the existing lamp to Hemi, add a new hemisphere lamp (Add>Lamp>Hemi)
or use the 'Create Lamps' option.

The textures will probably look like hell since they are very small by modern
standards and filtering destroys them. To see the map with nearest (non-filtered)
texturing, open the 'System' tab in Blender User Preferences (ctrl+alt+u) and
uncheck 'Mipmaps'. 

In version 0.0.5, all vertices are welded to create a seemless mesh. Note that 
this has been observed to cause texture alignment problems in some maps. If
cycles is having issues with a texture mapping, you can try triangulating the
problematic face using the 'Triangulate Face' command in edit mode.

History -----------------------------------------------------------------------
0.0.6
+ fix a small issue with uv calculation that broke the addon in Blender 2.75
0.0.5 (Ian Cunningham)
+ changed to welded vertices.
+ fixed uv calculation so that they don't rely on being in a particular order
+ create diffuse shaders with image textures for cycles node based materials
+ create lamps based on entities section
+ create a camera based on info_player_start
+ ignore broken miptex entries gracefully
0.0.4
+ fixed crash bug caused by texture names not being 0 padded in many older bsps
+ prints bsp version on import (only to terminal, most users won't even see this)
0.0.3
+ added scale option (scale geometry on import)
+ added create materials option (use textures from the bsp to create and assign materials)
+ added worldspawn only option (import just the main map geometry, not doors, triggers etc.)
0.0.2
+ now imports textures from the bsp as materials
+ uvs and materials are applied to faces
0.0.1
+ import bsp imports all models in a bsp file as objects in a blender scene

Suggestions For Improvements --------------------------------------------------
+ improve import speed
+ bsp import from pak file (by name would be fine)
+ import light map data
+ filter based on entity type model is attached to
  - don't import triggers
  - name objects by entity type
+ add option for wether to weld model vertices on import (default now is weld)
+ optionally use external textures (can do this by exporting to another format)
+ orient lava and water textures so that they face up
+ split sky textures into 2 layers

Known bugs --------------------------------------------------------------------
+ import speed is very slow on large maps (can take several minutes on very large maps)

Thanks ------------------------------------------------------------------------
+ John 'Metlslime' Fitzgibbons for the uv conversion code
+ People in #blendercoders and on blender.stackexchange.com for help
+ The people who wrote http://wiki.xentax.com/index.php?title=Blender_Import_Guide
+ The people who responded to my thread on BlenderArtists and pointed out bugs
+ The authors of http://www.gamers.org/dEngine/quake/spec
+ Everyone involved in making Quake and the Quake community


Legal crap --------------------------------------------------------------------
NOTE: This addon contains palette.lmp, which is the palette file for the game
Quake, by id software. This file is in the public domain.

#  ***** 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 3 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, see <http://www.gnu.org/licenses/>.
#  All rights reserved.
#  ***** GPL LICENSE BLOCK *****
