Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!BPY
- """ Registration info for Blender menus:
- Name: 'K2/HON (.model/.clip)...'
- Blender: 249
- Group: 'Import'
- Tip: 'Import a Heroes of Newerth model file'
- """
- __author__ = "Anton Romanov"
- __version__ = "2010.03.24"
- __bpydoc__ = """\
- """
- # Copyright (c) 2010 Anton Romanov
- #
- # Permission is hereby granted, free of charge, to any person obtaining a
- # copy of this software and associated documentation files (the "Software"),
- # to deal in the Software without restriction, including without limitation
- # the rights to use, copy, modify, merge, publish, distribute, sublicense,
- # and/or sell copies of the Software, and to permit persons to whom the
- # Software is furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- # IN THE SOFTWARE.
- import Blender,bpy
- import os
- import struct, chunk
- from Blender.Mathutils import *
- # determines the verbosity of loggin.
- # 0 - no logging (fatal errors are still printed)
- # 1 - standard logging
- # 2 - verbose logging
- # 3 - debug level. really boring (stuff like vertex data and verbatim lines)
- IMPORT_LOG_LEVEL = 1
- def log(msg):
- if IMPORT_LOG_LEVEL >= 1: print msg
- def vlog(msg):
- if IMPORT_LOG_LEVEL >= 2: print msg
- def dlog(msg):
- if IMPORT_LOG_LEVEL >= 3: print msg
- def err(msg):
- Blender.Draw.PupMenu('Error|%s' % msg)
- def roundVector(vec,dec=17):
- fvec=[]
- for v in vec:
- fvec.append(round(v,dec))
- return Vector(fvec)
- def roundMatrix(mat,dec=17):
- fmat = []
- for row in mat:
- fmat.append(roundVector(row,dec))
- return Matrix(*fmat)
- def CreateBlenderMesh(filename):
- file = open(filename,'rb')
- if not file:
- log("can't open file")
- return
- sig = file.read(4)
- if sig != 'SMDL':
- err('unknown file signature')
- return
- try:
- honchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- log('error reading first chunk')
- return
- if honchunk.chunkname != 'head':
- log('file does not start with head chunk!')
- return
- version = read_int(honchunk)
- num_meshes = read_int(honchunk)
- num_sprites = read_int(honchunk)
- num_surfs = read_int(honchunk)
- num_bones = read_int(honchunk)
- vlog("Version %d" % version)
- vlog("%d mesh(es)" % num_meshes)
- vlog("%d sprites(es)" % num_sprites)
- vlog("%d surfs(es)" % num_surfs)
- vlog("%d bones(es)" % num_bones)
- vlog("bounding box: (%f,%f,%f) - (%f,%f,%f)" % \
- struct.unpack("<ffffff", honchunk.read(24)))
- honchunk.skip()
- scn= bpy.data.scenes.active
- try:
- honchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- log('error reading bone chunk')
- return
- #read bones
- #create armature object
- armature_object = Blender.Object.New('Armature')
- armature_object.drawMode = Blender.Object.DrawModes.XRAY
- scn.objects.link(armature_object)
- armature = armature_object.getData()
- if armature is None:
- base_name = Blender.sys.basename(file_object.name)
- armature_name = Blender.sys.splitext(base_name)[0]
- armature = Blender.Armature.New(armature_name)
- armature_object.link(armature)
- armature.drawType = Blender.Armature.STICK
- armature.envelopes = False
- armature.vertexGroups = True
- armature.makeEditable()
- bones = []
- bone_names = []
- parents = []
- for i in xrange(num_bones):
- name = ''
- parent_bone_index = read_int(honchunk)
- if version == 3:
- inv_matrix = Matrix(struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (1.0,))
- matrix = Matrix(struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (0.0,), \
- struct.unpack('<3f', honchunk.read(12)) + (1.0,))
- name_length = struct.unpack("B" , honchunk.read(1))[0]
- name = honchunk.read(name_length)
- honchunk.read(1) #zero
- elif version == 1:
- name = ''
- pos = honchunk.tell() - 4
- b = honchunk.read(1)
- while b != '\0':
- name += b
- b = honchunk.read(1)
- honchunk.seek(pos + 0x24)
- inv_matrix = Matrix( struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)))
- matrix = Matrix(struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)), \
- struct.unpack('<4f', honchunk.read(16)))
- dlog("bone name: %s,parent %d" % (name,parent_bone_index))
- bone_names.append(name)
- edit_bone = Blender.Armature.Editbone()
- edit_bone.name = name
- edit_bone.matrix = roundMatrix(matrix,4)
- parents.append(parent_bone_index)
- bones.append(edit_bone)
- armature.bones[name] = edit_bone
- for i in xrange(num_bones):
- if parents[i] != -1:
- bones[i].parent = bones[parents[i]]
- armature.update()
- honchunk.skip()
- try:
- honchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- log('error reading mesh chunk')
- return
- while honchunk.chunkname == 'mesh':
- verts = []
- faces = []
- signs = []
- nrml = []
- texc = []
- colors = []
- #read mesh chunk
- vlog("mesh index: %d" % read_int(honchunk))
- mode = 1
- if version == 3:
- mode = read_int(honchunk)
- vlog("mode: %d" % mode)
- vlog("vertices count: %d" % read_int(honchunk))
- vlog("bounding box: (%f,%f,%f) - (%f,%f,%f)" % \
- struct.unpack("<ffffff", honchunk.read(24)))
- bone_link = read_int(honchunk)
- vlog("bone link: %d" % bone_link)
- sizename = struct.unpack('B',honchunk.read(1))[0]
- sizemat = struct.unpack('B',honchunk.read(1))[0]
- meshname = honchunk.read(sizename)
- honchunk.read(1) # zero
- materialname = honchunk.read(sizemat)
- elif version == 1:
- bone_link = -1
- pos = honchunk.tell() - 4
- b = honchunk.read(1)
- meshname = ''
- while b != '\0':
- meshname += b
- b = honchunk.read(1)
- honchunk.seek(pos + 0x24)
- b = honchunk.read(1)
- materialname = ''
- while b != '\0':
- materialname += b
- b = honchunk.read(1)
- honchunk.skip()
- if mode == 1 or not SKIP_NON_PHYSIQUE_MESHES:
- msh = bpy.data.meshes.new(meshname)
- #msh.mode |= Blender.Mesh.Modes.AUTOSMOOTH
- obj = scn.objects.new(msh)
- while 1:
- try:
- honchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- vlog('error reading chunk')
- break
- if honchunk.chunkname == 'mesh':
- break
- elif mode != 1 and SKIP_NON_PHYSIQUE_MESHES:
- honchunk.skip()
- else:
- if honchunk.chunkname == 'vrts':
- verts = parse_vertices(honchunk)
- msh.verts.extend(verts)
- elif honchunk.chunkname == 'face':
- faces = parse_faces(honchunk,version)
- elif honchunk.chunkname == 'nrml':
- nrml = parse_normals(honchunk)
- elif honchunk.chunkname == 'texc':
- texc = parse_texc(honchunk,version)
- elif honchunk.chunkname == 'colr':
- colors = parse_colr(honchunk)
- elif honchunk.chunkname == 'lnk1' or honchunk.chunkname == 'lnk3':
- armature_object.makeParentDeform([obj])
- parse_links(honchunk,msh,bone_names)
- elif honchunk.chunkname == 'sign':
- signs = parse_sign(honchunk)
- else:
- vlog('unknown chunk: %s' % honchunk.chunkname)
- honchunk.skip()
- if mode != 1 and SKIP_NON_PHYSIQUE_MESHES:
- continue
- try:
- msh.materials += [bpy.data.materials[materialname]]
- except:
- msh.materials += [bpy.data.materials.new(materialname)]
- if bone_link >=0 :
- armature_object.makeParentDeform([obj])
- msh.addVertGroup(bone_names[bone_link])
- msh.assignVertsToGroup(bone_names[bone_link],list(xrange(len(msh.verts))),1.0,Blender.Mesh.AssignModes.ADD)
- #vertices
- for i in xrange(len(nrml)):
- msh.verts[i].no = Vector(nrml[i])
- #remove doubles if needed
- if remove_doubles:
- doubles = []
- for vi,v in enumerate(verts):
- if vi in doubles:
- continue
- new_doubles = []
- for di,d in enumerate(verts[vi + 1:]):
- di += vi+1
- new_doubles = []
- if v == d and nrml[vi] == nrml[di]:
- new_doubles.append(di)
- if len(new_doubles) > 0:
- doubles.append(vi)
- doubles.extend(new_doubles)
- vlog('found %d duplicate vertices' % len(doubles))
- #faces
- if len(faces) > 0:
- for i in xrange(len(faces)):
- f = Blender.NMesh.Face()
- f.v.extend([vi for vi in faces[i]])
- f.materialIndex = 0
- msh.faces.extend(f)
- #UV texture coordinates
- if len(texc) > 0:
- msh.faceUV = True
- for fc in msh.faces:
- fc.mode |= Blender.NMesh.FaceModes['TEX']
- fc.mode |= Blender.NMesh.FaceModes['LIGHT']
- for ii, v in enumerate(fc):
- fc.uv[ii][0] = texc[v.index][0]
- if flip_uv:
- fc.uv[ii][1] = 1.0-texc[v.index][1]
- else:
- fc.uv[ii][1] = texc[v.index][1]
- #vertex colours
- if len(colors) > 0:
- msh.vertexColors = True
- for fc in msh.faces:
- for ii, v in enumerate(fc):
- for x in xrange(4):
- fc.col[ii][x] = colors[v.index][x]
- if remove_doubles:
- for v in msh.verts:
- if v.index in doubles:
- v.sel = 1
- else:
- v.sel = 0
- removed = msh.remDoubles(0)
- vlog('removed %d duplicate vertices' % removed)
- vlog('removing duplicate faces (making two-sided)')
- fdoubles = []
- for f in msh.faces:
- if f.index in fdoubles:
- continue
- newdoubles = []
- for f2 in [f2 for f2 in msh.faces if f2.index > f.index and f2.index not in fdoubles]:
- v1 = [v.co for v in f.verts]
- v2 = [v.co for v in f2.verts]
- v1.sort()
- v2.sort()
- n1 = [v.no for v in f.verts]
- n2 = [-v.no for v in f2.verts]
- n1.sort()
- n2.sort()
- double = True
- for i in xrange(len(v1)):
- if v1[i] != v2[i] or n1[i] != n2[i]:
- double = False
- if double:
- newdoubles.append(f2.index)
- if len(newdoubles) > 0:
- f.mode |= Blender.NMesh.FaceModes['TWOSIDE']
- fdoubles.extend(newdoubles)
- msh.faces.delete(1,fdoubles)
- vlog('removed %d duplicate faces' % len(fdoubles))
- vlog('removing orphaned vertices')
- for v in msh.verts:
- v.sel = 1
- for f in msh.faces:
- for v in f.verts:
- v.sel = 0
- selected = msh.verts.selected()
- vlog('removing %d orphaned vertices' % (len(selected)) )
- msh.verts.delete(selected)
- obj.select(False)
- #end reading submesh
- armature_object.select(True)
- def read_int(honchunk):
- return struct.unpack("<i",honchunk.read(4))[0]
- def read_float(honchunk):
- return struct.unpack("<f",honchunk.read(4))[0]
- def parse_links(honchunk,mesh,bone_names):
- mesh_index = read_int(honchunk)
- numverts = read_int(honchunk)
- dlog("links")
- dlog("mesh index: %d" % mesh_index)
- dlog("vertices number: %d" % numverts)
- for i in xrange(numverts):
- num_weights = read_int(honchunk)
- weights = struct.unpack("<%df" % num_weights,honchunk.read(num_weights * 4))
- indexes = struct.unpack("<%dI" % num_weights,honchunk.read(num_weights * 4))
- for ii, index in enumerate(indexes):
- name = bone_names[index]
- if name not in mesh.getVertGroupNames():
- mesh.addVertGroup(name)
- mesh.assignVertsToGroup(name,[i],weights[ii],Blender.Mesh.AssignModes.ADD)
- honchunk.skip()
- def parse_vertices(honchunk):
- vlog('parsing vertices chunk')
- numverts = (honchunk.chunksize - 4)/12
- vlog('%d vertices' % numverts)
- meshindex = read_int(honchunk)
- return [struct.unpack("<3f", honchunk.read(12)) for i in xrange(numverts)]
- def parse_sign(honchunk):
- vlog('parsing sign chunk')
- numverts = (honchunk.chunksize - 8)
- meshindex = read_int(honchunk)
- vlog(read_int(honchunk)) # huh?
- return [struct.unpack("<b", honchunk.read(1)) for i in xrange(numverts)]
- def parse_faces(honchunk,version):
- vlog('parsing faces chunk')
- meshindex = read_int(honchunk)
- numfaces = read_int(honchunk)
- vlog('%d faces' % numfaces)
- if version == 3:
- size = struct.unpack('B',honchunk.read(1))[0]
- elif version == 1:
- size = 4
- if size == 2:
- return [struct.unpack("<3H", honchunk.read(6)) for i in xrange(numfaces)]
- elif size ==1:
- return [struct.unpack("<3B", honchunk.read(3)) for i in xrange(numfaces)]
- elif size == 4:
- return [struct.unpack("<3I", honchunk.read(12)) for i in xrange(numfaces)]
- else:
- log("unknown size for faces:%d" % size)
- return []
- def parse_normals(honchunk):
- vlog('parsing normals chunk')
- numverts = (honchunk.chunksize - 4)/12
- vlog('%d normals' % numverts)
- meshindex = read_int(honchunk)
- return [struct.unpack("<3f", honchunk.read(12)) for i in xrange(numverts)]
- def parse_texc(honchunk,version):
- vlog('parsing uv texc chunk')
- numverts = (honchunk.chunksize - 4)/8
- vlog('%d texc' % numverts)
- meshindex = read_int(honchunk)
- if version == 3:
- vlog(read_int(honchunk)) # huh?
- return [struct.unpack("<2f", honchunk.read(8)) for i in xrange(numverts)]
- def parse_colr(honchunk):
- vlog('parsing vertex colours chunk')
- numverts = (honchunk.chunksize - 4)/4
- meshindex = read_int(honchunk)
- return [struct.unpack("<4B", honchunk.read(4)) for i in xrange(numverts)]
- ##############################
- #CLIPS
- ##############################
- MKEY_X,MKEY_Y,MKEY_Z,\
- MKEY_PITCH,MKEY_ROLL,MKEY_YAW,\
- MKEY_VISIBILITY,\
- MKEY_SCALE_X,MKEY_SCALE_Y,MKEY_SCALE_Z \
- = range(10)
- def bone_depth(bone):
- if not bone.parent:
- return 0
- else:
- return 1+bone_depth(bone.parent)
- def getTransformMatrix(motions,bone,i,version):
- motion = motions[bone.name]
- #translation
- if i >= len(motion[MKEY_X]):
- x = motion[MKEY_X][-1]
- else:
- x = motion[MKEY_X][i]
- if i >= len(motion[MKEY_Y]):
- y = motion[MKEY_Y][-1]
- else:
- y = motion[MKEY_Y][i]
- if i >= len(motion[MKEY_Z]):
- z = motion[MKEY_Z][-1]
- else:
- z = motion[MKEY_Z][i]
- #rotation
- if i >= len(motion[MKEY_PITCH]):
- rx = motion[MKEY_PITCH][-1]
- else:
- rx = motion[MKEY_PITCH][i]
- if i >= len(motion[MKEY_ROLL]):
- ry = motion[MKEY_ROLL][-1]
- else:
- ry = motion[MKEY_ROLL][i]
- if i >= len(motion[MKEY_YAW]):
- rz = motion[MKEY_YAW][-1]
- else:
- rz = motion[MKEY_YAW][i]
- #scaling
- if version == 1:
- if i >= len(motion[MKEY_SCALE_X]):
- sx = motion[MKEY_SCALE_X][-1]
- else:
- sx = motion[MKEY_SCALE_X][i]
- sy = sz = sx
- else:
- if i >= len(motion[MKEY_SCALE_X]):
- sx = motion[MKEY_SCALE_X][-1]
- else:
- sx = motion[MKEY_SCALE_X][i]
- if i >= len(motion[MKEY_SCALE_Y]):
- sy = motion[MKEY_SCALE_Y][-1]
- else:
- sy = motion[MKEY_SCALE_Y][i]
- if i >= len(motion[MKEY_SCALE_Z]):
- sz = motion[MKEY_SCALE_Z][-1]
- else:
- sz = motion[MKEY_SCALE_Z][i]
- size = Blender.Mathutils.Vector([sx,sy,sz])
- #commented till i can specify rotation order
- #euler = Blender.Mathutils.Euler(rx,ry,rz)
- euler = Blender.Mathutils.Euler()
- RotateEuler(euler,rz,'z')
- RotateEuler(euler,rx,'x')
- RotateEuler(euler,ry,'y')
- bone_rotation_matrix = euler.toMatrix()
- bone_rotation_matrix.resize4x4()
- bone_rotation_matrix *= Blender.Mathutils.TranslationMatrix(\
- Blender.Mathutils.Vector(x,y,z))
- return bone_rotation_matrix,size
- def AnimateBone(name,pose,motions,num_frames,armature,armOb,version):
- if name not in armature.bones.keys():
- log ('%s not found in armature' % name)
- return
- motion = motions[name]
- bone = armature.bones[name]
- bone_rest_matrix = bone.matrix['ARMATURESPACE'].copy()
- if bone.parent is not None:
- parent_bone = bone.parent
- parent_rest_bone_matrix = parent_bone.matrix['ARMATURESPACE'].copy()
- parent_rest_bone_matrix.invert()
- bone_rest_matrix *= parent_rest_bone_matrix
- bone_rest_matrix_inv = Blender.Mathutils.Matrix(bone_rest_matrix)
- bone_rest_matrix_inv.invert()
- pbone = pose.bones[name]
- for i in range(0, num_frames):
- transform,size = getTransformMatrix(motions,bone,i,version)
- pbone.localMatrix = transform * bone_rest_matrix_inv
- pbone.size = size
- pbone.insertKey(armOb, i + 1,[Blender.Object.Pose.ROT,Blender.Object.Pose.LOC,Blender.Object.Pose.SIZE],True)
- def CreateBlenderClip(filename):
- basename = Blender.sys.basename(filename)
- clipname = basename[0:basename.lower().find('.clip')]
- file = open(filename,'rb')
- if not file:
- log("can't open file")
- return
- sig = file.read(4)
- if sig != 'CLIP':
- err('unknown file signature')
- return
- try:
- clipchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- log('error reading first chunk')
- return
- version = read_int(clipchunk)
- num_bones = read_int(clipchunk)
- num_frames = read_int(clipchunk)
- vlog ("version: %d" % version)
- vlog ("num bones: %d" % num_bones)
- vlog ("num frames: %d" % num_frames)
- objList = Blender.Object.GetSelected()
- if len(objList) != 1:
- err('select needed armature only')
- armOb = objList[0]
- action = Blender.Armature.NLA.NewAction(clipname)
- action.setActive(armOb)
- pose = armOb.getPose()
- armature = armOb.getData()
- bone_index = -1
- motions = {}
- while 1:
- try:
- clipchunk = chunk.Chunk(file,bigendian=0,align=0)
- except EOFError:
- vlog('error reading chunk')
- break
- if version == 1:
- name = clipchunk.read(32)
- if '\0' in name:
- name = name[:name.index('\0')]
- boneindex = read_int(clipchunk)
- keytype = read_int(clipchunk)
- numkeys = read_int(clipchunk)
- if version > 1:
- namelength = struct.unpack("B",clipchunk.read(1))[0]
- name = clipchunk.read(namelength)
- clipchunk.read(1)
- if name not in motions:
- motions[name] = {}
- dlog ("%s,boneindex: %d,keytype: %d,numkeys: %d" % \
- (name,boneindex,keytype,numkeys))
- if keytype == MKEY_VISIBILITY:
- data = struct.unpack("%dB" % numkeys,clipchunk.read(numkeys))
- else:
- data = struct.unpack("<%df" % numkeys,clipchunk.read(numkeys * 4))
- motions[name][keytype] = list(data)
- clipchunk.skip()
- #file read, now animate that bastard!
- for bone_name in motions:
- AnimateBone(bone_name,pose,motions,num_frames,armature,armOb,version)
- pose.update()
- ############
- #common
- ###############################
- #-------------------------------\
- # common |
- #-------------------------------/
- ######################################################
- # GUI STUFF
- ######################################################
- draw_busy_screen = 0
- EVENT_NOEVENT = 1
- EVENT_IMPORT = 2
- EVENT_QUIT = 3
- EVENT_MESHFILENAME = 4
- EVENT_ANIMFILENAME = 5
- EVENT_MESHFILENAME_STRINGBUTTON = 6
- EVENT_ANIMFILENAME_STRINGBUTTON = 7
- SKIP_NON_PHYSIQUE_MESHES = False
- mesh_filename = Blender.Draw.Create("")
- anim_filename = Blender.Draw.Create("")
- import_all_clips = True
- IMPORT_ALL_CLIPS = Blender.Draw.Create(0)
- SKIP_NON_PHYSIQUE_MESHES_BUTTON = Blender.Draw.Create(0)
- REMOVE_DOUBLES = Blender.Draw.Create(1)
- FLIP_UV = Blender.Draw.Create(1)
- flip_uv = True
- remove_doubles = True
- ######################################################
- # Callbacks for Window functions
- ######################################################
- def meshname_callback(filename):
- global mesh_filename
- mesh_filename.val=filename
- def animname_callback(filename):
- global anim_filename
- anim_filename.val=filename
- ######################################################
- # GUI Functions
- ######################################################
- def handle_event(evt, val):
- if evt == Blender.Draw.ESCKEY:
- Blender.Draw.Exit()
- return
- def handle_button_event(evt):
- global EVENT_NOEVENT, EVENT_IMPORT, EVENT_QUIT, EVENT_MESHFILENAME, EVENT_ANIMFILENAME, EVENT_MESHFILENAME_STRINGBUTTON, EVENT_ANIMFILENAME_STRINGBUTTON,SKIP_NON_PHYSIQUE_MESHES_BUTTON
- global draw_busy_screen, mesh_filename, anim_filename, import_all_clips,IMPORT_ALL_CLIPS,REMOVE_DOUBLES,FLIP_UV,flip_uv,remove_doubles,SKIP_NON_PHYSIQUE_MESHES
- if evt == EVENT_IMPORT:
- import_all_clips = IMPORT_ALL_CLIPS.val
- remove_doubles = REMOVE_DOUBLES.val
- SKIP_NON_PHYSIQUE_MESHES = SKIP_NON_PHYSIQUE_MESHES_BUTTON.val
- flip_uv = FLIP_UV.val
- Blender.Window.WaitCursor(1)
- draw_busy_screen = 1
- Blender.Draw.Draw()
- if len(mesh_filename.val)>0:
- CreateBlenderMesh(mesh_filename.val)
- if len(anim_filename.val)>0:
- if not import_all_clips:
- CreateBlenderClip(anim_filename.val)
- else:
- dirname = Blender.sys.dirname(anim_filename.val)
- for fname in os.listdir(dirname):
- if fname.endswith('.clip'):
- CreateBlenderClip(Blender.sys.join(dirname,fname))
- draw_busy_screen = 0
- Blender.Draw.Redraw(1)
- Blender.Window.WaitCursor(0)
- return
- if evt == EVENT_QUIT:
- Blender.Draw.Exit()
- if evt == EVENT_MESHFILENAME:
- Blender.Window.FileSelector(meshname_callback, "Select mesh file...")
- Blender.Draw.Redraw(1)
- if evt == EVENT_ANIMFILENAME:
- Blender.Window.FileSelector(animname_callback, "Select anim file...")
- Blender.Draw.Redraw(1)
- def show_gui():
- global EVENT_NOEVENT, EVENT_IMPORT, EVENT_QUIT, EVENT_MESHFILENAME, EVENT_ANIMFILENAME, EVENT_MESHFILENAME_STRINGBUTTON, EVENT_ANIMFILENAME_STRINGBUTTON,SKIP_NON_PHYSIQUE_MESHES_BUTTON
- global draw_busy_screen, mesh_filename, anim_filename, IMPORT_ALL_CLIPS,REMOVE_DOUBLES,FLIP_UV
- global startframe_slider, endframe_slider
- button_width = 240
- browsebutton_width = 60
- button_height = 25
- if draw_busy_screen == 1:
- Blender.BGL.glClearColor(0.3,0.3,0.3,1.0)
- Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)
- Blender.BGL.glColor3f(1,1,1)
- Blender.BGL.glRasterPos2i(20,25)
- Blender.Draw.Text("Please wait...")
- return
- Blender.BGL.glClearColor(0.6,0.6,0.6,1.0)
- Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)
- Blender.Draw.Button("Import!", EVENT_IMPORT, 20, 2*button_height, button_width, button_height, "Start the import")
- Blender.Draw.Button("Quit", EVENT_QUIT, 20, button_height, button_width, button_height, "Quit this script")
- Blender.Draw.Button("Browse...", EVENT_MESHFILENAME, 21+button_width-browsebutton_width, 4*button_height, browsebutton_width, button_height, "Specify mesh-file")
- Blender.Draw.Button("Browse...", EVENT_ANIMFILENAME, 21+button_width-browsebutton_width, 3*button_height, browsebutton_width, button_height, "Specify anim-file")
- mesh_filename = Blender.Draw.String("Mesh file:", EVENT_MESHFILENAME_STRINGBUTTON, 20, 4*button_height, button_width-browsebutton_width, button_height, mesh_filename.val, 255, "Mesh-File to import")
- anim_filename = Blender.Draw.String("Anim dir/file:", EVENT_ANIMFILENAME_STRINGBUTTON, 20, 3*button_height, button_width-browsebutton_width, button_height, anim_filename.val, 255, "Anim-File to import")
- SKIP_NON_PHYSIQUE_MESHES_BUTTON = Blender.Draw.Toggle('Skip non physique meshes', EVENT_NOEVENT, 20, 6*button_height, button_width, button_height, SKIP_NON_PHYSIQUE_MESHES_BUTTON.val, 'Skip non-deforming objects')
- IMPORT_ALL_CLIPS = Blender.Draw.Toggle('All clips', EVENT_NOEVENT, 20, 7*button_height, button_width, button_height, IMPORT_ALL_CLIPS.val, 'Import all clips available in the same directory.')
- REMOVE_DOUBLES = Blender.Draw.Toggle('Remove doubles', EVENT_NOEVENT, 20, 8*button_height, button_width, button_height, REMOVE_DOUBLES.val, 'Merge duplicated vertices')
- FLIP_UV = Blender.Draw.Toggle('V-Flip UV', EVENT_NOEVENT, 20, 9*button_height, button_width, button_height, FLIP_UV.val, 'Flip UV mapping vertically')
- Blender.Draw.Register (show_gui, handle_event, handle_button_event)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement