Moved MDL settings from Object tab to export options/presets

This commit is contained in:
khreathor 2018-11-24 02:59:41 +01:00 committed by Bill Currie
parent 90a707f7f9
commit 8112c4e8b6
2 changed files with 73 additions and 14 deletions

View file

@ -66,6 +66,7 @@ EFFECTS=(
)
class QFMDLSettings(bpy.types.PropertyGroup):
'''
eyeposition = FloatVectorProperty(
name="Eye Position",
description="View possion relative to object origin")
@ -85,9 +86,7 @@ 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",
@ -95,6 +94,10 @@ class QFMDLSettings(bpy.types.PropertyGroup):
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'''
@ -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

View file

@ -27,6 +27,7 @@ from .qfplist import pldata, PListError
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.
@ -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:
@ -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):
@ -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:
@ -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)