TMB import script

I’ve been trying to create an import script for a binary format used by a game. I found a somewhat similar script and have been modifying it, but I’m not very good with python or the blender API.

Would someone be willing to take a look at what I have so far, and check for (primarily at this point) python/blenderAPI correctness?

Shouldn’t you try and use Blender 2.5 (it is now near beta) …?

If I had any idea whatsoever how to do so, then maybe.

Open Blender, create a TEXT area, copy your code in there and hit ALT+P to run the script. If it run w/o errors and does what you would like to = your script is finally ready!


Good morning. I also have the same problem and the code to export is the following one. I clarify I need script to export of blender to .tmb does not matter of the version of belnder that hagn script, thanks community.

“”" Name: ‘Tantra Online (*.tmb)…’
Blender: 246
Group: ‘Import’
Tooltip: ‘Import Tantra Online *.tmb game files’

author = ‘Peter S. Stevens’
email = ‘pstevens:cryptomail*org’
url = (‘blender’, ‘elysiun’, ‘Project homepage,’)
version = ‘09.05.0a’
bpydoc = “”"
This script imports Tantra Online *.tmb game files
import Blender
import struct

def tmb_read_mesh(file_object, revision):
data_chunk = # Read mesh name

  name = data_chunk[0:data_chunk.find('\0', 0)]
  print "mesh %s start 0x%x" % (name, file_object.tell() - 256)
  data_chunk = # Read vertex count
  vertex_count = struct.unpack('<I', data_chunk)[0]
  print "	vertex count %d" % vertex_count
  mesh_object = Blender.Object.New('Mesh', name)
  mesh = mesh_object.getData(mesh = True)
  if mesh is None:
      mesh = Blender.Mesh.New(name)
  mesh.vertexUV = True
  for x in xrange(vertex_count): # Read vertex positions
      data_chunk =
      position = Blender.Mathutils.Vector(struct.unpack('<3f', data_chunk))
  for x in xrange(vertex_count): # Read vertex normals
      data_chunk =
      normal = Blender.Mathutils.Vector(struct.unpack('<3f', data_chunk))
      vertex = mesh.verts[x]
    = normal
  for x in xrange(vertex_count): # Read texture coordinates
      data_chunk =
      uv_coordinates = Blender.Mathutils.Vector(struct.unpack('<2f', data_chunk))
      vertex.uvco = uv_coordinates
  data_chunk =
  matrix_count = struct.unpack('<I', data_chunk)[0]
  print "	matrix count %d" % matrix_count
  if matrix_count > 1:
      data_chunk = * (matrix_count - 1))
  for x in xrange(matrix_count):
      data_chunk = # Read matrix
  data_chunk =
  x_count, face_count = struct.unpack_from('<2I', data_chunk, 4)
  if matrix_count > 1:
      data_chunk = * (matrix_count - 1))
  print "	face count %d, %d" % (x_count, face_count)
  for x in xrange(face_count):
      data_chunk =
      face_vertices = [mesh.verts[y] for y in struct.unpack('<3I', data_chunk)]
      face = mesh.faces[-1]
      face.uv = [vertex.uvco for vertex in face_vertices]
  for x in xrange(matrix_count):
      data_chunk = # Read texture file name
      texture_file_name = data_chunk[0:data_chunk.find('\0', 0)]
      print "	texture %d: %s" % (x, texture_file_name)
  data_chunk =
  if revision == 2:
      data_chunk =
      joint_count, unknown_0 = struct.unpack('<2I', data_chunk) # Read joint count
      for x in xrange(joint_count):
          data_chunk =
          joint_name = data_chunk[0:data_chunk.find('\0', 0)]
          print "	joint %s" % joint_name
      unknown_1 = []
      for x in xrange(unknown_0):
          data_chunk =
          unknown_1.append(struct.unpack('<I', data_chunk)[0])
      for unknown in unknown_1:
          for x in xrange(unknown):
              data_chunk =
      data_chunk = # unknown_0
      unknown_2 =  struct.unpack('<I', data_chunk)[0]
      unknown_3 = []
      for x in xrange(unknown_2):
          data_chunk =
          unknown_3.append(struct.unpack('<I', data_chunk)[0])
      for unknown in unknown_3:
          for x in xrange(unknown):
              data_chunk =
      for x in xrange(vertex_count):
          data_chunk =
  print "mesh %s end 0x%x" % (name, file_object.tell())
  return mesh_object

def tmb_read(file_path):
file_object = None

      file_object = open(file_path, 'rb')
      data_chunk = # Read header chunk
      unknown_0, revision, mesh_count = struct.unpack('<3I', data_chunk)
      print "mesh count %d" % mesh_count
      mesh_objects = []
      for x in xrange(mesh_count):
          mesh_objects.append(tmb_read_mesh(file_object, revision))
      scene = Blender.Scene.GetCurrent()
      for mesh_object in mesh_objects:

  except IOError, (errno, strerror):
      Blender.Draw.PupMenu("Error%%t|I/O error(%d): %s." % (errno, strerror))
  except Exception, err:
      Blender.Draw.PupMenu("Error%%t|.%s" % err)
      if file_object is not None:

def main():
def tmb_file_selector(file_path):
if file_path and not Blender.sys.exists(file_path):
Blender.Draw.PupMenu(“Error%%t|The file %s does not exist.” % file_path)

  Blender.Window.FileSelector(tmb_file_selector, 'Ok', Blender.sys.makename(ext='.tmb'))

if name == “main”: