Page 1 of 1

b3d s3d importer for blender

Posted: Sat Apr 23, 2011 9:00 pm
by demolos

I asked a guy to build an b3d s3d importer for Blender 2.49. :D
Now we need an b3d s3d exporter. :wink:

Re: b3d s3d importer for blender

Posted: Sat Apr 23, 2011 9:23 pm
by Urfoex
demolos wrote:Hi,

I asked a guy to build an b3d s3d importer for Blender 2.49. :D
Now we need an b3d s3d exporter. :wink:


As Blender 2.57a (stable) is out and Blender 2.5 is very different from 2.49 and much more usable especially for beginners it *maybe* would be better to have a importer and exporter for Blender 2.5x instead of the 2.49 one. But having one for 2.49 in such a quick time is nice.

Here is the python-code from the blend-file:

Code: Select all

#2011-04-19 Glogow Poland Mariusz Szkaradek
import bpy,struct,os
import Blender
from Blender import *
from struct import *
from math import *
from Blender.Mathutils import *

def vertexuv():
   mesh.vertexUV = 1
   for m in range(len(mesh.verts)):
      mesh.verts[m].uvco = Vector(uvcoord[m])
   mesh.faceUV = 1
   for fc in mesh.faces: fc.uv = [v.uvco for v in fc.verts];fc.smooth = 1

def drawmesh(name):
   global obj,mesh
   mesh =
   if len(uvcoord)!=0:
   scene =
   obj =,name)

def make_vertex_group():
   for id_0 in range(len(weighting)):
      data = weighting[id_0]
      #print data
      for id_1 in range(2):
         grint = data[0][id_1]
         #gr = fix_groups[gr]
         gr = str(grint)
         #gr = bonenames[armature_name][gr]
         w  = data[1][id_1]/100.0
         if grint!=-1:
            if gr not in mesh.getVertGroupNames():
         #   pass

def b(n):
   return struct.unpack(n*'b',
def B(n):
   return struct.unpack(n*'B',
def h(n):
   return struct.unpack(n*'h',*2))
def H(n):
   return struct.unpack(n*'H',*2))
def i(n):
   return struct.unpack(n*'i',*4))
def f(n):
   return struct.unpack(n*'f',*4))

def word(long):
   for j in range(0,long):
      lit =  struct.unpack('c',[0]
      if ord(lit)!=0:
         if len(s)>300:
   return s

def check_armature():
   global armobj,newarm
   scn = Scene.GetCurrent()
   scene =
   for object in scene.objects:
      if object.getType()=='Armature':
         if == 'armature':
   for object in
      if == 'armature':
         armobj = Blender.Object.Get('armature')
         newarm = armobj.getData()
         for bone in newarm.bones.values():
            del newarm.bones[]
   if armobj==None:
      armobj = Blender.Object.New('Armature','armature')
   if newarm==None:
      newarm = Armature.New('armature')
   newarm.drawType = Armature.STICK
   armobj.drawMode = Blender.Object.DrawModes.XRAY
   for object in scene.objects:
      if 'model' in and object.getType()=='Mesh':

def make_bone():
   for bone_id in range(len(bonesdata)):
      bonedata = bonesdata[bone_id]
      bonename = bonedata[0]
      eb = Armature.Editbone()
      newarm.bones[bonename] = eb

def make_bone_parent():
   for bone_id in range(len(bonesdata)):
      bonedata = bonesdata[bone_id]
      parent_id = bonedata[3]
      bonename = bonedata[0]   
      if parent_id !=-1:
         bone = newarm.bones[bonename] 
         boneparent = newarm.bones[bonesdata[parent_id][0]]
         bone.parent = boneparent

def make_bone_position():
   for bone_id in range(len(bonesdata)):
      bonedata = bonesdata[bone_id]
      namebone = bonedata[0]
      pos = bonedata[1]
      rot = bonedata[2]
      qx,qy,qz,qw = rot[0],rot[1],rot[2],rot[3]
      rot = Quaternion(qw,qx,qy,qz)
      rot = rot.toMatrix().invert()
      bone = newarm.bones[namebone]
      #if bone.parent:
      #   bone.head =   bone.parent.head+Vector(pos) * bone.parent.matrix
         #tempM = rot * bone.parent.matrix
         #bone.matrix = tempM
      bone.head = Vector(pos)
      bone.matrix = rot
      bvec = bone.tail- bone.head
      bone.tail = bone.head + 0.01 * bvec

def skeleton():

def find_0():
      litera =  struct.unpack('c',[0]
      if  litera=='\x00':
   return s

def s3d():
   global vertexes,faceslist,weighting,uvcoord
   print word(4)
   data = H(9)
   print data
   images = []
   materials = []
   for m in range(data[2]):
      image_name = find_0().split('.')[0]
      for file_name in g:
         if image_name in file_name and '.dds' in file_name:
            print file_name
            if file_name not in Blender.Image.Get():
   for m in range(data[3]):
      material_name = find_0()
      mat = Material.New(material_name)
      image_id = H(1)[0]
         tex = Texture.New('diff')
         #tex.image = Blender.Image.Get(images[image_id])
         tex.image =  Blender.Image.Load(dir+os.sep+images[image_id])

      data1 = H(4)
      print data1
      if data1[2] == 1:
         print B(63)
      elif data1[2] == 3:
         print B(64)
         print B(55)
   for m in range(data[4]):
      print find_0()
      print find_0()
      mat_id = H(1)[0]
      print B(24),f(4)
      data2 = H(4)
      print data2
      vertexes = []
      faceslist = []
      weighting = []
      uvcoord = []
      for n in range(data2[1]):
         back = plik.tell()
         #print m,f(3)
      for n in range(data2[2]):
      for n in range(data2[1]):
   print plik.tell()

def b3d():
   global bonesdata
   bonesdata = []
   print word(4)
   nBones = i(1)[0]
   for m in range(nBones):
      bone_name = find_0()
      pos = f(3)
      rot = f(4)
      parent_id = i(1)[0]
   scene =
   for object in scene.objects:
      if 'model' in and object.getType()=='Mesh':
         mesh = object.getData(mesh=1)
         for m in range(len(bonesdata)):
            if str(m) in mesh.getVertGroupNames():
   print plik.tell()

def import_model(filename):
   global plik,g,dir
   plik = open(filename,'rb')
   print '============================'
   print filename
   print '============================'
   file = sys.basename(filename)
   dir = sys.dirname(filename)
   g = os.listdir(dir)
   if file.split('.')[-1].lower() == 's3d':
   if file.split('.')[-1].lower() == 'b3d':
Window.FileSelector (import_model)   

Re: b3d s3d importer for blender

Posted: Mon Oct 10, 2011 4:53 pm
by Twigger
Hi, I'm am trying to import a 3DS object with Blender. I've tried a model and even a simple box - each time I get the error "Python Script Error - Check Console". !! I'm stuck at this point, I thought it was because the files were on my desktop - and the path lenght was too long, so moved the file to a folder on the local HDD and still same problem.