mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-06-01 09:02:08 +00:00
Clean up export_mdl() a little.
This commit is contained in:
parent
4a3731652e
commit
8bec9cb203
2 changed files with 35 additions and 23 deletions
|
@ -26,9 +26,10 @@ from mathutils import Vector,Matrix
|
||||||
from .quakepal import palette
|
from .quakepal import palette
|
||||||
from .mdl import MDL
|
from .mdl import MDL
|
||||||
|
|
||||||
def export_mdl(operator, context, filepath):
|
def check_faces(mesh):
|
||||||
obj = context.active_object
|
#Check that all faces are tris because mdl does not support anything else.
|
||||||
mesh = obj.data
|
#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
|
faces_ok = True
|
||||||
save_select = []
|
save_select = []
|
||||||
for f in mesh.faces:
|
for f in mesh.faces:
|
||||||
|
@ -39,27 +40,14 @@ def export_mdl(operator, context, filepath):
|
||||||
faces_ok = False
|
faces_ok = False
|
||||||
if not faces_ok:
|
if not faces_ok:
|
||||||
mesh.update()
|
mesh.update()
|
||||||
operator.report({'ERROR'},
|
return False
|
||||||
"Mesh has faces with more than 3 vertices.")
|
|
||||||
return {'CANCELLED'}
|
|
||||||
#reset selection to what it was before the check.
|
#reset selection to what it was before the check.
|
||||||
for f, s in map(lambda x, y: (x, y), mesh.faces, save_select):
|
for f, s in map(lambda x, y: (x, y), mesh.faces, save_select):
|
||||||
f.select = s
|
f.select = s
|
||||||
mdl = MDL()
|
mesh.update()
|
||||||
mdl.name = obj.name
|
return True
|
||||||
mdl.ident = "IDPO" #only 8 bit for now
|
|
||||||
mdl.version = 6 #write only version 6 (nothing usable uses 3)
|
def make_skin(mdl, mesh):
|
||||||
mdl.scale = (1.0, 1.0, 1.0) #FIXME
|
|
||||||
mdl.scale_origin = (0.0, 0.0, 0.0) #FIXME
|
|
||||||
mdl.boundingradius = 1.0 #FIXME
|
|
||||||
mdl.eyeposition = (0.0, 0.0, 0.0) #FIXME
|
|
||||||
mdl.synctype = 0 #FIXME config (right default?)
|
|
||||||
mdl.flags = 0 #FIXME config
|
|
||||||
mdl.size = 0 #FIXME ???
|
|
||||||
mdl.skins = []
|
|
||||||
mdl.stverts = []
|
|
||||||
mdl.tris = []
|
|
||||||
mdl.frames = []
|
|
||||||
if (not mesh.uv_textures or not mesh.uv_textures[0].data
|
if (not mesh.uv_textures or not mesh.uv_textures[0].data
|
||||||
or not mesh.uv_textures[0].data[0].image):
|
or not mesh.uv_textures[0].data[0].image):
|
||||||
mdl.skinwidth = mdl.skinheight = 4
|
mdl.skinwidth = mdl.skinheight = 4
|
||||||
|
@ -91,5 +79,15 @@ def export_mdl(operator, context, filepath):
|
||||||
best = (r, i)
|
best = (r, i)
|
||||||
skin.pixels[outind] = best[1]
|
skin.pixels[outind] = best[1]
|
||||||
mdl.skins.append(skin)
|
mdl.skins.append(skin)
|
||||||
mdl.write (filepath)
|
|
||||||
|
def export_mdl(operator, context, filepath):
|
||||||
|
obj = context.active_object
|
||||||
|
mesh = obj.data
|
||||||
|
if not check_faces (mesh):
|
||||||
|
operator.report({'ERROR'},
|
||||||
|
"Mesh has faces with more than 3 vertices.")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
mdl = MDL(obj.name)
|
||||||
|
make_skin(mdl, mesh)
|
||||||
|
mdl.write(filepath)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
|
@ -207,7 +207,21 @@ class MDL:
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
self.write_bytes(data, size)
|
self.write_bytes(data, size)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name = "mdl"):
|
||||||
|
self.name = name
|
||||||
|
self.ident = "IDPO" #only 8 bit for now
|
||||||
|
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.eyeposition = (0.0, 0.0, 0.0) #FIXME
|
||||||
|
self.synctype = 0 #FIXME config (right default?)
|
||||||
|
self.flags = 0 #FIXME config
|
||||||
|
self.size = 0 #FIXME ???
|
||||||
|
self.skins = []
|
||||||
|
self.stverts = []
|
||||||
|
self.tris = []
|
||||||
|
self.frames = []
|
||||||
pass
|
pass
|
||||||
def read(self, filepath):
|
def read(self, filepath):
|
||||||
self.file = open(filepath, "rb")
|
self.file = open(filepath, "rb")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue