Skip to content

Commit

Permalink
Moved MDL settings from Object tab to export options/presets
Browse files Browse the repository at this point in the history
  • Loading branch information
khreathor authored and Aleksander Marhall committed Nov 24, 2018
1 parent ede5ad8 commit cceb9aa
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
33 changes: 30 additions & 3 deletions io_mesh_qfmdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
)

class QFMDLSettings(bpy.types.PropertyGroup):
'''
eyeposition = FloatVectorProperty(
name="Eye Position",
description="View possion relative to object origin")
Expand All @@ -85,16 +86,18 @@ class QFMDLSettings(bpy.types.PropertyGroup):
# type=bpy.types.Object,
# name="Script",
# description="Script for animating frames and skins")
script = StringProperty(
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")
'''
script = StringProperty(
name="Script",
description="Script for animating frames and skins")

class ImportMDL6(bpy.types.Operator, ImportHelper):
'''Load a Quake MDL (v6) File'''
Expand All @@ -114,10 +117,34 @@ class ExportMDL6(bpy.types.Operator, ExportHelper):

bl_idname = "export_mesh.quake_mdl_v6"
bl_label = "Export MDL"
bl_options = {'PRESET'};

filename_ext = ".mdl"
filter_glob = StringProperty(default="*.mdl", options={'HIDDEN'})

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)",
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")

@classmethod
def poll(cls, context):
return (context.active_object != None
Expand Down
54 changes: 43 additions & 11 deletions io_mesh_qfmdl/export_mdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .quakepal import palette
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.
Expand Down Expand Up @@ -185,14 +186,25 @@ def calc_average_area(mdl):
totalarea += (c * c) ** 0.5 / 2.0
return totalarea / len(mdl.tris)

def get_properties(operator, mdl, obj):
mdl.eyeposition = tuple(obj.qfmdl.eyeposition)
mdl.synctype = MDL.SYNCTYPE[obj.qfmdl.synctype]
mdl.flags = ((obj.qfmdl.rotate and MDL.EF_ROTATE or 0)
| MDL.EFFECTS[obj.qfmdl.effects])
if obj.qfmdl.md16:
def get_properties(
operator,
mdl,
eyeposition,
synctype,
rotate,
effects,
xform,
md16):
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 = obj.qfmdl.script

#tomporarily disabled
#script = obj.qfmdl.script
script = None
mdl.script = None
if script:
try:
Expand Down Expand Up @@ -276,7 +288,18 @@ def process_frame(mdl, scene, frame, vertmap, ingroup = False,
fr.name = name
return fr

def export_mdl(operator, context, filepath):
def export_mdl(
operator,
context,
filepath = "",
eyeposition = (0.0, 0.0, 0.0),
synctype = SYNCTYPE[1],
rotate = False,
effects = EFFECTS[1],
xform = True,
md16 = False
):

obj = context.active_object
mesh = obj.to_mesh(context.scene, True, 'PREVIEW') #wysiwyg?
#if not check_faces(mesh):
Expand All @@ -285,8 +308,17 @@ def export_mdl(operator, context, filepath):
# return {'CANCELLED'}
mdl = MDL(obj.name)
mdl.obj = obj
if not get_properties(operator, mdl, obj):
return {'CANCELLED'}
if not get_properties(
operator,
mdl,
eyeposition,
synctype,
rotate,
effects,
xform,
md16):
return {'CANCELLED'}

mdl.tris, mdl.stverts, vertmap = build_tris(mesh)
if mdl.script:
if 'skins' in mdl.script:
Expand All @@ -303,7 +335,7 @@ def export_mdl(operator, context, filepath):
for fno in range(context.scene.frame_start, context.scene.frame_end + 1):
context.scene.frame_set(fno)
mesh = obj.to_mesh(context.scene, True, 'PREVIEW') #wysiwyg?
if mdl.obj.qfmdl.xform:
if xform:
mesh.transform(mdl.obj.matrix_world)
mdl.frames.append(make_frame(mesh, vertmap))
convert_stverts(mdl, mdl.stverts)
Expand Down

0 comments on commit cceb9aa

Please sign in to comment.