KatsBits Community

Game Editing => Scripts & Support => Topic started by: keless on September 10, 2010, 02:48:24 AM

Title: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 10, 2010, 02:48:24 AM

IMPORTANT: When posting problems, errors or support requests please reference the exact version of Blender used along with which script - not all versions, or combinations of either (Blender release candidates included) are supported so this information helps track issues.


To download the latest MD5 export script from KatsBits click here (https://www.katsbits.com/tools/#md5).
Generic MD5 installation and usage instructions are condensed here for convenience. (https://www.katsbits.com/smforum/index.php?topic=178.0)
NOTES
Depending on the script used there may be issues with bone bounding-boxes (https://www.katsbits.com/smforum/index.php?topic=167.210). This does not have any negative bearing on the functionality of any exported models, unless, more sophisticated properties need to be used, i.e. using bone and their respective bound boxes for collision or collision-articulation (AF) which might be better suited to using external meshes or other system of mesh simplification and demarcation.

1) Re: 2.63. The MD5 export script for 2.63 has been found to work with the following versions of Blender; 2.67, 2.68a, 2.69, 2.70, 2.72. However, be sure to double-check support before use in any live projects (install Blender to a unique folder per version and test).

2) Re: 2.62. Script works correctly in Blender 2.62 ONLY.

3) Re: 2.59. Script works correctly in Blender 2.59 ONLY


MD5 Models, Multiple Textures/Materials

MD5 & Multiple Meshes (Blender)



Sadly not yet... I've been onto der_ton to see if he's had a chance to address this yet but so far he's not been able to do anything due to real life getting in the way. I think a number of these 'old' scripts are going to need the community to come up with the goods as the original authors of them have either lost interest and gone MIA or have other more pressing responsibilities - wife/baby/cat/goldfish [delete as appropriate].

I've recently added an MD5 loader and render support in my game engine, but I hate animating in old Blender 2.4x so it looks like I need to roll up my sleeves and write a 2.5x exporter. I'm somewhat familiar with the MD5 format now (plus its a human-readable format) but I'm not familiar with writing Blender exporters (or python for that matter, but no biggie I'm a professional).

Is anyone familiar with writing Blender 2.5x exporters that could give me an overview of that side of things before I delve in (someone did an Md3 exporter recently)? Alternatively, I'll bite the bullet and search for some tutorials.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 10, 2010, 03:19:21 AM
The MD3 was a bit of a 'hack' job from what the author told me. He did copy/paste some sections from the old ones to save time (why re-invent the wheel), but pretty much rewrote the thing. I'm having trouble getting Blenders website atm but there is supposed to be a knowledge base there for script authors looking for info on updating to 2.5.

http://www.blender.org/development/
The actual docs for Blender are here - http://wiki.blender.org/index.php/BlenderDev/Blender2.5
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 10, 2010, 07:42:51 AM
Thanks Kat.

With those, plus a python Quick Guide and Xembie's md3 exporter as reference, I've started down the yellow brick road. I have to diverge from the md3 script as it seems to be a binary format, whereas md5 is ascii (unless I'm reading the python code incorrectly)

Beginning to flesh out my data structs, can any python lovers remark if I'm messing things up?
Code: [Select]
__author__ = ["Paul Zirkle AKA Keless"]
__version__ = '0.1'
__url__ = ["www.blender.org","http://xreal.sourceforge.net","http://www.katsbits.com"]

# referenced export_md3_12.py by Xembie

"""
Name: 'Quake Model 5 (.md5mesh/.md5anim)'
Blender: 253
Group: 'Export'
Tooltip: 'Export a Md5 mesh/anim'
"""

import bpy,struct,math,os,time

MAX_QPATH = 64
MD5_VER_TAG = "MD5Version"
MD5_VERSION = 10

class Md5Joint_t:
name = "" #string
parent = -1 #int
pos = [] #float3 as vector3
orient = [] #float3 as quaternion3 (w is computed from xyz upon loading)

def __init__(self):
self.pos = [0.0, 0.0, 0.0]
self.orient = [0.0, 0.0, 0.0]

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, parentName):
strOut = '    "' + self.name + '" ' + parent \
+ ' ( ' + self.pos[0] + ' ' + self.pos[1] + ' ' + self.pos[2] + ' )' \
+ ' ( ' + self.orient[0] + ' ' + self.orient[1] + ' ' + self.orient[2] + ' ) ' \
+ '    // ' + parentName
file.write(strOut)

class Md5Vertex_t:
u
v
boneWeight = 0 #int
boneCount = 0 #int

def __init__(self):
self.u = 0.0
self.v = 0.0

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, index):
strOut = '    vert ' + index \
+ ' ( ' + self.u + ' ' + self.u + ' ) ' \
+ self.boneWeight + ' ' + self.boneCount
file.write(strOut)

class Md5Triangle_t:
indices = [] #int[3] vertex indicies

__init__(self):
self.indices = [ 0, 0, 0 ]

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, index):
strOut = '    tri ' + index + ' ' \
+ self.indicies[0] + ' ' \
+ self.indicies[1] + ' ' \
+ self.indicies[2]
file.write(strOut)



as reference, here are some of the relevant data structure outputs snipped from an md5 file:
Code: [Select]
"Body2" 1 ( 0 0.0000023712 39.7816314697 ) ( -0.7071067095 0 0 ) // Body
vert 4 ( 0.5554450154 0.2438279986 ) 13 4
tri 1 0 1 3

TIA
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 10, 2010, 04:10:50 PM
Not sure if this will be of use here but might be a good idea to keep an eye on rich_is_bored's ASE topic (http://www.doom3world.org/phpbb2/viewtopic.php?f=3&t=23758), there's an interesting problem cropping up with that script to do with the latest builds of Blender.

And yes you're right, MD3 is compiled binary format. Although MD5 is 'ascii', a couple of games - Quake Wars and Wolfenstein - made use of a binary version of the format; iirc you just output a normal MD5's and then run them through the game editing tools to produce the binary versions.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 13, 2010, 04:42:14 AM
Was on road trip this weekend, so didn't get a lot done, here is what I have:
Code: [Select]
__author__ = ["Paul Zirkle AKA Keless"]
__version__ = '0.1'
__url__ = ["www.blender.org","http://xreal.sourceforge.net","http://www.katsbits.com"]

# referenced export_md3_12.py by Xembie

"""
Name: 'Quake Model 5 (.md5mesh/.md5anim)'
Blender: 253
Group: 'Export'
Tooltip: 'Export a Md5 mesh/anim'
"""

import bpy,struct,math,os,time

MAX_QPATH = 64
MD5_COMMANDLINE = "created by Blender 2.53 with export_md5.py (v0.1) by Paul Zirkle"
MD5_VERSION = 10

class Md5Joint_t:
name = "" #string
parent = -1 #int
parentName = "" #string
pos = [] #float3 as vector3
orient = [] #float3 as quaternion3 (w is computed from xyz upon loading)

def __init__(self):
self.pos = [0.0, 0.0, 0.0]
self.orient = [0.0, 0.0, 0.0]

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file):
strOut = '    "%s" %d ( %f %f %f ) ( %f %f %f )    // %s ' % \
(self.name, parent, self.pos[0], self.pos[1], self.pos[2], \
self.orient[0], self.orient[1], self.orient[2], self.parentName )

#strOut = '    "' + self.name + '" ' + parent \
# + ' ( ' + self.pos[0] + ' ' + self.pos[1] + ' ' + self.pos[2] + ' )' \
# + ' ( ' + self.orient[0] + ' ' + self.orient[1] + ' ' + self.orient[2] + ' ) ' \
# + '    // ' + self.parentName
file.write(strOut)

#vertex texture and bone weight data
class Md5Vertex_t:
u = 0.0 #float
v = 0.0 #float
boneWeight = 0 #int
boneCount = 0 #int

def __init__(self):
self.u = 0.0
self.v = 0.0

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, index):
strOut = '    vert %d ( %f %f ) %d %d ' % \
( index, self.u, self.v, self.boneWeight, self.boneCount)
#strOut = '    vert ' + index \
# + ' ( ' + self.u + ' ' + self.v + ' ) ' \
# + self.boneWeight + ' ' + self.boneCount
file.write(strOut + '\n')

#triangle index data
class Md5Triangle_t:
indices = [] #int[3] vertex indicies

def __init__(self):
self.indices = [ 0, 0, 0 ]

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, index):
strOut = '    tri %d %d %d %d ' % \
( index, self.indices[0], self.indices[1], self.indices[2] )
#strOut = '    tri ' + index + ' ' \
# + self.indicies[0] + ' ' \
# + self.indicies[1] + ' ' \
# + self.indicies[2]
file.write(strOut + '\n')

#weighted vertex data
class Md5Weight_t:
jointIdx = 0 #int
bias = 0.0 #float
pos = [] #float[3] vertex

def __init__(self):
self.pos = [ 0.0, 0.0, 0.0 ]

def GetSize(self):
return struct.calcsize(self.binaryFormat)

#serialize
def Save(self, file, index):
strOut = '    weight %d %d %f ( %f %f %f ) ' % \
( index, self.jointIdx, self.bias, self.pos[0], self.pos[1], self.pos[2] )
#strOut = '    weight ' + index +  ' ' \
# + self.jointIdx + ' ' + self.bias  \
# + ' ( ' +  self.pos[0] + ' ' + self.pos[1] + ' ' + self.pos[2] + ' ) '
file.write(strOut + '\n')

#holds verts, tris, and weights
class Md5Mesh:
name = ""
shader = "" #string referencing skin file (dont appent ext)
verts = [] # list of Md5Vertex_t
tris = [] # list of Md5Triangle_t
weights = [] # list of Md5Weight_t

def __init__(self):
self.numVerts = 0
self.numTris = 0
self.numWeights = 0

#serialize
def Save(self, file):
strOut = 'mesh { \n'
strOut += '    // meshes: ' + self.name + '\n'
strOut += '    shader "' + self.shader + '" \n'
strOut += '\n'
strOut += '    numVerts ' + str( len(self.verts) ) + '\n'
file.write(strOut)
for vi in range(len(self.verts)):
self.verts[vi].Save(file, vi)

strOut = '\n'
strOut += '    numtris ' + str( len(self.tris) ) + '\n'
file.write(strOut)
for ti in range(len(self.tris)):
self.tris[ti].Save(file, ti)

strOut = '\n'
strOut += '    numweights ' + str( len(self.weights) ) + '\n'
file.write(strOut)
for wi in range(len(self.weights)):
self.weights[wi].Save(file, wi)

strOut = '\n'
strOut += '} \n\n'
file.write(strOut)


class md5meshFileObject:
ver = 0 # should be "MD5Version 10"
commandLine = "" # ignored, so insert blatant self-promotion
skeleton = [] # list of Md5Joint_t
meshes = [] # list of Md5Mesh

def __init__(self):
self.ver = MD5_VERSION
self.commandLine = MD5_COMMANDLINE

def Save(self, file):
strOut = 'MD5Version ' + str(self.ver) + '\n'
strOut += 'commandline "' + self.commandLine + '" \n'
strOut += '\n'
strOut += 'numJoints ' + str( len(self.skeleton) ) + '\n'
strOut += 'numMeshes ' + str( len(self.meshes) ) + '\n'
strOut += '\n'
strOut += 'joints { \n'
file.write(strOut)
for joint in self.skeleton:
  joint.Save(file)

strOut = '} \n'
strOut += '\n'
file.write(strOut)
for mesh in self.meshes:
  mesh.Save(file)


def message(log,msg):
  if log:
    log.write(msg + "\n")
  else:
    print(msg)

class md5Settings:
def __init__(self, savepath, name, logtype, scale=1.0, offsetx=0.0, offsety=0.0, offsetz=0.0):
self.savepath = savepath
self.name = name
self.logtype = logtype
self.scale = scale
self.offsetx = offsetx
self.offsety = offsety
self.offsetz = offsetz

#serialize
def save_md5(settings):
starttime = time.clock() #start timer
newlogpath = os.path.splitext(settings.savepath)[0] + ".log"
if settings.logtype == "append":
log = open(newlogpath,"a")
elif settings.logtype == "overwrite":
log = open(newlogpath,"w")
else:
log = 0

message(log,"######################BEGIN######################")
message(log,"Exporting selected objects...")
bpy.ops.object.mode_set(mode='OBJECT')
md5 = md5meshFileObject()

for obj in bpy.context.selected_objects:
  if obj.type == 'MESH':
    bpy.context.scene.set_frame(bpy.context.scene.frame_start) #set timeline to 0 so we get clean mesh
    nobj = obj.create_mesh(bpy.context.scene,True,'PREVIEW') #make a copy of the pure mesh

    md5mesh = Md5Mesh()
    md5mesh.name = obj.name

    md5.meshes.append( md5mesh )

    try:
      md5mesh.shader = obj["md5shader"] #pull from custom property
    except:
      md5mesh.shader = ""

    #we will store a list of unique vertex indicies here as we iterate the mesh's faces
    vertlist = []

    for f,face in enumerate(nobj.faces): #iterate each triangle face
      md5tri = Md5Triangle_t()
      if len(face.verts) != 3:
        message(log,"WARNING: Skipping a non-triangle face in object " + obj.name)
        continue
      for v,vert_index in enumerate(face.verts):
        uv_u = round(nobj.active_uv_texture.data[f].uv[v][0],5)
        uv_v = round(nobj.active_uv_texture.data[f].uv[v][1],5)
        match  = 0 #boolean, true if this is a non-unique vertex
        match_index = 0 #int, index of vertex if already listed
        for i,vi in enumerate(vertlist):
          if vi == vert_index:
            if md5mesh.verts[i].u == uv_u and md5mesh.verts[i].v == uv_v:
              match = 1
              match_index = i

        #ERROR: this isnt right, it assumes the same number of weights and verts, which is a lie!
        if match == 0: #found new unique vertex
          vertlist.append(vert_index)
          md5tri.indices[v] = md5mesh.numVerts
          md5vert = Md5Vertex_t()
          md5vert.u = uv_u
          md5vert.v = uv_v
          #TODO: md5vert.boneWeight
          #TODO: md5vert.boneCount
          md5weight = Md5Weight_t()
          #TODO: md5weight.jointIdx
          #TODO: md5weight.bias
          md5weight.pos = nobj.verts[vert_index].co * obj.matrix_world
          md5weight.pos[0] = round(((md5weight.pos[0] + obj.matrix_world[3][0]) * settings.scale) + settings.offsetx,5)
          md5weight.pos[1] = round(((md5weight.pos[0] + obj.matrix_world[3][1]) * settings.scale) + settings.offsety,5)
          md5weight.pos[2] = round(((md5weight.pos[0] + obj.matrix_world[3][2]) * settings.scale) + settings.offsetz,5)
          md5mesh.verts.append(md5vert)
          md5mesh.weights.append(md5weight)
          md5mesh.numVerts += 1
        else: #found matched vertex
          md5tri.indices[v] = match_index

      md5mesh.tris.append(md5tri)
      md5mesh.numTris += 1


    #end for f,face in enumerate(nobj.face)
    bpy.data.meshes.remove(nobj) #clean up temporary copy
    #TODO: now read in reference skeleton

  elif obj.type == 'EMPTY':
  message(log, "skip empty obj " + obj.name)

if bpy.context.selected_objects:
  file = open(settings.savepath + ".md5mesh", "w")  #removed "wb" -- ascii, so dont open in binary mode
  md5.Save(file)
  file.close()
  #TODO: save md5anim
  message(log, "MD5 saved to " + settings.savepath)
  elapsedtime = round(time.clock() - starttime,5)
  message(log, "Elapsed " + str(elapsedtime) + " seconds")
else:
  message(log, "Select an object to export!")

if log:
  print("Logged to", newlogpath)
  log.close()
 
#now create the UI registration interface
from bpy.props import *
class ExportMD5(bpy.types.Operator):
  '''Export to Quake Model 5 (.md5mesh)'''
  bl_idname = "export.md5"
  bl_label = 'Export MD5'
 
  logenum = [("console","Console","log to console"),
             ("append","Append","append to log file"),
             ("overwrite","Overwrite","overwrite log file")]
 
  filepath = StringProperty(subtype = 'FILE_PATH',name="File Path", description="Filepath for exporting", maxlen= 1024, default= "")
  md5name = StringProperty(name="MD5 Name", description="MD5 header name / skin path (64 bytes)",maxlen=64,default="")
  md5logtype = EnumProperty(name="Save log", items=logenum, description="File logging options",default = 'console')
  md5scale = FloatProperty(name="Scale", description="Scale all objects from world origin (0,0,0)",default=1.0,precision=5)
  md5offsetx = FloatProperty(name="Offset X", description="Transition scene along x axis",default=0.0,precision=5)
  md5offsety = FloatProperty(name="Offset Y", description="Transition scene along y axis",default=0.0,precision=5)
  md5offsetz = FloatProperty(name="Offset Z", description="Transition scene along z axis",default=0.0,precision=5)
 
  def execute(self, context):
   settings = md5Settings(savepath = self.properties.filepath,
                          name = self.properties.md5name,
                          logtype = self.properties.md5logtype,
                          scale = self.properties.md5scale,
                          offsetx = self.properties.md5offsetx,
                          offsety = self.properties.md5offsety,
                          offsetz = self.properties.md5offsetz)
   save_md5(settings)
   return {'FINISHED'}
   
  def invoke(self, context, event):
    wm = context.manager
    wm.add_fileselect(self)
    return {'RUNNING_MODAL'}

  def poll(self, context):
    return context.active_object != None
   
def menu_func(self, context):
  newpath = os.path.splitext(bpy.context.main.filepath)[0] + ".md5"
  self.layout.operator(ExportMD5.bl_idname, text="Quake Model 5 (.md5)", icon='BLENDER').filepath = newpath
     
def register():
  bpy.types.register(ExportMD5)
  bpy.types.INFO_MT_file_export.append(menu_func)
   
def unregister():
  bpy.types.unregister(ExportMD5)
  bpy.types.INFO_MT_file_export.remove(menu_func)
   
if __name__ == "__main__":
  register()
   

When used with the simple start up cube in blender (after CTRL-T to subdivide it into triangles), I get this result:
Code: [Select]
MD5Version 10
commandline "created by Blender 2.53 with export_md5.py (v0.1) by Paul Zirkle"

numJoints 0
numMeshes 1

joints {
}

mesh {
    // meshes: Cube
    shader ""

    numVerts 20
    vert 0 ( 0.000000 0.000000 ) 0 0
    vert 1 ( 1.000000 0.000000 ) 0 0
    vert 2 ( 1.000000 1.000000 ) 0 0
    vert 3 ( 0.000000 1.000000 ) 0 0
    vert 4 ( 0.000000 0.000000 ) 0 0
    vert 5 ( 1.000000 0.000000 ) 0 0
    vert 6 ( 1.000000 1.000000 ) 0 0
    vert 7 ( 0.000000 1.000000 ) 0 0
    vert 8 ( 0.000000 0.000000 ) 0 0
    vert 9 ( 1.000000 0.000000 ) 0 0
    vert 10 ( 0.000000 1.000000 ) 0 0
    vert 11 ( 1.000000 1.000000 ) 0 0
    vert 12 ( 0.000000 0.000000 ) 0 0
    vert 13 ( 1.000000 0.000000 ) 0 0
    vert 14 ( 0.000000 1.000000 ) 0 0
    vert 15 ( 1.000000 1.000000 ) 0 0
    vert 16 ( 1.000000 0.000000 ) 0 0
    vert 17 ( 0.000000 1.000000 ) 0 0
    vert 18 ( 1.000000 0.000000 ) 0 0
    vert 19 ( 1.000000 1.000000 ) 0 0

    numtris 12
    tri 0 0 1 2
    tri 1 0 2 3
    tri 2 4 5 6
    tri 3 4 6 7
    tri 4 8 9 10
    tri 5 9 11 10
    tri 6 12 13 14
    tri 7 13 15 14
    tri 8 0 16 17
    tri 9 16 11 17
    tri 10 12 18 19
    tri 11 12 19 7

    numweights 20
    weight 0 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 1 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 2 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 3 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 4 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 5 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 6 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 7 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 8 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 9 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 10 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 11 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 12 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 13 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 14 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 15 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 16 0 0.000000 ( -1.000000 -1.000000 -1.000000 )
    weight 17 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 18 0 0.000000 ( 1.000000 1.000000 1.000000 )
    weight 19 0 0.000000 ( -1.000000 -1.000000 -1.000000 )

}


I don't have any code to pull the skeleton yet (and that sample doesnt have bones anyway) but there is a problem besides that: the num weights and num verts are exactly the same. I tried to use analogies from the original md3 exporter when writing this, but they dont quite work out. I'm not really sure what I should be pulling the "weights" and "verts" from (though I think the "tris" section is correct).

Part of the problem being the MD5 naming scheme is terrible since "weights" has actual XYZ vertex data, and "verts" has UV texcoords data.

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 13, 2010, 06:09:48 AM
I just looked at my old 'Bob' character model files (http://www.katsbits.com/download/models/#md5) I've got on site and the *.md5mesh data is not that far off what you've got there.

NumWeights looks like this;
Code: [Select]
weight 0 15 1.000000 0.872552 4.004826 1.665381NumVerts looks like this;
Code: [Select]
vert 0 0.162109 0.550781 0 1So at first glance it looks like the format is actually structured that way in terms of it's appearance without necessarily meaning that it *is* XYZ coordinate data?... if that makes sense?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 13, 2010, 06:21:55 AM
I just looked at my old 'Bob' character model files (http://www.katsbits.com/download/models/#md5) I've got on site and the *.md5mesh data is not that far off what you've got there.

NumWeights looks like this;
Code: [Select]
weight 0 15 1.000000 0.872552 4.004826 1.665381NumVerts looks like this;
Code: [Select]
vert 0 0.162109 0.550781 0 1So at first glance it looks like the format is actually structured that way in terms of it's appearance without necessarily meaning that it *is* XYZ coordinate data?... if that makes sense?

Well, if the vector3f in Weight _isnt_ an XYZ coordinate of a vector, where IS that data? I basically assumed it was positional since there doesnt seem to be any other positional data other than the quat+pos for bones.

Tomorrow I'll take a look at the old 2.4x export script and see what I can figure out.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ratty redemption on September 13, 2010, 10:28:41 AM
@keless, although i can't help i 'applaud' you for working on this *thumbs up*
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 13, 2010, 08:39:49 PM
@keless, although i can't help i 'applaud' you for working on this *thumbs up*

np, I needed to practice some python anyway  ;)   Just wish it wasn't a weakly typed language, it makes it harder to read other people's scripts when they don't comment their variable declarations
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ratty redemption on September 13, 2010, 08:54:31 PM
@keless, understood and i can imagine that would be frustrating, but well done for persevering, it's a shame there aren't more coders like you willing to work on these import/export scripts.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: der_ton on September 14, 2010, 12:30:16 AM
Hi, I'm the guy who wrote the script for the 2.4x Blender version. I think you could save some time by reusing some of it and just updating the parts that interface with Blender to get the data out of Blender and into the python script's structures, and from there the already existing md5 output will work, independently of the changes in Blender2.5.

I can fully understand that you don't want to use the existing script though. Programming is fun, and programming your own stuff and going all the way on your own legs (or brains, hehe) is much more fun than reusing someone else's stuff (even though I like to think my old script is not too bad code, you're right, python makes it a bit more difficult if the script documentation isn't that good).

on topic: The file format apparently was laid out so there's a minimum of preprocessing that the game engine has to do on load-time. The data in the weights is indeed xyz positions, in bone-space of their respective bone. A vertex (in the md5 naming scheme) doesn't have a position because there is no fixed position in an animated mesh. A md5mesh vertex' position is determined by its position relative to its (possibly multiple) influencing bones, and these relative positions are those 'weights' positions. There are pages on doom3world.org and I also think on http://www.modwiki.net/ that describe the semantics of the md5 file contents. Sorry if that sounds rude, but how did you write md5 rendering code for your engine if a detail like that raises questions?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 14, 2010, 12:55:00 AM
Hey der_ton--   yes, thats actually what I'm doing right now (using the module registration code from the md3 loader, but converting your 2.4 code into 2.5)

On that note, does anyone know what the Blender 2.5x translation of the 2.4x call to
Code: [Select]
data.getVertexInfluences(face.v[i].index) would be?

EDIT:
I'm reading some of the other 2.5x exporters (like export_obj.py) and I'm thinking the 'bone' names associated with the vertex are found as the vertex group names? So a vertex with 4 groups named 'g1, g2, g3, g4' would be associated with bones 'g1', 'g2', 'g3', and 'g4' and somewhere there will be a per-vertex list of weights.

So to get a list of bones associated with a vertex, it looks like syntax might be:
Code: [Select]
mesh = someMeshObj
for vert in mesh.verts:
  boneWeights = [0] * len( vert.groups )
  for vgIdx in range(len(vert.groups)):
    boneWeights[vgIdx].objVgIdx = vert.groups[vgIdx].group
    boneWeights[vgIdx].weight = vert.groups[vgIdx].weight
  
  for weight in boneWeights:
    weight.name = mesh.vertex_groups[ weight.objVgIdx ].name

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 14, 2010, 11:18:59 PM
Anyone know how to remove objects from a bpy_prop_collection in 2.5x?

specifically:
Code: [Select]
nobj = obj.create_mesh(bpy.context.scene,True,'PREVIEW')
faces = nopj.faces

for face in faces[:]:
  #some code here
  faces.remove(face.index)  #ERROR HERE

in the 2.4x md5 script, he iterates over the list of faces in a mesh, and removes each face as it's processed. However, with the 2.5x code the list of faces is such that the array of faces held by the "preview" object (or by bpy.data.meshes['meshname'].faces ) is 'protected' and remove() function exists but fails:

"TypeError: bpy_prop_collection.remove() not supported for this collection"
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 15, 2010, 12:36:11 AM
Take a look on the ModWiki page for bone info (http://www.modwiki.net/wiki/MD5MESH_%28file_format%29) because there are significant organisational differences between older and newer MD5's and their data structure. I just had a look at the file I posted above vs the files contained in the source zip on the same page, one's a v6 file, the other a v10 (something I need to correct as I missed that one)  :-\
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 15, 2010, 12:57:44 AM
Yeah, the MD5s I've been working with are all v10, and der_ton's export script is v10 as well.

I don't know of any versions greater than v10, but I'm only planning on getting 10 to work (ignoring older versions) at the moment.

I'm skipping animation for right now, but I've got a valid md5mesh output going. However, the texture coordinates seem wrong and some of my test files fail to export due to index OOB error.

The file is getting kind of long, is there a way to add attachments to forum posts, or should I set up a public host for sharing?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 15, 2010, 06:41:22 PM
Here is the current WIP script:http://dl.dropbox.com/u/1556553/io_export_md5.9-15-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-15-2010.py)

EDIT: for Blender 2.54 beta

* The joints section at the top of the file seems CORRECT.

* Actual vertex data seems CORRECT.

* Tex UV coordinates are WRONG.

* Bone weights are INCONCLUSIVE (since I don't export animation data to test them out yet).

This script will FAIL on line 500 on some models due to index OOB error, which I'm currently looking at.

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 15, 2010, 06:58:53 PM
Couldn't get this to run for some reason. Tried loading it into a text view and Alt+P'd it but that doesn't run scripts at present. Also dropped it into scripts/io and had to change the name to "export_md5.py" for it to appear in the export list, but it shows up as a list heading rather than an active script for me.

This is with 2.53beta running on Vista.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 15, 2010, 07:22:13 PM
Couldn't get this to run for some reason. Tried loading it into a text view and Alt+P'd it but that doesn't run scripts at present. Also dropped it into scripts/io and had to change the name to "export_md5.py" for it to appear in the export list, but it shows up as a list heading rather than an active script for me.

This is with 2.53beta running on Vista.

Sorry, I forgot to specify, this is for the latest public beta version of Blender which is now 2.54  (they changed the module registration methods which broke 2.53 scripts, so it wont even run if you try it in 2.53)

Also; small update to the script, which fixed the index OOB error, however the model that had that error now compiles but vertices are messed up when rendered.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 15, 2010, 08:23:15 PM
Tried two tests with this once I got it loaded into Blender ... btw... "grrrrr" on the fact that they've changed things around internally yet again. Distributied scripts are in a different location, if you put customs in there they don't work, so thankfully it still seems that "scripts/io" is where they should be placed.

Tried the script with the source file version of bob (linked to above) loaded into 2.54 and got some output but just a few lines;
Code: [Select]
MD5Version 10
commandline "Exported from Blender by export_md5.py by Paul Zirkle"

numJoints 0
numMeshes 1

joints {
}

mesh {
shader "body"
numverts 0
numtris 0
numweights 0
}
Produces the same output regardless as to whether the mesh has a parent or not. A second test on a simple textured cube has Blender go through the motions of exporting without actually producing a file; it's been a long time since I used MD5 meshes so I can't remember if there were some necessary requirements for export - vertex_groups and or Armatures etc?.

[EDIT]Console writes the following error on the simple cube
Code: [Select]
Exporting selected objects...
Processing mesh: Cube
Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Roaming\Blender Foundation\Blender\2.54\scripts\io\
io_export_md5.py", line 637, in execute
    save_md5(settings)
  File "C:\Users\[user]\AppData\Roaming\Blender Foundation\Blender\2.54\scripts\io\
io_export_md5.py", line 491, in save_md5
    ), matrix))
NameError: global name 'matrix' is not defined
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 15, 2010, 08:50:54 PM
MD5 requires an armature

the samples I'm working with have 2 meshes (one head and one body) and a 30 bone armature which uses vertex groups to bind the bones: so I think yes, both are required.

Then to export, I select the two meshes and the armature (since the script pulls from the list of highlighted objects). You should only have ONE armature in the selection (the script will use the first armature it finds and ignore any others), but will export any number of meshes and ignore any other object types. The meshes can be Tri or Quad, but the script will cut quads down into tris, and throw away any faces with overlapping (forget the term; degenerate?) vertices.

looks like line 492 is a bug, since that should be "w_matrix" not "matrix" -- I renamed the variable from the original to be a little less generic (that is the obj.matrix_world matrix). Don't know why it not complaining about it in my tests, I guess its just accepting a null?

EDIT: just ran my samples thru der_ton's script on blender 2.49b and it seems like a lot of differences (not just a texUV Y thats flipped, but different bone coords and also more verts, tris and weights showing up!)


First thing I'm trying to address is the skeleton code, specifically the def treat_bone() function, since that should be the easiest.

Currently the position of the bones is wrong, but the rotation is correct.

In the original code, there is both a mat and pmat that is calculated, however pmat is stored in the Bone object but never used-- so I'll ignore it, leaving me with the following original code:
Code: [Select]
matrix = obj.getMatrix('worldspace')

def treat_bone(b, parent = None):
  ...
  mat = Blender.Mathutils.Matrix(b.matrix['ARMATURESPACE'])*matrix
  ...
  bone = Bone( ..., mat, ... )
  ...

Initially, I have translated this to Blender 2.5x as:
Code: [Select]
w_matrix = obj.matrix_world

def treat_bone(b, parent = None):
  ...
  mat = b.matrix_local * w_matrix
  ...
  bone = Bone( ..., mat, ... )
  ...

And the results of the first two bones in each case:
Code: [Select]
"Torso" -1 ( 0.019181 0.011407 7.975472 ) ( -0.707107 -0.000000 -0.000000 )       //2.49
"L_Up_Arm" 0 ( 0.019181 0.011407 12.575473 ) ( 0.000000 0.017672 0.707106 )           //2.49
"Torso" -1 ( 0.019181 -7.975471 0.011409 ) ( -0.707107 -0.000000 -0.000000 ) //2.54
"L_Up_Arm" 0 ( -0.187871 0.180156 12.571256 ) ( 0.000000 0.017672 0.707106 )            //2.54

In both cases, the rotations (the second set of xyz data) are correct, however the positions are off. Specifically the position of the root bone looks like "x -z y", while the second bone is much further deformed (probably error propagation). In which case the problem seems to be a coordinate system change in Blender from 2.4 to 2.5? Amirite?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 16, 2010, 01:38:49 AM
Okay this is weird as hell. I'm comparing the actual matrix values found in 2.4 and 2.5

The actual matrix values before the multiplication match up. Specifically:

obj.getMatrix('worldspace')  == obj.matrix_world ==
[1.000000, 0.000000, 0.000000, 0.000000]
[0.000000, 1.000000, 0.000000, 0.000000]
[0.000000, 0.000000, 1.000000, 0.000000]
[0.019181, 0.011407, 7.975471, 1.000000]

and

b.matrix['ARMATURESPACE'] == b.matrix_local ==
[1.000000, 0.000000, -0.000000, 0.000000]
[-0.000000, 0.000000, 1.000000, 0.000000]
[0.000000, -1.000000, 0.000000, 0.000000]
[0.000000, 0.000000, 0.000002, 1.000000]

however, it seems like the matrix multiplication result is DIFFERENT?!

in Blender 2.49b the result is:
[1.000000, 0.000000, -0.000000, 0.000000]
[-0.000000, 0.000000, 1.000000, 0.000000]
[0.000000, -1.000000, 0.000000, 0.000000]
[0.019181, 0.011407, 7.975472, 1.000000]

in Blender 2.54 the result is:
[1.000000, 0.000000, -0.00000, 0.00000]
[-0.00000, 0.000000, 1.000000, 0.00000]
[0.000000, -1.00000, 0.000000, 0.00000]
[0.019181, -7.975471, 0.011409, 1.0000]

ARRRGGG!! order of multiplication changed!

instead of multiplying the bone space * world matrix in 2.4, we need to multiply the world matrix * bone space in 2.5

updated script in place (http://dl.dropbox.com/u/1556553/io_export_md5.9-15-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-15-2010.py) )

now I need to figure out why there is a major difference in the number of verts/tris/weights section. Probably a problem with the whole face_vertices code, and how it does or doesnt cut quads up into tris and handles cloning vertices (since I didn't fully understand the code when I was translating it to 2.5)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 16, 2010, 02:12:01 AM
If I'm understanding what you're saying there would it make any difference to *require* meshes be properly prepped *before* export so the script isn't doing what is effectively unnecessary work?

[EDIT]Good job so far. Results of export in the MD5 viewer. Mesh seems to be solid and everything in place, only UVW's are a messed up as per your comments above about that.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 16, 2010, 03:38:29 AM
If I'm understanding what you're saying there would it make any difference to *require* meshes be properly prepped *before* export so the script isn't doing what is effectively unnecessary work?

[EDIT]Good job so far. Results of export in the MD5 viewer. Mesh seems to be solid and everything in place, only UVW's are a messed up as per your comments above about that.

The md3 exporter for 2.5x _requires_ that the mesh already be 'triangulated' (CTRL+T) before its run. Personally, I'd rather not have this requirement, but it may be possible to copy the mesh data and run the Quad->Triangle algorithm on the copy and cull the degenerates before parsing into Face() s

I dont think the UV code is technically the problem right now, since flipping the Y/V coord worked. I think the texture problems you see are related to the improper way I'm counting up the faces/tris, and should work itself out when thats done. I know you dont see vertex problems with the guard char, but I dont see vertex problems with my frog character, and I do see plenty with my panda character.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 16, 2010, 11:03:41 PM
I've nailed down another problem in the script, specific to the getVertexInfluences code I had hacked out earlier.

In this example, the left bone name is what my function returns (always the same as the last bone name) and the right is what a hand-crafted lookup of the bone name returns.

influences for vert 1115 are:
R_Hip vs: L_Hip
R_Hip vs: L_U_Leg
R_Hip vs: R_Hip
influences for vert 1885 are:
R_Hip vs: Torso
R_Hip vs: L_Hip
R_Hip vs: R_Hip

This would probably account for the difference in WEIGHT values since there are less unique bones associated with each vertex as a result. We'll see how much this helps when I fix it.

EDIT: I've now fixed this issue, the bone influences are now returned correctly.

However, this does NOT increase the number of entries in the VERTS and WEIGHTS section. In my frog character the result is not graphically noticable. In my panda character, the body looks less like a mess of spaghetti and slightly more like a stick figure, but still not a panda.

I'm now looking into why exactly my number of VERTS/WEIGHTS doesnt match the original.

The latest: ( http://dl.dropbox.com/u/1556553/io_export_md5.9-16-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-16-2010.py) )

EDIT2:  (sorry for all the updates, but it helps me think about it clearly to write out what I know)
* the number of VERTS in the Body sub-mesh of frogger.md5mesh generated from the 2.4 script is 2298
* the number of VERTS in the Body sub-mesh of frogger.md5mesh generated from my 2.5 script is 2010
* the number of vertices in the Body mesh of frogger in memory in Blender 2.4 AND Blender 2.5 is 2010
* weights are generated as a direct result of the list of verts
>> conclusion: the old mesh generates 288 extra verts that my script does not
* there are 3 places VERTS are generated; (1) once for each vertex in the blender mesh, (2) once AGAIN for each vertex shared by non-smooth faces because they have diff normals, (3) once AGAIN for each vertex with two separate UV coords for different faces

... carp, the original script has a weirdly tabbed for-if-else section that I 'fixed' the indentation of.. this might have broken something
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 17, 2010, 01:38:21 AM
Progress: the frogger character is now 100% correct, but the panda character is still messed up.
(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fdl.dropbox.com%2Fu%2F1556553%2Fmd5_export_front.png&hash=0ff909f4f495ab92b7c7c0a36abf9b89)
(I made these models myself, and I'm a programmer, and there is no lighting in this shader, so dont worry about how crappy they are  :D )

Upon exporting the panda from the 2.4x script and comparing the results, I realized that the left/right hip bones aren't actually attached to the intended root bone (so there were effectively 3 root bones). However, after fixing this I still get the exact same result as the previously posted screenshot.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 17, 2010, 02:58:47 AM
Personally I'm glad to see you writing out what you are, so few people do this so it actually makes what they're doing more difficult to follow. So... keep doing it if you have a mind to ;)

On the extra verts... so if the script reads that a vert is on the border of both a smoothing and UVW split it introducing extra vertices per each dataset? Meaning you end up with three vertices at any given junction?

With the panda character... how old is it and what version of Blender was used to originally make it? And has it been through any iterations in different versions of Blender up to and including 2.5?

I say this because that looks like a Blender 'data' problem that happens occasionally when working with old files that have been passed through and saved in a number of different versions of Blender, this is **especially** so with Armatures. To test the output as an MD5 it might be worth stripping the current rig and replacing it with a simple two bone set up, that way you can see if there's an issue with it or not on re-export. Cute characters btw ;)

Not tested the new script yet but will post when done so, I've got a couple of rigged characters including the old version of Bob I can cross-test this with.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 17, 2010, 03:32:30 AM
re:verts -- I think technically you could end up with N verts per junction, where N = number of unique UV + normal pairs associated with that vertex. Average case will probably result in 1-n_faces verts per junction depending on whether or not the normals are same, and more on UV texture seams. In short: yes.

re:panda -- I think it was modeled in 2.48 and animated in 2.50, so it's probably worth remaking the skeleton.

meanwhile, I think I'm ready to move on to exporting md5anims next.

EDIT: Replaced the armature and the panda looks good now. Thanks for the tip, Kat; I might have been chasing my tail in the script code forever without it.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 17, 2010, 06:22:58 PM
Okay so I was never 100% clear on this in blender, and I want to make sure I have my head on straight about animations before interpreting their API.

When an artist is finished rigging, they select the armature and go into "Pose Mode". There they can modify bone positions and insert key-frame data (as a combination of Loc/Rot/Scale) per-bone at given time frames.

When this is done, it seems to automatically create an "Animation" child of that Armature (visible in the Outliner window), with an "Action" default named 'ArmatureAction'.

* I can delete or rename the action in the DopeSheet view (but no where else?)
* I cant seem to add other 'actions'
* I cant seem to add other 'animations'

* clicking the "snowflake" icon in the red strip found in the NLA Editor causes Bad Things to happen (seems to bake the action into an NLA track object which cant be edited? is this actually a Good Thing?)
* after creating a few of these, the animations seem to be floating around in memory not really attached to the 'armature' or the 'animation', however selecting one in the DopeSheet drop down and then playing it a few times seems to cause that 'action' to replace the single 'action' child of the 'Animation'
* I can create new NLA tracks, and have them consume the currently active 'action' in the NLA Editor, such that an 'Animation' object can have one "active" child 'action' and a number of NLA tracks each with their own 'action' (that might or might not also be the active 'action')

* in python, one can access the 'Animation' object from bpy.context.object.animation_data while an armature is selected in object mode (cant currently select it from bpy.data.armatures['armature name'].animation_data for some reason)

* from the animation_data, one can access a singular  .action object, or a list of .nla_tracks which seems to correspond to the results above.

THE QUESTION:

How does an artist that knows what they're doing set up character animations? To they simply have one long 'action' with all animations inserted in a row (keyframes 1-99 are 'idle', 100 - 199 are 'walk', 200 - 299 are 'kick') or do they somehow set up a series of separate NLA tracks each with their own 'action' child, meaning that the single 'action' child of the 'animation' object is just the 'currently selected action'

I need to know this so that I pull the animation(s) from the right place, instead of forcing animators to mess up their .blend to squeeze out .md5anim file(s)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 17, 2010, 10:01:54 PM
The engine you're exporting to or working with determines which animation process you use. There are basically two types or ways to animate.
1) Most games work this way, meaning that you create separate animation tracks - 'run', 'walk' and so on - each of which is then exported out as a separate animation file, in this case you could have ten separate *.md5anim files and one *.md5mesh file.
2) Tech like Unity3D use this approach whereby all the animations are included into a single track which is exported out. In the engine you then set up the animations doing what you said - 1-99 = 'walk', 100-199 = 'run' and so on

Now with regards to the 'structure' they've changed that again. In previous versions you'd have the 'Armature' at the top and then the animations as a child connections;
But they appear to have changed that so in the OOPS/Outliner view its now listing animations only on being actively selected like this;
And again if a different action/animation is active;
That's bound to change the internal data structure but at the same time it does mean that Blender is dealing with only the data that selected/active?

You can change the name of animations in the OOPS/Outline be Ctrl+LMB clicking the name to active 'edit' mode on that, you can only change user generated data though and not 'core' data - "Animation" as a named datablock can't be changed.

For the other stuff you mentioned, the "Action" editor is now a sub-editor of the main "Dopesheet" editor, so you have to go into Dopesheet and select "Action" from the dropdown menu in the header. Once there you can do all the usual edit/delete/new functions previously available.

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fimages%2Ftutorials%2Fblender-animation%2Fblender-action-editor-dopesheet_sml.jpg&hash=19ad3549727695b4d075fa942851b75a) (http://www.katsbits.com/images/tutorials/blender-animation/blender-action-editor-dopesheet.jpg)
(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fimages%2Ftutorials%2Fblender-animation%2Fblender-action-animation_sml.jpg&hash=d08d14c1a645b64cb9c88b9635576ecc) (http://www.katsbits.com/images/tutorials/blender-animation/blender-action-animation.jpg)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 17, 2010, 11:05:16 PM
Okay, I'm starting to see how I can go in to the NLA Editor and select an animation (or add a new one) in the "animation data" section of the properties panel (hotkey 'N') of that window.

1) you dont mention NLA Tracks at all; useful? ignore them?
2) if not NLA tracks, then actions are basically floating in memory and only the "active" one is really visible at any one time, so I wouldn't be able to export more than one action at a time it seems?

Aside: Blender seems to have a couple of places (this, and texture image links come to mind) where stuff can be created and just floats around in memory unless its also attached to something, which bugs the carp out of me. Stupid myTexture.001, myTexture.002 IDs that I don't know exist and cant get rid off once I do. In my mind, EVERYTHING data wise should be accessible from the Outliner tree.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2010, 12:19:00 AM
The NLA is more of a 'global' animation system in that you can track and animate objects and items, it's basically to top level system where objects and events are animated rather than bones and armatures - you can animate characters using it but it's messy as it's not easy to drill down into the working data. For example you could rig a 'walk' anim for a character, armature legs and body move, but no actual forward motion. Using the NLA would then allow you to move the character forward in *object* mode - you'd *never* do this for an actual game character though, I just use it as an example of how the NLA can be used.

Because of the way I rig my characters, I've never yet had a need to use anything other than the Action Editor, messing with IPO data and what have you has never seemed that intuitive to me.

So in answer to 1) yes (I've got some tutorials in mind to explain why but finding the time as always). 2) As far as I understand, yes, Blender works and relies on those Datablocks, so you're correct.. if there are no connections to them they tend to just sit there - you have to re-load and save the file a couple of times to get rid of them. And again yes, if there are no connections to the datablock they can't be exported from what I understand.

And I agree, Outliner for the win (certainly the way it used to list everything), I often find myself referring to that to see what's in the file and connected to what.. especially the OPPS Schematic of pre 2.49.

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 18, 2010, 01:42:26 AM
Here is the first pass at exporting the .md5anim data ( http://dl.dropbox.com/u/1556553/io_export_md5.9-17-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-17-2010.py) )

I'm just using the currently active 'action' and ignoring any others that may be in memory-- to export a series of .md5anims right now, you'd have to select each animation and perform the export one by one.

It seems to output a file in the correct format, however running the file shows the bone matrix values are corrupted. My frog character looks like a twisted mess.

The code in question should be local to:
Code: [Select]
      for bonename in thearmature.data.bones.keys():
        posebonemat = mathutils.Matrix(pose.bones[bonename].matrix ) # @ivar poseMatrix: The total transformation of this PoseBone including constraints. -- different from localMatrix
       
        try:
          bone  = BONES[bonename] #look up md5bone
        except:
          print( "found a posebone animating a bone that is not part of the exported armature: " + bonename )
          continue
        if bone.parent: # need parentspace-matrix
          parentposemat = mathutils.Matrix(pose.bones[bone.parent.name].matrix ) # @ivar poseMatrix: The total transformation of this PoseBone including constraints. -- different from localMatrix
          posebonemat = posebonemat*parentposemat.invert()
        else:
          posebonemat = posebonemat*thearmature.matrix_world
        loc = [posebonemat[3][0],
            posebonemat[3][1],
            posebonemat[3][2],
            ]
        rot = posebonemat.to_quat().normalize()
        rot = [rot.w,rot.x,rot.y,rot.z]
           
        animation.addkeyforbone(bone.id, time, loc, rot)

and changing the .matrix values to .matrix_local changes the result, but its just a slightly different twisted mess.. perhaps something somewhere else is messed up.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2010, 03:38:15 AM
Mesh exports OK.. no UVW issues from what I could tell. Will try other characters when I get a chance. Animations mess up quite bad as per your experiences, the bones seem to export OK as the rig looks sound without an animation loaded (into the MD5 viewer again). Loading in the *.md5anim 'breaks' the rig and splats the model all over the place.

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fmisc%2Fblender-md5-test2a.jpg&hash=c0927397839cdb799b7ac068a01df7d8) (http://www.katsbits.com/misc/blender-md5-test2a.jpg)
(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fmisc%2Fblender-md5-test2b.jpg&hash=7f426fc7f64bec6c1728c1f07986806b) (http://www.katsbits.com/misc/blender-md5-test2b.jpg)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 18, 2010, 07:25:55 AM
Yay, squishbunny is squishy. Also, didn't I _just_ learn that matrix multiplication order got flipped in Blender 2.5?? Durrrr...

Problem solved, correct script is available at ( http://dl.dropbox.com/u/1556553/io_export_md5.9-17-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-17-2010.py) ) pending rigorous testing.

There are plenty of bells and whistles that could be added to the script, like the ability to toggle mesh or anim generation off (if you only wanted to cut a new .md5anim file, for example), which I may or may not continue with-- anyone with the moxy is welcome to add their polish.

Also, my dropbox account may get cut off at some point in the future: if someone has a more stable place to host the script, I'd be obliged.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2010, 04:04:33 PM
Works perfectly! Excellent work on this btw and don't worry about hosting, I'll sort that out here.

I'd be inclined to add the bells and whistles you can think of to avoid 'feature creep' added by other people, gets confusing sometimes trying to figure out which scripts to use sometimes when there are several version available. Speaking of which I can only really think of two... the export option you mentioned (export either/or/both). And exporting multiple Actions, not sure how that would work based on what you discovered during the development of this though.

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fmisc%2Fblender-md5-test3.jpg&hash=4b322644c6db7422711806e8cca6e254) (http://www.katsbits.com/misc/blender-md5-test3.jpg)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 18, 2010, 07:01:18 PM
Yeah, I don't know how I'd access the other actions unless they were stored in NLA tracks. There's just no access to them through the API, unless there is some place I haven't looked.

BTW; I know bunny is somewhat low poly, but is he supposed to be that faceted, or am I exporting the normals incorrectly?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2010, 08:03:48 PM
Ah yes, everything is fine, that's just the dynamic shadow volumes of the MD5 viewer doing that, the volumes don't 'blend' or 'soften' over edges (which you probably know already), so the edge of the volume tends to be hard, causing the wierd visuals - character models in idtech games generally have 'self-shadow' turned aff because of this problem.

They've moved datablock access again. In the Outliner view click the dropdown list and select "Datablocks", actions are listed in that view under "Actions" - it should be expandable with any animation Action present in the file being listed there. So the data is there, I've just no idea how you get at it to do export all of it in one go  :-\

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fwww.katsbits.com%2Fimages%2Ftutorials%2Fblender-animation%2Fblender-outliner-datablocks-actions_sml.jpg&hash=456ae5b0885f17982002f1e3f1046cd3) (http://www.katsbits.com/images/tutorials/blender-animation/blender-outliner-datablocks-actions.jpg)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 18, 2010, 08:18:40 PM
Hrm, I thought I'd looked at that Datablocks mode of the Outliner-- guess I missed it. In my frog sample I can see the "rock" animation and the "action" (default that I though I threw away) in the data blocks. Interestingly it seems its the "action" action that has the rocking out keyframes in it, and the "rock" action is empty >.<

In python I can access it from bpy.data.actions['actionName'] so I can definitely iterate over all the actions. But in order to pull the actual animation data from it, I need a way to bind that action to the armature as the active action...

Looks like setting theArmatureObject.animation_data.action = bpy.data.actions['ActionName'] may work.
(Note: dont use theArmatureObject.data.animation_data -- seems to be an empty pointer)

I don't think there's any way to tell if an action BELONGS to an armature before you do this, so it may be error prone if you have actions that belong to other armatures in the same blend file, which may not be common for this usage anyway.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2010, 08:49:39 PM
I can't see any connection either looking at the datablock info, there seems to be a lot of recursive data in each Action but nothing that identifies it as being parented to the rig. How about doing it the other way around... If you can pull the blocks, what about a checklist option type approach? That would act as a safeguard in respect to not exporting files the user didn't select? Would that work?

You'll need to go through the save >> reload >> save >> reload process to remove that dead datablock
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 18, 2010, 09:43:31 PM
Yeah that seems the best solution, I just gotta figure out the UI api necessary to do it.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 20, 2010, 02:13:11 AM
Was testing the script today and came across a minor issue, it's currently exporting all frames present in the Actions editor time line. Sometimes you need to 'over-pose' an animation to make sure it cycles correctly, right now the script is exporting those extra unwanted frames (its exporting 1>120 instead of 1>100). You need to add a UI input field so "start >> end" frames can be marked? Or read the rendering datablock that has "start >> end" data associated with still image rendering to get the actual limit?.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 20, 2010, 08:02:09 AM
Was testing the script today and came across a minor issue, it's currently exporting all frames present in the Actions editor time line. Sometimes you need to 'over-pose' an animation to make sure it cycles correctly, right now the script is exporting those extra unwanted frames (its exporting 1>120 instead of 1>100). You need to add a UI input field so "start >> end" frames can be marked? Or read the rendering datablock that has "start >> end" data associated with still image rendering to get the actual limit?.

Currently the script is pulling the start and stop frames from action.frame_range[0,1]. I don't see any data blocks that specify an "output animation frame set" that I could pull from instead of that range. If I knew the UI api well enough (still cant get the actions list selection interface working), I would add a "force end frame" input and check box so you could toggle that on and type in your end frame.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 20, 2010, 05:47:48 PM
I've found a couple of references in the Outliner for the start/end datablock info. As it's in two locations I don't know if that means it's two sets of the same datablock info just duplicating each other or two links back to the original datablock (which I can't find).


Any use?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 21, 2010, 03:29:03 AM
Okay, looks like I can access that data from bpy.context.scene.frame_start and .frame_end

Try this: http://dl.dropbox.com/u/1556553/io_export_md5.9-20-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-20-2010.py)

Hrm, busy right now but I should check to see what happens when the "scene frame range" is larger than the "action frame range" (like the scene is from -20 to 200, but the action itself has keyframes from 0 to 202, or -30 to 50, or 20 to 100 ), might need to cap the "scene frame range" down into a subset of "action frame range"..
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 21, 2010, 06:21:19 AM
I'm not getting any output with that version for some reason and the following error crops up in the console;
Code: [Select]
found bundled python: D:\PROGRA~1\BLENDE~1\BLENDE~1.54B\2.54\python
read blend: F:\IMvu-WIPs\PET bunny\sneakyidle3 v254.blend
Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Roaming\Blender Foundation\Blender\2.54\scripts\io\
io_export_md5.py", line 832, in execute
    name = self.properties.md5name,
AttributeError: 'EXPORT_OT_md5' object has no attribute 'md5name'
I usually select both the mesh and armature with the mesh as the active object when exported (not sure if that makes a difference but it's a force of habit), adding the *.md5mesh extension to the file - tried with and without, nadda from either.

With regards the negative keyframes(?) I'm not sure that's possible, certainly not using the normal Action/Dopesheet editors, traditionally speaking Blender has always had frame "1" as the first frame into which data can be placed as "0" is used as a 'base' frame(? iirc).

Incidentally, are there some export options missing in this version or is that a result of the error? I could have sworn there were some adjustable option fields on previous versions?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 21, 2010, 07:24:10 AM
Shoot, ignore those errors-- I left in some (failed) attempt at action animation selection in the export UI. Try again, same link.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 21, 2010, 08:08:47 PM
Yep, sterling work. Its now exporting animation length based on the "Start:" and "End:" positions.

There is a caveat using this approach though; you can't do a multi-export. Because the start/end data determines the length of an animation it would mean all anims being exported using the same values irrespective of actual (needed) length. The only way around that would be to add some sort of option field per animation where users set the start and end point of each action, a bit impractical doing that though (not too mention over-complicating the script).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 23, 2010, 06:19:25 AM
Added an enum drop-down for "mesh & anim", "mesh only" or "anim only" exporting.
http://dl.dropbox.com/u/1556553/io_export_md5.9-22-2010.py (http://dl.dropbox.com/u/1556553/io_export_md5.9-22-2010.py)

It's not something I'd sell to my grandmother, but I'm calling this full featured.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 24, 2010, 07:18:18 AM
Not had a chance to test this yet, but once I've done that I'll add it to the site as a download.

[EDIT]Now had a chance to use and yep so far everything exports out correctly. Well done. Will add this to the sites tools page ASAP.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: keless on September 29, 2010, 04:48:22 PM
Thanks all around for the support. Cheers!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on October 29, 2010, 01:24:48 PM
Awesome exporter, thank you.

I have modified blender2md5 (by der_ton) that exports to Half-Life 2 SMD along with Doom 3 MD5. However the exporter is for Blender 2.49b.
Is there a way you could add an option to export to HL2 SMD to your exporter?
Thanks.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 05, 2010, 09:12:38 PM
Tested in Blender 2.55beta, exported the same bunny mesh and an animation without any issues.

@ motorsep: wouldn't the HL2 *.smd be better off as a separate exporter or is does it use the same data as MD5?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on November 06, 2010, 01:09:47 AM
The output is not the same, but I think it uses the same math as for MD5.

Posted the same question at Blenderartists and the answer solved all the problems:

http://developer.valvesoftware.com/wiki/Blender_SMD_Tools

I haven't tried it yet, so I am not sure how comfortable GUI is, but sounds like it's what we have been waiting for, for a long time :)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on December 09, 2010, 11:47:49 PM
Doesn't work with 2.55.1

======================================
Traceback (most recent call last):
  File "/home/motorsep/software/blender25/2.55/scripts/io/io_export_md5.py", line 848, in invoke
    WindowManager.add_fileselect(self)
AttributeError: 'WindowManager' object has no attribute 'add_fileselect'

location:<unknown location>:-1

location:<unknown location>:-1
======================================
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 10, 2010, 12:31:59 AM
In development subtrees of Blender always tend to break scripts so make sure you're using the latest official release from Blender.org (http://www.blender.org/).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on December 10, 2010, 12:50:06 AM
Aye. Switched to official 2.55 beta.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 31, 2010, 05:52:32 PM
Script is broken in Blender 2.56beta with the following error;
Code: [Select]
Traceback (most recent call last):
  File "C:\Users\[user]\AppData\Roaming\Blender Foundation\Blender\2.56\scripts\io\io_export_md5.py", line 848, in invoke
    WindowManager.add_fileselect(self)
AttributeError: 'WindowManager' object has no attribute 'add_fileselect'

location:<unknown location>:-1
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on January 14, 2011, 12:50:38 AM
Are script authors still around? Reallly need a fix to those issues, please.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 14, 2011, 04:36:38 AM
Are both the MD5 and ASE script still broken in the 2.56b update!? I've not had a chance to test them yet.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on January 14, 2011, 01:01:09 PM
last time I tried they were both broken.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 25, 2011, 10:01:11 AM
OK, a fix came in via NB - cheers matey.
Download the fixed MD5 export script (http://www.katsbits.com/tools/index.php#md5) from the downloads page. Or open the script in a text editor and find line 848 or the below text;
Code: [Select]
WindowManager.add_fileselect(self)
Replace with;
Code: [Select]
WindowManager.fileselect_add(self)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 25, 2011, 10:22:30 AM
OK, a fix came in via NB - cheers matey.
Download the fixed MD5 export script (http://www.katsbits.com/tools/index.php#md5) from the downloads page. Or open the script in a text editor and find line 848 or the below text;
Code: [Select]
WindowManager.add_fileselect(self)
Replace with;
Code: [Select]
WindowManager.fileselect_add(self)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 01, 2011, 08:47:12 PM
Blender 2.57 will be using Python 3.2, and will require another set of changes.

What I've gathered so far:
bl_addon_info is now bl_info
to_quat is now to_quaternion
3rd-party scripts are added to scripts/addons/ instead of scripts/io/
there is some difference in the register and unregister of addons

I've gotten Blender 2.57 to load the add-on into the menu, but there's no way I have the knowledge to make it work.


Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on April 01, 2011, 09:44:37 PM
Oh not again! I knew they were going to do something like this when I saw that effing folder! I'm guessing this is going to be across the board right? ASE, MD3, MD5 (here) et-al? To be honest I think we're going to have to throw the scripts open to the community to fix up from here on in as the various authors have all gone MIA and I certainly don't know enough programming or scripting to know my donkey from my elbow. I really do wish Blender would find a formula and stick to it, changing things around each iteration doesn't help build a solid user-base. Sorry had to rant that one out there ;D

Oh, and... welcome by the way and thanks for posting the info lol!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 02, 2011, 12:52:20 AM
I've started reading up on Python, but I'm sure it will be a while before I'm able to do anything useful with it.
Lua I can do, to a point, and Python doesn't look to be terribly different, so hoping it will be relatively easy to pick up.

I should mention that when I started using the exporter for Blender 2.5, the resulting md5mesh was missing a line (// meshes: meshname) that is necessary for proper placement of textures in Sauerbraten.  So I changed line 130 to look like this:
buf=buf + "mesh {\n\t// meshes: " + submesh.name + "\n"
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on April 02, 2011, 01:23:31 AM
That change sounds like it's resulted from SB's content being exported originally using the older versions of the MD5 export scripts? I'd be reluctant to drop that into the general MD5 script and push those out if it is, it makes adoption by other parties problematic because of engine tech and code differences; over the years modders have taken the baseline files (from KatsBits), modified them, then served them up locally, which works well as a delivery system. Hmm that was a bit off topic!

GL learning Python
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 02, 2011, 01:43:44 AM
I would say you're probably right about that. I don't know much about the guts of file formats or anything like that...I just poke at things if something doesn't look right to me, and hope to find or create solutions, even though they usually tend to be kludges.

 I'd already posted my change on the sauerbraten forum for anyone who might find it useful, so if it helps someone there, good.  If it doesn't mean anything to anyone but me, that's fine too.  It at least helped me not have to manually edit the file after every export.

Thanks for the GL =o)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 03, 2011, 07:43:23 PM
I think I might have actually fixed it...and I don't even Python! =o)
http://www.pasteall.org/20522/python

All the changed lines have been tagged with 'mikshaw'
and I commented out my Sauerbraten fix on 130.

This hasn't been thoroughly tested, particularly considering the conditionals that don't apply to my file might not work at all.  I just exported one animation and it works the same as the one from 2.56
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on April 03, 2011, 09:06:34 PM
I'll test this on a couple of characters I've got and see what results I get - will use der_tons MD5 viewer for playback as I don't have anything with MD5 capability loaded atm.

Do we know *for definite* if the internal changes made to 2.57 that's forcing these updates is going to remain in place upon public release? They've done this several time before where something has had to be adjusted only to find it doesn't work because they changed something back or around on final version release.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 03, 2011, 11:42:07 PM
Apparently I didn't need to break up that line at 737ish.  I got this at blenderartists:
Quote from: zeffii
the invert() function was modified, I'm a little dim on the precise reasons, but I think the early .invert() returned an inverted matrix, while the new .invert() modifies the parentposemat in place. now if you want to simply return an inverted matrix you do a .inverted()

So rather than separating the invert() function onto its own line, the original line can just be changed from invert() to inverted():
Code: [Select]
posebonemat = parentposemat.inverted() * posebonematThe result is, as far as I can tell, identical.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 05, 2011, 02:30:48 AM
Don't know *for definite*, but i just tested it in the RC2 that was released today, and it still works.

One of these days I plan to test Lee Salzman's IQM exporter too (works in 2.56, probably broken in 2.57), but since I'm sticking with MD5 for my current project I'm not sure when that will be.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on April 19, 2011, 11:50:29 PM
Has anyone tried the exporter with Blender 2.57 ?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on April 21, 2011, 05:08:54 PM
Yes, that's what this last page of posts has been about.  The pasteall link above points to an edited version of the 2.56 script which seems to work, although it's still not thoroughly tested (and the "posebonemat" optimization mentioned a couple posts back hasn't been changed in the pasteall link).  I've been puttering around with other projects lately and haven't gotten back to Blender.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Optimonkey on May 05, 2011, 05:12:34 PM
mikshaw - Thanks for fixing that!

I am new to blender and trying out 2.57 and couldn't get the script to run.

I took your script and installed it from the ..user preferences...add_ons and ... it Worked!!!!

I am primarily learning Blender to create some MD5s for my game - (coming from Modo and Zbrush neither of which have any Character animation.)

So this was a critical component I wanted to have working before investing significant time.

Thanks again for your work...

Now I am off to write some md5 loading code in my ios app  :-)

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 05, 2011, 06:33:56 PM
Thanks for double checking mikshaws edits work in 2.57b. I just double checked as well and it works fine. I'll add the updated version to the tools page and amend the first post. Cheers guys.

[EDIT]File is now available on the tools page (http://www.katsbits.com/tools/index.php#md5) and the Installation and Usage instructions (http://www.katsbits.com/smforum/index.php?topic=178.0) have been updated.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: dersaidin on May 07, 2011, 04:48:10 PM
Hello.

I made a few improvements to mikshaw's version to make the script easier to use when exporting static models.

If there is no armature, it will make a fake bone and automatically change from "mesh & anim" to "mesh only" mode. Also fixed the scale global, and the script smarter with adding the file extension.

I took the liberty of restoring the GPL license present in der_ton's original, as this is clearly based on it. Would be best to have other authors affirm this.

This version has bumped the "blender" to (2, 5, 7) and "api" to 35622. This works (for me at least) on 2.57b. If you want earlier versions (ie 2.57) you may need to reduce those numbers back to what mikshaw had.

http://www.dersaidin.net/other/io_export_md5_2011-05-08.zip
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 07, 2011, 05:33:31 PM
I can kind of understand the changes but why not just make a mesh with a single root bone from the get-go and export that using the 'standard' script? I'm assuming the 'fake' bone is written into the file, so you're still actually exporting a rigged mesh (albeit very simple rig)?. Is there a particular reason for the changes (other than using a single format for both static and animated models)? Will take a look nontheless  ;)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: dersaidin on May 08, 2011, 04:43:11 AM
I can kind of understand the changes but why not just make a mesh with a single root bone from the get-go and export that using the 'standard' script? I'm assuming the 'fake' bone is written into the file, so you're still actually exporting a rigged mesh (albeit very simple rig)?. Is there a particular reason for the changes (other than using a single format for both static and animated models)? Will take a look nontheless  ;)

If your making a static model, you NEED to have a bone. Thats part of the md5mesh format. Your already using a single format for static and animated meshes.

For users who don't care about bones and animation, its extra effort to work out how to add the bone, and bind the mesh to it - especially when unfamiliar with blender. The thing that makes it really annoying, is that this bone isn't special - it needs no extra information to add (you don't need to know what coordinates to put it at, {0,0,0} is fine). Theres no reason to make the user do this manually when the script can take care of it.

This makes it easier to use for users that don't know blender. Usability is very important.

When I say 'fake' bone ('dummy' if you prefer), this bone is never at any point part of the blender model. The mesh your exporting always has no armature. Its not needed, the script will deal with it. This is why it is simpler for users to do the export.

Model with no armature goes into the md5 export script.
Script then checks theres no armature, adds a 'fake' or 'dummy' bone to the data to be exported and points vertices to that bone.
The md5 export script does an export at usual, which will include the 'fake' bone, and exporting the mesh.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 08, 2011, 05:16:23 AM
Oh I understand all that yes.. my question was why use an *animated* format to export *static* models when other formats are more suited - ASE, OBJ etc?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: dersaidin on May 08, 2011, 05:29:57 AM
Sorry, I was meaning a different level of static.

For static (compiled into bsp), yes theres ase, we use that. Obj isn't supported by the engine (XreaL).

For dynamically added models, which aren't animated - i.e. static mesh - such as shell casings, or items lying around. XreaL prefers md5mesh.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 08, 2011, 06:19:50 AM
Ah right, I understand what you're doing. I'll take a look at the script as soon as pos...
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on August 15, 2011, 06:02:56 AM
Blender 2.59 is out. Has anyone tested ASE exporter with it and can confirm the script is working with 2.59 ? Thanks.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on August 15, 2011, 06:12:15 AM
Not yet. I loaded up 2.59 the other day but have only had time to check the .map exporter so far.

[EDIT]MD5 exporter needs a minor edit so I'll upload an update later. It seems to be exporting OK (I only tested it quickly exporting a single mesh and animation for my bunneh character).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on September 15, 2011, 03:52:26 PM
Finally got to the point where I need to export to MD5 from Blender 2.59. And the export doesn't work :(

Here is what I am getting: http://www.kot-in-action.com/files/blend2MD5_error.png

Any chance to fix that error rather sooner? Thank you.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on September 15, 2011, 04:21:55 PM
please disregard. Somehow I had outdated exporter.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 15, 2011, 05:34:47 PM
Sorry about that. The main link on the Tools page (http://www.katsbits.com/tools/#md5) was still pointing at the 'old' version of the script. Fixed it now. The zip should be called "io_export_md5-259.zip (http://www.katsbits.com/files/md5/io_export_md5.zip)". With so much going on when Blender updates it too easy to loose track of what I'm doing and/or have done when uploading updates :-\
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ge5 on September 30, 2011, 08:12:08 PM
here is the error message i am getting after installing the 2.59 md5 exporter:
"location<unknown location>:-1
AttributeERROR:  'int' object has no attribute 'animation _data'
   arm action=thearmature.animation_data.action
File"/Users/ge5/Library/Application Support/Blender/2.59/scripts/addons/io_export_md5.py", line 713, in save_md5 save_md5(settings)
File"/Users/ge5/Library/Application Support/Blender/2.59/scripts/addons/io_export_md5.py", line849, in executeTraceback(most recent last call);"

I followed all the decribed steps/and this is starnge because my animation is threre on stage and in the action editor--any help?pointers? i am new to this, though have been exporting blender models as .dae (2.49 and before!) and .js files...thanks.
//////////
to kat + motorsep: Thanks for your tips/got this to work. now the action script stuff!...
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on September 30, 2011, 08:15:32 PM
Did you make an Action set for your Armature with animations keys set to LocRot?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 30, 2011, 08:52:24 PM
In addition to moterseps comment, check the location of the script, in 2.59 they changed where the AddOns folder is, it's not a "User" file but dropped directly into the installation folder, e.g. (will be slightly different for you obviously)
Code: [Select]
D:\[path]\Blender Foundation\Blender 2.59\2.59\scripts\addons
@ge5: I moved your question by the way, it keeps all the troubleshooting stuff in one place, makes it easier to track.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on October 20, 2011, 08:10:14 AM
AddOn seems to work OK in Blender 2.60, I've only done a quick export test though but the mesh and animation exported without any issues (so far as I can tell using the MD5 model viewer).

NOTE: the script was loaded via User Preferences which created a scripts/addon folder in the main Windows "User" profile, it seems custom scripts are placed there (need to be?) rather than in with the defaults located in the installation directory.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on November 14, 2011, 04:25:21 PM
NOTE: the script was loaded via User Preferences which created a scripts/addon folder in the main Windows "User" profile, it seems custom scripts are placed there (need to be?) rather than in with the defaults located in the installation directory.

I haven't done much of anything with 2.6 yet, but this might be related to an issue I was having with installing addons through user preferences.  Since my Blender installation folder is not writable by a normal user, addon installation had to be done manually, either by copying it into the installation folder as root, or by putting it in my personal blender config directory.  Perhaps they changed the process so that a non-administrator could install addons through user preferences, much like the way Firefox installs extensions into the user's directory rather than the installation directory.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 14, 2011, 04:34:02 PM
If you're on Windows 7 then yes the UAC permissions causes havoc with user content creators (http://www.katsbits.com/smforum/index.php?topic=324.msg1919#msg1919). I've found in the end I had to disable it and I still have issues with certain applications don't save program changes because they're not run with Administrative privileges - it's a royal pain in the potato.

Blender keeps changing how it handles community scripts, it seems they've settled on anything we add to it  being save to the "User" roaming profile on the C:\ drive.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: mikshaw on November 15, 2011, 04:27:53 PM
I'm on Linux, and have become accustomed to having no write-access to system files and directories as a normal user.  There are very few Linux applications that are not already built with this in mind, but I could understand there being some trouble in Windows during a transitional period between the "write-anywhere" system they've had in the past to the more secure method of allowing writes only to specific directories.  There seem to be still many Windows software developers who attempt to write to system directories, but I think Blender has the right idea now.  But even then, they've made what I think are unnecessary changes, such as changing from scripts and plugins directories to a single addons directory...not saying the change isn't more logical, but it wasn't needed especially at a time when so much else was changed.

It sounds like your problem with UAC might be a separate issue...having more to do with specific types of files than with directory structure and permissions.   Microsoft might be attempting to push developers into some sort of authorization of file types used by their programs, thinking the majority of end users aren't going to even notice, much less care about, the potential problems it may cause.

Sorry to take this thread off-topic
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: gavlig on December 09, 2011, 05:06:13 PM
Hey everybody!
I have the same problem ge5 has(or had) and don't know how to deal with it. I've downloaded quake4 map katq4dm1(blender sources), installed export script, selected all meshes, selected "export" and got this error:

Quote
Traceback (most recent call last):
  File "/home/gavlig/.blender/2.60/scripts/addons/io_export_md5.py", line 849, in execute
    save_md5(settings)
  File "/home/gavlig/.blender/2.60/scripts/addons/io_export_md5.py", line 713, in save_md5
    arm_action = thearmature.animation_data.action
AttributeError: 'int' object has no attribute 'animation_data'

location:<unknown location>:-1

I use archlinux x86_64 and blender r42422(2.60.6)

I see that error occurs because some armature data, but i don't have any. Maybe it's the problem? :)

here some screenshots:

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fi5.pixs.ru%2Fstorage%2F8%2F3%2F7%2F2011120918_3259231_3518837.png&hash=680fd23215da8f03ca7d9cafe0c2789d) (http://pixs.ru/?r=3518837)
(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fi5.pixs.ru%2Fstorage%2F8%2F4%2F3%2F2011120918_4623023_3518843.png&hash=5024bed414897bc8d83a9a550e2b234b) (http://pixs.ru/?r=3518843)

Thanks in advance!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on December 09, 2011, 05:32:51 PM
You are using wrong exporter. MD5 is for animated with bones models. If you simply trying to export level or a piece of a level, you need to export into ASE. There is another exporter for that.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 09, 2011, 05:37:18 PM
You are using wrong exporter. MD5 is for animated with bones models. If you simply trying to export level or a piece of a level, you need to export into ASE. There is another exporter for that.
Or failing that, if you need to export to MD5 and because the error is due to you missing animation data, you'll need to add a simple Armature and Action to the mesh before export. I'd go with what motorsep said though and export to another format that's more appropriate for large static objects like that (ASE, OBJ).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: gavlig on December 09, 2011, 07:17:32 PM
Ok, thanks! So, in order to export a map I should use another exporter. Sorry for offtop, but how can i do that? All tutorials I found don't seem to fit my purpose because they all are old(there is no *.map exporter for blender2.6). I want to create a map for idtech4 engine. Could you please give me some advice?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 09, 2011, 07:29:53 PM
If you get stuck making a map, post a separate topic. In the meantime have a look on the tutorials page of the site (http://www.katsbits.com/tutorials/), for what you're doing everything you need to know is there, including what how to export to ASE (http://www.katsbits.com/tutorials/blender/blender-2.5-export-ase-models.php), and how you can make a map in Blender (http://www.katsbits.com/tutorials/blender/blender-2.5-map-basics-tutorial.php) (you will need to make sure you're using the correct export script for the version of Blender being used though).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: razvanab on January 16, 2012, 06:42:02 PM
I think the exporter is broken for 2.61
even a simple export / animation looks bad...

http://www.sendspace.com/file/6s04zc
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 16, 2012, 08:29:05 PM
Looks like you tried to export a single framed animation, which is generally a no-no. If you add a few frames (make sure your start and end are the same with something changed in between so you can see what's going on), you should be able to get a complete output even untextured or UVW mapped as your test was. If you want a 'static' Object, export at least 2 frames, both being the same, it's the single frame export that messes things up.

Remember to scale your mesh before you add a rig and start animating - relative to what the MD5 format is usually used for your stick exports really small, only about 2 or 3 'game' units (you can use the script to scale but that's not generally advised).

[EDIT] see attached zip
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: razvanab on January 16, 2012, 09:03:57 PM
I usually do a weekly blender build from svn and it look like that was a problem too...
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 16, 2012, 09:23:08 PM
Oh right, yes be v. careful about using those when you need to produce something for use 'outside' Blender, if you get a problem revert back to an official build to double check it's not something that's propagated.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: razvanab on January 16, 2012, 09:26:15 PM
 I've learned my lesson :)

Thank You !
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: renderluz on February 17, 2012, 05:03:03 PM
Hi, first thanks for making the exporter compatible with 2.61, and to the original creators, thanks for making the exporter :D

Now I'm having some issues,
have anyone tried exporting a mode with the new blender 2.62, I'm not been able to do so, I get a exploded model full of skinning errors, could somebody code savy take look and see of there something that needs to be changed for the exporter to work with 2.62?, I works like a charm on 2.61, also since bmesh is coming on blender 2.63 and this will most likely change the mesh API would this means the exporter will need to to be made compatible with this changes as well?
Please make it work with the new versions, there's a ton of really good changes on the UV editor and I really don't want to roll back to 2.61.
Thanks for your time.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ratty redemption on February 17, 2012, 06:24:24 PM
i didn't even know there was a 2.62, which i'll go and dl after this post. looking forward to seeing what improvements they have, and hopefully someone here can help you soon, personally i'm still exporting with .ase
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on February 17, 2012, 06:55:01 PM
...I get a exploded model full of skinning errors...
Yes, I just checked, bone position data is not being exported correctly, it looks like it's resetting to locations to "0" - I couldn't even get the files to open in the MD5Viewer as it crashes when it gets this sort of corrupted input. So far as I can tell, all the mesh data is OK, it's just the bones/rig that are broken.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: renderluz on February 23, 2012, 07:42:54 PM
Hi Kat, I'm glad you where able to reproduce my findings, can you fix this? 
and if you can't, can somebody here make it compatible with 2.62?
the exporter worked like a dream on previous versions, please
can somebody update it? pretty please with a cherry on top.

redemption: Yeah but .ase is just for static models, I need to export skeletal models.
do take a look man there has been a lot of improvements as of late, and bmesh will be
merged for the next version, things are moving forward fast this days :)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ratty redemption on February 24, 2012, 12:04:35 AM
renderluz, kat and i aren't really coders, but there are a few guys that do visit or hang out here who might be able to update the exporter. and thanks for the recommendation, i only recently made the huge jump from 2.49b to the 2.6 builds and although i've found a few annoying bugs, over all i do prefer the latest blenders over the 2.4x builds.

sorry, i previously didn't make myself clear with my not very helpful comment about .ase, i'm behind times when it comes to exporting into game engines, although i used to make some abstract art animations and render them in blender years ago. i would eventually like to learn how to import and export rigged characters for games, as opposed to just working with static models, which is the reason for me still using .ase
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: thurok on March 10, 2012, 10:01:11 AM
Hi everyone!

I also have problems with Blender 2.62 and the md5 exporter. I'm making a game in which I want to use this model: http://thefree3dmodels.com/stuff/characters/human_knight/14-1-0-1589 (http://thefree3dmodels.com/stuff/characters/human_knight/14-1-0-1589).

I have added a simple skeletal animation and I wanted to export it to load it later in the C++ OpenGL game. I have no md5 loader yet, I have just used (and will adapt if I get my purposes) sample 2 from http://tfc.duke.free.fr/coding/md5-specs-en.html (http://tfc.duke.free.fr/coding/md5-specs-en.html) to load the exported md5 files. Here is my simple animation in Blender: http://obj.sytes.net/downloads/humanknightAnimated.blend (http://obj.sytes.net/downloads/humanknightAnimated.blend)

When I load the md5 into the md5 loader sample, the mesh seems to be not correctly loaded neither the animation. Don't know which is the problem.  I'm programmer but I'm just learning 3D, so I could try to update the exporter if I knew which is the problem and how works the exporter and Blender.

Thanks for all and sorry for my English!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on March 10, 2012, 10:39:46 AM
The scripts don't work with 2.62 at present so your animations are going to be messing up due to changes inside Blender that's causing the bone rotations/positions differences on export. You'll need to go back to 2.61 for now until the scripts are fixed (I don't know when that might be).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: xt_hydra on May 06, 2012, 05:08:49 AM
ive been trying to make the exporter work.. like for example that i dont select anything within my scene it start saying no armature so i select it.. then it say no mesh then i select it then after it say no material.. but where the hell do i need to click to get the material??? well at least from my experience with blender theres no such way to select it within the scene manager from top right default interface.. so.. whats up guys.. im using linux 64 bit on linux mint AKA ubuntu oneric
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 06, 2012, 01:38:50 PM
What version of Blender are you using? I've not had a chance to test any of the scripts with 2.63 so that may be an issue.

But to address your problem, you need to select the objects to be exported, mesh first then Armature last (the Armature needs to be the lighter colour indicating it's the 'active' object). The Object must have a material, texture and UVW map, you can't export an 'empty' mesh. Read the "how to export MD5 (http://www.katsbits.com/smforum/index.php?topic=178.0)" for some basic info, essentially though the model needs to be properly prepped.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ge5 on May 13, 2012, 08:36:20 PM
I am using the 'official' 2.61 build of Blender and followed all your instructions on these threads re .MD5 with the proper exporter, proper 'prepping',etc. --PLEASE see URL below-- i need a 'still' model for use with a kinect camera,actionscript, etc. i have narrowed down the problem to this: the model only loads correctly if both the mesh + the anim files are loaded. unfortunately, all the code i am using calls for just the mesh file, and it loads in totally distorted! (see the accompanying pix/the super skinny figure is the INCORRECT mesh only)--any ideas or tips or suggestions? i've been messing with this for days...thanks
http://geraldineerman.com/md5.jpg (http://geraldineerman.com/md5.jpg)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 13, 2012, 09:35:28 PM
I don't think you can use MD5 like, you need both the md5mesh and md5anim for it to work otherwise you might as well be using an OBJ. The md5anim file 'locks' the mesh structure to a pose so without one it does what yours is doing (as there's nothing to bind the mesh relative to the default idle pose). You need to export out an idle pose (single frame) which should then allow you to do that you need.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: nemyax on May 15, 2012, 11:07:44 PM
I don't think you can use MD5 like, you need both the md5mesh and md5anim for it to work
Barring bugs, an MD5 mesh should look fine on its own. However, an MD5 animation can sometimes look right despite a screwed-up underlying mesh. I saw this happen when writing an exporter.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on May 15, 2012, 11:56:24 PM
That's what I couldn't figure out, md5meshes load into the MD5 viewer without issue (using a 'bindpose' of sorts), so any deviation from that means something else is causing the problem - most of the issues I've encountered usually result from a missing or 'broken' md5anim because both were being used.

P.S. for clarity I should have said "*may* need to".
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: robertzoone on June 18, 2012, 12:29:01 AM
Hello

I have a problem when try to export MD5 on Blender 2.62

System: Mac OSX 10.7
My Blender version is: 2.62
MD5 export from here: For Blender 2.57 (OK for 2.60, 2.61, 2.62) http://www.katsbits.com/smforum/index.php?topic=167.0 (http://www.katsbits.com/smforum/index.php?topic=167.0)

For export first I type A for select Mesh and go to export. Configuration is: scale 1.0
Exports: Mesh only

And I got this error:

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fimg705.imageshack.us%2Fimg705%2F5660%2Fblendererror.jpg&hash=07e5c77608f76ef33f411ef867b7c18a) (http://imageshack.us/photo/my-images/705/blendererror.jpg/)

Uploaded with ImageShack.us (http://imageshack.us)

For example I download Blender 2.63 and new export module.
When I want something to export and save the file, nothing happens. File can not be save or not showing any error.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on June 18, 2012, 02:26:44 AM
Yes that happens when you try to export an MD5 that doesn't have an Armature and/or animation, even if you only want the *.m5dmesh (using the exporter you linked to that is).

To 'fix' the issue you'll need to add a basic (one or two bones) Armature to the scene and give it a one frame Action. Once you do that select the mesh first, the armature last and then export - select "Mesh Only" from the export options bottom-left.

PS. I merged your topic into the main thread to keep all the MD5 troubleshooting in the one place.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: nemyax on June 18, 2012, 04:02:25 PM
For example I download Blender 2.63 and new export module.
When I want something to export and save the file, nothing happens. File can not be save or not showing any error.
Do you mean this exporter?
http://www.katsbits.com/smforum/index.php?topic=404.0
There's a readme file in the .zip that explains how to use the export.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on July 28, 2012, 05:58:31 PM
Ok, I took upon myself to fix MD5 exporter that works with Blender 2.61 and get it working with Blender 2.62. Here is what I got: http://blenderartists.org/forum/showthread.php?262020-Need-help-fixing-MD5-exporter&p=2171984#post2171984 (http://blenderartists.org/forum/showthread.php?262020-Need-help-fixing-MD5-exporter&p=2171984#post2171984)

Turned out that Blender 2.62 had change of heart about how matrices are handled. So I did my best, but now I am stuck. If someone can finish what i started, we all can have Blender 2.62 exporting MD5's. Thanks.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 31, 2012, 08:13:03 AM
Thanks to motorsep (special thanks to MCampagnini) the MD5 export scripts now work with Blender 2.62 and 2.63. Note: each script work with it's respective version of Blender so double-check correct pairing before use (most issues arise from using the wrong version of Blender). For local download of MD5 scripts see first post (http://www.katsbits.com/smforum/index.php?topic=167.0). More information and usage instructions can be found by clicking here (http://www.katsbits.com/smforum/index.php?topic=178.0).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on July 31, 2012, 08:18:49 AM
@kat: I added minor fixes (mostly to how they appear in the Export menu)  and removed warning from the scripts. Added description of the workflow and a video depicting it :P

It's all on BlenderArtists thread

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 31, 2012, 08:50:12 AM
Yep I grabbed the versions you posted to PasteAll after you made the initial edits ;)

I added the GPL block to the versions available on KatsBits tools page for clarity with respect to usage (and copyright malarkey) and updated the "Report a Bug" link so it comes straight here when users click the button in Blender (rather than going to the home page as it was doing). Two minors but things that needed to be addressed.

Cheers for the hard work you put in to getting these fixed up to run motorsep, it now means there is an alternative route open to content creators making their own games using the later versions of Blender *thumbsup*. I watched the vid, heh.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on July 31, 2012, 04:29:39 PM
No problem. Cool stuff! Hope people will use it :D
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: xt_hydra on August 18, 2012, 01:08:48 AM
so like.. i recently got back to trying to make the exporter make something...and now i got a mesh
but now i got an error saying i need a bounding box or something about it when i try to make an anim
im thinking about this could be produce by a transformation.. not applyed? i don't know seriously..i think i remember trying to resolve to this by pressing space and write "apply" n stuff...well damnit
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: motorsep on August 18, 2012, 01:13:40 AM
Why don't you try exporter I just fixed?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: xt_hydra on August 18, 2012, 02:17:13 AM
im already using 2.62 and i also tryed plugin for 2.63
seriously.. this bounding box is irevelant.. isnt bounding box is for physic?

also ive saw ur post about your 2.62 fix but im not sure what u meant by unparenting armature from mesh
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on August 18, 2012, 03:18:58 AM
Unparenting the meshfrom the armature (select the mesh, press "Alt+P" and select "Clear Parent" or "Keep Transform") isn't an absolute necessity as the exporter will output the correct files is either case. Just make sure your mesh has vertex_groups assigned and you should be good to go.

Have you read through the general prep and export information linked in the first post xt_? I'd recommend doing that and then looking at how you have your mesh, rig and animation set up in relation to it. Basically, if you're being asked for a bounding box on export then something isn't set-up correctly (the MD5 exporter has no idea what a Bounding Box is so won't ask for it specifically).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: dgis on August 20, 2012, 10:24:35 AM
Hi,
May be I'm wrong but I think the weights are not well calculated.
They are computed too early before knowing if several faces share the same vertex (and weight).
So, I would want to share with you my fix for the version 2.63:  http://www.pasteall.org/34591/python
I hope it help. Anyway, keep on the good work!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: wtrsltnk on September 16, 2012, 09:30:53 AM
Hi there,

First of all thanks for this nice plug-in! It works great, except for one thing: The shader names. When i have a mesh with multiple materials assigned, all meshes in the md5mesh file get the first material as shader name. Is this a bug? I tried tot fix it, but i don't see how.

Thanks,
wouter
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 16, 2012, 02:14:25 PM
It's a (built-in/designed) 'limitation' of the format, you can only have a single material assigned per mesh. So in instances where more than one are assigned, the mesh would need to be broken down into corresponding sections - a "head", "body", "feet" material assignment would have the mesh split into "head", "body" and "feet" sections. Or, the texture/material assignments would need to be unified (from multiple, into a single image). If you do break the mesh up, you may also need to make sure you 'close' the sections - they ideally need to be seen as 'solid' and 'complete' objects rather than shells or skins the innards of which can be seen - in other words, any openings, gaps or holes need to be filled, UV-mapped and textured (this only needs to be done approximately).

Come time to export, just make sure to select all the sections that are supposed to be part of the main object, the process will then output the lot as a series of sub-meshes in the MD5 file - so a single MD5 object composed from a series of sub-meshes.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: wtrsltnk on September 18, 2012, 12:05:56 PM
The weird thing with a blender scene I have, is that I have one mesh that is fully connected. But it also has multiple materials assigned. Every material is assigned to a unique 'group'. With this 'group' i mean all vertices that are assigned to the same materialindex, not a vertexgroup. When I export this scene to md5, i get meshes for all of these 'groups'. I think these exported meshes are based on the material index in blender, except for their shader name, that is the name of the first material assigned to the blender mesh.

I am not sure, I will try to make a blender scene to show this.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 18, 2012, 01:57:45 PM
Are the meshes individual objects in Blender just (object) grouped together or are you saying the export process is somehow splitting a mesh into corresponding sections based on the (unique) MaterialIndex? If it's the latter, that's the first time I've ever heard of that happening (and it wouldn't be specifically desirable an occurrence!).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: nemyax on September 19, 2012, 08:39:39 AM
wtrsltnk
The mesh may be split up by UV "island". Can you check if this is the case? Your materials may simply match the UV splits.
A vertex can have only one set of 3D coordinates, but multiple sets of UV coordinates. The way MD5 handles this is to split meshes at the UV seams.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: ramzez on October 04, 2012, 12:07:04 PM
Guys, I went through the entire instructions and this thread, still I cannot export the simplest action and a mesh. I used the default cube and three simple key frames with one action. The error is thrown during export:

Code: [Select]
Traceback (most recent call last):
  File "C:\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 905, in execute
    return {'FINISHED'}
  File "C:\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 855, in save_md5
    buffer = anim.to_md5anim()
  File "C:\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 560, in generateboundingbox
    md5animation.bounds.append((min[0]*scale, min[1]*scale, min[2]*scale, max[0]*scale, max[1]*scale, max[2]*scale))
  File "C:\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 514, in getminmax
    if len(listofpoints[0]) == 0: return ([0,0,0],[0,0,0])
IndexError: list index out of range

location:<unknown location>:-1

Blender 2.63 (r45996)
Export script for 2.63

Test case:

I'm not sure what is wrong with matrix used in getminmax(). Thanks in advance.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on October 04, 2012, 03:29:17 PM
Looks like you've not set up any vertex_groups?. You'll also need to export an Armature with at least two bones, one being the 'root' the other being whatever your mesh is vertex_grouped to (generally the mesh shouldn't be vertex group to the root bone because it's used for position/location stuff). Note you ideally want to use Apply before you parent.

Just an FYI, when using the scripts make sure you're using a public release version of Blender, SVN/release candidates are notorious for breaking script support.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: taka on October 20, 2012, 03:37:30 AM
it seems like latest exporter fails to export if "Anim only" option is selected.

adding line below to around line 847 solved issue.
847:       for submesh in meshes[0].submeshes:
848:         submesh.generateweights() <----------added this line
849:         if len(submesh.weights) > 0:

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on October 20, 2012, 04:16:18 AM
The script should work for 2.63a so is this an issue that's being fixed with 2.64 using the script amendment posted above?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: A_W_O_L__ on April 13, 2013, 06:45:38 PM
hey im having trouble using the exporter.

which exporter is the most stable? as i used the one for 2.62 & 2.63 and both give me an error saying that it cant find an armature action ( says this if i have an action attached or not & i am only exporting the mesh not mesh & animation ) and i am using the original blender versions 2.62 & 2.63

and i followed these steps

1. apply scale to the mesh

2. add armature and add a bone to parent the object to

3. parent the object to the bone with empty groups

4. cleared parent from object

5. uv unwrapped object

6. added material 

7. added key frame and made sure there was an action in the dope sheet ( did this because it throws an action error when exporting even if im only exporting a static object )

8. selected armature ( not in pose mode ) shift+ selected object so both are highlighted then i export and i select mesh only in the exporter

and i get the following error:

Traceback (most recent call last):
  File "C:\Users\Awol\AppData\Roaming\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 904, in execute
    save_md5(settings)
  File "C:\Users\Awol\AppData\Roaming\Blender Foundation\Blender\2.63\scripts\addons\io_export_md5-263.py", line 768, in save_md5
    action = armature.animation_data.action
AttributeError: 'NoneType' object has no attribute 'action'

location:<unknown location>:-1

any help would be nice! Thanks In Advance!!!


Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on April 13, 2013, 07:22:04 PM
Both scripts are pretty stable (for 2.62 and 2.63), so that shouldn't be an issue, so it's likely something your doing (or not doing as the case may be). Can you check to see if you have an Actual "Action" sequence assigned to the Armature? In the "Dopesheet" select "Action Editor" from the Header drop-down menu and check you have one listed - if you look at the images in the first post of the 'usage' topic (http://www.katsbits.com/smforum/index.php?topic=178.0), does your set-up look like those?. If you can post a pic that might help track the problem (if you can't don't worry).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: A_W_O_L__ on April 14, 2013, 12:20:51 AM
Thanks for the quick reply :)

i found out what my problem was. you have to make sure that your object also has a action attached to it too ( it doesnt have to have any data it can be empty )

thanks for all the help!!!!
Ps: i may be back later if i run into any more trouble ;)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on April 14, 2013, 01:21:49 AM
Glad you got it working but that's a little odd having to do that, you shouldn't need to really (an Action assigned to the mesh implies 'Object' based animation which isn't generally supported) - when you select the mesh all you should have is an Armature Modifier present. Just tested this to double-check using 2.63a. When selecting "Anim. Only" on export, the script does crash but selecting "Mesh & Anim." on the same mesh works fine so perhaps that's the caveat.

Also, try exporting without unparenting the two Objects and see what that does (so long as you have the Armature Modifier you should still get valid animations/deformation but just for the sake of bug tracking do the aforementioned and see what that does.

And you're welcome  ;D
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: tea monster on October 14, 2013, 05:02:36 PM
I'm getting the dreaded "Mesh contains XX vertices with zero weights assigned". I've tried cleaning the weights and normalizing them and still getting the error message.  How do you search through and find the ones with no weights assigned?

EDIT: I've even tried going into the vertex groups and applying a .2 weight on all the vertices to the origin bone and now it tells me that ALL the verts have no weight!!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on October 14, 2013, 05:32:36 PM
The only thing I can suggest is trawling through the file in NotePad or other text editor to sus out the differences between 'valid' and 'invalid' weight references, sometimes the only available option is a methodical search through the data. Other than that, use weight-paint mode to go over the mesh and identify areas you suspect might be causing issues, you can then select individual vertices for inspection in "Transform" properties ("N") and deal with them appropriately. In other words, so far as I'm aware there isn't a shortcut to fixing this problem (absent the changes nemyax queried).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: tea monster on October 14, 2013, 05:40:06 PM
The problem is that it won't allow me to export the MD5 till I fix this. Previously, I could make the MD5, I would see the errors and then I could open the MD5 and 'hack' it manually.

But if it won't let me output the MD5, then how am I supposed to do this?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on October 14, 2013, 05:50:00 PM
Have you checked the System Console to see if it says anything else or is it just spitting out the error?. Beyond that, you'll need to go back over your mesh to check you don't have any detached vertices and/or individual vertices weighting using the "Vertex Weights" sub-section of "Transform" properties ("N") - just select a mesh and remove groups with "0" values.

What version of Blender are you using by the way?

[EDIT] see also the suggestions nemyax makes here in reply to your other post (http://www.katsbits.com/smforum/index.php?topic=404.msg3061#msg3061)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: tea monster on October 14, 2013, 06:37:09 PM
Cheers. I'm using 2.6 as that's what was on the top of the thread.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on November 20, 2013, 03:24:28 PM
Hello !

I'm trying to export a md5 out of a simple model (no animation or weight mapping, only geometry and UV) from Blender 6.9, and here's what it says :
Code: [Select]
Traceback (most recent call last):
  File "C:\Users\dmeat\AppData\Roaming\Blender Foundation\Blender\2.69\scripts\addons\io_export_md5-263.py", line 904, in execute
    save_md5(settings)
  File "C:\Users\dmeat\AppData\Roaming\Blender Foundation\Blender\2.69\scripts\addons\io_export_md5-263.py", line 726, in save_md5
    uv = [uv_textures.active.data[face.index].uv[i][0], uv_textures.active.data[face.index].uv[i][1]]
IndexError: bpy_prop_array[index]: index 3 out of range

location: <unknown location>:-1

I have no knowledge in python / Blender scripting so I can't fix this myself at the moment ... Is anybody working on this ?

Thanks by advance !

D-Meat
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 20, 2013, 04:37:30 PM
The script appears to work fine in Blender 2.69 from the tests I've done so I suspect that error is likely the result of a bad, incomplete or improperly prepped mesh - make sure you have at least one Material assigned as simply applying a texture to the UV isn't enough (typically results in the message you got). Read through the "How to export MD5 (http://www.katsbits.com/smforum/index.php?topic=178.0)" if you haven't already, it'll save you a lot of headaches. You may also need to have a basic Armature set up (Armature with at least two bones) to which the mesh should be properly parented (see link for details).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on November 20, 2013, 07:54:48 PM
I've attached my Blend file just in case I'm getting something wrong.
Don't mind about the strange normal map included, This is a test model.

I did my UV unwrapping and work like I usually do, and I added a basic armature with 2 bones. All the mesh's verticles are assigned to the base bone.

This model is not made to be animated, even if I later plan on doing some "procedural animation" on the wings's fins.

Thanks for replying !

I'm actually working on a game using ioQuake 3, and I wanted to experiment the md5 model format because bone based animations are much better than the quake 1-2-3 method :)
Here's my project's description : http://www.quake3world.com/forum/viewtopic.php?f=16&t=49611 (http://www.quake3world.com/forum/viewtopic.php?f=16&t=49611)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 20, 2013, 08:46:03 PM
OK that is odd.. I'm not entirely sure why it faults on "uv_texture" unless that's the point at which the export process realises there's an oopsie. But yes... the problem was you hadn't properly (fully) prepped the item for export - you must make sure this is done. What you're missing is and Armature Modifier assigned to the mesh, and an Armature Action (animation) with more than one frame. Read through the How to export and MD5 (http://www.katsbits.com/smforum/index.php?topic=178.0)" guide I linked to previously as everything you need to know and should be doing is explained there in detail.

Not that you may get additional but different errors until the mesh is set-up correctly and exportable.

[EDIT] I deleted the attachment after I downloaded it by the way, in case you were wondering why it doesn't appear.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on November 20, 2013, 10:46:44 PM
Did you manage to export it ?
I added the armature modifier (somehow it disappeared at some point , i'm pretty sure I added it before sending you the file), I did a 2 frame animation with different angles for the upper bone, and named the animation "none" in the action editor. I think I followed all the instructions correctly.

The error remains the same.

Right now I'm trying again with a simple cube, maybe that will do ...
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 20, 2013, 11:25:06 PM
Yes, it exported for me (send an email info@katsbits.com and I'll return the 'fixed' files). In the meantime, in addition to the above, make sure you triangulate the mesh ("Ctrl+T" on a selection) before export, that looks to be the reason for the initial error (the script doesn't auto-tris meshes - it's usually best to do that manually though for better control over edge-flipping). The Action and Armature don't necessarily need to articulate, there just needs to be two or more frames for export. Also don't worry about loosing the animation as that likely just means you didn't have the Fake-User set against the sequence (http://www.katsbits.com/tutorials/blender/character-7-animation.php#userdata).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on November 20, 2013, 11:42:59 PM
I could export a single cube, textured and with a 2 bone armature and everything.

Thanks for all the info ! I'll try to export my plane again, and if nothing works, I'll send you an e-mail.

Tomorrow's challenge will be to make this work in ioQuake 3, and this doesn't seem very easy :)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 21, 2013, 12:14:50 AM
If it were easy, everyone would be doing it and we'd no longer be special ;)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on November 21, 2013, 10:18:14 AM
If it were easy, everyone would be doing it and we'd no longer be special ;)

I guess so :D

I could export my plane, and I could point out the problem : it's not acutally a hard triangulization that it needed, having quads is just fine, but it won't support faces with more than 4 edges, and I actually had one I forgot at the nose of the plane.

Since 2.67, I think, blender supports multi edge faces. I'll check if it can be turned off somewhere.

Maybe you can add that detail to the tutorial you wrote :)

Thanks again !
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on November 21, 2013, 10:28:04 AM
Ah that would explain why triangulation 'fixes' the problem and allows export, breaking the mesh down kills the nGon (creates 'standard' faces). Will update the tutorial. Glad you got this sorted out.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: overdrivekaz on December 15, 2013, 11:16:13 PM
Hello Admin Masters.

I have problem with exporting to md5. I have the same problem with D-meat, but I've manage to export successfully while reading the previous post. but there is one problem. how come the UV map doesn't appear?.. i have output only mesh and anim file... Hope I could get help. THanks :)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: D-Meat on December 15, 2013, 11:23:30 PM
from my experience from idTech3 and ioQuake 3 (which actually doesn't support md5, but what I learned about md5 exporting was useful to export IQM), you have to name your material to the path of your shader / material ("models/player/sarge", maybe). if you open the console, there might be a line where it says "texture for shader **** not found", and from what the **** are, you can guess where to specify where to put your shader / texture :)

Just guessing ...
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: overdrivekaz on December 16, 2013, 12:03:39 AM
nope. there are no notifications displayed or etc. it seems to have successfull. but i can't get the textures displayed.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 16, 2013, 02:06:33 AM
Hmm, yes in addition to what D-Meat (http://www.katsbits.com/smforum/index.php?topic=167.msg3355#msg3355) said check the resulting files in the MD5 Modelveiwer (http://www.katsbits.com/tools/#md5). If the md5mesh and md5anim files exported correctly you should get a message asking you to add the textures/materials for viewing in the app. If you don't get that then there's an issue with material and or UVW assignments. One thing to note though, your objects MUST have a Materials assigned, you can't simply UVW map the mesh and assigned the texture directly because that doesn't provide the necessary underlying material data the MD5 format needs. Also remember that MD5 are text files, you can open them in NotePad or similar and check the data that way.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: overdrivekaz on December 16, 2013, 11:17:35 PM
i see. thanks.

btw I have assigned materials for objects of course. yes yes. I do got a prompt that is looking for the texture files. currently my image source are png format. does it necessary to convert them to TGA?. Thanks very much.

btw. i have a total of 10 shaders. each have different material names. but when i open it in notepad. all shaders have only 1 shader name.

i tried to edit the txt file manually. but still i get no shade display.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 17, 2013, 02:49:05 AM
I can't remember off the top of my head if the MD5Viewer supports PNG images so yes, you may need to have a working file as TGA so you can properly/fully test the mesh once it's been exported.

As for the number of materials issue: MD5 doesn't allow multiple shaders/materials/textures on the same object. That means the object needs to be split per-material (the mesh then is composed from several sub-meshes, each one assigned a unique material/texture). Or, you will need to condense the materials together as best you can (which may still mean that where multiple materials are used, associated mesh sections will need to be separated into sub-objects). See the How To section on "MESH PREP Materials, Textures & UVW maps (http://www.katsbits.com/smforum/index.php?topic=178.0)"
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: overdrivekaz on December 19, 2013, 02:20:22 AM
thanks sir.. that is exactly my model looks like. 1 mesh with multiple shaders.. but i removed the rest and used only one material. then still doesn't show its effect. i also used tga format and still nothing happens.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 19, 2013, 03:26:42 AM
What effect are you referring to? Can you post a screenshot of what you're looking at in Blender or the MD5 model viewer?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: cebugdev on December 20, 2013, 02:12:29 AM
hi admin,

i work with overdrivekaz for this project and he is the modeler and i did the model viewer and the engine, i decided to use MD5 because it is lightweight and easy to implement model with skinned animation. anyways, what he meant was when looking at the inside of the MD5 file, the filename of the texture does not appear in the "shader" part of the code each mesh, it only displays shader "Material.001" and also no texture files imported along with md5mesh and md5anim.

overdrivekaz will post more details soon, hope you guys can help us with this, thanks,
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 20, 2013, 11:39:02 AM
@cebugdev (http://www.katsbits.com/smforum/index.php?topic=167.msg3368#msg3368): thanks for clarifying. I've just added a new section to the MD5 prep & export information (http://www.katsbits.com/smforum/index.php?topic=178.0) (cf. MESH PREP Material, Texture, UVW names/ID's (http://www.katsbits.com/smforum/index.php?topic=178.msg966#msg966)) which explains in-depth what the problem is likely to be. Suffice to say here though, make sure your Material names are 'valid'; you'll need to remove the automatic numerical append, that's the ".001" bit from the Material name (and other data for that matter). Depending on what you're doing (how you've implemented the format in the engine), Material names ("ID") will be important in terms of their referencing a 'path' or just a (descriptive) 'word', "wood" vs "textures/floor/wood" for example.

Failing all that the resulting *.md5mesh, being text based, can be corrected manually in NotePad or similar if there are problems - you can test material/texture assignment in MD5View, just try loading in a random image to see if it gets applied, if it does you have a valid mesh, if it doesn't you'll know there's an issue (make sure to use *.tga formatted images initially).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: overdrivekaz on December 20, 2013, 10:47:06 PM
Sir. can i send the file through pm?.. i will also include the md5 file for your reference. thanks

update: i renamed a unique shader/material name but still the same.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 21, 2013, 12:03:27 AM
Yep, send it through and I'll take a look - info@katsbits.com

[EDIT] upon further investigation the issue overdrivekaz was having related to the texture assigned to the mesh not being 'power of two' (http://www.katsbits.com/tutorials/textures/make-better-textures-correct-size-and-power-of-two.php); make sure texture assets are valid sizes related to that 'rule' else they won't appear in MD5View for testing (and likely any game engine using the format).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 05, 2014, 01:38:32 AM
I've tried using this script in both Blender 2.63 and 2.66, however with any mesh I use I always get what seems to be invalid bounds (i.e. for min the x, y and z values are all the same for each frame, and I'm not sure if max values are valid). I've included a sample below:

bounds {
   ( -1.463064 -1.463064 -1.463064 ) ( -1.463064 3.384057 2.877697 )
   ( -1.390775 -1.390775 -1.390775 ) ( -1.390775 3.384057 2.877697 )
   ( -1.274601 -1.274601 -1.274601 ) ( -1.274601 3.384057 2.877697 )
   ( -1.235497 -1.235497 -1.235497 ) ( -1.235497 3.384057 2.877697 )
   ( -1.234138 -1.234138 -1.234138 ) ( -1.234138 3.384057 2.877697 )
   ( -1.233475 -1.233475 -1.233475 ) ( -1.233475 3.384057 2.877697 )
   ( -1.234469 -1.234469 -1.234469 ) ( -1.234469 3.384057 2.877697 )
   ( -1.252545 -1.252545 -1.252545 ) ( -1.252545 3.384057 2.877697 )
   ( -1.349897 -1.349897 -1.349897 ) ( -1.349897 3.384057 2.877697 )
   ( -1.463064 -1.463064 -1.463064 ) ( -1.463064 3.384057 2.877697 )
   ( -1.349896 -1.349896 -1.349896 ) ( -1.349896 3.384057 2.877697 )
   ( -1.252545 -1.252545 -1.252545 ) ( -1.252545 3.384057 2.877697 )
   ( -1.234469 -1.234469 -1.234469 ) ( -1.234469 3.384057 2.877697 )
   ( -1.233475 -1.233475 -1.233475 ) ( -1.233475 3.384057 2.877697 )
   ( -1.234468 -1.234468 -1.234468 ) ( -1.234468 3.384057 2.877697 )
   ( -1.252475 -1.252475 -1.252475 ) ( -1.252475 3.384057 2.877697 )
   ( -1.349568 -1.349568 -1.349568 ) ( -1.349568 3.384057 2.877697 )
   ( -1.463064 -1.463064 -1.463064 ) ( -1.463064 3.384057 2.877697 )
}

I've taken a quick look at the script and can't see anything obviously wrong (I've never done Python scripting though), so is there anything I could be doing incorrectly? Note that other than that, the models get exported perfectly.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 05, 2014, 03:05:54 AM
The coordinates shown in "bounds" represent the MD5's bounding box (volume of space occupied) per frame of a given animation sequence.

Assuming the mesh and Armature are properly centered on Blenders grid so the Objects 'Origin' point is placed at grid-centre (0,0,0) prior to export, both positive and negative values should be seen in the resulting output because they represent, in 'Object Space' (values based on the Objects Origin iirc), the 'min' and 'max' "X", "Y" and "Z" coordinates of each face of the six-sided volume as it changes shape and size due to articulation of the underlying mesh.

If you're not seeing any obvious errors, i.e. the mesh is all over the place, what you have there appears to be fine.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 05, 2014, 03:42:53 AM
Thanks for the quick reply. The models I've tried look fine - they are properly centered and have width in all axes. With all of them I get the same issue, the min x, y, z and max x values are all the same. When trying this with the "Bob" MD5 model provided in the MD5 downloads section on this site I get the min x, z and max x values being the same, so the bounds ends up being a 2d square along the y-z plane with no width, which definitely looks wrong (this was in Blender 2.63 and 2.66a)?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 05, 2014, 06:55:22 AM
What are you using to test/view the mesh data? Using 'Bob' there shouldn't be any general issues using the files as-is, so there must be something else going on. To check try exporting from Blender 2.69 using the same script (http://www.katsbits.com/smforum/index.php?topic=167.msg840#msg840) (which works fine) to see if that fixes the issue.. if it does then you know there's a problem exporting from the mentioned versions of Blender rather than the files you're actually exporting.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 05, 2014, 01:55:58 PM
I've downloaded Blender 2.69 and unfortunately get the same issue. I'm using my own engine to view the MD5 mesh/animation and it's per-frame AABB, however the AABB problem can be verified by just opening the file in Notepad++ and comparing the values. The actual exported model and animation work perfectly, it's just the bounding boxes that have an issue.

If you have the time, could you verify these results by trying to export the Bob MD5 model and checking what the exported bounds are? I only ask because I'm at a loss :(
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 05, 2014, 05:34:22 PM
OK looking in to this as the bob example files exported from Blender 2.69 are showing some odd distortion errors for me when opened into MD5View - something that doesn't happen with other recent files/projects so I suspect these issues are the result of the many internal changes Blender has undergone with 2.5/2.6 series. Will post an update shortly.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 05, 2014, 06:42:36 PM
Thanks very much for double checking. Please take your time there's no rush, also if there's any way I can help (providing test cases e.t.c) then let me know :)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 06, 2014, 12:57:36 AM
Sample file has been updated for Blender 2.69 and above (subject to Blender Foundation subsequently breaking stuff internally again). Old version is still available but both can now be found on the MD5 sample file page (http://www.katsbits.com/download/models/md5-example.php).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 07, 2014, 02:17:54 PM
I think there's been a misunderstanding, the problem wasn't with the Bob MD5 sample model, the problem is with the MD5 export script. Taking a look at the updated model, the newly-created "bob_lamp_update.md5anim" and "bob_lamp_update_export.md5anim" animation files still have the same problem - the bounds are incorrect. Open up those files with Notepad++ and compare the values for each bounding box's min and max x, y and z values and you'll see that the bounds were calculated/exported incorrectly.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 07, 2014, 08:34:12 PM
Just to check this further the below is the first line from the 'bounds' block exporting the same (original) Bob file from each script corresponding version of Blender - before export MESH objects were reset so their size and origin were relative to Blenders grid-centre (used "Apply" to set Origin points at 0,0,0) - the bounding box values are calculated relative to that position (outwards).

Bounds from 2.54
( -1.634066 -1.325154 -0.028520 ) ( 1.632142 7.007772 6.647473 )

Bounds from 2.57
( -1.634066 -1.325154 -0.028520 ) ( 1.632142 7.007772 6.647473 )

Bounds from 2.62
( -1.634067 -1.634067 -1.634067 ) ( -1.634067 6.444686 5.410537 )

Bounds from 2.63
( -1.634067 -1.634067 -1.634067 ) ( -1.634067 6.444686 5.410537 )

Bounds from 2.69
( -1.634067 -1.634067 -1.634067 ) ( -1.634067 6.444686 5.410537 )

It looks like either there's an error in the script or Blender itself (in terms of what it's doing relative to the script) after the significant change that happened Blender 2.60 onwards - looking at the numbers from 2.62 the bounds do indeed appear to be a flat box compared to prior that.

Unfortunately I can't do anything beyond confirming what you've found as I'm not a code-monkey.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Rajveer on January 07, 2014, 10:12:29 PM
Thanks for double checking the different Blender versions for which work and don't. If I have time I'll take a look at the changes between 2.57 and 2.63 and hopefully be able to figure out what changes need to be made to the script. If I'm able to fix it I'll report back.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: majki on January 17, 2014, 02:19:46 PM
Okay, I hope there are still here ppl reading this.


I installed script in Blender 2.69. Created simple plane, UV mapped it and assigned 1 texture to it. What I want it to export it as MD5 and load into idtech4 with DarkRadiant as level editor to be level geometry.

During export, I checked only "mesh" box and I got this error:

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fy0wYSTt.png&hash=1527eba42ac96c5568d6cec5a9a27d58)

What Am I doing wrong?

My aim is - build level for idtech4 made not with brushes, but with models created in Blender.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 17, 2014, 03:30:54 PM
You need to have a basic rig and associated animation available for the script to produce a proper (usable) MD5, even on simple meshes. Regards building the level from models, you may need to make extensive use of portals and may need to caulk hull the level to prevent leaks. Aside from that it should be OK.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: majki on January 17, 2014, 03:33:36 PM
So I can't just export ie building? I have to add rigs? I'm not into animation in Blender - are there simple few steps I should follow? Just for idtech4 needs?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 17, 2014, 03:56:15 PM
It's not really a question of not being into animation, rather making content that caters to a specific purpose or function. You can facilitate certain types of 'events' using static meshes, say a light fixture that changes colour, those are typically ASE, OBJ or LWO meshes and just a simple show/hide script triggered event.

On the other hand if you wanted a structure to perform more complex operations you might then need to use MD5 or 'dynamic' content - with or without an animation; this might mean the skeleton acting as a basis upon which 'ragdoll' responses to player intiated events ir based - lamps  hanging from the ceiling which move when shot are MD5, the skeleton allows for that type of movement where only a single frame 'idle' animation might be needed.

For a building then, a static or 'world' object, that does nothing, it's best to use the aforementioned ASE, LWO or OBJ.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: majki on January 17, 2014, 04:01:13 PM
Hm... So for pure level editing - md5 is not needed? That makes things easier.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on January 17, 2014, 04:15:22 PM
Much of a level can be built using static mesh objects yes, MD5 are usually used for event triggered actions - a chandelier reacting to the player firing an arrow at it for example.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on March 29, 2014, 12:40:37 PM
MD5 script has been tested with 2.70 and appears to work.

As always make sure to test per requirements before making any changes to your respective development environments. See first post for download (http://www.katsbits.com/smforum/index.php?topic=167.0).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 04:58:53 PM
I tried using the script for both blender 2.69 and 2.71 and get the same error:

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FD86SdXX.png&hash=3b62c65f938539bf3cf4b05b5b1fffa7)

None of the assimp opengl tutorials I know of use anything other than md5 for some weird reason..
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 19, 2014, 05:11:17 PM
The text is too small in the image to read.. Can you type what it's telling you?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 05:27:14 PM
The text is too small in the image to read.. Can you type what it's telling you?

If you copy the url and load it the text is clearer:

File ".....\io_export_md5-263.py" line 904, in execute save_md5(settings)
File ".....\io_export_md5-263.py" line 826, in save_md5 buffer = skeleton.to_md5mesh(len(meshes[0].submeshes))

IndexsError: List index out of range
Location: <unknown location>:-1

I have a mesh, I have a bunch of bones, an animation, IK bones, and some bones for determining the angle of the arms/legs (where they point).

Although the skeleton follows This rigging tutorial (https://www.youtube.com/watch?v=cGvalWG8HBU) so there might not be a super clear parent-child relationship from a root bone to all the other bones, is that an issue?

Here's my blend file (https://drive.google.com/file/d/0B6oLZ_d7S-U7a0NUN1VsdHRYNFU/edit?usp=sharing)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 19, 2014, 05:44:23 PM
Looks like it could be the mesh objects (Shapes) you're using as part of the rigging - MD5 rigs generally can't contain non-bone objects, which includes meshes and empties. Disable/remove those then try again. Basically you should only be exporting the character mesh and the Armature composed of bones. So long as you have the Armature modifier and other bits set up you should then be able to export without issue.

To answer you other point about assimp using MD5, it's because its a purely text based format, making it super useful for teaching game development - everything is easily readable/accessible.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 06:16:51 PM
Looks like it could be the mesh objects (Shapes) you're using as part of the rigging - MD5 rigs generally can't contain non-bone objects, which includes meshes and empties. Disable/remove those then try again. Basically you should only be exporting the character mesh and the Armature composed of bones. So long as you have the Armature modifier and other bits set up you should then be able to export without issue.

To answer you other point about assimp using MD5, it's because its a purely text based format, making it super useful for teaching game development - everything is easily readable/accessible.

What do you mean by Armature modifier, can you explain what settings I should have?

The only options I see are: MD5 Name, Exports: Mesh & Animation/Mesh/Animation and Scale.

Also if I have different things selected, I get different errors, what am I supposed to have selected?

Removing the custom shapes for the bones presents me the following:

The same error as before with the bones selected in rest position and in pose position.

With just the mesh selected:

line 647, in save_md5 material = Material(obj.data.materials[0].name ) # call the shader name by the material's name

IndexError: bpy_prop_collection[index]: index 0 out of range, size 0

location: <unknown location>:-1

Do you have a tutorial as to how my settings should look like? Beyond making a mesh and a simple animation I have no idea what I'm doing.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 19, 2014, 06:46:08 PM
Based on what you've said there it pretty much looks like you're not properly prepping for export. Read through this, How to export MD5 (http://www.katsbits.com/smforum/index.php?topic=178.0) (it's linked in the first post of this topic incidentally), it's a more detailed, but generic overview, of what you should be doing - single mesh, single armature with bones only, an animation action selected, etc.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 07:13:17 PM
Based on what you've said there it pretty much looks like you're not properly prepping for export. Read through this, How to export MD5 (http://www.katsbits.com/smforum/index.php?topic=178.0) (it's linked in the first post of this topic incidentally), it's a more detailed, but generic overview, of what you should be doing - single mesh, single armature with bones only, an animation action selected, etc.

The very first step is causing me issues, I try to unparent the mesh and it detatches the bones from my mesh, so the animation breaks, the mesh is parented to the bones so I'm not sure how to proceed..
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 07:36:25 PM
New error trying some of the steps in the provided link:

line 760, in save_md5 arm_axction = thearmature.animation_data.action
AttributeError: 'int' object has no attribute 'animation_data'

location: <unknown location>:-1

Can you help me by looking at my .blend file for what I need to do? Many of the provided instructions are along the lines of "Make sure x,y,z is correct." and I have no idea as to whether they are or aren't. All I know is, my animation works as is.

I did the steps under "Exporting Animations" and that was where the above error came from.

Additionally, I don't think this version of my scene has any materials or textures, I'll assume its required to have one and see if I can add a simple texture.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 19, 2014, 07:52:38 PM
I GOT IT!!!! I needed to have a material and a texture thrown in. <("<)

I still don't know if this is everything assimp needs yet and can still break on me in a spectacular fashion but this is a good start.

Thanks for your help!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 19, 2014, 08:02:58 PM
Send the blend to info@katsbits.com and I'll take a look for you.

Heh, you fixed it whilst I was reading/posting! And yes, you need a material and texture/UV map assigned otherwise it'll throw out another error.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 20, 2014, 11:18:05 PM
A'ight, I've encountered a problem, it doesn't seem to actually export the animation file and there isn't an error message.

I've also managed to load the mesh using assimp (although textures and materials are eluding me because ImageMagick seems broken, I sicked a 50 point bounty on it over at stackoverflow) but while the head is fine the rest of the body is horribly deformed after following the unparent-reparent steps in the linked tutorial, I'm not sure exactly I'm doing wrong.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 20, 2014, 11:59:23 PM
There's usually two reasons for the deformity you're describing, either; 1) the vertex weighting has some odd assignments (vertexes weighted to 'odd' bones may pull the mesh out of shape when it animates); or 2) when you set "Apply", the mesh and it's Origin point were not centered on Blenders 0,0,0 grid.

The upshot is that if you want the character to walk along a path (the curved line in the image from the previous page?), the mesh and armatures corresponding Origin Points need to be located at Blenders 0,0,0, that's the starting point from which the character and rig move - if it's 'off set' in some way the result is often the kind of corruption you're seeing.

Make sure also when you export, there is an active "Action" sequence shown in the Action Editor (when you select the Armature, the sequence should display in the Editor indicating it's the current active dataset). That's where the animation data comes from.

If you want/are able to, send me the file and I'll take a look (email above).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 21, 2014, 12:23:26 AM
Blend file sent, to reiterate what I mentioned in the email, it looks like all the bones got moved to the origin of the mesh except for the head bone.

(https://www.katsbits.com/smforum/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fem8aCQz.png&hash=3091f2378d854ea91307d101f094d96a)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 21, 2014, 03:19:55 AM
You're almost there, you just have to reconsider the mechanics of animating relative to a game engine rather than Blender - there's a difference because Blender understands what the Scene data means and the way it's set up to make the character walk the line. Third-party game engines don't. To get a character to walk a path the way you want you have to fully animate it, i.e. the model has to be posed and keyframed the full distance and duration. In essence you're producing a unique sequence rather than looping a walk.

The way that should actually be done is to keep the root bone static, it should never move, the appearance of motion comes from the other bones moving in relation to the root, and away from it. If this isn't done the sequences gets mushed because the positional data of each keyframe is rooted at the origin and grid centre (0,0,0), that point, and manipulation from it, is what determines distance. So whilst the keyframes are thusly rooted, the Armature isn't, it's origin is moving with the mesh resulting in a collapsed sequence (gets squished like an accordion).

To correct this you need to unparent everything and then reassign an Armature modifier to the mesh, linked to the Armature. That's your basic structure. In the Action Editor when you animate, the "Control" bone should remain static, everything else being posed and keyframed appropriately relative to the sequence needed, in other words, you have to physically move the character incrementally along the guide and pose each step whilst doing so.

A couple of other observations.

When you create animated object you'll generally want to 'ground' them so the base of the feet sit on the on the horizontal plain. This is also where the mesh and armature origins are located (they are again, what determine the position of objects in game). Loading the little guy into a previewing tool it's buried up to the waist.

The mesh is collapsed when loaded because it doesn't have a properly formed 'default' pose - usually this is because the vertex weighting or pose data isn't corresponding properly to the mesh structure. The problem disappears once an md5anim file is loaded though.

Ideally you'll want to reduce the polycount of the mesh, 50k is super high so use a Decimate Modifier on it to reduce it to a reasonable level (anything under 2500 for the kind of simple structure you have there).

Hopefully all this make sense. If not ask away ;)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 21, 2014, 03:35:20 AM
It's going to take me a minute to full absorb it all, I'll clarify that right now I just want to pull the mesh and render it at its rest pose; I don't want to animate it yet as I just want to test my engine one module at a time.

If I follow what you say it should still work for just making the T-Pose mesh right?

Edit: The absurd polycount size on the Mesh is because it was provided by my professor during my graphics course two semesters ago, (the course itself was horribly out of date so I've been working on updating the code to modern opengl specs) so for testing performance stuff I kept the absurd polycount size for academic purposes; practically when I make my own characters hopefully they won't be so absurdly large in numbers :D

Edit2: Still undergoing implosion with the file you sent me, is that because I'm not applying its animations?
Edit3: Yeah that's exactly what you're saying, I'm not loading the animation file so it ain't lookin' right.

Regarding animating a unique sequence, so you mean do what I did to keyframe it for 30 frames and then just keep repeating that while incrementally moving it bit by bit away from the control bone?

Edit4: Wouldn't it actually make more sense to not do movement in blender and do it in the engine?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 21, 2014, 10:43:05 AM
The characters Armature has not been reset so it carries a scale value, the likely cause of the mushed up mesh when its loaded without a supporting anim file - the Armature should carry a "Scale:" value of "1.0" indicating it's been 'reset' ("Apply") but if that's done now the rig will get messed up (this is why both mesh and Armature need to be reset before being parented and animated, if it's done after the fact it'll mess up any sequences that already exist; and why when making content the origin should always sit on the horizontal plain as a representation of the ground, you then build and animated relative to that).

Re: Edit 1. Make sure to triangulate the mesh before export (in Edit mode, Select All, press "Ctrl+T") otherwise a mesh like that can crash Blender when its parsed by the script.

Re: Edit 2. You should be able to export a single framed sequence (can be a couple of frames, they just need to be the exact same pose) so you have a posed character to work with.

Re: Edit 3. Yes, you animate the sequence as one long event. In this instance it might result in an animation that has the character walk, that is swing the arms and legs for a full cycle, 20 or so times over a duration of about 30 seconds and maybe 250 frames.

Re: Edit 4. That is infact how objects generally move, it's done in-game. There are different way to physically do it depending on what the character is supposed to do, but essentially you export a walk cycle, a loop of a couple of steps like the one you've already got (you can do either a 'static' or 'dynamic' animation - the character will loop standing on the spot, or will move a short distance away from the origin as part of the cycle) , and move the game object around based on controlled input (mouse/keyboard) whilst the loop is triggered to play. This gives the impression of an actual walk.

If you want the character to walk along a path, you'd normally set that up in game, treating the character as a scripted event (if the character is the player you'll usually script the event using a 'third-person' representation - its mechanically easier to script movement of a 'bot' than doing it to the object the player is observing the game through).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 21, 2014, 07:46:56 PM
Thanks, I'll get back to fiddling with that in a moment as soon as I can get my animation code working :D

Is there a way in blender to make sure no vertex is affected by no more than four bones? I think that might be better than trying to get the code to work for 4+.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 21, 2014, 08:21:03 PM
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them (http://www.katsbits.com/smforum/index.php?topic=610.msg3620#msg3620) by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 21, 2014, 08:26:51 PM
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them (http://www.katsbits.com/smforum/index.php?topic=610.msg3620#msg3620) by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!

Yeah :(
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 21, 2014, 09:11:32 PM
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them (http://www.katsbits.com/smforum/index.php?topic=610.msg3620#msg3620) by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!

Huh, why isn't there a way to select all vertices by vertex group? That would be way easier, the only 'quick' solution would be to subdivide the mesh into a mesh for each vertex group.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 21, 2014, 09:36:10 PM
You can select vertices based on group.

With the mesh in Edit mode and Vertex selection active ("Ctrl+Tab"), click the "Object Data" properties button (the triangle with dots each corner). Find/expand the "Vertex Groups" subsection to reveal the "Vertex Groups Index", a list of vertex group assigned to the active mesh. Groups can be managed by selecting an entry and then clicking one of the buttons to "Select", "Deselect", "Assign" or "Remove" - individual vertices can be removed or assigned to different groups using these.

Do note however that checking "which groups are assigned to an individual vertex" and "which vertices are assigned to a group" are slightly different questions that address different aspects of the process - they may appear to be the same but it's a question of macro versus micro management of structure.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Blayne Bradley on July 22, 2014, 04:37:11 AM
Stackoverflow to the rescue!

"In weight paint mode, select the Weight Tools panel in the toolbar, and run Limit Total, This removes vertex groups with lowest weights.

This defaults to 4 which is a common limit for game-engines."

This works! So in the future if some other poor fellow has the same question we know what to do. :D
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 22, 2014, 12:40:56 PM
Learn something new everyday heh ;)

Be mindful how the tool is used though, there are obviously a lot of situations where more than four groups will be needed, especially on a whole character. With that said, it looks like it may be a good way to remove errant group assignments and clean up a mesh.
Title: Problems with 2.63 MD5 Anim Only export
Post by: oladitan on August 26, 2014, 12:39:37 AM
Hello. I am using the Blender 2.63 MD5 export script. Everything seems to work fine when I export my model with the active animation together with the 'Mesh and Anim' option. however when I try to export other animation with the 'Anim Only' option. blender has an error. This error occurs in both blender 2.63 and 2.71

Code: [Select]
location: <unknown location>:-1
Exporting selected objects...
root bone: Bone
Processing mesh: mesh1
created verts at A 80, B 0, C 88
<io_export_md5-263.MD5Animation object at 0x0000000009A026D8>
Traceback (most recent call last):
File "C:\Users\oladitan\AppData\Roaming\Blender Foundation\Blender\2.71\script
s\addons\io_export_md5-263.py", line 904, in execute
save_md5(settings)
File "C:\Users\oladitan\AppData\Roaming\Blender Foundation\Blender\2.71\script
s\addons\io_export_md5-263.py", line 854, in save_md5
generateboundingbox(objects, anim, [rangestart, rangeend])
File "C:\Users\oladitan\AppData\Roaming\Blender Foundation\Blender\2.71\script
s\addons\io_export_md5-263.py", line 559, in generateboundingbox
(min, max) = getminmax(corners)
File "C:\Users\oladitan\AppData\Roaming\Blender Foundation\Blender\2.71\script
s\addons\io_export_md5-263.py", line 514, in getminmax
if len(listofpoints[0]) == 0: return ([0,0,0],[0,0,0])
IndexError: list index out of range

I followed the instructions on the page where I downloaded the ad don.

Do I need to change a line in plugin code or something. Thanks.
Title: Re: Problems with 2.63 MD5 Anim Only export
Post by: kat on August 26, 2014, 08:34:16 AM
Which script did you use? The one authored by keless here (http://www.katsbits.com/smforum/index.php?topic=167.0), or the one by nemyax here (http://www.katsbits.com/smforum/index.php?topic=404.0)? If you used keless' script that looks like a bounding-box issue so make sure you have the mesh selected even though you're only exporting the animation (also make sure its assigned to the Armature before export - it should be the active sequence).
Title: Re: Problems with 2.63 MD5 Anim Only export
Post by: oladitan on August 27, 2014, 09:05:19 AM
Which script did you use? The one authored by keless here (http://www.katsbits.com/smforum/index.php?topic=167.0), or the one by nemyax here (http://www.katsbits.com/smforum/index.php?topic=404.0)? If you used keless' script that looks like a bounding-box issue so make sure you have the mesh selected even though you're only exporting the animation (also make sure its assigned to the Armature before export - it should be the active sequence).

Thanks kat. I was using the keles script. I have tried the nemyax script as well. It gives me this error when I try to the mesh or the animation : The

Code: [Select]
The deforming armature has no bones in layer 5.
Add all of the bones you want to export to the armature's layer 5,
or change the reserved bone layer in the scene properties,
and retry export.

All of the bones of the armature are on the first layer of the armature layers. the armature is on layer 1 of the scene. The object, in this case a cube, is parented to the armature and deforms. The animation that I want to export is active int the action editor.


I have attached a file that I made using blender 2.71. Maybe you can reproduce the error.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on August 27, 2014, 11:37:53 AM
Hmm problem replicated in 2.71 using keless' script when exporting to "Anim only". Otherwise there are no issues. It looks like Blender can't determine the animations boundingbox area for some reason, not sure why.

The work-around for the moment (obviously aside from the script being fixed) is to just export each sequence with a copy of the mesh at the same time, that works without OK - just delete the unwanted mesh files once done.

Side note: generally speaking MD5 can't make use of animations with scaled/resized bones - if you do that, whilst you'll get data output, unless you specifically allow for it in the game engine you're using, nothing will happen on playback.

P.S. merged topics to keep everything in one place by the way.

Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Bitterman on July 16, 2015, 01:31:58 AM
Long time ago in thread “[MD5] EXPORT script for Blender 2.6x (OPEN)” kat wrote (by answer to Rajveer):

Quote
“Just to check this further the below is the first line from the 'bounds' block exporting the same (original) Bob file from each script corresponding version of Blender - before export MESH objects were reset so their size and origin were relative to Blenders grid-centre (used "Apply" to set Origin points at 0,0,0) - the bounding box values are calculated relative to that position (outwards).

It looks like either there's an error in the script or Blender itself (in terms of what it's doing relative to the script) after the significant change that happened Blender 2.60 onwards - looking at the numbers from 2.62 the bounds do indeed appear to be a flat box compared to prior that.”

Rajveer talk about problem with incorrect values inside “bounds” section into .md5anim.

This is not obvious problem because Blender and modelviewer (imho) don’t show ‘bounds’.

But if anyone try to test exported model in Doom 3 with ‘testmodel <name>/testanim <name>/r_showskel 1’ console commands then we see as md5 bounding box is offset and distorted along one of axis (Y-components in max [X,Y,Z] as I think).

Not sure but it’s may be bad for game physics (see pictures).

Take a look (this is “io_export_md5.py” for Blender 2.59+ but algorithm is same in 2.4x-2.6x):

Code: [Select]
>>> corners.append(point_by_matrix (v, matrix)) <<<
(min, max) = getminmax(corners)
md5animation.bounds.append((min[0]*scale, min[1]*scale, min[2]*scale, max[0]*scale, max[1]*scale, max[2]*scale))

We see that ‘bounds’ based on ‘corners’ and ‘corners’ are mul by ‘matrix’ (few lines above):

Code: [Select]
def generateboundingbox(objects, md5animation, framerange):
  …
        matrix = [[1.0,  0.0, 0.0, 0.0],
          [0.0,  1.0, 0.0, 0.0],
  >>> [0.0,  1.0, 1.0, 0.0], <<< there is two (not one) correction values!
          [0.0,  0.0, 0.0, 1.0],
          ]
     
I belive this row (or column) >>> [0.0,  1.0, 1.0, 0.0] <<< give a distortion by added some value to Y-component (or other) in max[X,Y,Z] because:

Code: [Select]
def point_by_matrix(p, m):

return [p[0] * m[0][0] + p[1] * m[1][0] + p[2] * m[2][0] + m[3][0],
          p[0] * m[0][1] + p[1] * m[1][1] + p[2] * m[2][1] + m[3][1],
          p[0] * m[0][2] + p[1] * m[1][2] + p[2] * m[2][2] + m[3][2]]

Now try to solved (I hope):

1.   Open “io_export_md5.py” in editor (Notepad).
2.   Add “cornersb = []” after “corners = []”.
3.   Add “matrixb = [[1.0,  0.0, 0.0, 0.0],
          [0.0,  1.0, 0.0, 0.0],
          [0.0,  0.0, 1.0, 0.0], 
          [0.0,  0.0, 0.0, 1.0],
          ]”

after “matrix = […]”.

4.   Add “cornersb.append(point_by_matrix (v, matrixb))” after “corners.append(point_by_matrix (v, matrix))”.
5.   Change “(min, max) = getminmax(corners)” to “(min, max) = getminmax(cornersb)”.
6.   Save modified “io_export_md5.py” in same place (blender/…/scripts/addons).

After this I see correct (well… almost correct) values into ‘bounds’ (see pictures).
Not sure about others but it seems work.

Hope this help.

Bitterman.





Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 16, 2015, 02:04:13 AM
Ah that makes sense. Will test this ASAP then post an updated version of the script. Thanks for figuring out where the problem seemed to lie so this error can be put to rest ;)
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Bitterman on July 18, 2015, 01:58:40 AM
Sorry, not so easy.

Almost work for idle anim, but work incorrect for move. Some axis troubles.

Problem is marked correct but solution is somewhere nearby.

Need more complex changes (perhaps with reorient [x,y,z] into 'bounds').

Can you show this guys who wrote script (keless, der_ton or others)?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 18, 2015, 03:10:46 AM
Not sure how active either keless or der_ton are these days so it may be a case of looking at what other options there are.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Bitterman on July 19, 2015, 05:34:53 AM
Well it seems to work with simple anims.

Is there a special rules for origin bone (move, loc/rot/scale)? Perhaps I do it wrong.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on July 19, 2015, 07:55:27 AM
Just had a look at an old file and it seems this may be a long standing issue that's not been noticed before because preference was to using simple primitives for collision and AF rather than using bone shapes and boundings. Do you explicitly need to use bone bounding boxes to define something? I should add the the character I checked seemed to interact with the world without any noticeable issues even though the pink boxes were much larger than they should probably be.
Title: (md5) HELP! Blender md5 exporter messes up bones!
Post by: Ganataphy on September 04, 2015, 02:37:13 AM
Can anyone explain what is going on here?
I keep trying to export md5mesh and md5 anim models using Blender 2.75 with the latest version of the KatsBits md5 exporter, but everytime that happens I just keep getting the mess depicted below, where ALL THE BONES ARE REALIGNED, destroying the entire hierarchy and positioning I had originally specified.

Suggestions to insert a root bone at 0,0,0 (is this EVEN possible?) and to make it non-deformable by unchecking "Deform" have also failed to prevent the problem from recurring.

I am really pressed for time and there is very little information to go around on what exactly is causing this issue. I've tried five different tutorials, redid the armature, apply changes in dimension and so forth, but NOTHING WORKS. Is there something wrong or am I just another stupid noobe as usual?

Title: Re: (md5) HELP! Blender md5 exporter messes up bones!
Post by: kat on September 04, 2015, 02:55:23 AM
The script does work for 2.75a so it's not that causing the problem per se. Also when exporting are you exporting BOTH *.md5mesh and *.md5anim at the same time, or just choosing to export one or the other - EITHER *.md5mesh OR *.md5anim (you're exporting only the mesh or only the animation)? Post a screenshot of what your character or object should look like.

Indecently, yes whatever is being animated the rig needs to have a 'root' or 'master' bone to which everything is parented/chained, that bone acts as a positional anchor so if the rig doesn't have one that might explain why it collapses in on itself.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Ganataphy on September 04, 2015, 04:39:57 AM
I can't export md5anim, I need an md5mesh first. But attempting to export the following model below resulted in the following faults:
The only thing that worked was the md5anim, and even then the md5anim files were useless.

I have no idea what is going on. I rigged it with empty groups connected to bones, I parented the multiple meshes of the scene to the armature, I also set a SINGLE root bone, but to no avail. Are you trying to say that EVERY bone has to be parented to BOTH the root bone as well to whatever other bones they are linked? it does not make sense because some bones such as those controlling eyes were soon relinked by the MD5 exporter to the root bone (or whatever passed for it). Moreover AFAIK you can't have an object have multiple parents under Blender.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 04, 2015, 06:22:30 AM
The 'root' or 'master' bone is just that, the 'root' of the entire rig, it sits at the very top of the skeletons hierarchy (http://www.katsbits.com/tutorials/blender/gingerbread-3-rigging.php#armature) similar to like this;
Code: [Select]
root
> hips
> > legs
> > spine
> > > arms
> > > head

If you try to export a rig without one the result is similar to what you're seeing; output considers the first bone of each chain as a 'root', re-positioning the 'head' end of the bone to "0".

You should be able to export the mesh and rig without a animation but it might be worth creating a single framed Action so something is there export can reference - its possible that exporting without an animation could collapse the rig but that's unlikely as the 'bindpose' (the default position of each bone) is usually baked as reference.

You can export multiple mesh at the same time so long as they are correctly parented/linked to the Armature so that shouldn't be the issue.

If you have any Modifiers assigned to any of the bones try removing them and exporting the raw rig to see if the problem persists.
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Ganataphy on September 04, 2015, 07:55:06 AM
You will have to give me some time to experiment with it. My skills at Blender are fairly rudimentary, and extend only so far as rigging and texturing is concerned - modelling and unwrapping takes place under 3ds Max 5.1.

All I can say is that I do the following:

This is all I do, nothing more, nothing less. Is there something missing from my armature/rigging workflow that is causing the issue of bone heads re-aligning?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on September 04, 2015, 10:17:57 AM
That looks to be about right. Read through the MD5 export guide (http://www.katsbits.com/smforum/index.php?topic=178.0) though to make sure you're not missing something obvious (or not so obvious as the case may be as there's a lot of info to go through).
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: Dementei on December 20, 2015, 01:35:33 AM
Hello, so I went through the guide the best I could, hit some snags though and got an exporter error. I think I may need direct help as the player model and rig I am using are from a different game and I'd like to figure out how to get that working for Cube2/Tesseract. Would you mind getting in contact with me over Skype or Steam or something?
Title: Re: [MD5] EXPORT script for Blender 2.6x (OPEN)
Post by: kat on December 20, 2015, 01:46:31 AM
[Edit] in relation to using MD5 with Cube 2 have you read through their guide for using MD5 here - http://sauerbraten.org/docs/models.html#md5_format (http://sauerbraten.org/docs/models.html#md5_format)

[Edit II] for future reference Cube 2 uses a modified MD5 export script that only appears to be available for Blender 2.49, the generic script provided here onsite (http://www.katsbits.com/tools/#md5) (and the instructions that accompany it (http://www.katsbits.com/smforum/index.php?topic=178.0)) won't work as it/they are not fully compatible with Cube's particular export requirements.