Add io_mesh_qfmdl_blubs

This commit is contained in:
unknown 2022-02-08 21:42:02 -05:00
parent 05f34cc0ee
commit a57f2f5e55
16 changed files with 2788 additions and 1 deletions

View file

@ -6,4 +6,5 @@
This repository is designated toward misc. tools and scripts to assist in development of the project but are not necessarily required. This repository is designated toward misc. tools and scripts to assist in development of the project but are not necessarily required.
## "Modules" ## "Modules"
* `fteqw-docker`: a raw `Dockerfile` aiming to build [FTEQW](https://github.com/nzp-team/fteqw) on most platforms. An image is also available on [Docker Hub](https://hub.docker.com/r/motolegacy/fteqw). * `fteqw-docker`: A raw `Dockerfile` aiming to build [FTEQW](https://github.com/nzp-team/fteqw) on most platforms. An image is also available on [Docker Hub](https://hub.docker.com/r/motolegacy/fteqw).
* `io_mesh_qfmdl_blubs`: A modified version of the [io_mesh_qfmdl](https://github.com/robrohan/blender_ie_quake_mdl) Blender MDL plugin to support restricting the boundaries of the vertex grid and mitigate vertex swimming, made by Blubs.

2
io_mesh_qfmdl_blubs/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.DS_Store
__pycache__

339
io_mesh_qfmdl_blubs/LICENSE Normal file
View file

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View file

@ -0,0 +1,29 @@
For more information about the vanilla plugin features, check out the original [io_mesh_qfmdl](https://github.com/robrohan/blender_ie_quake_mdl) Blender MDL plugin.
## Demo
![](img/demo_ppsh.webp)
## Usage
![](img/ui.webp)
This plugin modification adds 2 extra 3D Vector settings to Object Properties. These vectors define a rectangular bounding box that forms around the mesh. Upon export, any vertices that are set to leave these bounds will instead cling to the edge, mitigating vertex swimming as a result of a large difference in position per vertex per frame.
These bounding vector points are relative to the 3D Grid in the Blender view, and are in no way correlated to Quake client-view positioning. This makes the Grid a beneficial tool for determining the points used to form your bounding box.
<center>
<img src="img/out_of_bounds_vertices.webp" height="400"/>
<i>Example of vertices reaching the end of their bounding box</i>
<br>
<br>
<br>
</center>
## Export Example
![](img/export_ppsh.webp)
It is important to note this feature may only be valuable in very niche viewmodel cases, as projects that allow Field of View customization are likely to have the effect of the animation continuing off-camera broken by the end user.

View file

@ -0,0 +1,277 @@
# 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 #####
# copied from io_scene_obj
# <pep8 compliant>
bl_info = {
"name": "Quake MDL format",
"author": "Bill Currie, Aleksander Marhall",
"version": (0, 7, 0),
"blender": (2, 80, 0),
"api": 35622,
"location": "File > Import-Export",
"description": "Import-Export Quake MDL (version 6) files. (.mdl)",
"warning": "still work in progress",
"wiki_url": "",
"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 "import_mdl" in locals():
imp.reload(import_mdl)
if "export_mdl" in locals():
imp.reload(export_mdl)
import bpy
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
from bpy.props import FloatVectorProperty, PointerProperty
from bpy_extras.io_utils import ExportHelper, ImportHelper, path_reference_mode, axis_conversion
PALETTE=(
('PAL_QUAKE', "Quake", "Quake palette"),
('PAL_HEXEN2', "Hexen 2", "Hexen 2 palette"),
#('PAL_CUSTOM', "Custom", "Custom palette from file"),
)
SYNCTYPE=(
('ST_SYNC', "Syncronized", "Automatic animations are all together"),
('ST_RAND', "Random", "Automatic animations have random offsets"),
)
EFFECTS=(
('EF_NONE', "None", "No effects"),
('EF_ROCKET', "Rocket", "Leave a rocket trail"),
('EF_GRENADE', "Grenade", "Leave a grenade trail"),
('EF_GIB', "Gib", "Leave a trail of blood"),
('EF_TRACER', "Tracer", "Green split trail"),
('EF_ZOMGIB', "Zombie Gib", "Leave a smaller blood trail"),
('EF_TRACER2', "Tracer 2", "Orange split trail + rotate"),
('EF_TRACER3', "Tracer 3", "Purple split trail"),
)
class QFMDLSettings(bpy.types.PropertyGroup):
palette : EnumProperty(
items=PALETTE,
name="Palette",
description="Palette")
eyeposition : FloatVectorProperty(
name="Eye Position",
description="View possion relative to object origin")
synctype : EnumProperty(
items=SYNCTYPE,
name="Sync Type",
description="Add random time offset for automatic animations")
rotate : BoolProperty(
name="Rotate",
description="Rotate automatically (for pickup items)")
effects : EnumProperty(
items=EFFECTS,
name="Effects",
description="Particle trail effects")
#doesn't work :(
#script = PointerProperty(
# type=bpy.types.Object,
# name="Script",
# description="Script for animating frames and skins")
xform : BoolProperty(
name="Auto transform",
description="Auto-apply location/rotation/scale when exporting",
default=True)
md16 : BoolProperty(
name="16-bit",
description="16 bit vertex coordinates: QuakeForge only")
xform : BoolProperty(
name="Auto transform",
description="Auto-apply location/rotation/scale when exporting",
default=True)
# md16 : BoolProperty(
# name="16-bit",
# description="16 bit vertex coordinates: QuakeForge only")
#script = StringProperty(
# name="Script",
# description="Script for animating frames and skins")
mdl_scale_mins : FloatVectorProperty(
name="MDL Mins",
default=(-400.0,-100.0,-100.0),
description="Minimum allowed vertex coordinates")
mdl_scale_maxs : FloatVectorProperty(
name="MDL Maxs",
default=(100.0,100.0,100.0),
description="Maximum allowed vertex coordinates")
class ImportMDL6(bpy.types.Operator, ImportHelper):
'''Load a Quake MDL (v6) File'''
bl_idname = "import_mesh.quake_mdl_v6"
bl_label = "Import MDL"
bl_options = {'PRESET'}
filename_ext = ".mdl"
filter_glob : StringProperty(default="*.mdl", options={'HIDDEN'})
palette : EnumProperty(
items=PALETTE,
name="Palette",
description="Palette")
def execute(self, context):
from . import import_mdl
keywords = self.as_keywords (ignore=("filter_glob",))
return import_mdl.import_mdl(self, context, **keywords)
class ExportMDL6(bpy.types.Operator, ExportHelper):
'''Save a Quake MDL (v6) File'''
bl_idname = "export_mesh.quake_mdl_v6"
bl_label = "Export MDL"
bl_options = {'PRESET'}
filename_ext = ".mdl"
filter_glob : StringProperty(default="*.mdl", options={'HIDDEN'})
palette : EnumProperty(
items=PALETTE,
name="Palette",
description="Palette")
eyeposition : FloatVectorProperty(
name="Eye Position",
description="View possion relative to object origin")
#default = bpy.context.active_object.qfmdl.eyeposition)
synctype : EnumProperty(
items=SYNCTYPE,
name="Sync Type",
description="Add random time offset for automatic animations")
rotate : BoolProperty(
name="Rotate",
description="Rotate automatically (for pickup items)",
default=False)
effects : EnumProperty(
items=EFFECTS,
name="Effects",
description="Particle trail effects")
xform : BoolProperty(
name="Auto transform",
description="Auto-apply location/rotation/scale when exporting",
default=True)
md16 : BoolProperty(
name="16-bit",
description="16 bit vertex coordinates: QuakeForge only")
mdl_scale_mins : FloatVectorProperty(
name="MDL Mins",
default=(-100.0,-100.0,-100.0),
# default = bpy.context.active_object.qfmdl.mdl_scale_mins,
description="Minimum allowed vertex coordinates")
mdl_scale_maxs : FloatVectorProperty(
name="MDL Maxs",
default=(100.0,100.0,100.0),
# default = bpy.context.active_object.qfmdl.mdl_scale_maxs,
description="Maximum allowed vertex coordinates")
@classmethod
def poll(cls, context):
return (context.active_object != None
and type(context.active_object.data) == bpy.types.Mesh)
def execute(self, context):
from . import export_mdl
keywords = self.as_keywords (ignore=("check_existing", "filter_glob"))
return export_mdl.export_mdl(self, context, **keywords)
def invoke(self, context, event):
# self.eyeposition = bpy.context.active_object.qfmdl.eyeposition
self.mdl_scale_mins = bpy.context.active_object.qfmdl.mdl_scale_mins
self.mdl_scale_maxs = bpy.context.active_object.qfmdl.mdl_scale_maxs
return ExportHelper.invoke(self,context,event)
# return {"RUNNING_MODAL"}
# return {'FINISHED'}
class OBJECT_PT_MDLPanel(bpy.types.Panel):
bl_label = "MDL Properties"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'object'
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == 'MESH'
def draw_header(self, context):
layout = self.layout
obj = context.object
# layout.prop(obj, "select", text="")
def draw(self, context):
layout = self.layout
obj = context.active_object
layout.prop(obj.qfmdl, "palette")
layout.prop(obj.qfmdl, "eyeposition")
layout.prop(obj.qfmdl, "synctype")
layout.prop(obj.qfmdl, "rotate")
layout.prop(obj.qfmdl, "effects")
# layout.prop(obj.qfmdl, "script")
layout.prop(obj.qfmdl, "xform")
layout.prop(obj.qfmdl, "md16")
layout.prop(obj.qfmdl, "mdl_scale_mins")
layout.prop(obj.qfmdl, "mdl_scale_maxs")
def menu_func_import(self, context):
self.layout.operator(ImportMDL6.bl_idname, text="Quake MDL (.mdl)")
def menu_func_export(self, context):
self.layout.operator(ExportMDL6.bl_idname, text="Quake MDL (.mdl)")
classes = (
QFMDLSettings,
OBJECT_PT_MDLPanel,
ImportMDL6,
ExportMDL6
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Object.qfmdl = PointerProperty(type=QFMDLSettings)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()

View file

@ -0,0 +1,417 @@
# 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 #####
# <pep8 compliant>
import bpy
from bpy_extras.object_utils import object_data_add
from mathutils import Vector,Matrix
from .qfplist import pldata, PListError
from .quakepal import quakepal
from .hexen2pal import hexen2pal
from .quakenorm import map_normal
from .mdl import MDL
from .__init__ import SYNCTYPE, EFFECTS
def check_faces(mesh):
#Check that all faces are tris because mdl does not support anything else.
#Because the diagonal on which a quad is split can make a big difference,
#quad to tri conversion will not be done automatically.
faces_ok = True
save_select = []
for f in mesh.polygons:
save_select.append(f.select)
f.select = False
if len(f.vertices) > 3:
f.select = True
faces_ok = False
if not faces_ok:
mesh.update()
return False
#reset selection to what it was before the check.
for f, s in map(lambda x, y: (x, y), mesh.polygons, save_select):
f.select = s
mesh.update()
return True
def convert_image(image, palette):
if(palette == 0):
pal = quakepal
else:
pal = hexen2pal
size = image.size
skin = MDL.Skin()
skin.type = 0
skin.pixels = bytearray(size[0] * size[1]) # preallocate
cache = {}
pixels = image.pixels[:]
for y in range(size[1]):
for x in range(size[0]):
outind = y * size[0] + x
# quake textures are top to bottom, but blender images
# are bottom to top
inind = ((size[1] - 1 - y) * size[0] + x) * 4
rgb = pixels[inind : inind + 3] # ignore alpha
rgb = tuple(map(lambda x: int(x * 255 + 0.5), rgb))
if rgb not in cache:
best = (3*256*256, -1)
for i, p in enumerate(pal):
if i > 255: # should never happen
break
r = 0
for x in map(lambda a, b: (a - b) ** 2, rgb, p):
r += x
if r < best[0]:
best = (r, i)
cache[rgb] = best[1]
skin.pixels[outind] = cache[rgb]
return skin
def null_skin(size):
skin = MDL.Skin()
skin.type = 0
skin.pixels = bytearray(size[0] * size[1]) # black skin
return skin
def active_uv(mesh):
for uvt in mesh.uv_layers:
if uvt.active:
return uvt
return None
def make_skin(operator, mdl, mesh):
uvt = active_uv(mesh)
mdl.skinwidth, mdl.skinheight = (4, 4)
skin = null_skin((mdl.skinwidth, mdl.skinheight))
materials = bpy.context.object.data.materials
if len(materials) > 0:
for mat in materials:
allTextureNodes = list(filter(lambda node: node.type == "TEX_IMAGE", mat.node_tree.nodes))
if len(allTextureNodes) > 1: #=== skingroup
skingroup = MDL.Skin()
skingroup.type = 1
skingroup.skins = []
skingroup.times = []
sortedNodes = list(allTextureNodes)
sortedNodes.sort(key=lambda x: x.location[1], reverse=True)
for node in sortedNodes:
if node.type == "TEX_IMAGE":
image = node.image
mdl.skinwidth, mdl.skinheight = image.size
skin = convert_image(image,mdl.palette)
skingroup.skins.append(skin)
skingroup.times.append(0.1) # hardcoded at the moment
mdl.skins.append(skingroup)
elif len(allTextureNodes) == 1: #=== single skin
for node in allTextureNodes:
if node.type == "TEX_IMAGE":
image = node.image
mdl.skinwidth, mdl.skinheight = image.size
skin = convert_image(image,mdl.palette)
mdl.skins.append(skin)
else:
mdl.skins.append(skin) # add empty skin - no texture nodes
else:
mdl.skins.append(skin) # add empty skin - no materials
'''
if (uvt and uvt.data and uvt.data[0].image):
image = uvt.data[0].image
if (uvt.data[0].image.size[0] and uvt.data[0].image.size[1]):
mdl.skinwidth, mdl.skinheight = image.size
skin = convert_image(image)
else:
operator.report({'WARNING'},
"Texture '%s' invalid (missing?)." % image.name)
mdl.skins.append(skin)
'''
def build_tris(mesh):
# mdl files have a 1:1 relationship between stverts and 3d verts.
# a bit sucky, but it does allow faces to take less memory
#
# modelgen's algorithm for generating UVs is very efficient in that no
# vertices are duplicated (thanks to the onseam flag), but it can result
# in fairly nasty UV layouts, and worse: the artist has no control over
# the layout. However, there seems to be nothing in the mdl format
# preventing the use of duplicate 3d vertices to allow complete freedom
# of the UV layout.
uvfaces = mesh.uv_layers.active.data
stverts = []
tris = []
vertmap = [] # map mdl vert num to blender vert num (for 3d verts)
vuvdict = {}
for face in mesh.polygons:
fv = list(face.vertices)
uv = uvfaces[face.loop_start:face.loop_start + face.loop_total]
uv = list(map(lambda a: a.uv, uv))
face_tris = []
for i in range(1, len(fv) - 1):
# blender's and quake's vertex order are opposed
face_tris.append([(fv[0], tuple(uv[0])),
(fv[i + 1], tuple(uv[i + 1])),
(fv[i], tuple(uv[i]))])
for ft in face_tris:
tv = []
for vuv in ft:
if vuv not in vuvdict:
vuvdict[vuv] = len(stverts)
vertmap.append(vuv[0])
stverts.append(vuv[1])
tv.append(vuvdict[vuv])
tris.append(MDL.Tri(tv))
return tris, stverts, vertmap
def convert_stverts(mdl, stverts):
for i, st in enumerate(stverts):
s, t = st
# quake textures are top to bottom, but blender images
# are bottom to top
s = round(s * (mdl.skinwidth - 1) + 0.5)
t = round((1 - t) * (mdl.skinheight - 1) + 0.5)
# ensure st is within the skin
s = ((s % mdl.skinwidth) + mdl.skinwidth) % mdl.skinwidth
t = ((t % mdl.skinheight) + mdl.skinheight) % mdl.skinheight
stverts[i] = MDL.STVert((s, t))
def make_frame(mesh, vertmap, idx):
frame = MDL.Frame()
frame.name = "frame" + str(idx)
if bpy.context.object.data.shape_keys:
shape_keys_amount = len(bpy.context.object.data.shape_keys.key_blocks)
if shape_keys_amount > idx:
frame.name = bpy.context.object.data.shape_keys.key_blocks[idx].name
for v in vertmap:
mv = mesh.vertices[v]
vert = MDL.Vert(tuple(mv.co), map_normal(mv.normal))
frame.add_vert(vert)
return frame
def scale_verts(mdl,mdl_scale_mins,mdl_scale_maxs):
tf = MDL.Frame()
for f in mdl.frames:
tf.add_frame(f, 0.0) # let the frame class do the dirty work for us
tf.clamp_to_bounds(mdl_scale_mins, mdl_scale_maxs)
size = Vector(tf.maxs) - Vector(tf.mins)
rsqr = tuple(map(lambda a, b: max(abs(a), abs(b)) ** 2, tf.mins, tf.maxs))
mdl.boundingradius = (rsqr[0] + rsqr[1] + rsqr[2]) ** 0.5
mdl.scale_origin = tf.mins
mdl.scale = tuple(map(lambda x: x / 255.0, size))
for f in mdl.frames:
f.clamp_to_bounds(mdl_scale_mins, mdl_scale_maxs)
f.scale(mdl)
def calc_average_area(mdl):
frame = mdl.frames[0]
if frame.type:
frame = frame.frames[0]
totalarea = 0.0
for tri in mdl.tris:
verts = tuple(map(lambda i: frame.verts[i], tri.verts))
a = Vector(verts[0].r) - Vector(verts[1].r)
b = Vector(verts[2].r) - Vector(verts[1].r)
c = a.cross(b)
totalarea += (c @ c) ** 0.5 / 2.0
return totalarea / len(mdl.tris)
def get_properties(
operator,
mdl,
palette,
eyeposition,
synctype,
rotate,
effects,
xform,
md16,
mdl_scale_mins,
mdl_scale_maxs):
mdl.palette = MDL.PALETTE[palette]
mdl.eyeposition = eyeposition
mdl.synctype = MDL.SYNCTYPE[synctype]
mdl.flags = ((rotate and MDL.EF_ROTATE or 0)
| MDL.EFFECTS[effects])
if md16:
mdl.ident = "MD16"
script = None
mdl.script = None
'''
#tomporarily disabled
#script = obj.qfmdl.script
if script:
try:
script = bpy.data.texts[script].as_string()
except KeyError:
operator.report({'ERROR'},
"Script '%s' not found." % script)
return False
pl = pldata(script)
try:
mdl.script = pl.parse()
except PListError as err:
operator.report({'ERROR'}, "Script error: %s." % err)
return False
'''
return True
def process_skin(mdl, skin, ingroup=False):
if 'skins' in skin:
if ingroup:
raise ValueError("nested skin group")
intervals=['0.0']
if 'intervals' in skin:
intervals += list(skin['intervals'])
intervals = list(map(lambda x: float(x), intervals))
while len(intervals) < len(skin['skins']):
intervals.append(intervals[-1] + 0.1)
sk = MDL.Skin()
sk.type = 1
sk.times = intervals[1:len(skin['skins']) + 1]
sk.skins = []
for s in skin['skins']:
sk.skins.append(process_skin(mdl, s, True))
return sk
else:
#FIXME error handling
name = skin['name']
image = bpy.data.images[name]
if hasattr(mdl, 'skinwidth'):
if (mdl.skinwidth != image.size[0]
or mdl.skinheight != image.size[1]):
raise ValueError("%s: different skin size (%d %d) (%d %d)"
% (name, mdl.skinwidth, mdl.skinheight,
int(image.size[0]), int(image.size[1])))
else:
mdl.skinwidth, mdl.skinheight = image.size
sk = convert_image(image, mdl.palette)
return sk
def process_frame(mdl, scene, frame, vertmap, ingroup = False,
frameno = None, name = 'frame'):
sc = bpy.context.scene
if frameno == None:
frameno = scene.frame_current + scene.frame_subframe
if 'frameno' in frame:
frameno = float(frame['frameno'])
if 'name' in frame:
name = frame['name']
if 'frames' in frame:
if ingroup:
raise ValueError("nested frames group")
intervals=['0.0']
if 'intervals' in frame:
intervals += list(frame['intervals'])
intervals = list(map(lambda x: float(x), intervals))
while len(intervals) < len(frame['frames']) + 1:
intervals.append(intervals[-1] + 0.1)
fr = MDL.Frame()
for i, f in enumerate(frame['frames']):
fr.add_frame(process_frame(mdl, scene, f, vertmap, True,
frameno + i, name + str(i + 1)),
intervals[i + 1])
if 'intervals' in frame:
return fr
mdl.frames += fr.frames[:-1]
return fr.frames[-1]
scene.frame_set(int(frameno), frameno - int(frameno))
mesh = mdl.obj.to_mesh(scene, True, 'PREVIEW') #wysiwyg?
if mdl.obj.qfmdl.xform:
mesh.transform(mdl.obj.matrix_world)
fr = make_frame(mesh, vertmap)
fr.name = name
return fr
def export_mdl(
operator,
context,
filepath = "",
palette = 'PAL_QUAKE',
eyeposition = (0.0, 0.0, 0.0),
synctype = SYNCTYPE[1],
rotate = False,
effects = EFFECTS[1],
xform = True,
md16 = False,
mdl_scale_mins=(-100,-100,-100),
mdl_scale_maxs=(100,100,100),
):
obj = context.active_object
obj.update_from_editmode()
depsgraph = context.evaluated_depsgraph_get()
ob_eval = obj.evaluated_get(depsgraph)
mesh = ob_eval.to_mesh()
#if not check_faces(mesh):
# operator.report({'ERROR'},
# "Mesh has faces with more than 3 vertices.")
# return {'CANCELLED'}
mdl = MDL(obj.name)
mdl.obj = obj
if not get_properties(
operator,
mdl,
palette,
eyeposition,
synctype,
rotate,
effects,
xform,
md16,
mdl_scale_mins,
mdl_scale_maxs):
return {'CANCELLED'}
mdl.tris, mdl.stverts, vertmap = build_tris(mesh)
if mdl.script:
if 'skins' in mdl.script:
for skin in mdl.script['skins']:
mdl.skins.append(process_skin(mdl, skin))
if 'frames' in mdl.script:
for frame in mdl.script['frames']:
mdl.frames.append(process_frame(mdl, context.scene, frame,
vertmap))
if not mdl.skins:
make_skin(operator, mdl, mesh)
if not mdl.frames:
# Export up to the last scene frame:
# for fno in range(context.scene.frame_start, context.scene.frame_end + 1):
# Only export up to current frame:
for fno in range(context.scene.frame_start, context.scene.frame_current + 1):
context.scene.frame_set(fno)
obj.update_from_editmode()
depsgraph = context.evaluated_depsgraph_get()
ob_eval = obj.evaluated_get(depsgraph)
mesh = ob_eval.to_mesh()
if xform:
mesh.transform(mdl.obj.matrix_world)
mdl.frames.append(make_frame(mesh, vertmap, fno))
convert_stverts(mdl, mdl.stverts)
mdl.size = calc_average_area(mdl)
scale_verts(mdl,mdl_scale_mins,mdl_scale_maxs)
mdl.write(filepath)
return {'FINISHED'}

View file

@ -0,0 +1,258 @@
hexen2pal = (
(0x00, 0x00, 0x00),
(0x00, 0x00, 0x00),
(0x08, 0x08, 0x08),
(0x10, 0x10, 0x10),
(0x18, 0x18, 0x18),
(0x20, 0x20, 0x20),
(0x28, 0x28, 0x28),
(0x30, 0x30, 0x30),
(0x38, 0x38, 0x38),
(0x40, 0x40, 0x40),
(0x48, 0x48, 0x48),
(0x50, 0x50, 0x50),
(0x54, 0x54, 0x54),
(0x58, 0x58, 0x58),
(0x60, 0x60, 0x60),
(0x68, 0x68, 0x68),
(0x70, 0x70, 0x70),
(0x78, 0x78, 0x78),
(0x80, 0x80, 0x80),
(0x88, 0x88, 0x88),
(0x94, 0x94, 0x94),
(0x9C, 0x9C, 0x9C),
(0xA8, 0xA8, 0xA8),
(0xB4, 0xB4, 0xB4),
(0xB8, 0xB8, 0xB8),
(0xC4, 0xC4, 0xC4),
(0xCC, 0xCC, 0xCC),
(0xD4, 0xD4, 0xD4),
(0xE0, 0xE0, 0xE0),
(0xE8, 0xE8, 0xE8),
(0xF0, 0xF0, 0xF0),
(0xFC, 0xFC, 0xFC),
(0x08, 0x08, 0x0C),
(0x10, 0x10, 0x14),
(0x18, 0x18, 0x1C),
(0x1C, 0x20, 0x24),
(0x24, 0x24, 0x2C),
(0x2C, 0x2C, 0x34),
(0x30, 0x34, 0x3C),
(0x38, 0x38, 0x44),
(0x40, 0x40, 0x48),
(0x4C, 0x4C, 0x58),
(0x5C, 0x5C, 0x68),
(0x6C, 0x70, 0x80),
(0x80, 0x84, 0x98),
(0x98, 0x9C, 0xB0),
(0xA8, 0xAC, 0xC4),
(0xBC, 0xC4, 0xDC),
(0x20, 0x18, 0x14),
(0x28, 0x20, 0x1C),
(0x30, 0x24, 0x20),
(0x34, 0x2C, 0x28),
(0x3C, 0x34, 0x2C),
(0x44, 0x38, 0x34),
(0x4C, 0x40, 0x38),
(0x54, 0x48, 0x40),
(0x5C, 0x4C, 0x48),
(0x64, 0x54, 0x4C),
(0x6C, 0x5C, 0x54),
(0x70, 0x60, 0x58),
(0x78, 0x68, 0x60),
(0x80, 0x70, 0x64),
(0x88, 0x74, 0x6C),
(0x90, 0x7C, 0x70),
(0x14, 0x18, 0x14),
(0x1C, 0x20, 0x1C),
(0x20, 0x24, 0x20),
(0x28, 0x2C, 0x28),
(0x2C, 0x30, 0x2C),
(0x30, 0x38, 0x30),
(0x38, 0x40, 0x38),
(0x40, 0x44, 0x40),
(0x44, 0x4C, 0x44),
(0x54, 0x5C, 0x54),
(0x68, 0x70, 0x68),
(0x78, 0x80, 0x78),
(0x8C, 0x94, 0x88),
(0x9C, 0xA4, 0x98),
(0xAC, 0xB4, 0xA8),
(0xBC, 0xC4, 0xB8),
(0x30, 0x20, 0x08),
(0x3C, 0x28, 0x08),
(0x48, 0x30, 0x10),
(0x54, 0x38, 0x14),
(0x5C, 0x40, 0x1C),
(0x64, 0x48, 0x24),
(0x6C, 0x50, 0x2C),
(0x78, 0x5C, 0x34),
(0x88, 0x68, 0x3C),
(0x94, 0x74, 0x48),
(0xA0, 0x80, 0x54),
(0xA8, 0x88, 0x5C),
(0xB4, 0x90, 0x64),
(0xBC, 0x98, 0x6C),
(0xC4, 0xA0, 0x74),
(0xCC, 0xA8, 0x7C),
(0x10, 0x14, 0x10),
(0x14, 0x1C, 0x14),
(0x18, 0x20, 0x18),
(0x1C, 0x24, 0x1C),
(0x20, 0x2C, 0x20),
(0x24, 0x30, 0x24),
(0x28, 0x38, 0x28),
(0x2C, 0x3C, 0x2C),
(0x30, 0x44, 0x30),
(0x34, 0x4C, 0x34),
(0x3C, 0x54, 0x3C),
(0x44, 0x5C, 0x40),
(0x4C, 0x64, 0x48),
(0x54, 0x6C, 0x4C),
(0x5C, 0x74, 0x54),
(0x64, 0x80, 0x5C),
(0x18, 0x0C, 0x08),
(0x20, 0x10, 0x08),
(0x28, 0x14, 0x08),
(0x34, 0x18, 0x0C),
(0x3C, 0x1C, 0x0C),
(0x44, 0x20, 0x0C),
(0x4C, 0x24, 0x10),
(0x54, 0x2C, 0x14),
(0x5C, 0x30, 0x18),
(0x64, 0x38, 0x1C),
(0x70, 0x40, 0x20),
(0x78, 0x48, 0x24),
(0x80, 0x50, 0x2C),
(0x90, 0x5C, 0x38),
(0xA8, 0x70, 0x48),
(0xC0, 0x84, 0x58),
(0x18, 0x04, 0x04),
(0x24, 0x04, 0x04),
(0x30, 0x00, 0x00),
(0x3C, 0x00, 0x00),
(0x44, 0x00, 0x00),
(0x50, 0x00, 0x00),
(0x58, 0x00, 0x00),
(0x64, 0x00, 0x00),
(0x70, 0x00, 0x00),
(0x84, 0x00, 0x00),
(0x98, 0x00, 0x00),
(0xAC, 0x00, 0x00),
(0xC0, 0x00, 0x00),
(0xD4, 0x00, 0x00),
(0xE8, 0x00, 0x00),
(0xFC, 0x00, 0x00),
(0x10, 0x0C, 0x20),
(0x1C, 0x14, 0x30),
(0x20, 0x1C, 0x38),
(0x28, 0x24, 0x44),
(0x34, 0x2C, 0x50),
(0x3C, 0x38, 0x5C),
(0x44, 0x40, 0x68),
(0x50, 0x48, 0x74),
(0x58, 0x54, 0x80),
(0x64, 0x60, 0x8C),
(0x6C, 0x6C, 0x98),
(0x78, 0x74, 0xA4),
(0x84, 0x84, 0xB0),
(0x90, 0x90, 0xBC),
(0x9C, 0x9C, 0xC8),
(0xAC, 0xAC, 0xD4),
(0x24, 0x14, 0x04),
(0x34, 0x18, 0x04),
(0x44, 0x20, 0x04),
(0x50, 0x28, 0x00),
(0x64, 0x30, 0x04),
(0x7C, 0x3C, 0x04),
(0x8C, 0x48, 0x04),
(0x9C, 0x58, 0x08),
(0xAC, 0x64, 0x08),
(0xBC, 0x74, 0x0C),
(0xCC, 0x80, 0x0C),
(0xDC, 0x90, 0x10),
(0xEC, 0xA0, 0x14),
(0xFC, 0xB8, 0x38),
(0xF8, 0xC8, 0x50),
(0xF8, 0xDC, 0x78),
(0x14, 0x10, 0x04),
(0x1C, 0x18, 0x08),
(0x24, 0x20, 0x08),
(0x2C, 0x28, 0x0C),
(0x34, 0x30, 0x10),
(0x38, 0x38, 0x10),
(0x40, 0x40, 0x14),
(0x44, 0x48, 0x18),
(0x48, 0x50, 0x1C),
(0x50, 0x5C, 0x20),
(0x54, 0x68, 0x28),
(0x58, 0x74, 0x2C),
(0x5C, 0x80, 0x34),
(0x5C, 0x8C, 0x34),
(0x5C, 0x94, 0x38),
(0x60, 0xA0, 0x40),
(0x3C, 0x10, 0x10),
(0x48, 0x18, 0x18),
(0x54, 0x1C, 0x1C),
(0x64, 0x24, 0x24),
(0x70, 0x2C, 0x2C),
(0x7C, 0x34, 0x30),
(0x8C, 0x40, 0x38),
(0x98, 0x4C, 0x40),
(0x2C, 0x14, 0x08),
(0x38, 0x1C, 0x0C),
(0x48, 0x20, 0x10),
(0x54, 0x28, 0x14),
(0x60, 0x2C, 0x1C),
(0x70, 0x34, 0x20),
(0x7C, 0x38, 0x28),
(0x8C, 0x40, 0x30),
(0x18, 0x14, 0x10),
(0x24, 0x1C, 0x14),
(0x2C, 0x24, 0x1C),
(0x38, 0x2C, 0x20),
(0x40, 0x34, 0x24),
(0x48, 0x3C, 0x2C),
(0x50, 0x44, 0x30),
(0x5C, 0x4C, 0x34),
(0x64, 0x54, 0x3C),
(0x70, 0x5C, 0x44),
(0x78, 0x64, 0x48),
(0x84, 0x70, 0x50),
(0x90, 0x78, 0x58),
(0x98, 0x80, 0x60),
(0xA0, 0x88, 0x68),
(0xA8, 0x94, 0x70),
(0x24, 0x18, 0x0C),
(0x2C, 0x20, 0x10),
(0x34, 0x28, 0x14),
(0x3C, 0x2C, 0x14),
(0x48, 0x34, 0x18),
(0x50, 0x3C, 0x1C),
(0x58, 0x44, 0x1C),
(0x68, 0x4C, 0x20),
(0x94, 0x60, 0x38),
(0xA0, 0x6C, 0x40),
(0xAC, 0x74, 0x48),
(0xB4, 0x7C, 0x50),
(0xC0, 0x84, 0x58),
(0xCC, 0x8C, 0x5C),
(0xD8, 0x9C, 0x6C),
(0x3C, 0x14, 0x5C),
(0x64, 0x24, 0x74),
(0xA8, 0x48, 0xA4),
(0xCC, 0x6C, 0xC0),
(0x04, 0x54, 0x04),
(0x04, 0x84, 0x04),
(0x00, 0xB4, 0x00),
(0x00, 0xD8, 0x00),
(0x04, 0x04, 0x90),
(0x10, 0x44, 0xCC),
(0x24, 0x84, 0xE0),
(0x58, 0xA8, 0xE8),
(0xD8, 0x04, 0x04),
(0xF4, 0x48, 0x00),
(0xFC, 0x80, 0x00),
(0xFC, 0xAC, 0x18),
(0xFC, 0xFC, 0xFC)
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -0,0 +1,436 @@
# 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 #####
# <pep8 compliant>
import bpy
from bpy_extras.object_utils import object_data_add
from mathutils import Vector,Matrix
from .quakepal import quakepal
from .hexen2pal import hexen2pal
from .mdl import MDL
from .qfplist import pldata
def make_verts(mdl, framenum, subframenum=0):
frame = mdl.frames[framenum]
if frame.type:
frame = frame.frames[subframenum]
verts = []
s = Vector(mdl.scale)
o = Vector(mdl.scale_origin)
m = Matrix(((s.x, 0, 0,o.x),
( 0,s.y, 0,o.y),
( 0, 0,s.z,o.z),
( 0, 0, 0, 1)))
for v in frame.verts:
verts.append(m @ Vector(v.r))
return verts
def make_faces(mdl):
faces = []
uvs = []
for tri in mdl.tris:
tv = list(tri.verts)
sts = []
for v in tri.verts:
stv = mdl.stverts[v]
s = stv.s
t = stv.t
if stv.onseam and not tri.facesfront:
s += mdl.skinwidth / 2
# quake textures are top to bottom, but blender images
# are bottom to top
sts.append((s * 1.0 / mdl.skinwidth, 1 - t * 1.0 / mdl.skinheight))
# blender's and quake's vertex order seem to be opposed
tv.reverse()
sts.reverse()
# annoyingly, blender can't have 0 in the final vertex, so rotate the
# face vertices and uvs
if not tv[2]:
tv = [tv[2]] + tv[:2]
sts = [sts[2]] + sts[:2]
faces.append(tv)
uvs.append(sts)
return faces, uvs
def load_skins(mdl):
def load_skin(skin, name):
if mdl.palette == 0:
pal = quakepal
else:
pal = hexen2pal
skin.name = name
img = bpy.data.images.new(name, mdl.skinwidth, mdl.skinheight)
mdl.images.append(img)
p = [0.0] * mdl.skinwidth * mdl.skinheight * 4
d = skin.pixels
for j in range(mdl.skinheight):
for k in range(mdl.skinwidth):
c = pal[d[j * mdl.skinwidth + k]]
# quake textures are top to bottom, but blender images
# are bottom to top
l = ((mdl.skinheight - 1 - j) * mdl.skinwidth + k) * 4
p[l + 0] = c[0] / 255.0
p[l + 1] = c[1] / 255.0
p[l + 2] = c[2] / 255.0
p[l + 3] = 1.0
img.pixels[:] = p[:]
img.pack()
img.use_fake_user = True
mdl.images=[]
for i, skin in enumerate(mdl.skins):
if skin.type:
for j, subskin in enumerate(skin.skins):
load_skin(subskin, "%s_%d_%d" % (mdl.name, i, j))
else:
load_skin(skin, "%s_%d" % (mdl.name, i))
def setup_main_material(mdl):
mat = bpy.data.materials.new(mdl.name)
mat.blend_method = 'OPAQUE'
mat.diffuse_color = (1, 1, 1, 1)
mat.metallic = 1
mat.roughness = 1
mat.specular_intensity = 0
mat.use_nodes = True
return mat
def setup_skins(mdl, uvs):
load_skins(mdl)
# img = mdl.images[0] # use the first skin for now
# uvlay = mdl.mesh.uv_textures.new(mdl.name)
# uvloop = mdl.mesh.uv_layers[0]
# for i, texpoly in enumerate(uvlay.data):
uvloop = mdl.mesh.uv_layers.new(name = mdl.name)
for i in range(len(mdl.mesh.polygons)):
poly = mdl.mesh.polygons[i]
mdl_uv = uvs[i]
# texpoly.image = img # TODO: commented out by jazz
for j,k in enumerate(poly.loop_indices):
uvloop.data[k].uv = mdl_uv[j]
#Load all skins
img_counter = 0
for i, skin in enumerate(mdl.skins):
if skin.type:
mat = setup_main_material(mdl)
emissionNode = mat.node_tree.nodes.new("ShaderNodeEmission")
shaderOut = mat.node_tree.nodes["Material Output"]
mat.node_tree.nodes.remove(mat.node_tree.nodes["Principled BSDF"])
emissionNode.location = (0, 0)
shaderOut.location = (200, 0)
yPos = 0
for j, subskin in enumerate(skin.skins):
tex_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
tex_node.image = mdl.images[img_counter]
img_counter += 1
tex_node.interpolation = "Closest"
tex_node.location = (-300, yPos)
yPos -= 280
if j == 0:
# connect only first texture (we'll need something smarter in the future)
mat.node_tree.links.new(tex_node.outputs[0], emissionNode.inputs[0])
mat.node_tree.links.new(emissionNode.outputs[0], shaderOut.inputs[0])
mdl.mesh.materials.append(mat)
else:
mat = setup_main_material(mdl)
# TODO: turn transform to True and position it properly in editor
emissionNode = mat.node_tree.nodes.new("ShaderNodeEmission")
shaderOut = mat.node_tree.nodes["Material Output"]
mat.node_tree.nodes.remove(mat.node_tree.nodes["Principled BSDF"])
tex_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
tex_node.image = mdl.images[img_counter]
img_counter += 1
tex_node.interpolation = "Closest"
emissionNode.location = (0, 0)
shaderOut.location = (200, 0)
tex_node.location = (-300, 0)
mat.node_tree.links.new(tex_node.outputs[0], emissionNode.inputs[0])
mat.node_tree.links.new(emissionNode.outputs[0], shaderOut.inputs[0])
mdl.mesh.materials.append(mat)
def make_shape_key(mdl, framenum, subframenum=0):
frame = mdl.frames[framenum]
name = "%s_%d" % (mdl.name, framenum)
if frame.type:
frame = frame.frames[subframenum]
name = "%s_%d_%d" % (mdl.name, framenum, subframenum)
if frame.name:
name = frame.name
else:
frame.name = name
frame.key = mdl.obj.shape_key_add(name=name)
frame.key.value = 0.0
mdl.keys.append(frame.key)
s = Vector(mdl.scale)
o = Vector(mdl.scale_origin)
m = Matrix(((s.x, 0, 0,o.x),
( 0,s.y, 0,o.y),
( 0, 0,s.z,o.z),
( 0, 0, 0, 1)))
for i, v in enumerate(frame.verts):
frame.key.data[i].co = m @ Vector(v.r)
def build_shape_keys(mdl):
mdl.keys = []
mdl.obj.shape_key_add(name="Basis",from_mix=False)
mdl.mesh.shape_keys.name = mdl.name
mdl.obj.active_shape_key_index = 0
bpy.context.scene.frame_end = 0
for i, frame in enumerate(mdl.frames):
frame = mdl.frames[i]
if frame.type:
for j in range(len(frame.frames)):
make_shape_key(mdl, i, j)
bpy.context.scene.frame_end += 1
else:
make_shape_key(mdl, i)
bpy.context.scene.frame_end += 1
bpy.context.scene.frame_start = 1
def set_keys(act, data):
for d in data:
key, co = d
dp = """key_blocks["%s"].value""" % key.name
fc = act.fcurves.new(data_path = dp)
fc.keyframe_points.add(len(co))
for i in range(len(co)):
fc.keyframe_points[i].co = co[i]
fc.keyframe_points[i].interpolation = 'LINEAR'
def build_actions(mdl):
sk = mdl.mesh.shape_keys
ad = sk.animation_data_create()
track = ad.nla_tracks.new();
track.name = mdl.name
start_frame = 1.0
for frame in mdl.frames:
act = bpy.data.actions.new(frame.name)
data = []
other_keys = mdl.keys[:]
if frame.type:
for j, subframe in enumerate(frame.frames):
subframe.frameno = start_frame + j
co = []
if j > 1:
co.append((1.0, 0.0))
if j > 0:
co.append((j * 1.0, 0.0))
co.append(((j + 1) * 1.0, 1.0))
if j < len(frame.frames) - 2:
co.append(((j + 2) * 1.0, 0.0))
if j < len(frame.frames) - 1:
co.append((len(frame.frames) * 1.0, 0.0))
data.append((subframe.key, co))
if subframe.key in other_keys:
del(other_keys[other_keys.index(subframe.key)])
co = [(1.0, 0.0), (len(frame.frames) * 1.0, 0.0)]
for k in other_keys:
data.append((k, co))
else:
sub.frameno = start_frame + j
data.append((frame.key, [(1.0, 1.0)]))
if frame.key in other_keys:
del(other_keys[other_keys.index(frame.key)])
co = [(1.0, 0.0)]
for k in other_keys:
data.append((k, co))
set_keys(act, data)
track.strips.new(act.name, start_frame, act)
start_frame += act.frame_range[1]
def merge_frames(mdl):
def get_base(name):
i = 0
while i < len(name) and name[i] not in "0123456789":
i += 1
return name[:i]
i = 0
while i < len(mdl.frames):
if mdl.frames[i].type:
i += 1
continue
base = get_base(mdl.frames[i].name)
j = i + 1
while j < len(mdl.frames):
if mdl.frames[j].type:
break
if get_base(mdl.frames[j].name) != base:
break
j += 1
f = MDL.Frame()
f.name = base
f.type = 1
f.frames = mdl.frames[i:j]
mdl.frames[i:j] = [f]
i += 1
def write_text(mdl):
header="""
/* This script represents the animation data within the model file. It
is generated automatically on import, and is optional when exporting.
If no script is used when exporting, frames will be exported one per
blender frame from frame 1 to the current frame (inclusive), and only
one skin will be exported.
The fundamental format of the script is documented at
http://quakeforge.net/doxygen/property-list.html
The expected layout is a top-level dictionary with two expected
entries:
frames array of frame entries. If missing, frames will be handled
as if there were no script.
skins array of skin entries. If missing, skins will be handled
as if there were no script.
A frame entry is a dictionary with the following fields:
name The name of the frame to be written to the mdl file. In a
frame group, this will form the base for sub-frame names
(name + relative frame number: eg, frame1) if the
sub-frame does not have a name field. (string)
frameno The blender frame to use for the captured animation. In a
frame group, this will be used as the base frame for any
sub-frames that do not specify a frame. While fractional
frames are supported, YMMV. (string:float)
frames Array of frame entries. If present, the current frame
entry is a frame group, and the frame entries specify
sub-frames. (array of dictionary)
NOTE: only top-level frames may be frame groups
intervals Array of frame end times for frame groups. No meaning
in blender, but the quake engine uses them for client-side
animations. Times must be ascending, but any step > 0 is
valid. Ignored for single frames. If not present in a
frame group, the sub-frames of the group will be written
as single frames (in order to undo the auto-group feature
of the importer). Excess times will be ignored, missing
times will be generated at 0.1
second intervals.
(array of string:float).
A skin entry is a dictionary with the following fields:
name The name of the blender image to be used as the skin.
Ignored for skin groups (animated skins). (string)
skins Array of skin entries. If present, the current skin
entry is a skin group (animated skin), and the skin
entries specify sub-skin. (array of dictionary)
NOTE: only top-level skins may be skins groups
intervals Array of skin end times for skin groups. No meaning
in blender, but the quake engine uses them for client-side
animations. Times must be ascending, but any step > 0 is
valid. Ignored for single skins. If not present in a
skin group, it will be generated using 0.1 second
intervals. Excess times will be ignored, missing times
will be generated at 0.1 second intervals.
(array of string:float).
*/
"""
d={'frames':[], 'skins':[]}
for f in mdl.frames:
d['frames'].append(f.info())
for s in mdl.skins:
d['skins'].append(s.info())
pl = pldata()
string = header + pl.write(d)
txt = bpy.data.texts.new(mdl.name)
txt.from_string(string)
mdl.text = txt
def parse_flags(flags):
#NOTE these are in QuakeForge priority order; a little different to id.
# id has rocket and grenate between tracer2 and tracer3
if flags & MDL.EF_ROCKET:
return 'EF_ROCKET'
elif flags & MDL.EF_GRENADE:
return 'EF_GRENADE'
elif flags & MDL.EF_GIB:
return 'EF_GIB'
elif flags & MDL.EF_ZOMGIB:
return 'EF_ZOMGIB'
elif flags & MDL.EF_TRACER:
return 'EF_TRACER'
elif flags & MDL.EF_TRACER2:
return 'EF_TRACER2'
elif flags & MDL.EF_TRACER3:
return 'EF_TRACER3'
else:
return 'EF_NONE'
def set_properties(mdl):
mdl.obj.qfmdl.eyeposition = mdl.eyeposition
try:
mdl.obj.qfmdl.synctype = MDL.SYNCTYPE[mdl.synctype]
except IndexError:
mdl.obj.qfmdl.synctype = 'ST_SYNC'
mdl.obj.qfmdl.rotate = (mdl.flags & MDL.EF_ROTATE) and True or False
mdl.obj.qfmdl.effects = parse_flags(mdl.flags)
#mdl.obj.qfmdl.script = mdl.text.name #FIXME really want the text object
mdl.obj.qfmdl.md16 = (mdl.ident == "MD16")
def import_mdl(operator, context, filepath, palette = 'PAL_QUAKE'):
bpy.context.preferences.edit.use_global_undo = False
for obj in bpy.context.scene.collection.objects:
obj.select_set(False)
mdl = MDL()
if not mdl.read(filepath):
operator.report({'ERROR'},
"Unrecognized format: %s %d" % (mdl.ident, mdl.version))
return {'CANCELLED'}
faces, uvs = make_faces(mdl)
verts = make_verts(mdl, 0)
mdl.mesh = bpy.data.meshes.new(mdl.name)
mdl.mesh.from_pydata(verts, [], faces)
mdl.obj = bpy.data.objects.new(mdl.name, mdl.mesh)
bpy.context.scene.collection.objects.link(mdl.obj)
mdl.obj.select_set(True)
bpy.context.view_layer.objects.active = mdl.obj
mdl.palette = MDL.PALETTE[palette]
setup_skins(mdl, uvs)
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 1
if len(mdl.frames) > 1 or mdl.frames[0].type:
build_shape_keys(mdl)
merge_frames(mdl)
build_actions(mdl)
write_text(mdl)
set_properties(mdl)
mdl.mesh.update()
bpy.context.preferences.edit.use_global_undo = True
return {'FINISHED'}

415
io_mesh_qfmdl_blubs/mdl.py Normal file
View file

@ -0,0 +1,415 @@
# 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 #####
# <pep8 compliant>
from struct import unpack, pack
class MDL:
ST_SYNC = 0
ST_RAND = 1
SYNCTYPE={'ST_SYNC':ST_SYNC, 'ST_RAND':ST_RAND,
ST_SYNC:'ST_SYNC', ST_RAND:'ST_RAND'}
EF_ROCKET = 1
EF_GRENADE = 2
EF_GIB = 4
EF_ROTATE = 8
EF_TRACER = 16
EF_ZOMGIB = 32
EF_TRACER2 = 64
EF_TRACER3 = 128
EFFECTS={'EF_NONE':0, 'EF_ROCKET':EF_ROCKET, 'EF_GRENADE':EF_GRENADE,
'EF_GIB':EF_GIB, 'EF_TRACER':EF_TRACER, 'EF_ZOMGIB':EF_ZOMGIB,
'EF_TRACER2':EF_TRACER2, 'EF_TRACER3':EF_TRACER3}
PALETTE = {'PAL_QUAKE': 0, 'PAL_HEXEN2': 1}
class Skin:
def __init__(self):
self.name = ''
def info(self):
info={}
if self.type:
if self.times:
info['intervals'] = list(map(lambda t: str(t), self.times))
info['skins'] = []
for s in self.skins:
info['skins'].append(s.info())
if self.name:
info['name'] = self.name
return info
def read(self, mdl, sub=0):
self.width, self.height = mdl.skinwidth, mdl.skinheight
if sub:
self.type = 0
self.read_pixels(mdl)
return self
self.type = mdl.read_int()
if self.type:
# skin group
num = mdl.read_int()
self.times = mdl.read_float(num)
self.skins = []
for i in range(num):
self.skins.append(MDL.Skin().read(mdl, 1))
num -= 1
return self
self.read_pixels(mdl)
return self
def write(self, mdl, sub=0):
if not sub:
mdl.write_int(self.type)
if self.type:
mdl.write_int(len(self.skins))
mdl.write_float(self.times)
for subskin in self.skins:
subskin.write(mdl, 1)
return
mdl.write_bytes(self.pixels)
def read_pixels(self, mdl):
size = self.width * self.height
self.pixels = mdl.read_bytes(size)
class STVert:
def __init__(self, st=None, onseam=False):
if not st:
st = (0, 0)
self.onseam = onseam
self.s, self.t = st
pass
def read(self, mdl):
self.onseam = mdl.read_int()
self.s, self.t = mdl.read_int(2)
return self
def write(self, mdl):
mdl.write_int(self.onseam)
mdl.write_int((self.s, self.t))
class Tri:
def __init__(self, verts=None, facesfront=True):
if not verts:
verts = (0, 0, 0)
self.facesfront = facesfront
self.verts = verts
def read(self, mdl):
self.facesfront = mdl.read_int()
self.verts = mdl.read_int(3)
return self
def write(self, mdl):
mdl.write_int(self.facesfront)
mdl.write_int(self.verts)
class Frame:
def __init__(self):
self.type = 0
self.name = ""
self.mins = [0, 0, 0]
self.maxs = [0, 0, 0]
self.verts = []
self.frames = []
self.times = []
def info(self):
info={}
if self.type:
if self.times:
info['intervals'] = list(map(lambda t: str(t), self.times))
info['frames'] = []
for f in self.frames:
info['frames'].append(f.info())
if hasattr(self, 'frameno'):
info['frameno'] = str(self.frameno)
if self.name:
info['name'] = self.name
return info
def add_vert(self, vert):
self.verts.append(vert)
for i, v in enumerate(vert.r):
self.mins[i] = min(self.mins[i], v)
self.maxs[i] = max(self.maxs[i], v)
def add_frame(self, frame, time):
self.type = 1
self.frames.append(frame)
self.times.append(time)
for i in range(3):
self.mins[i] = min(self.mins[i], frame.mins[i])
self.maxs[i] = max(self.maxs[i], frame.maxs[i])
def scale(self, mdl):
self.mins = tuple(map(lambda x, s, t: int((x - t) / s),
self.mins, mdl.scale, mdl.scale_origin))
self.maxs = tuple(map(lambda x, s, t: int((x - t) / s),
self.maxs, mdl.scale, mdl.scale_origin))
if self.type:
for subframe in self.frames:
subframe.scale(mdl)
else:
for vert in self.verts:
vert.scale(mdl)
def read(self, mdl, numverts, sub=0):
if sub:
self.type = 0
else:
self.type = mdl.read_int()
if self.type:
num = mdl.read_int()
self.read_bounds(mdl)
self.times = mdl.read_float(num)
self.frames = []
for i in range(num):
self.frames.append(MDL.Frame().read(mdl, numverts, 1))
return self
self.read_bounds(mdl)
self.read_name(mdl)
self.read_verts(mdl, numverts)
return self
def write(self, mdl, sub=0):
if not sub:
mdl.write_int(self.type)
if self.type:
mdl.write_int(len(self.frames))
self.write_bounds(mdl)
mdl.write_float(self.times)
for frame in self.frames:
frame.write(mdl, 1)
return
self.write_bounds(mdl)
self.write_name(mdl)
self.write_verts(mdl)
def read_name(self, mdl):
if mdl.version == 6:
name = mdl.read_string(16)
else:
name = ""
if "\0" in name:
name = name[:name.index("\0")]
self.name = name
def write_name(self, mdl):
if mdl.version == 6:
mdl.write_string(self.name, 16)
def read_bounds(self, mdl):
self.mins = mdl.read_byte(4)[:3] #discard normal index
self.maxs = mdl.read_byte(4)[:3] #discard normal index
def write_bounds(self, mdl):
mdl.write_byte(self.mins + (0,))
mdl.write_byte(self.maxs + (0,))
def read_verts(self, mdl, num):
self.verts = []
for i in range(num):
self.verts.append(MDL.Vert().read(mdl))
if mdl.ident == 'MD16':
for i in range(num):
v = MDL.Vert().read(mdl)
r = tuple(map(lambda a, b: a + b / 256.0,
self.verts[i].r, v.r))
self.verts[i].r = r
def write_verts(self, mdl):
for vert in self.verts:
vert.write(mdl, True)
if mdl.ident == 'MD16':
for vert in self.verts:
vert.write(mdl, False)
def clamp_to_bounds(self, mins, maxs):
"""
Clamps all vertices and subframes to the bounds specified by mins/maxs
NOTE - This should be called _before_ Frame.scale(...)
Keyword Arguments:
mins -- (min x, min y, min z)
maxs -- (max x, max y, max z)
"""
clamp_to_mins = lambda x : tuple(map(max, zip(x, mins)))
clamp_to_maxs = lambda x : tuple(map(min, zip(x, maxs)))
clamp_to_bounds = lambda x : clamp_to_mins(clamp_to_maxs(x))
self.mins = clamp_to_bounds(self.mins)
self.maxs = clamp_to_bounds(self.maxs)
if self.type:
for subframe in self.frames:
subframe.clamp_to_bounds(mins,maxs)
else:
for vert in self.verts:
vert.r = clamp_to_bounds(vert.r)
class Vert:
def __init__(self, r=None, ni=0):
if not r:
r = (0, 0, 0)
self.r = r
self.ni = ni
pass
def read(self, mdl):
self.r = mdl.read_byte(3)
self.ni = mdl.read_byte()
return self
def write(self, mdl, high=True):
if mdl.ident == 'MD16' and not high:
r = tuple(map(lambda a: int(a * 256) & 255, self.r))
else:
r = tuple(map(lambda a: int(a) & 255, self.r))
mdl.write_byte(r)
mdl.write_byte(self.ni)
def scale(self, mdl):
self.r = tuple(map(lambda x, s, t: (x - t) / s,
self.r, mdl.scale, mdl.scale_origin))
def read_byte(self, count=1):
size = 1 * count
data = self.file.read(size)
data = unpack("<%dB" % count, data)
if count == 1:
return data[0]
return data
def read_int(self, count=1):
size = 4 * count
data = self.file.read(size)
data = unpack("<%di" % count, data)
if count == 1:
return data[0]
return data
def read_float(self, count=1):
size = 4 * count
data = self.file.read(size)
data = unpack("<%df" % count, data)
if count == 1:
return data[0]
return data
def read_bytes(self, size):
return self.file.read(size)
def read_string(self, size):
data = self.file.read(size)
s = ""
for c in data:
s = s + chr(c)
return s
def write_byte(self, data):
if not hasattr(data, "__len__"):
data = (data,)
self.file.write(pack(("<%dB" % len(data)), *data))
def write_int(self, data):
if not hasattr(data, "__len__"):
data = (data,)
self.file.write(pack(("<%di" % len(data)), *data))
def write_float(self, data):
if not hasattr(data, "__len__"):
data = (data,)
self.file.write(pack(("<%df" % len(data)), *data))
def write_bytes(self, data, size=-1):
if size == -1:
size = len(data)
self.file.write(data[:size])
if size > len(data):
self.file.write(bytes(size - len(data)))
def write_string(self, data, size=-1):
data = data.encode()
self.write_bytes(data, size)
def __init__(self, name = "mdl", md16 = False):
self.name = name
self.ident = md16 and "MD16" or "IDPO"
self.version = 6 #write only version 6 (nothing usable uses 3)
self.scale = (1.0, 1.0, 1.0) #FIXME
self.scale_origin = (0.0, 0.0, 0.0) #FIXME
self.boundingradius = 1.0 #FIXME
self.palette = 0
self.eyeposition = (0.0, 0.0, 0.0) #FIXME
self.synctype = MDL.ST_SYNC
self.flags = 0 #FIXME config
self.size = 0 #FIXME ???
self.skins = []
self.stverts = []
self.tris = []
self.frames = []
pass
def read(self, filepath):
self.file = open(filepath, "rb")
self.name = filepath.split('/')[-1]
self.name = self.name.split('.')[0]
self.ident = self.read_string(4)
self.version = self.read_int()
if self.ident not in ["IDPO", "MD16"] or self.version not in [3, 6]:
return None
self.scale = self.read_float(3)
self.scale_origin = self.read_float(3)
self.boundingradius = self.read_float()
self.eyeposition = self.read_float(3)
numskins = self.read_int()
self.skinwidth, self.skinheight = self.read_int(2)
numverts, numtris, numframes = self.read_int(3)
self.synctype = self.read_int()
if self.version == 6:
self.flags = self.read_int()
self.size = self.read_float()
# read in the skin data
self.skins = []
for i in range(numskins):
self.skins.append(MDL.Skin().read(self))
#read in the st verts (uv map)
self.stverts = []
for i in range(numverts):
self.stverts.append(MDL.STVert().read(self))
#read in the tris
self.tris = []
for i in range(numtris):
self.tris.append(MDL.Tri().read(self))
#read in the frames
self.frames = []
for i in range(numframes):
self.frames.append(MDL.Frame().read(self, numverts))
return self
def write(self, filepath):
self.file = open(filepath, "wb")
self.write_string(self.ident, 4)
self.write_int(self.version)
self.write_float(self.scale)
self.write_float(self.scale_origin)
self.write_float(self.boundingradius)
self.write_float(self.eyeposition)
self.write_int(len(self.skins))
self.write_int((self.skinwidth, self.skinheight))
self.write_int(len(self.stverts))
self.write_int(len(self.tris))
self.write_int(len(self.frames))
self.write_int(self.synctype)
if self.version == 6:
self.write_int(self.flags)
self.write_float(self.size)
# write out the skin data
for skin in self.skins:
skin.write(self)
#write out the st verts (uv map)
for stvert in self.stverts:
stvert.write(self)
#write out the tris
for tri in self.tris:
tri.write(self)
#write out the frames
for frame in self.frames:
frame.write(self)

View file

@ -0,0 +1,258 @@
# 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 #####
# <pep8 compliant>
quotables = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz!#$%&*+-./:?@|~_^")
class PListError(Exception):
def __init__(self, line, message):
Exception.__init__(self, "%d: %s" % (line, message))
self.line = line
class pldata:
def __init__(self, src = ''):
self.src = src
self.pos = 0;
self.end = len(self.src)
self.line = 1
def skip_space(self):
while self.pos < self.end:
c = self.src[self.pos]
if not c.isspace():
if c == '/' and self.pos < self.end - 1: #comments
if self.src[self.pos + 1] == '/': # // coment
self.pos += 2
while self.pos < self.end:
c = self.src[self.pos]
if c == '\n':
break
self.pos += 1
if self.pos >= self.end:
raise PListError(self.line,
"Reached end of string in comment")
elif self.src[self.pos + 1] == '*': # /* comment */
start_line = self.line
self.pos += 2
while self.pos < self.end:
c = self.src[self.pos]
if c == '\n':
self.line += 1
elif (c == '*' and self.pos < self.end - 1
and self.src[self.pos + 1] == '/'):
self.pos += 1
break
self.pos += 1
if self.pos >= self.end:
raise PListError(start_line,
"Reached end of string in comment")
else:
return True
else:
return True
if c == '\n':
self.line += 1
self.pos += 1
raise PListError(self.line, "Reached end of string")
def parse_quoted_string(self):
start_line = self.line
long_string = False
escaped = 0
shrink = 0
hexa = False
self.pos += 1
start = self.pos
if (self.pos < self.end - 1 and self.src[self.pos] == '"'
and self.src[self.pos + 1] == '"'):
self.pos += 2
long_string = True
start += 2
while self.pos < self.end:
c = self.src[self.pos]
if escaped:
if escaped == 1 and c == '0':
escaped += 1
hexa = False
elif escaped > 1:
if escaped == 2 and c == 'x':
hexa = True
shring += 1
escaped += 1
elif hex and c.isxdigit():
shrink += 1
escaped += 1
elif c in range(0, 8):
shrink += 1
escaped += 1
else:
self.pos -= 1
escaped = 0
else:
escaped = 0
else:
if c == '\\':
escaped = 1
shrink += 1
elif (c == '"'
and (not long_string
or (self.pos < self.end - 2
and self.src[self.pos + 1] == '"'
and self.src[self.pos + 2] == '"'))):
break
if c == '\n':
self.line += 1
self.pos += 1
if self.pos >= self.end:
raise PListError(start_line,
"Reached end of string while parsing quoted string")
if self.pos - start - shrink == 0:
return ""
s = self.src[start:self.pos]
self.pos += 1
if long_string:
self.pos += 2
return eval('"""' + s + '"""')
def parse_unquoted_string(self):
start = self.pos
while self.pos < self.end:
if self.src[self.pos] not in quotables:
break
self.pos += 1
return self.src[start:self.pos]
def parse_data(self):
start_line = self.line
self.pos += 1
start = self.pos
nibbles = 0
while self.pos < self.end:
if self.src[self.pos].isxdigit:
nibbles += 1
self.pos += 1
continue
if self.src[self.pos] == '>':
if nibbles & 1:
raise PListError(self.line,
"Invalid data, missing nibble")
s = self.src[start:self.pos]
self.pos += 1
return binascii.a2b_hex(s)
raise PListError(self.line,
"Invalid character in data")
raise PListError(start_line,
"Reached end of string while parsing data")
def parse(self):
self.skip_space()
if self.src[self.pos] == '{':
item = {}
self.pos += 1
while self.skip_space() and self.src[self.pos] != '}':
key = self.parse()
if type(key) != str:
raise PListError(self.line,
"Key is not a string")
self.skip_space()
if self.src[self.pos] != '=':
raise PListError(self.line,
"Unexpected character (expected '=')")
self.pos += 1
value = self.parse()
if self.src[self.pos] == ';':
self.pos += 1
elif self.src[self.pos] != '}':
raise PListError(self.line,
"Unexpected character (wanted ';' or '}')")
item[key] = value
if self.pos >= self.end:
raise PListError(self.line,
"Unexpected end of string when parsing dictionary")
self.pos += 1
return item
elif self.src[self.pos] == '(':
item = []
self.pos += 1
while self.skip_space() and self.src[self.pos] != ')':
value = self.parse()
self.skip_space()
if self.src[self.pos] == ',':
self.pos += 1
elif self.src[self.pos] != ')':
raise PListError(self.line,
"Unexpected character (wanted ',' or ')')")
item.append(value)
self.pos += 1
return item
elif self.src[self.pos] == '<':
return self.parse_data()
elif self.src[self.pos] == '"':
return self.parse_quoted_string()
else:
return self.parse_unquoted_string()
def write_string(self, item):
quote = False
for i in item:
if i not in quotables:
quote = True
break
if quote:
item = repr(item)
# repr uses ', we want "
item = '"' + item[1:-1].replace('"', '\\"') + '"'
self.data.append(item)
def write_item(self, item, level):
if type(item) == dict:
if not item:
self.data.append("{ }")
return
self.data.append("{\n")
for i in item.items():
self.data.append('\t' * (level + 1))
self.write_string(i[0])
self.data.append(' = ')
self.write_item(i[1], level + 1)
self.data.append(';\n')
self.data.append('\t' * (level))
self.data.append("}")
elif type(item) in(list, tuple):
if not item:
self.data.append("( )")
return
self.data.append("(\n")
for n, i in enumerate(item):
self.data.append('\t' * (level + 1))
self.write_item(i, level + 1)
if n < len(item) - 1:
self.data.append(',\n')
self.data.append('\n')
self.data.append('\t' * (level))
self.data.append(")")
elif type(item) == bytes:
self.data.append('<')
self.data.append(binascii.b2a_hex(item))
self.data.append('>')
elif type(item) == str:
self.write_string(item)
elif type(item) in [int, float]:
self.write_string(str(item))
else:
raise PListError(0, "unsupported type")
def write(self, item):
self.data = []
self.write_item(item, 0)
return ''.join(self.data)

View file

@ -0,0 +1,97 @@
# 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 #####
# <pep8 compliant>
from mathutils import Vector
# Covert normals to quake's normal palette. Implementation taken from ajmdl
#
# AJA: I use the following shortcuts to speed up normal lookup:
#
# Firstly, a preliminary match only uses the first quadrant
# (where all coords are >= 0). Then we use the appropriate
# normal index for the actual quadrant. We can do this because
# the 162 MDL/MD2 normals are not arbitrary but are mirrored in
# every quadrant. The eight numbers in the lists above are the
# indices for each quadrant (+++ ++- +-+ +-- -++ -+- --+ ---).
#
# Secondly we use the axis with the greatest magnitude (of the
# incoming normal) to search an axis-specific group, which means
# we only need to check about 1/3rd of the normals.
# Actually, about 1/14th (taniwha)
x_group = (
(Vector((1.0000, 0.0000, 0.0000)), (52,52,52,52,143,143,143,143)),
(Vector((0.9554, 0.2952, 0.0000)), (51,51,55,55,141,141,145,145)),
(Vector((0.9511, 0.1625, 0.2629)), (53,63,57,70,142,148,146,151)),
(Vector((0.8642, 0.4429, 0.2389)), (46,61,56,69,19,147,123,150)),
(Vector((0.8507, 0.5257, 0.0000)), (41,41,54,54,18,18,116,116)),
(Vector((0.8507, 0.0000, 0.5257)), (60,67,60,67,144,155,144,155)),
(Vector((0.8090, 0.3090, 0.5000)), (48,62,58,68,16,149,124,152)),
(Vector((0.7166, 0.6817, 0.1476)), (42,43,111,100,20,25,118,117)),
(Vector((0.6882, 0.5878, 0.4253)), (47,76,140,101,21,156,125,161)),
(Vector((0.6817, 0.1476, 0.7166)), (49,65,59,66,15,153,126,154)),
(Vector((0.5878, 0.4253, 0.6882)), (50,75,139,102,17,157,128,160)) )
y_group = (
(Vector((0.0000, 1.0000, 0.0000)), (32,32,104,104,32,32,104,104)),
(Vector((0.0000, 0.9554, 0.2952)), (33,30,107,103,33,30,107,103)),
(Vector((0.2629, 0.9511, 0.1625)), (36,39,109,105,34,31,122,115)),
(Vector((0.2389, 0.8642, 0.4429)), (35,38,108,97,23,29,121,113)),
(Vector((0.5257, 0.8507, 0.0000)), (44,44,112,112,27,27,119,119)),
(Vector((0.0000, 0.8507, 0.5257)), (6,28,106,90,6,28,106,90)),
(Vector((0.5000, 0.8090, 0.3090)), (37,40,110,98,22,26,120,114)),
(Vector((0.1476, 0.7166, 0.6817)), (8,71,136,92,7,77,130,91)),
(Vector((0.4253, 0.6882, 0.5878)), (45,73,138,99,24,158,131,159)),
(Vector((0.7166, 0.6817, 0.1476)), (42,43,111,100,20,25,118,117)),
(Vector((0.6882, 0.5878, 0.4253)), (47,76,140,101,21,156,125,161)) )
z_group = (
(Vector((0.0000, 0.0000, 1.0000)), (5,84,5,84,5,84,5,84)),
(Vector((0.2952, 0.0000, 0.9554)), (12,85,12,85,2,82,2,82)),
(Vector((0.1625, 0.2629, 0.9511)), (14,86,134,96,4,83,132,89)),
(Vector((0.4429, 0.2389, 0.8642)), (13,74,133,95,1,81,127,87)),
(Vector((0.5257, 0.0000, 0.8507)), (11,64,11,64,0,80,0,80)),
(Vector((0.0000, 0.5257, 0.8507)), (9,79,137,93,9,79,137,93)),
(Vector((0.3090, 0.5000, 0.8090)), (10,72,135,94,3,78,129,88)),
(Vector((0.6817, 0.1476, 0.7166)), (49,65,59,66,15,153,126,154)),
(Vector((0.5878, 0.4253, 0.6882)), (50,75,139,102,17,157,128,160)),
(Vector((0.1476, 0.7166, 0.6817)), (8,71,136,92,7,77,130,91)),
(Vector((0.4253, 0.6882, 0.5878)), (45,73,138,99,24,158,131,159)) )
def map_normal(n):
fn = Vector((abs(n.x),abs(n.y),abs(n.z)));
group = x_group
if fn.y > fn.x and fn.y > fn.z:
group = y_group
if fn.z > fn.x and fn.z > fn.y:
group = z_group
best = 0
best_dot = -1
for i in range(len(group)):
dot = group[i][0].dot(fn)
if dot > best_dot:
best = i
best_dot = dot
quadrant = 0
if n.x < 0:
quadrant += 4
if n.y < 0:
quadrant += 2
if n.z < 0:
quadrant += 1
return group[best][1][quadrant]

View file

@ -0,0 +1,258 @@
quakepal = (
(0x00, 0x00, 0x00),
(0x0f, 0x0f, 0x0f),
(0x1f, 0x1f, 0x1f),
(0x2f, 0x2f, 0x2f),
(0x3f, 0x3f, 0x3f),
(0x4b, 0x4b, 0x4b),
(0x5b, 0x5b, 0x5b),
(0x6b, 0x6b, 0x6b),
(0x7b, 0x7b, 0x7b),
(0x8b, 0x8b, 0x8b),
(0x9b, 0x9b, 0x9b),
(0xab, 0xab, 0xab),
(0xbb, 0xbb, 0xbb),
(0xcb, 0xcb, 0xcb),
(0xdb, 0xdb, 0xdb),
(0xeb, 0xeb, 0xeb),
(0x0f, 0x0b, 0x07),
(0x17, 0x0f, 0x0b),
(0x1f, 0x17, 0x0b),
(0x27, 0x1b, 0x0f),
(0x2f, 0x23, 0x13),
(0x37, 0x2b, 0x17),
(0x3f, 0x2f, 0x17),
(0x4b, 0x37, 0x1b),
(0x53, 0x3b, 0x1b),
(0x5b, 0x43, 0x1f),
(0x63, 0x4b, 0x1f),
(0x6b, 0x53, 0x1f),
(0x73, 0x57, 0x1f),
(0x7b, 0x5f, 0x23),
(0x83, 0x67, 0x23),
(0x8f, 0x6f, 0x23),
(0x0b, 0x0b, 0x0f),
(0x13, 0x13, 0x1b),
(0x1b, 0x1b, 0x27),
(0x27, 0x27, 0x33),
(0x2f, 0x2f, 0x3f),
(0x37, 0x37, 0x4b),
(0x3f, 0x3f, 0x57),
(0x47, 0x47, 0x67),
(0x4f, 0x4f, 0x73),
(0x5b, 0x5b, 0x7f),
(0x63, 0x63, 0x8b),
(0x6b, 0x6b, 0x97),
(0x73, 0x73, 0xa3),
(0x7b, 0x7b, 0xaf),
(0x83, 0x83, 0xbb),
(0x8b, 0x8b, 0xcb),
(0x00, 0x00, 0x00),
(0x07, 0x07, 0x00),
(0x0b, 0x0b, 0x00),
(0x13, 0x13, 0x00),
(0x1b, 0x1b, 0x00),
(0x23, 0x23, 0x00),
(0x2b, 0x2b, 0x07),
(0x2f, 0x2f, 0x07),
(0x37, 0x37, 0x07),
(0x3f, 0x3f, 0x07),
(0x47, 0x47, 0x07),
(0x4b, 0x4b, 0x0b),
(0x53, 0x53, 0x0b),
(0x5b, 0x5b, 0x0b),
(0x63, 0x63, 0x0b),
(0x6b, 0x6b, 0x0f),
(0x07, 0x00, 0x00),
(0x0f, 0x00, 0x00),
(0x17, 0x00, 0x00),
(0x1f, 0x00, 0x00),
(0x27, 0x00, 0x00),
(0x2f, 0x00, 0x00),
(0x37, 0x00, 0x00),
(0x3f, 0x00, 0x00),
(0x47, 0x00, 0x00),
(0x4f, 0x00, 0x00),
(0x57, 0x00, 0x00),
(0x5f, 0x00, 0x00),
(0x67, 0x00, 0x00),
(0x6f, 0x00, 0x00),
(0x77, 0x00, 0x00),
(0x7f, 0x00, 0x00),
(0x13, 0x13, 0x00),
(0x1b, 0x1b, 0x00),
(0x23, 0x23, 0x00),
(0x2f, 0x2b, 0x00),
(0x37, 0x2f, 0x00),
(0x43, 0x37, 0x00),
(0x4b, 0x3b, 0x07),
(0x57, 0x43, 0x07),
(0x5f, 0x47, 0x07),
(0x6b, 0x4b, 0x0b),
(0x77, 0x53, 0x0f),
(0x83, 0x57, 0x13),
(0x8b, 0x5b, 0x13),
(0x97, 0x5f, 0x1b),
(0xa3, 0x63, 0x1f),
(0xaf, 0x67, 0x23),
(0x23, 0x13, 0x07),
(0x2f, 0x17, 0x0b),
(0x3b, 0x1f, 0x0f),
(0x4b, 0x23, 0x13),
(0x57, 0x2b, 0x17),
(0x63, 0x2f, 0x1f),
(0x73, 0x37, 0x23),
(0x7f, 0x3b, 0x2b),
(0x8f, 0x43, 0x33),
(0x9f, 0x4f, 0x33),
(0xaf, 0x63, 0x2f),
(0xbf, 0x77, 0x2f),
(0xcf, 0x8f, 0x2b),
(0xdf, 0xab, 0x27),
(0xef, 0xcb, 0x1f),
(0xff, 0xf3, 0x1b),
(0x0b, 0x07, 0x00),
(0x1b, 0x13, 0x00),
(0x2b, 0x23, 0x0f),
(0x37, 0x2b, 0x13),
(0x47, 0x33, 0x1b),
(0x53, 0x37, 0x23),
(0x63, 0x3f, 0x2b),
(0x6f, 0x47, 0x33),
(0x7f, 0x53, 0x3f),
(0x8b, 0x5f, 0x47),
(0x9b, 0x6b, 0x53),
(0xa7, 0x7b, 0x5f),
(0xb7, 0x87, 0x6b),
(0xc3, 0x93, 0x7b),
(0xd3, 0xa3, 0x8b),
(0xe3, 0xb3, 0x97),
(0xab, 0x8b, 0xa3),
(0x9f, 0x7f, 0x97),
(0x93, 0x73, 0x87),
(0x8b, 0x67, 0x7b),
(0x7f, 0x5b, 0x6f),
(0x77, 0x53, 0x63),
(0x6b, 0x4b, 0x57),
(0x5f, 0x3f, 0x4b),
(0x57, 0x37, 0x43),
(0x4b, 0x2f, 0x37),
(0x43, 0x27, 0x2f),
(0x37, 0x1f, 0x23),
(0x2b, 0x17, 0x1b),
(0x23, 0x13, 0x13),
(0x17, 0x0b, 0x0b),
(0x0f, 0x07, 0x07),
(0xbb, 0x73, 0x9f),
(0xaf, 0x6b, 0x8f),
(0xa3, 0x5f, 0x83),
(0x97, 0x57, 0x77),
(0x8b, 0x4f, 0x6b),
(0x7f, 0x4b, 0x5f),
(0x73, 0x43, 0x53),
(0x6b, 0x3b, 0x4b),
(0x5f, 0x33, 0x3f),
(0x53, 0x2b, 0x37),
(0x47, 0x23, 0x2b),
(0x3b, 0x1f, 0x23),
(0x2f, 0x17, 0x1b),
(0x23, 0x13, 0x13),
(0x17, 0x0b, 0x0b),
(0x0f, 0x07, 0x07),
(0xdb, 0xc3, 0xbb),
(0xcb, 0xb3, 0xa7),
(0xbf, 0xa3, 0x9b),
(0xaf, 0x97, 0x8b),
(0xa3, 0x87, 0x7b),
(0x97, 0x7b, 0x6f),
(0x87, 0x6f, 0x5f),
(0x7b, 0x63, 0x53),
(0x6b, 0x57, 0x47),
(0x5f, 0x4b, 0x3b),
(0x53, 0x3f, 0x33),
(0x43, 0x33, 0x27),
(0x37, 0x2b, 0x1f),
(0x27, 0x1f, 0x17),
(0x1b, 0x13, 0x0f),
(0x0f, 0x0b, 0x07),
(0x6f, 0x83, 0x7b),
(0x67, 0x7b, 0x6f),
(0x5f, 0x73, 0x67),
(0x57, 0x6b, 0x5f),
(0x4f, 0x63, 0x57),
(0x47, 0x5b, 0x4f),
(0x3f, 0x53, 0x47),
(0x37, 0x4b, 0x3f),
(0x2f, 0x43, 0x37),
(0x2b, 0x3b, 0x2f),
(0x23, 0x33, 0x27),
(0x1f, 0x2b, 0x1f),
(0x17, 0x23, 0x17),
(0x0f, 0x1b, 0x13),
(0x0b, 0x13, 0x0b),
(0x07, 0x0b, 0x07),
(0xff, 0xf3, 0x1b),
(0xef, 0xdf, 0x17),
(0xdb, 0xcb, 0x13),
(0xcb, 0xb7, 0x0f),
(0xbb, 0xa7, 0x0f),
(0xab, 0x97, 0x0b),
(0x9b, 0x83, 0x07),
(0x8b, 0x73, 0x07),
(0x7b, 0x63, 0x07),
(0x6b, 0x53, 0x00),
(0x5b, 0x47, 0x00),
(0x4b, 0x37, 0x00),
(0x3b, 0x2b, 0x00),
(0x2b, 0x1f, 0x00),
(0x1b, 0x0f, 0x00),
(0x0b, 0x07, 0x00),
(0x00, 0x00, 0xff),
(0x0b, 0x0b, 0xef),
(0x13, 0x13, 0xdf),
(0x1b, 0x1b, 0xcf),
(0x23, 0x23, 0xbf),
(0x2b, 0x2b, 0xaf),
(0x2f, 0x2f, 0x9f),
(0x2f, 0x2f, 0x8f),
(0x2f, 0x2f, 0x7f),
(0x2f, 0x2f, 0x6f),
(0x2f, 0x2f, 0x5f),
(0x2b, 0x2b, 0x4f),
(0x23, 0x23, 0x3f),
(0x1b, 0x1b, 0x2f),
(0x13, 0x13, 0x1f),
(0x0b, 0x0b, 0x0f),
(0x2b, 0x00, 0x00),
(0x3b, 0x00, 0x00),
(0x4b, 0x07, 0x00),
(0x5f, 0x07, 0x00),
(0x6f, 0x0f, 0x00),
(0x7f, 0x17, 0x07),
(0x93, 0x1f, 0x07),
(0xa3, 0x27, 0x0b),
(0xb7, 0x33, 0x0f),
(0xc3, 0x4b, 0x1b),
(0xcf, 0x63, 0x2b),
(0xdb, 0x7f, 0x3b),
(0xe3, 0x97, 0x4f),
(0xe7, 0xab, 0x5f),
(0xef, 0xbf, 0x77),
(0xf7, 0xd3, 0x8b),
(0xa7, 0x7b, 0x3b),
(0xb7, 0x9b, 0x37),
(0xc7, 0xc3, 0x37),
(0xe7, 0xe3, 0x57),
(0x7f, 0xbf, 0xff),
(0xab, 0xe7, 0xff),
(0xd7, 0xff, 0xff),
(0x67, 0x00, 0x00),
(0x8b, 0x00, 0x00),
(0xb3, 0x00, 0x00),
(0xd7, 0x00, 0x00),
(0xff, 0x00, 0x00),
(0xff, 0xf3, 0x93),
(0xff, 0xf7, 0xc7),
(0xff, 0xff, 0xff),
(0x9f, 0x5b, 0x53),
)