From 84c40946e4197841c6345af32bab15524742fb6b Mon Sep 17 00:00:00 2001 From: Campbell Barton <ideasman42@gmail.com> Date: Tue, 18 Jan 2011 01:58:49 +0000 Subject: [PATCH] correct bad spelling; 'indicies' --> 'indices' --- curve_simplify.py | 12 +- io_anim_bvh/import_bvh.py | 2 +- io_scene_3ds/export_3ds.py | 2 +- io_scene_fbx/__init__.py | 12 - io_scene_fbx/export_fbx.py | 1027 ++++++++++++++++++------------------ io_scene_obj/export_obj.py | 4 +- io_scene_obj/import_obj.py | 112 ++-- io_scene_x3d/import_x3d.py | 4 +- render_povray/render.py | 24 +- 9 files changed, 605 insertions(+), 594 deletions(-) diff --git a/curve_simplify.py b/curve_simplify.py index 69ace7531..43a9c4b7a 100644 --- a/curve_simplify.py +++ b/curve_simplify.py @@ -44,7 +44,7 @@ import math ############################## #### simplipoly algorithm #### ############################## -# get SplineVertIndicies to keep +# get SplineVertIndices to keep def simplypoly(splineVerts, options): # main vars newVerts = [] # list of vertindices to keep @@ -79,7 +79,7 @@ def simplypoly(splineVerts, options): distances.append(dist) distances.append(0.0) # last vert is always kept - # generate list of vertindicies to keep + # generate list of vertindices to keep # tested against averaged curvatures and distances of neighbour verts newVerts.append(0) # first vert is always kept for i, curv in enumerate(curvatures): @@ -172,7 +172,7 @@ def iterate(points, newVerts, error): return False return new -#### get SplineVertIndicies to keep +#### get SplineVertIndices to keep def simplify_RDP(splineVerts, options): #main vars error = options[4] @@ -264,7 +264,7 @@ def main(context, obj, options): if mode == 'curvature': newVerts = simplypoly(splineVerts, options) - # convert indicies into vectors3D + # convert indices into vectors3D newPoints = vertsToPoints(newVerts, splineVerts, splineType) # create new spline @@ -324,7 +324,7 @@ def fcurves_simplify(context, obj, options, fcurves): scene = context.scene fcurves_obj = obj.animation_data.action.fcurves - #get indicies of selected fcurves + #get indices of selected fcurves fcurve_sel = selectedfcurves(obj) # go through fcurves @@ -339,7 +339,7 @@ def fcurves_simplify(context, obj, options, fcurves): if mode == 'curvature': newVerts = simplypoly(fcurve, options) - # convert indicies into vectors3D + # convert indices into vectors3D newPoints = [] #this is different from the main() function for normal curves, different api... diff --git a/io_anim_bvh/import_bvh.py b/io_anim_bvh/import_bvh.py index 5a0c0fcfd..464b76bf2 100644 --- a/io_anim_bvh/import_bvh.py +++ b/io_anim_bvh/import_bvh.py @@ -38,7 +38,7 @@ class bvh_node_class(object): 'rest_tail_world', # worldspace rest location for the tail of this node 'rest_tail_local', # worldspace rest location for the tail of this node 'channels', # list of 6 ints, -1 for an unused channel, otherwise an index for the BVH motion data lines, lock triple then rot triple - 'rot_order', # a triple of indicies as to the order rotation is applied. [0,1,2] is x/y/z - [None, None, None] if no rotation. + 'rot_order', # a triple of indices as to the order rotation is applied. [0,1,2] is x/y/z - [None, None, None] if no rotation. 'rot_order_str', # same as above but a string 'XYZ' format. 'anim_data', # a list one tuple's one for each frame. (locx, locy, locz, rotx, roty, rotz), euler rotation ALWAYS stored xyz order, even when native used. 'has_loc', # Conveinience function, bool, same as (channels[0]!=-1 or channels[1]!=-1 channels[2]!=-1) diff --git a/io_scene_3ds/export_3ds.py b/io_scene_3ds/export_3ds.py index 65ed8fbce..b4fb7deb8 100644 --- a/io_scene_3ds/export_3ds.py +++ b/io_scene_3ds/export_3ds.py @@ -485,7 +485,7 @@ class tri_wrapper(object): self.mat= mat self.image= image self.faceuvs= faceuvs - self.offset= [0, 0, 0] # offset indicies + self.offset= [0, 0, 0] # offset indices def extract_triangles(mesh): diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index a0544e442..6a76cf0d7 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -18,18 +18,6 @@ # <pep8 compliant> -bl_info = { - "name": "Autodesk FBX format", - "author": "Campbell Barton", - "location": "File > Import-Export", - "description": "Import-Export FBX meshes, UV's, vertex colors, materials, textures, cameras and lamps", - "warning": "", - "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\ - "Scripts/Import-Export/Autodesk_FBX", - "tracker_url": "", - "support": 'OFFICIAL', - "category": "Import-Export"} - # To support reload properly, try to access a package var, if it's there, reload everything if "bpy" in locals(): import imp diff --git a/io_scene_fbx/export_fbx.py b/io_scene_fbx/export_fbx.py index 40cac6ddb..2a1d70c3b 100644 --- a/io_scene_fbx/export_fbx.py +++ b/io_scene_fbx/export_fbx.py @@ -20,6 +20,9 @@ # Script copyright (C) Campbell Barton +# Modified by Steven Batchelor on 01/16/2011 to include these features: +# 1. Bone and object rotation constraints. + """ This script is an exporter to the FBX file format. @@ -28,17 +31,16 @@ http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_fbx import os import time -import math # math.pi -import shutil # for file copying +import math # math.pi +import shutil # for file copying import bpy from mathutils import Vector, Euler, Matrix - # XXX not used anymore, images are copied one at a time def copy_images(dest_dir, textures): import shutil - + if not dest_dir.endswith(os.sep): dest_dir += os.sep @@ -52,17 +54,16 @@ def copy_images(dest_dir, textures): if Blender.sys.exists(image_path): # Make a name for the target path. dest_image_path = dest_dir + image_path.split('\\')[-1].split('/')[-1] - if not Blender.sys.exists(dest_image_path): # Image isnt already there + if not Blender.sys.exists(dest_image_path): # Image isnt already there print("\tCopying %r > %r" % (image_path, dest_image_path)) try: shutil.copy(image_path, dest_image_path) - copyCount += 1 + copyCount+=1 except: print("\t\tWarning, file failed to copy, skipping.") print('\tCopied %d images' % copyCount) - # I guess FBX uses degrees instead of radians (Arystan). # Call this function just before writing to FBX. # 180 / math.pi == 57.295779513 @@ -83,31 +84,30 @@ sane_name_mapping_group = {} sane_name_mapping_ob['Scene'] = 'Scene_' sane_name_mapping_ob['blend_root'] = 'blend_root_' - def increment_string(t): name = t num = '' while name and name[-1].isdigit(): num = name[-1] + num name = name[:-1] - if num: - return '%s%d' % (name, int(num) + 1) - else: - return name + '_0' + if num: return '%s%d' % (name, int(num)+1) + else: return name + '_0' + # todo - Disallow the name 'Scene' and 'blend_root' - it will bugger things up. def sane_name(data, dct): #if not data: return None - if type(data) == tuple: # materials are paired up with images + if type(data)==tuple: # materials are paired up with images data, other = data use_other = True else: other = None use_other = False - name = data.name if data else None + if data: name = data.name + else: name = None orig_name = name if other: @@ -122,40 +122,25 @@ def sane_name(data, dct): #except: pass if not name: - name = 'unnamed' # blank string, ASKING FOR TROUBLE! + name = 'unnamed' # blank string, ASKING FOR TROUBLE! else: - name = bpy.path.clean_name(name) # use our own + name = bpy.path.clean_name(name) # use our own - while name in iter(dct.values()): - name = increment_string(name) + while name in iter(dct.values()): name = increment_string(name) - if use_other: # even if other is None - orig_name_other will be a string or None + if use_other: # even if other is None - orig_name_other will be a string or None dct[orig_name, orig_name_other] = name else: dct[orig_name] = name return name - -def sane_obname(data): - return sane_name(data, sane_name_mapping_ob) - - -def sane_matname(data): - return sane_name(data, sane_name_mapping_mat) - - -def sane_texname(data): - return sane_name(data, sane_name_mapping_tex) - - -def sane_takename(data): - return sane_name(data, sane_name_mapping_take) - - -def sane_groupname(data): - return sane_name(data, sane_name_mapping_group) +def sane_obname(data): return sane_name(data, sane_name_mapping_ob) +def sane_matname(data): return sane_name(data, sane_name_mapping_mat) +def sane_texname(data): return sane_name(data, sane_name_mapping_tex) +def sane_takename(data): return sane_name(data, sane_name_mapping_take) +def sane_groupname(data): return sane_name(data, sane_name_mapping_group) # def derived_paths(fname_orig, basepath, FORCE_CWD=False): # ''' @@ -178,8 +163,7 @@ def sane_groupname(data): def mat4x4str(mat): - return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([f for v in mat for f in v]) - + return '%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f,%.15f' % tuple([ f for v in mat for f in v ]) # XXX not used # duplicated in OBJ exporter @@ -193,7 +177,6 @@ def getVertsFromGroup(me, group_index): return ret - # ob must be OB_MESH def BPyMesh_meshWeight2List(ob, me): ''' Takes a mesh and return its group names and a list of lists, one list per vertex. @@ -202,14 +185,14 @@ def BPyMesh_meshWeight2List(ob, me): ''' # Clear the vert group. - groupNames = [g.name for g in ob.vertex_groups] - len_groupNames = len(groupNames) + groupNames= [g.name for g in ob.vertex_groups] + len_groupNames= len(groupNames) if not len_groupNames: # no verts? return a vert aligned empty list return [[] for i in range(len(me.vertices))], [] else: - vWeightList = [[0.0] * len_groupNames for i in range(len(me.vertices))] + vWeightList= [[0.0]*len_groupNames for i in range(len(me.vertices))] for i, v in enumerate(me.vertices): for g in v.groups: @@ -217,24 +200,24 @@ def BPyMesh_meshWeight2List(ob, me): return groupNames, vWeightList - def meshNormalizedWeights(ob, me): - try: # account for old bad BPyMesh + try: # account for old bad BPyMesh groupNames, vWeightList = BPyMesh_meshWeight2List(ob, me) +# groupNames, vWeightList = BPyMesh.meshWeight2List(me) except: - return [], [] + return [],[] if not groupNames: - return [], [] + return [],[] for i, vWeights in enumerate(vWeightList): tot = 0.0 for w in vWeights: - tot += w + tot+=w if tot: for j, w in enumerate(vWeights): - vWeights[j] = w / tot + vWeights[j] = w/tot return groupNames, vWeightList @@ -246,34 +229,33 @@ header_comment = \ ''' - # This func can be called with just the filepath def save(operator, context, filepath="", - GLOBAL_MATRIX=None, - EXP_OBS_SELECTED=True, - EXP_MESH=True, - EXP_MESH_APPLY_MOD=True, - EXP_ARMATURE=True, - EXP_LAMP=True, - EXP_CAMERA=True, - EXP_EMPTY=True, - EXP_IMAGE_COPY=False, - ANIM_ENABLE=True, - ANIM_OPTIMIZE=True, - ANIM_OPTIMIZE_PRECISSION=6, - ANIM_ACTION_ALL=False, - BATCH_ENABLE=False, - BATCH_GROUP=True, - BATCH_FILE_PREFIX='', - BATCH_OWN_DIR=False + GLOBAL_MATRIX = None, + EXP_OBS_SELECTED = True, + EXP_MESH = True, + EXP_MESH_APPLY_MOD = True, + EXP_ARMATURE = True, + EXP_LAMP = True, + EXP_CAMERA = True, + EXP_EMPTY = True, + EXP_IMAGE_COPY = False, + ANIM_ENABLE = True, + ANIM_OPTIMIZE = True, + ANIM_OPTIMIZE_PRECISSION = 6, + ANIM_ACTION_ALL = False, + BATCH_ENABLE = False, + BATCH_GROUP = True, + BATCH_FILE_PREFIX = '', + BATCH_OWN_DIR = False ): - #XXX, missing arg + #XXX, missing arg batch_objects = None # testing - mtx_x90 = Matrix.Rotation(math.pi / 2.0, 3, 'X') # used - mtx4_z90 = Matrix.Rotation(math.pi / 2.0, 4, 'Z') + mtx_x90 = Matrix.Rotation( math.pi/2.0, 3, 'X') # used + mtx4_z90 = Matrix.Rotation( math.pi/2.0, 4, 'Z') if GLOBAL_MATRIX is None: GLOBAL_MATRIX = Matrix() @@ -287,18 +269,21 @@ def save(operator, context, filepath="", # get the path component of filepath tmp_exists = bpy.utils.exists(fbxpath) +# tmp_exists = Blender.sys.exists(fbxpath) - if tmp_exists != 2: # a file, we want a path + if tmp_exists != 2: # a file, we want a path fbxpath = os.path.dirname(fbxpath) # while fbxpath and fbxpath[-1] not in ('/', '\\'): # fbxpath = fbxpath[:-1] if not fbxpath: +# if not filepath: # XXX print('Error%t|Directory does not exist!') # Draw.PupMenu('Error%t|Directory does not exist!') return tmp_exists = bpy.utils.exists(fbxpath) +# tmp_exists = Blender.sys.exists(fbxpath) if tmp_exists != 2: # XXX @@ -310,6 +295,7 @@ def save(operator, context, filepath="", fbxpath += os.sep del tmp_exists + if BATCH_GROUP: data_seq = bpy.data.groups else: @@ -317,11 +303,13 @@ def save(operator, context, filepath="", # call this function within a loop with BATCH_ENABLE == False orig_sce = context.scene +# orig_sce = bpy.data.scenes.active - new_fbxpath = fbxpath # own dir option modifies, we need to keep an original - for data in data_seq: # scene or group + new_fbxpath = fbxpath # own dir option modifies, we need to keep an original + for data in data_seq: # scene or group newname = BATCH_FILE_PREFIX + bpy.path.clean_name(data.name) + if BATCH_OWN_DIR: new_fbxpath = fbxpath + newname + os.sep # path may already exist @@ -331,15 +319,16 @@ def save(operator, context, filepath="", # if Blender.sys.exists(new_fbxpath) == 0: os.mkdir(new_fbxpath) + filepath = new_fbxpath + newname + '.fbx' print('\nBatch exporting %s as...\n\t%r' % (data, filepath)) # XXX don't know what to do with this, probably do the same? (Arystan) - if BATCH_GROUP: # group + if BATCH_GROUP: #group # group, so objects update properly, add a dummy scene. scene = bpy.data.scenes.new() - scene.Layers = (1 << 20) - 1 + scene.Layers = (1<<20) -1 bpy.data.scenes.active = scene for ob_base in data.objects: scene.objects.link(ob_base) @@ -348,9 +337,12 @@ def save(operator, context, filepath="", # TODO - BUMMER! Armatures not in the group wont animate the mesh - else: # scene + else:# scene + + data_seq.active = data + # Call self with modified args # Dont pass batch options since we already usedt them write(filepath, data.objects, @@ -376,7 +368,7 @@ def save(operator, context, filepath="", bpy.data.scenes.active = orig_sce - return # so the script wont run after we have batch exported. + return # so the script wont run after we have batch exported. # end batch support @@ -388,38 +380,40 @@ def save(operator, context, filepath="", # ---------------------------------------------- # storage classes class my_bone_class(object): - __slots__ = ("blenName", - "blenBone", - "blenMeshes", - "restMatrix", - "parent", - "blenName", - "fbxName", - "fbxArm", - "__pose_bone", - "__anim_poselist") + __slots__ =("blenName", + "blenBone", + "blenMeshes", + "restMatrix", + "parent", + "blenName", + "fbxName", + "fbxArm", + "poseBone", + "__anim_poselist") def __init__(self, blenBone, fbxArm): - + pose = fbxArm.blenObject.pose + # This is so 2 armatures dont have naming conflicts since FBX bones use object namespace self.fbxName = sane_obname(blenBone) - self.blenName = blenBone.name - self.blenBone = blenBone - self.blenMeshes = {} # fbxMeshObName : mesh - self.fbxArm = fbxArm - self.restMatrix = blenBone.matrix_local + self.blenName = blenBone.name + self.blenBone = blenBone + self.blenMeshes = {} # fbxMeshObName : mesh + self.fbxArm = fbxArm + self.restMatrix = blenBone.matrix_local + self.poseBone = pose.bones[self.blenName] # self.restMatrix = blenBone.matrix['ARMATURESPACE'] # not used yet # self.restMatrixInv = self.restMatrix.copy().invert() # self.restMatrixLocal = None # set later, need parent matrix - self.parent = None + self.parent = None # not public - pose = fbxArm.blenObject.pose - self.__pose_bone = pose.bones[self.blenName] +# pose = fbxArm.blenObject.getPose() + #self.__pose_bone = pose.bones[self.blenName] # store a list if matricies here, (poseMatrix, head, tail) # {frame:posematrix, frame:posematrix, ...} @@ -438,22 +432,23 @@ def save(operator, context, filepath="", # Didnt end up needing head or tail, if we do - here it is. ''' self.__anim_poselist[f] = (\ - self.__pose_bone.poseMatrix.copy(),\ - self.__pose_bone.head.copy(),\ - self.__pose_bone.tail.copy() ) + self.poseBone.poseMatrix.copy(),\ + self.poseBone.head.copy(),\ + self.poseBone.tail.copy() ) ''' - self.__anim_poselist[f] = self.__pose_bone.matrix.copy() + self.__anim_poselist[f] = self.poseBone.matrix.copy() +# self.__anim_poselist[f] = self.poseBone.poseMatrix.copy() # get pose from frame. - def getPoseMatrix(self, f): # ---------------------------------------------- + def getPoseMatrix(self, f):# ---------------------------------------------- return self.__anim_poselist[f] ''' def getPoseHead(self, f): - #return self.__pose_bone.head.copy() + #return self.poseBone.head.copy() return self.__anim_poselist[f][1].copy() def getPoseTail(self, f): - #return self.__pose_bone.tail.copy() + #return self.poseBone.tail.copy() return self.__anim_poselist[f][2].copy() ''' # end @@ -475,37 +470,36 @@ def save(operator, context, filepath="", def flushAnimData(self): self.__anim_poselist.clear() + class my_object_generic(object): - __slots__ = ("fbxName", - "blenObject", - "blenData", - "origData", - "blenTextures", - "blenMaterials", - "blenMaterialList", - "blenAction", - "blenActionList", - "fbxGroupNames", - "fbxParent", - "fbxBoneParent", - "fbxBones", - "fbxArm", - "matrixWorld", - "__anim_poselist", - ) + __slots__ =("fbxName", + "blenObject", + "blenData", + "origData", + "blenTextures", + "blenMaterials", + "blenMaterialList", + "blenAction", + "blenActionList", + "fbxGroupNames", + "fbxParent", + "fbxBoneParent", + "fbxBones", + "fbxArm", + "matrixWorld", + "__anim_poselist", + ) # Other settings can be applied for each type - mesh, armature etc. - def __init__(self, ob, matrixWorld=None): + def __init__(self, ob, matrixWorld = None): self.fbxName = sane_obname(ob) self.blenObject = ob self.fbxGroupNames = [] - self.fbxParent = None # set later on IF the parent is in the selection. - if matrixWorld: - self.matrixWorld = GLOBAL_MATRIX * matrixWorld - else: - self.matrixWorld = GLOBAL_MATRIX * ob.matrix_world - - self.__anim_poselist = {} # we should only access this + self.fbxParent = None # set later on IF the parent is in the selection. + if matrixWorld: self.matrixWorld = GLOBAL_MATRIX * matrixWorld + else: self.matrixWorld = GLOBAL_MATRIX * ob.matrix_world +# else: self.matrixWorld = ob.matrixWorld * GLOBAL_MATRIX + self.__anim_poselist = {} # we should only access this def parRelMatrix(self): if self.fbxParent: @@ -516,9 +510,9 @@ def save(operator, context, filepath="", def setPoseFrame(self, f, fake=False): if fake: # annoying, have to clear GLOBAL_MATRIX - self.__anim_poselist[f] = self.matrixWorld * GLOBAL_MATRIX.copy().invert() + self.__anim_poselist[f] = self.matrixWorld * GLOBAL_MATRIX.copy().invert() else: - self.__anim_poselist[f] = self.blenObject.matrix_world.copy() + self.__anim_poselist[f] = self.blenObject.matrix_world.copy() def getAnimParRelMatrix(self, frame): if self.fbxParent: @@ -535,16 +529,20 @@ def save(operator, context, filepath="", matrix_rot = (GLOBAL_MATRIX * self.__anim_poselist[frame]).rotation_part() # Lamps need to be rotated - if obj_type == 'LAMP': + if obj_type =='LAMP': matrix_rot = matrix_rot * mtx_x90 - elif obj_type == 'CAMERA': + elif obj_type =='CAMERA': y = Vector((0.0, 1.0, 0.0)) * matrix_rot - matrix_rot = Matrix.Rotation(math.pi / 2.0, 3, y) * matrix_rot + matrix_rot = Matrix.Rotation(math.pi/2.0, 3, y) * matrix_rot return matrix_rot # ---------------------------------------------- + + + + print('\nFBX export starting... %r' % filepath) start_time = time.clock() try: @@ -555,12 +553,13 @@ def save(operator, context, filepath="", scene = context.scene world = scene.world + # ---------------------------- Write the header first file.write(header_comment) if time: curtime = time.localtime()[0:6] else: - curtime = (0, 0, 0, 0, 0, 0) + curtime = (0,0,0,0,0,0) # file.write(\ '''FBXHeaderExtension: { @@ -585,10 +584,11 @@ def save(operator, context, filepath="", file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime) file.write('\nCreator: "Blender version %s"' % bpy.app.version_string) - pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way + + pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way # --------------- funcs for exporting - def object_tx(ob, loc, matrix, matrix_mod=None): + def object_tx(ob, loc, matrix, matrix_mod = None): ''' Matrix mod is so armature objects can modify their bone matricies ''' @@ -597,27 +597,26 @@ def save(operator, context, filepath="", # we know we have a matrix # matrix = mtx4_z90 * (ob.matrix['ARMATURESPACE'] * matrix_mod) - matrix = ob.matrix_local * mtx4_z90 # dont apply armature matrix anymore + matrix = ob.matrix_local * mtx4_z90 # dont apply armature matrix anymore # matrix = mtx4_z90 * ob.matrix['ARMATURESPACE'] # dont apply armature matrix anymore parent = ob.parent if parent: #par_matrix = mtx4_z90 * (parent.matrix['ARMATURESPACE'] * matrix_mod) - par_matrix = parent.matrix_local * mtx4_z90 # dont apply armature matrix anymore + par_matrix = parent.matrix_local * mtx4_z90 # dont apply armature matrix anymore # par_matrix = mtx4_z90 * parent.matrix['ARMATURESPACE'] # dont apply armature matrix anymore matrix = par_matrix.copy().invert() * matrix loc, rot, scale = matrix.decompose() matrix_rot = rot.to_matrix() - + loc = tuple(loc) - rot = tuple(rot.to_euler()) # quat -> euler + rot = tuple(rot.to_euler()) # quat -> euler scale = tuple(scale) else: # This is bad because we need the parent relative matrix from the fbx parent (if we have one), dont use anymore #if ob and not matrix: matrix = ob.matrix_world * GLOBAL_MATRIX - if ob and not matrix: - raise Exception("error: this should never happen!") + if ob and not matrix: raise Exception("error: this should never happen!") matrix_rot = matrix #if matrix: @@ -628,11 +627,11 @@ def save(operator, context, filepath="", matrix_rot = rot.to_matrix() # Lamps need to be rotated - if ob and ob.type == 'LAMP': + if ob and ob.type =='LAMP': matrix_rot = matrix_rot * mtx_x90 - elif ob and ob.type == 'CAMERA': + elif ob and ob.type =='CAMERA': y = Vector((0.0, 1.0, 0.0)) * matrix_rot - matrix_rot = Matrix.Rotation(math.pi / 2.0, 3, y) * matrix_rot + matrix_rot = Matrix.Rotation(math.pi/2, 3, y) * matrix_rot # else do nothing. loc = tuple(loc) @@ -640,13 +639,13 @@ def save(operator, context, filepath="", scale = tuple(scale) else: if not loc: - loc = 0.0, 0.0, 0.0 - scale = 1.0, 1.0, 1.0 - rot = 0.0, 0.0, 0.0 + loc = 0,0,0 + scale = 1,1,1 + rot = 0,0,0 return loc, rot, scale, matrix, matrix_rot - def write_object_tx(ob, loc, matrix, matrix_mod=None): + def write_object_tx(ob, loc, matrix, matrix_mod= None): ''' We have loc to set the location if non blender objects that have a location @@ -660,7 +659,24 @@ def save(operator, context, filepath="", file.write('\n\t\t\tProperty: "Lcl Scaling", "Lcl Scaling", "A+",%.15f,%.15f,%.15f' % scale) return loc, rot, scale, matrix, matrix_rot - def write_object_props(ob=None, loc=None, matrix=None, matrix_mod=None): + def write_object_props(ob=None, loc=None, matrix=None, matrix_mod=None, pose=None): + # Set variables to their default zero. + rot_min = [0, 0, 0] + rot_max = [0, 0, 0] + rot_limit = [0, 0, 0] + # Check if a pose exists for this object and set the constraint soruce accordingly. (Poses only exsit if the object is a bone.) + if pose == None: + const_src = ob; + else: + const_src = pose; + # Iterate through the list of constraints for this object to get the information in a format which is compatible with the FBX format. + if ob != None: + for constraint in const_src.constraints: + if constraint.type == 'LIMIT_ROTATION': + rot_min = [int(round(180 / math.pi * constraint.min_x)), int(round(180 / math.pi * constraint.min_y)), int(round(180 / math.pi * constraint.min_z))] + rot_max = [int(round(180 / math.pi * constraint.max_x)), int(round(180 / math.pi * constraint.max_y)), int(round(180 / math.pi * constraint.max_z))] + rot_limit = [int(constraint.use_limit_x), int(constraint.use_limit_y), int(constraint.use_limit_z)] + # if the type is 0 its an empty otherwise its a mesh # only difference at the moment is one has a color file.write(''' @@ -678,71 +694,70 @@ def save(operator, context, filepath="", # eEULER_YXZ # eEULER_ZXY # eEULER_ZYX - - file.write(''' - Property: "RotationOffset", "Vector3D", "",0,0,0 - Property: "RotationPivot", "Vector3D", "",0,0,0 - Property: "ScalingOffset", "Vector3D", "",0,0,0 - Property: "ScalingPivot", "Vector3D", "",0,0,0 - Property: "TranslationActive", "bool", "",0 - Property: "TranslationMin", "Vector3D", "",0,0,0 - Property: "TranslationMax", "Vector3D", "",0,0,0 - Property: "TranslationMinX", "bool", "",0 - Property: "TranslationMinY", "bool", "",0 - Property: "TranslationMinZ", "bool", "",0 - Property: "TranslationMaxX", "bool", "",0 - Property: "TranslationMaxY", "bool", "",0 - Property: "TranslationMaxZ", "bool", "",0 - Property: "RotationOrder", "enum", "",0 - Property: "RotationSpaceForLimitOnly", "bool", "",0 - Property: "AxisLen", "double", "",10 - Property: "PreRotation", "Vector3D", "",0,0,0 - Property: "PostRotation", "Vector3D", "",0,0,0 - Property: "RotationActive", "bool", "",0 - Property: "RotationMin", "Vector3D", "",0,0,0 - Property: "RotationMax", "Vector3D", "",0,0,0 - Property: "RotationMinX", "bool", "",0 - Property: "RotationMinY", "bool", "",0 - Property: "RotationMinZ", "bool", "",0 - Property: "RotationMaxX", "bool", "",0 - Property: "RotationMaxY", "bool", "",0 - Property: "RotationMaxZ", "bool", "",0 - Property: "RotationStiffnessX", "double", "",0 - Property: "RotationStiffnessY", "double", "",0 - Property: "RotationStiffnessZ", "double", "",0 - Property: "MinDampRangeX", "double", "",0 - Property: "MinDampRangeY", "double", "",0 - Property: "MinDampRangeZ", "double", "",0 - Property: "MaxDampRangeX", "double", "",0 - Property: "MaxDampRangeY", "double", "",0 - Property: "MaxDampRangeZ", "double", "",0 - Property: "MinDampStrengthX", "double", "",0 - Property: "MinDampStrengthY", "double", "",0 - Property: "MinDampStrengthZ", "double", "",0 - Property: "MaxDampStrengthX", "double", "",0 - Property: "MaxDampStrengthY", "double", "",0 - Property: "MaxDampStrengthZ", "double", "",0 - Property: "PreferedAngleX", "double", "",0 - Property: "PreferedAngleY", "double", "",0 - Property: "PreferedAngleZ", "double", "",0 - Property: "InheritType", "enum", "",0 - Property: "ScalingActive", "bool", "",0 - Property: "ScalingMin", "Vector3D", "",1,1,1 - Property: "ScalingMax", "Vector3D", "",1,1,1 - Property: "ScalingMinX", "bool", "",0 - Property: "ScalingMinY", "bool", "",0 - Property: "ScalingMinZ", "bool", "",0 - Property: "ScalingMaxX", "bool", "",0 - Property: "ScalingMaxY", "bool", "",0 - Property: "ScalingMaxZ", "bool", "",0 - Property: "GeometricTranslation", "Vector3D", "",0,0,0 - Property: "GeometricRotation", "Vector3D", "",0,0,0 - Property: "GeometricScaling", "Vector3D", "",1,1,1 - Property: "LookAtProperty", "object", "" - Property: "UpVectorProperty", "object", "" - Property: "Show", "bool", "",1 - Property: "NegativePercentShapeSupport", "bool", "",1 - Property: "DefaultAttributeIndex", "int", "",0''') + + file.write('\n\t\t\tProperty: "RotationOffset", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "RotationPivot", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "ScalingOffset", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "ScalingPivot", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "TranslationActive", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMin", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "TranslationMax", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "TranslationMinX", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMinY", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMinZ", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMaxX", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMaxY", "bool", "",0') + file.write('\n\t\t\tProperty: "TranslationMaxZ", "bool", "",0') + file.write('\n\t\t\tProperty: "RotationOrder", "enum", "",0') + file.write('\n\t\t\tProperty: "RotationSpaceForLimitOnly", "bool", "",0') + file.write('\n\t\t\tProperty: "AxisLen", "double", "",10') + file.write('\n\t\t\tProperty: "PreRotation", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "PostRotation", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "RotationActive", "bool", "",0') + file.write('\n\t\t\tProperty: "RotationMin", "Vector3D", "",' + str(rot_min[0]) + ',' + str(rot_min[1]) + ',' + str(rot_min[2])) + file.write('\n\t\t\tProperty: "RotationMax", "Vector3D", "",' + str(rot_max[0]) + ',' + str(rot_max[1]) + ',' + str(rot_max[2])) + file.write('\n\t\t\tProperty: "RotationMinX", "bool", "",' + str(rot_limit[0])) + file.write('\n\t\t\tProperty: "RotationMinY", "bool", "",' + str(rot_limit[1])) + file.write('\n\t\t\tProperty: "RotationMinZ", "bool", "",' + str(rot_limit[2])) + file.write('\n\t\t\tProperty: "RotationMaxX", "bool", "",' + str(rot_limit[0])) + file.write('\n\t\t\tProperty: "RotationMaxY", "bool", "",' + str(rot_limit[1])) + file.write('\n\t\t\tProperty: "RotationMaxZ", "bool", "",' + str(rot_limit[2])) + file.write('\n\t\t\tProperty: "RotationStiffnessX", "double", "",0') + file.write('\n\t\t\tProperty: "RotationStiffnessY", "double", "",0') + file.write('\n\t\t\tProperty: "RotationStiffnessZ", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampRangeX", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampRangeY", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampRangeZ", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampRangeX", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampRangeY", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampRangeZ", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampStrengthX", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampStrengthY", "double", "",0') + file.write('\n\t\t\tProperty: "MinDampStrengthZ", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampStrengthX", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampStrengthY", "double", "",0') + file.write('\n\t\t\tProperty: "MaxDampStrengthZ", "double", "",0') + file.write('\n\t\t\tProperty: "PreferedAngleX", "double", "",0') + file.write('\n\t\t\tProperty: "PreferedAngleY", "double", "",0') + file.write('\n\t\t\tProperty: "PreferedAngleZ", "double", "",0') + file.write('\n\t\t\tProperty: "InheritType", "enum", "",0') + file.write('\n\t\t\tProperty: "ScalingActive", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMin", "Vector3D", "",1,1,1') + file.write('\n\t\t\tProperty: "ScalingMax", "Vector3D", "",1,1,1') + file.write('\n\t\t\tProperty: "ScalingMinX", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMinY", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMinZ", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMaxX", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMaxY", "bool", "",0') + file.write('\n\t\t\tProperty: "ScalingMaxZ", "bool", "",0') + file.write('\n\t\t\tProperty: "GeometricTranslation", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "GeometricRotation", "Vector3D", "",0,0,0') + file.write('\n\t\t\tProperty: "GeometricScaling", "Vector3D", "",1,1,1') + file.write('\n\t\t\tProperty: "LookAtProperty", "object", ""') + file.write('\n\t\t\tProperty: "UpVectorProperty", "object", ""') + file.write('\n\t\t\tProperty: "Show", "bool", "",1') + file.write('\n\t\t\tProperty: "NegativePercentShapeSupport", "bool", "",1') + file.write('\n\t\t\tProperty: "DefaultAttributeIndex", "int", "",0') if ob and not isinstance(ob, bpy.types.Bone): # Only mesh objects have color file.write('\n\t\t\tProperty: "Color", "Color", "A",0.8,0.8,0.8') @@ -751,6 +766,7 @@ def save(operator, context, filepath="", return loc, rot, scale, matrix, matrix_rot + # -------------------------------------------- Armatures #def write_bone(bone, name, matrix_mod): def write_bone(my_bone): @@ -758,8 +774,9 @@ def save(operator, context, filepath="", file.write('\n\t\tVersion: 232') #poseMatrix = write_object_props(my_bone.blenBone, None, None, my_bone.fbxArm.parRelMatrix())[3] - poseMatrix = write_object_props(my_bone.blenBone)[3] # dont apply bone matricies anymore - pose_items.append((my_bone.fbxName, poseMatrix)) + poseMatrix = write_object_props(my_bone.blenBone, None, None, None, my_bone.poseBone)[3] # dont apply bone matricies anymore. Now we also need to export the pose for this bone. + pose_items.append( (my_bone.fbxName, poseMatrix) ) + # file.write('\n\t\t\tProperty: "Size", "double", "",%.6f' % ((my_bone.blenData.head['ARMATURESPACE'] - my_bone.blenData.tail['ARMATURESPACE']) * my_bone.fbxArm.parRelMatrix()).length) file.write('\n\t\t\tProperty: "Size", "double", "",1') @@ -809,7 +826,7 @@ def save(operator, context, filepath="", }''') def write_camera_dummy(name, loc, near, far, proj_type, up): - file.write('\n\tModel: "Model::%s", "Camera" {' % name) + file.write('\n\tModel: "Model::%s", "Camera" {' % name ) file.write('\n\t\tVersion: 232') write_object_props(None, loc) @@ -900,26 +917,26 @@ def save(operator, context, filepath="", def write_camera_default(): # This sucks but to match FBX converter its easier to # write the cameras though they are not needed. - write_camera_dummy('Producer Perspective', (0, 71.3, 287.5), 10, 4000, 0, (0, 1, 0)) - write_camera_dummy('Producer Top', (0, 4000, 0), 1, 30000, 1, (0, 0, -1)) - write_camera_dummy('Producer Bottom', (0, -4000, 0), 1, 30000, 1, (0, 0, -1)) - write_camera_dummy('Producer Front', (0, 0, 4000), 1, 30000, 1, (0, 1, 0)) - write_camera_dummy('Producer Back', (0, 0, -4000), 1, 30000, 1, (0, 1, 0)) - write_camera_dummy('Producer Right', (4000, 0, 0), 1, 30000, 1, (0, 1, 0)) - write_camera_dummy('Producer Left', (-4000, 0, 0), 1, 30000, 1, (0, 1, 0)) + write_camera_dummy('Producer Perspective', (0,71.3,287.5), 10, 4000, 0, (0,1,0)) + write_camera_dummy('Producer Top', (0,4000,0), 1, 30000, 1, (0,0,-1)) + write_camera_dummy('Producer Bottom', (0,-4000,0), 1, 30000, 1, (0,0,-1)) + write_camera_dummy('Producer Front', (0,0,4000), 1, 30000, 1, (0,1,0)) + write_camera_dummy('Producer Back', (0,0,-4000), 1, 30000, 1, (0,1,0)) + write_camera_dummy('Producer Right', (4000,0,0), 1, 30000, 1, (0,1,0)) + write_camera_dummy('Producer Left', (-4000,0,0), 1, 30000, 1, (0,1,0)) def write_camera(my_cam): ''' Write a blender camera ''' render = scene.render - width = render.resolution_x - height = render.resolution_y - aspect = width / height + width = render.resolution_x + height = render.resolution_y + aspect = width / height data = my_cam.blenObject.data - file.write('\n\tModel: "Model::%s", "Camera" {' % my_cam.fbxName) + file.write('\n\tModel: "Model::%s", "Camera" {' % my_cam.fbxName ) file.write('\n\t\tVersion: 232') loc, rot, scale, matrix, matrix_rot = write_object_props(my_cam.blenObject, None, my_cam.parRelMatrix()) @@ -928,8 +945,8 @@ def save(operator, context, filepath="", file.write('\n\t\t\tProperty: "FieldOfViewX", "FieldOfView", "A+",1') file.write('\n\t\t\tProperty: "FieldOfViewY", "FieldOfView", "A+",1') # file.write('\n\t\t\tProperty: "FocalLength", "Real", "A+",14.0323972702026') - file.write('\n\t\t\tProperty: "OpticalCenterX", "Real", "A+",%.6f' % data.shift_x) # not sure if this is in the correct units? - file.write('\n\t\t\tProperty: "OpticalCenterY", "Real", "A+",%.6f' % data.shift_y) # ditto + file.write('\n\t\t\tProperty: "OpticalCenterX", "Real", "A+",%.6f' % data.shift_x) # not sure if this is in the correct units? + file.write('\n\t\t\tProperty: "OpticalCenterY", "Real", "A+",%.6f' % data.shift_y) # ditto file.write('\n\t\t\tProperty: "BackgroundColor", "Color", "A+",0,0,0') file.write('\n\t\t\tProperty: "TurnTable", "Real", "A+",0') file.write('\n\t\t\tProperty: "DisplayTurnTableIcon", "bool", "",1') @@ -1038,8 +1055,7 @@ def save(operator, context, filepath="", light_type_items = {'POINT': 0, 'SUN': 1, 'SPOT': 2, 'HEMI': 3, 'AREA': 4} light_type = light_type_items[light.type] - if light_type > 2: - light_type = 1 # hemi and area lights become directional + if light_type > 2: light_type = 1 # hemi and area lights become directional # mode = light.mode if light.shadow_method == 'RAY_SHADOW' or light.shadow_method == 'BUFFER_SHADOW': @@ -1054,7 +1070,7 @@ def save(operator, context, filepath="", else: do_light = 1 - scale = abs(GLOBAL_MATRIX.scale_part()[0]) # scale is always uniform in this case + scale = abs(GLOBAL_MATRIX.scale_part()[0]) # scale is always uniform in this case file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type) file.write('\n\t\t\tProperty: "CastLightOnObject", "bool", "",1') @@ -1063,13 +1079,13 @@ def save(operator, context, filepath="", file.write('\n\t\t\tProperty: "DrawFrontFacingVolumetricLight", "bool", "",0') file.write('\n\t\t\tProperty: "GoboProperty", "object", ""') file.write('\n\t\t\tProperty: "Color", "Color", "A+",1,1,1') - file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy * 100.0, 200.0))) # clamp below 200 + file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200 if light.type == 'SPOT': file.write('\n\t\t\tProperty: "Cone angle", "Cone angle", "A+",%.2f' % math.degrees(light.spot_size)) file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50') file.write('\n\t\t\tProperty: "Color", "Color", "A",%.2f,%.2f,%.2f' % tuple(light.color)) - file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy * 100.0, 200.0))) # clamp below 200 + file.write('\n\t\t\tProperty: "Intensity", "Intensity", "A+",%.2f' % (min(light.energy*100, 200))) # clamp below 200 file.write('\n\t\t\tProperty: "Fog", "Fog", "A+",50') file.write('\n\t\t\tProperty: "LightType", "enum", "",%i' % light_type) @@ -1098,10 +1114,9 @@ def save(operator, context, filepath="", file.write('\n\t}') # matrixOnly is not used at the moment - def write_null(my_null=None, fbxName=None, matrixOnly=None): + def write_null(my_null = None, fbxName = None, matrixOnly = None): # ob can be null - if not fbxName: - fbxName = my_null.fbxName + if not fbxName: fbxName = my_null.fbxName file.write('\n\tModel: "Model::%s", "Null" {' % fbxName) file.write('\n\t\tVersion: 232') @@ -1110,11 +1125,9 @@ def save(operator, context, filepath="", if matrixOnly: poseMatrix = write_object_props(None, None, matrixOnly)[3] - else: # all other Null's - if my_null: - poseMatrix = write_object_props(my_null.blenObject, None, my_null.parRelMatrix())[3] - else: - poseMatrix = write_object_props()[3] + else: # all other Null's + if my_null: poseMatrix = write_object_props(my_null.blenObject, None, my_null.parRelMatrix())[3] + else: poseMatrix = write_object_props()[3] pose_items.append((fbxName, poseMatrix)) @@ -1128,10 +1141,9 @@ def save(operator, context, filepath="", }''') # Material Settings - if world: - world_amb = world.ambient_color[:] - else: - world_amb = 0.0, 0.0, 0.0 # default value + if world: world_amb = tuple(world.ambient_color) +# if world: world_amb = world.getAmb() + else: world_amb = (0,0,0) # Default value def write_material(matname, mat): file.write('\n\tMaterial: "Material::%s", "" {' % matname) @@ -1145,8 +1157,8 @@ def save(operator, context, filepath="", mat_dif = mat.diffuse_intensity mat_amb = mat.ambient - mat_hard = (float(mat.specular_hardness) - 1.0) / 5.10 - mat_spec = mat.specular_intensity / 2.0 + mat_hard = (float(mat.specular_hardness)-1)/5.10 + mat_spec = mat.specular_intensity/2.0 mat_alpha = mat.alpha mat_emit = mat.emit mat_shadeless = mat.use_shadeless @@ -1159,7 +1171,7 @@ def save(operator, context, filepath="", mat_shader = 'Phong' else: mat_cols = mat_cold = 0.8, 0.8, 0.8 - mat_colamb = 0.0, 0.0, 0.0 + mat_colamb = 0.0,0.0,0.0 # mat_colm mat_dif = 1.0 mat_amb = 0.5 @@ -1177,7 +1189,7 @@ def save(operator, context, filepath="", file.write('\n\t\tProperties60: {') file.write('\n\t\t\tProperty: "ShadingModel", "KString", "", "%s"' % mat_shader) file.write('\n\t\t\tProperty: "MultiLayer", "bool", "",0') - file.write('\n\t\t\tProperty: "EmissiveColor", "ColorRGB", "",%.4f,%.4f,%.4f' % mat_cold) # emit and diffuse color are he same in blender + file.write('\n\t\t\tProperty: "EmissiveColor", "ColorRGB", "",%.4f,%.4f,%.4f' % mat_cold) # emit and diffuse color are he same in blender file.write('\n\t\t\tProperty: "EmissiveFactor", "double", "",%.4f' % mat_emit) file.write('\n\t\t\tProperty: "AmbientColor", "ColorRGB", "",%.4f,%.4f,%.4f' % mat_colamb) @@ -1242,6 +1254,7 @@ def save(operator, context, filepath="", file.write('\n\t\t\tProperty: "Path", "charptr", "", "%s"' % fname_strip) + file.write(''' Property: "StartFrame", "int", "",0 Property: "StopFrame", "int", "",0 @@ -1255,11 +1268,11 @@ def save(operator, context, filepath="", UseMipMap: 0''') file.write('\n\t\tFilename: "%s"' % fname_strip) - if fname_strip: - fname_strip = '/' + fname_strip - file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # make relative + if fname_strip: fname_strip = '/' + fname_strip + file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # make relative file.write('\n\t}') + def write_texture(texname, tex, num): # if tex is None then this is a dummy tex file.write('\n\tTexture: "Texture::%s", "TextureVideoClip" {' % texname) @@ -1275,6 +1288,7 @@ def save(operator, context, filepath="", Property: "Scaling", "Vector", "A+",1,1,1''') file.write('\n\t\t\tProperty: "Texture alpha", "Number", "A+",%i' % num) + # WrapModeU/V 0==rep, 1==clamp, TODO add support file.write(''' Property: "TextureTypeUse", "enum", "",0 @@ -1302,7 +1316,7 @@ def save(operator, context, filepath="", fname = fname_strip = fname_rel = '' file.write('\n\t\tFileName: "%s"' % fname_strip) - file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # need some make relative command + file.write('\n\t\tRelativeFilename: "%s"' % fname_rel) # need some make relative command file.write(''' ModelUVTranslation: 0,0 @@ -1373,27 +1387,27 @@ def save(operator, context, filepath="", i = -1 for vg in vgroup_data: if i == -1: - file.write('%i' % vg[0]) - i = 0 + file.write('%i' % vg[0]) + i=0 else: - if i == 23: + if i==23: file.write('\n\t\t') - i = 0 + i=0 file.write(',%i' % vg[0]) - i += 1 + i+=1 file.write('\n\t\tWeights: ') i = -1 for vg in vgroup_data: if i == -1: - file.write('%.8f' % vg[1]) - i = 0 + file.write('%.8f' % vg[1]) + i=0 else: - if i == 38: + if i==38: file.write('\n\t\t') - i = 0 + i=0 file.write(',%.8f' % vg[1]) - i += 1 + i+=1 if my_mesh.fbxParent: # TODO FIXME, this case is broken in some cases. skinned meshes just shouldnt have parents where possible! @@ -1406,7 +1420,7 @@ def save(operator, context, filepath="", matstr = mat4x4str(m) matstr_i = mat4x4str(m.invert()) - file.write('\n\t\tTransform: %s' % matstr_i) # THIS IS __NOT__ THE GLOBAL MATRIX AS DOCUMENTED :/ + file.write('\n\t\tTransform: %s' % matstr_i) # THIS IS __NOT__ THE GLOBAL MATRIX AS DOCUMENTED :/ file.write('\n\t\tTransformLink: %s' % matstr) file.write('\n\t}') @@ -1420,7 +1434,7 @@ def save(operator, context, filepath="", do_uvs = bool(me.uv_textures) file.write('\n\tModel: "Model::%s", "Mesh" {' % my_mesh.fbxName) - file.write('\n\t\tVersion: 232') # newline is added in write_object_props + file.write('\n\t\tVersion: 232') # newline is added in write_object_props # convert into lists once. me_vertices = me.vertices[:] @@ -1436,9 +1450,10 @@ def save(operator, context, filepath="", file.write('\n\t\tShading: Y') file.write('\n\t\tCulling: "CullingOff"') + # Write the Real Mesh data here file.write('\n\t\tVertices: ') - i = -1 + i=-1 for v in me_vertices: if i == -1: @@ -1448,11 +1463,11 @@ def save(operator, context, filepath="", if i == 7: file.write('\n\t\t') i = 0 - file.write(',%.6f,%.6f,%.6f' % v.co[:]) - i += 1 + file.write(',%.6f,%.6f,%.6f'% v.co[:]) + i+=1 file.write('\n\t\tPolygonVertexIndex: ') - i = -1 + i=-1 for f in me_faces: fi = f.vertices[:] @@ -1479,28 +1494,29 @@ def save(operator, context, filepath="", ed_val = ed.vertices[:] ed_val = ed_val[0], ed_val[-1] ^ -1 - if i == -1: + if i==-1: file.write('%i,%i' % ed_val) - i = 0 + i=0 else: - if i == 13: + if i==13: file.write('\n\t\t') - i = 0 + i=0 file.write(',%i,%i' % ed_val) - i += 1 + i+=1 + file.write('\n\t\tEdges: ') - i = -1 + i=-1 for ed in me_edges: - if i == -1: + if i==-1: file.write('%i,%i' % (ed.vertices[0], ed.vertices[1])) - i = 0 + i=0 else: - if i == 13: + if i==13: file.write('\n\t\t') - i = 0 + i=0 file.write(',%i,%i' % (ed.vertices[0], ed.vertices[1])) - i += 1 + i+=1 file.write('\n\t\tGeometryVersion: 124') @@ -1512,17 +1528,15 @@ def save(operator, context, filepath="", ReferenceInformationType: "Direct" Normals: ''') - i = -1 + i=-1 for v in me_vertices: - if i == -1: - file.write('%.15f,%.15f,%.15f' % v.normal[:]) - i = 0 + if i==-1: + file.write('%.15f,%.15f,%.15f' % v.normal[:]); i=0 else: - if i == 2: - file.write('\n\t\t\t ') - i = 0 + if i==2: + file.write('\n '); i=0 file.write(',%.15f,%.15f,%.15f' % v.normal[:]) - i += 1 + i+=1 file.write('\n\t\t}') # Write Face Smoothing @@ -1534,17 +1548,15 @@ def save(operator, context, filepath="", ReferenceInformationType: "Direct" Smoothing: ''') - i = -1 + i=-1 for f in me_faces: - if i == -1: - file.write('%i' % f.use_smooth) - i = 0 + if i==-1: + file.write('%i' % f.use_smooth); i=0 else: - if i == 54: - file.write('\n\t\t\t ') - i = 0 + if i==54: + file.write('\n '); i=0 file.write(',%i' % f.use_smooth) - i += 1 + i+=1 file.write('\n\t\t}') @@ -1557,20 +1569,19 @@ def save(operator, context, filepath="", ReferenceInformationType: "Direct" Smoothing: ''') - i = -1 + i=-1 for ed in me_edges: - if i == -1: - file.write('%i' % (ed.use_edge_sharp)) - i = 0 + if i==-1: + file.write('%i' % (ed.use_edge_sharp)); i=0 else: - if i == 54: - file.write('\n\t\t\t ') - i = 0 + if i==54: + file.write('\n '); i=0 file.write(',%i' % (ed.use_edge_sharp)) - i += 1 + i+=1 file.write('\n\t\t}') + # Write VertexColor Layers # note, no programs seem to use this info :/ collayers = [] @@ -1587,7 +1598,7 @@ def save(operator, context, filepath="", Colors: ''') i = -1 - ii = 0 # Count how many Colors we write + ii = 0 # Count how many Colors we write for fi, cf in enumerate(collayer.data): if len(me_faces[fi].vertices) == 4: @@ -1596,32 +1607,34 @@ def save(operator, context, filepath="", colors = cf.color1[:], cf.color2[:], cf.color3[:] for col in colors: - if i == -1: + if i==-1: file.write('%.4f,%.4f,%.4f,1' % col) - i = 0 + i=0 else: - if i == 7: + if i==7: file.write('\n\t\t\t\t') - i = 0 + i=0 file.write(',%.4f,%.4f,%.4f,1' % col) - i += 1 - ii += 1 # One more Color + i+=1 + ii+=1 # One more Color file.write('\n\t\t\tColorIndex: ') i = -1 for j in range(ii): if i == -1: file.write('%i' % j) - i = 0 + i=0 else: - if i == 55: + if i==55: file.write('\n\t\t\t\t') - i = 0 + i=0 file.write(',%i' % j) - i += 1 + i+=1 file.write('\n\t\t}') + + # Write UV and texture layers. uvlayers = [] if do_uvs: @@ -1638,34 +1651,34 @@ def save(operator, context, filepath="", UV: ''') i = -1 - ii = 0 # Count how many UVs we write + ii = 0 # Count how many UVs we write for uf in uvlayer.data: # workaround, since uf.uv iteration is wrong atm for uv in uf.uv: - if i == -1: + if i==-1: file.write('%.6f,%.6f' % uv[:]) - i = 0 + i=0 else: - if i == 7: + if i==7: file.write('\n\t\t\t ') - i = 0 + i=0 file.write(',%.6f,%.6f' % uv[:]) - i += 1 - ii += 1 # One more UV + i+=1 + ii+=1 # One more UV file.write('\n\t\t\tUVIndex: ') i = -1 for j in range(ii): if i == -1: - file.write('%i' % j) - i = 0 + file.write('%i' % j) + i=0 else: - if i == 55: + if i==55: file.write('\n\t\t\t\t') - i = 0 + i=0 file.write(',%i' % j) - i += 1 + i+=1 file.write('\n\t\t}') @@ -1687,28 +1700,28 @@ def save(operator, context, filepath="", if len(my_mesh.blenTextures) == 1: file.write('0') else: - texture_mapping_local = {None: -1} + texture_mapping_local = {None:-1} - i = 0 # 1 for dummy + i = 0 # 1 for dummy for tex in my_mesh.blenTextures: - if tex: # None is set above + if tex: # None is set above texture_mapping_local[tex] = i - i += 1 + i+=1 - i = -1 + i=-1 for f in uvlayer.data: img_key = f.image - if i == -1: - i = 0 - file.write('%s' % texture_mapping_local[img_key]) + if i==-1: + i=0 + file.write( '%s' % texture_mapping_local[img_key]) else: - if i == 55: + if i==55: file.write('\n ') - i = 0 + i=0 file.write(',%s' % texture_mapping_local[img_key]) - i += 1 + i+=1 else: file.write(''' @@ -1722,7 +1735,9 @@ def save(operator, context, filepath="", TextureId: ''') file.write('\n\t\t}') + # Done with UV/textures. + if do_materials: file.write('\n\t\tLayerElementMaterial: 0 {') file.write('\n\t\t\tVersion: 101') @@ -1740,7 +1755,7 @@ def save(operator, context, filepath="", file.write('0') else: # Build a material mapping for this - material_mapping_local = {} # local-mat & tex : global index. + material_mapping_local = {} # local-mat & tex : global index. for j, mat_tex_pair in enumerate(my_mesh.blenMaterials): material_mapping_local[mat_tex_pair] = j @@ -1754,29 +1769,25 @@ def save(operator, context, filepath="", else: uv_faces = [None] * len(me_faces) - i = -1 + i=-1 for f, uf in zip(me_faces, uv_faces): # for f in me_faces: - try: - mat = mats[f.material_index] - except: - mat = None + try: mat = mats[f.material_index] + except:mat = None - if do_uvs: - tex = uf.image # WARNING - MULTI UV LAYER IMAGES NOT SUPPORTED :/ - else: - tex = None + if do_uvs: tex = uf.image # WARNING - MULTI UV LAYER IMAGES NOT SUPPORTED :/ + else: tex = None - if i == -1: - i = 0 - file.write('%s' % (material_mapping_local[mat, tex])) # None for mat or tex is ok + if i==-1: + i=0 + file.write( '%s' % (material_mapping_local[mat, tex])) # None for mat or tex is ok else: - if i == 55: + if i==55: file.write('\n\t\t\t\t') - i = 0 + i=0 file.write(',%s' % (material_mapping_local[mat, tex])) - i += 1 + i+=1 file.write('\n\t\t}') @@ -1810,13 +1821,14 @@ def save(operator, context, filepath="", TypedIndex: 0 }''') - if do_uvs: # same as me.faceUV + if do_uvs: # same as me.faceUV file.write(''' LayerElement: { Type: "LayerElementUV" TypedIndex: 0 }''') + file.write('\n\t\t}') if len(uvlayers) > 1: @@ -1846,10 +1858,9 @@ def save(operator, context, filepath="", if len(collayers) > 1: # Take into account any UV layers layer_offset = 0 - if uvlayers: - layer_offset = len(uvlayers) - 1 + if uvlayers: layer_offset = len(uvlayers)-1 - for i in range(layer_offset, len(collayers) + layer_offset): + for i in range(layer_offset, len(collayers)+layer_offset): file.write('\n\t\tLayer: %i {' % i) file.write('\n\t\t\tVersion: 100') @@ -1875,6 +1886,7 @@ def save(operator, context, filepath="", MultiLayer: 0 }''') + # add meshes here to clear because they are not used anywhere. meshes_to_clear = [] @@ -1885,23 +1897,21 @@ def save(operator, context, filepath="", # armatures not a part of a mesh, will be added to ob_arms ob_bones = [] ob_arms = [] - ob_null = [] # emptys + ob_null = [] # emptys # List of types that have blender objects (not bones) ob_all_typegroups = [ob_meshes, ob_lights, ob_cameras, ob_arms, ob_null] - groups = [] # blender groups, only add ones that have objects in the selections - materials = {} # (mat, image) keys, should be a set() - textures = {} # should be a set() + groups = [] # blender groups, only add ones that have objects in the selections + materials = {} # (mat, image) keys, should be a set() + textures = {} # should be a set() - tmp_ob_type = ob_type = None # incase no objects are exported, so as not to raise an error + tmp_ob_type = ob_type = None # incase no objects are exported, so as not to raise an error # if EXP_OBS_SELECTED is false, use sceens objects if not batch_objects: - if EXP_OBS_SELECTED: - tmp_objects = context.selected_objects - else: - tmp_objects = scene.objects + if EXP_OBS_SELECTED: tmp_objects = context.selected_objects + else: tmp_objects = scene.objects else: tmp_objects = batch_objects @@ -1922,6 +1932,7 @@ def save(operator, context, filepath="", # This causes the makeDisplayList command to effect the mesh scene.frame_set(scene.frame_current) + for ob_base in tmp_objects: # ignore dupli children @@ -1945,8 +1956,7 @@ def save(operator, context, filepath="", elif tmp_ob_type == 'ARMATURE': if EXP_ARMATURE: # TODO - armatures dont work in dupligroups! - if ob not in ob_arms: - ob_arms.append(ob) + if ob not in ob_arms: ob_arms.append(ob) # ob_arms.append(ob) # replace later. was "ob_arms.append(sane_obname(ob), ob)" elif tmp_ob_type == 'EMPTY': if EXP_EMPTY: @@ -1954,26 +1964,28 @@ def save(operator, context, filepath="", elif EXP_MESH: origData = True if tmp_ob_type != 'MESH': - try: - me = ob.create_mesh(scene, True, 'PREVIEW') - except: - me = None - +# me = bpy.data.meshes.new() + try: me = ob.create_mesh(scene, True, 'PREVIEW') +# try: me.getFromObject(ob) + except: me = None if me: - meshes_to_clear.append(me) + meshes_to_clear.append( me ) mats = me.materials origData = False else: # Mesh Type! if EXP_MESH_APPLY_MOD: +# me = bpy.data.meshes.new() me = ob.create_mesh(scene, True, 'PREVIEW') +# me.getFromObject(ob) # print ob, me, me.getVertGroupNames() - meshes_to_clear.append(me) + meshes_to_clear.append( me ) origData = False mats = me.materials else: me = ob.data +# me = ob.getData(mesh=1) mats = me.materials # # Support object colors @@ -1986,6 +1998,7 @@ def save(operator, context, filepath="", # del tmp_ob_mats # del tmp_colbits + if me: # # This WILL modify meshes in blender if EXP_MESH_APPLY_MOD is disabled. # # so strictly this is bad. but only in rare cases would it have negative results @@ -2001,12 +2014,10 @@ def save(operator, context, filepath="", tex = uf.image textures[tex] = texture_mapping_local[tex] = None - try: - mat = mats[f.material_index] - except: - mat = None + try: mat = mats[f.material_index] + except: mat = None - materials[mat, tex] = material_mapping_local[mat, tex] = None # should use sets, wait for blender 2.5 + materials[mat, tex] = material_mapping_local[mat, tex] = None # should use sets, wait for blender 2.5 else: for mat in mats: @@ -2025,9 +2036,10 @@ def save(operator, context, filepath="", armob = ob.parent blenParentBoneName = ob.parent_bone + if armob and armob not in ob_arms: ob_arms.append(armob) - + # Warning for scaled, mesh objects with armatures if abs(ob.scale[0] - 1.0) > 0.05 or abs(ob.scale[1] - 1.0) > 0.05 or abs(ob.scale[1] - 1.0) > 0.05: operator.report('WARNING', "Object '%s' has a scale of (%.3f, %.3f, %.3f), Armature deformation will not work as expected!, Apply Scale to fix." % ((ob.name,) + tuple(ob.scale))) @@ -2036,24 +2048,24 @@ def save(operator, context, filepath="", blenParentBoneName = armob = None my_mesh = my_object_generic(ob, mtx) - my_mesh.blenData = me - my_mesh.origData = origData - my_mesh.blenMaterials = list(material_mapping_local.keys()) + my_mesh.blenData = me + my_mesh.origData = origData + my_mesh.blenMaterials = list(material_mapping_local.keys()) my_mesh.blenMaterialList = mats - my_mesh.blenTextures = list(texture_mapping_local.keys()) + my_mesh.blenTextures = list(texture_mapping_local.keys()) # if only 1 null texture then empty the list if len(my_mesh.blenTextures) == 1 and my_mesh.blenTextures[0] is None: my_mesh.blenTextures = [] - my_mesh.fbxArm = armob # replace with my_object_generic armature instance later - my_mesh.fbxBoneParent = blenParentBoneName # replace with my_bone instance later + my_mesh.fbxArm = armob # replace with my_object_generic armature instance later + my_mesh.fbxBoneParent = blenParentBoneName # replace with my_bone instance later - ob_meshes.append(my_mesh) + ob_meshes.append( my_mesh ) # not forgetting to free dupli_list - if ob_base.dupli_list: - ob_base.free_dupli_list() + if ob_base.dupli_list: ob_base.free_dupli_list() + if EXP_ARMATURE: # now we have the meshes, restore the rest arm position @@ -2074,22 +2086,22 @@ def save(operator, context, filepath="", ob_arms[i] = my_arm = my_object_generic(ob) - my_arm.fbxBones = [] - my_arm.blenData = ob.data + my_arm.fbxBones = [] + my_arm.blenData = ob.data if ob.animation_data: - my_arm.blenAction = ob.animation_data.action + my_arm.blenAction = ob.animation_data.action else: my_arm.blenAction = None # my_arm.blenAction = ob.action - my_arm.blenActionList = [] + my_arm.blenActionList = [] # fbxName, blenderObject, my_bones, blenderActions #ob_arms[i] = fbxArmObName, ob, arm_my_bones, (ob.action, []) for bone in my_arm.blenData.bones: my_bone = my_bone_class(bone, my_arm) - my_arm.fbxBones.append(my_bone) - ob_bones.append(my_bone) + my_arm.fbxBones.append( my_bone ) + ob_bones.append( my_bone ) # add the meshes to the bones and replace the meshes armature with own armature class #for obname, ob, mtx, me, mats, arm, armname in ob_meshes: @@ -2110,12 +2122,13 @@ def save(operator, context, filepath="", if my_bone.blenBone.use_deform: my_bone.blenMeshes[my_mesh.fbxName] = me + # parent bone: replace bone names with our class instances # my_mesh.fbxBoneParent is None or a blender bone name initialy, replacing if the names match. if my_mesh.fbxBoneParent == my_bone.blenName: my_mesh.fbxBoneParent = my_bone - bone_deformer_count = 0 # count how many bones deform a mesh + bone_deformer_count = 0 # count how many bones deform a mesh my_bone_blenParent = None for my_bone in ob_bones: my_bone_blenParent = my_bone.blenBone.parent @@ -2132,9 +2145,10 @@ def save(operator, context, filepath="", del my_bone_blenParent + # Build blenObject -> fbxObject mapping # this is needed for groups as well as fbxParenting - bpy.data.objects.tag(False) + for ob in bpy.data.objects: ob.tag = False # using a list of object names for tagging (Arystan) @@ -2153,23 +2167,25 @@ def save(operator, context, filepath="", fbxGroupName = sane_groupname(blenGroup) groups.append((fbxGroupName, blenGroup)) - tmp_obmapping[ob].fbxGroupNames.append(fbxGroupName) # also adds to the objects fbxGroupNames + tmp_obmapping[ob].fbxGroupNames.append(fbxGroupName) # also adds to the objects fbxGroupNames - groups.sort() # not really needed + groups.sort() # not really needed # Assign parents using this mapping for ob_generic in ob_all_typegroups: for my_ob in ob_generic: parent = my_ob.blenObject.parent - if parent and parent.tag: # does it exist and is it in the mapping + if parent and parent.tag: # does it exist and is it in the mapping my_ob.fbxParent = tmp_obmapping[parent] + del tmp_obmapping # Finished finding groups we use - materials = [(sane_matname(mat_tex_pair), mat_tex_pair) for mat_tex_pair in materials.keys()] - textures = [(sane_texname(tex), tex) for tex in textures.keys() if tex] - materials.sort() # sort by name + + materials = [(sane_matname(mat_tex_pair), mat_tex_pair) for mat_tex_pair in materials.keys()] + textures = [(sane_texname(tex), tex) for tex in textures.keys() if tex] + materials.sort() # sort by name textures.sort() camera_count = 8 @@ -2181,16 +2197,16 @@ def save(operator, context, filepath="", Definitions: { Version: 100 Count: %i''' % (\ - 1 + 1 + camera_count + \ - len(ob_meshes) + \ - len(ob_lights) + \ - len(ob_cameras) + \ - len(ob_arms) + \ - len(ob_null) + \ - len(ob_bones) + \ - bone_deformer_count + \ - len(materials) + \ - (len(textures) * 2))) # add 1 for the root model 1 for global settings + 1+1+camera_count+\ + len(ob_meshes)+\ + len(ob_lights)+\ + len(ob_cameras)+\ + len(ob_arms)+\ + len(ob_null)+\ + len(ob_bones)+\ + bone_deformer_count+\ + len(materials)+\ + (len(textures)*2))) # add 1 for the root model 1 for global settings del bone_deformer_count @@ -2198,13 +2214,13 @@ Definitions: { ObjectType: "Model" { Count: %i }''' % (\ - 1 + camera_count + \ - len(ob_meshes) + \ - len(ob_lights) + \ - len(ob_cameras) + \ - len(ob_arms) + \ - len(ob_null) + \ - len(ob_bones))) # add 1 for the root model + 1+camera_count+\ + len(ob_meshes)+\ + len(ob_lights)+\ + len(ob_cameras)+\ + len(ob_arms)+\ + len(ob_null)+\ + len(ob_bones))) # add 1 for the root model file.write(''' ObjectType: "Geometry" { @@ -2221,17 +2237,17 @@ Definitions: { file.write(''' ObjectType: "Texture" { Count: %i - }''' % len(textures)) # add 1 for an empty tex + }''' % len(textures)) # add 1 for an empty tex file.write(''' ObjectType: "Video" { Count: %i - }''' % len(textures)) # add 1 for an empty tex + }''' % len(textures)) # add 1 for an empty tex tmp = 0 # Add deformer nodes for my_mesh in ob_meshes: if my_mesh.fbxArm: - tmp += 1 + tmp+=1 # Add subdeformers for my_bone in ob_bones: @@ -2274,7 +2290,7 @@ Objects: {''') write_camera_switch() # Write the null object - write_null(None, 'blend_root') # , GLOBAL_MATRIX) + write_null(None, 'blend_root')# , GLOBAL_MATRIX) for my_null in ob_null: write_null(my_null) @@ -2298,7 +2314,7 @@ Objects: {''') write_camera_default() for matname, (mat, tex) in materials: - write_material(matname, mat) # We only need to have a material per image pair, but no need to write any image info into the material (dumb fbx standard) + write_material(matname, mat) # We only need to have a material per image pair, but no need to write any image info into the material (dumb fbx standard) # each texture uses a video, odd for texname, tex in textures: @@ -2306,7 +2322,7 @@ Objects: {''') i = 0 for texname, tex in textures: write_texture(texname, tex, i) - i += 1 + i+=1 for groupname, group in groups: write_group(groupname) @@ -2342,14 +2358,16 @@ Objects: {''') NbPoseNodes: ''') file.write(str(len(pose_items))) + for fbxName, matrix in pose_items: file.write('\n\t\tPoseNode: {') - file.write('\n\t\t\tNode: "Model::%s"' % fbxName) + file.write('\n\t\t\tNode: "Model::%s"' % fbxName ) file.write('\n\t\t\tMatrix: %s' % mat4x4str(matrix if matrix else Matrix())) file.write('\n\t\t}') file.write('\n\t}') + # Finish Writing Objects # Write global settings file.write(''' @@ -2431,7 +2449,7 @@ Relations: {''') #for bonename, bone, obname, me, armob in ob_bones: for my_bone in ob_bones: - for fbxMeshObName in my_bone.blenMeshes: # .keys() - fbxMeshObName + for fbxMeshObName in my_bone.blenMeshes: # .keys() - fbxMeshObName # is this bone effecting a mesh? file.write('\n\tDeformer: "SubDeformer::Cluster %s %s", "Cluster" {\n\t}' % (fbxMeshObName, my_bone.fbxName)) @@ -2453,10 +2471,11 @@ Connections: {''') # for instance, defining the material->mesh connection # before the mesh->blend_root crashes cinema4d + # write the fake root node file.write('\n\tConnect: "OO", "Model::blend_root", "Model::Scene"') - for ob_generic in ob_all_typegroups: # all blender 'Object's we support + for ob_generic in ob_all_typegroups: # all blender 'Object's we support for my_ob in ob_generic: if my_ob.fbxParent: file.write('\n\tConnect: "OO", "Model::%s", "Model::%s"' % (my_ob.fbxName, my_ob.fbxParent.fbxName)) @@ -2467,8 +2486,11 @@ Connections: {''') for my_mesh in ob_meshes: # Connect all materials to all objects, not good form but ok for now. for mat, tex in my_mesh.blenMaterials: - mat_name = mat.name if mat else None - tex_name = tex.name if tex else None + if mat: mat_name = mat.name + else: mat_name = None + + if tex: tex_name = tex.name + else: tex_name = None file.write('\n\tConnect: "OO", "Material::%s", "Model::%s"' % (sane_name_mapping_mat[mat_name, tex_name], my_mesh.fbxName)) @@ -2489,23 +2511,24 @@ Connections: {''') #for bonename, bone, obname, me, armob in ob_bones: for my_bone in ob_bones: - for fbxMeshObName in my_bone.blenMeshes: # .keys() + for fbxMeshObName in my_bone.blenMeshes: # .keys() file.write('\n\tConnect: "OO", "SubDeformer::Cluster %s %s", "Deformer::Skin %s"' % (fbxMeshObName, my_bone.fbxName, fbxMeshObName)) # limbs -> deformers # for bonename, bone, obname, me, armob in ob_bones: for my_bone in ob_bones: - for fbxMeshObName in my_bone.blenMeshes: # .keys() + for fbxMeshObName in my_bone.blenMeshes: # .keys() file.write('\n\tConnect: "OO", "Model::%s", "SubDeformer::Cluster %s %s"' % (my_bone.fbxName, fbxMeshObName, my_bone.fbxName)) + #for bonename, bone, obname, me, armob in ob_bones: for my_bone in ob_bones: # Always parent to armature now if my_bone.parent: - file.write('\n\tConnect: "OO", "Model::%s", "Model::%s"' % (my_bone.fbxName, my_bone.parent.fbxName)) + file.write('\n\tConnect: "OO", "Model::%s", "Model::%s"' % (my_bone.fbxName, my_bone.parent.fbxName) ) else: # the armature object is written as an empty and all root level bones connect to it - file.write('\n\tConnect: "OO", "Model::%s", "Model::%s"' % (my_bone.fbxName, my_bone.fbxArm.fbxName)) + file.write('\n\tConnect: "OO", "Model::%s", "Model::%s"' % (my_bone.fbxName, my_bone.fbxArm.fbxName) ) # groups if groups: @@ -2519,6 +2542,7 @@ Connections: {''') file.write('\n}') + # Needed for scene footer as well as animation render = scene.render @@ -2526,13 +2550,12 @@ Connections: {''') #define KTIME_ONE_SECOND KTime (K_LONGLONG(46186158000)) def fbx_time(t): # 0.5 + val is the same as rounding. - return int(0.5 + ((t / fps) * 46186158000)) + return int(0.5 + ((t/fps) * 46186158000)) fps = float(render.fps) - start = scene.frame_start - end = scene.frame_end - if end < start: - start, end = end, st + start = scene.frame_start + end = scene.frame_end + if end < start: start, end = end, st # comment the following line, otherwise we dont get the pose # if start==end: ANIM_ENABLE = False @@ -2559,6 +2582,7 @@ Connections: {''') # bpy.data.actions.tag = False tmp_actions = bpy.data.actions[:] + # find which actions are compatible with the armatures # blenActions is not yet initialized so do it now. tmp_act_count = 0 @@ -2572,10 +2596,10 @@ Connections: {''') for action in tmp_actions: - action_chan_names = arm_bone_names.intersection(set([g.name for g in action.groups])) + action_chan_names = arm_bone_names.intersection( set([g.name for g in action.groups]) ) # action_chan_names = arm_bone_names.intersection( set(action.getChannelNames()) ) - if action_chan_names: # at least one channel matches. + if action_chan_names: # at least one channel matches. my_arm.blenActionList.append(action) tagged_actions.append(action.name) # action.tag = True @@ -2591,7 +2615,7 @@ Connections: {''') del action_lastcompat - tmp_actions.insert(0, None) # None is the default action + tmp_actions.insert(0, None) # None is the default action file.write(''' ;Takes and animation section @@ -2617,11 +2641,11 @@ Takes: {''') if blenAction is None: # Warning, this only accounts for tmp_actions being [None] file.write('\n\tTake: "Default Take" {') - act_start = start - act_end = end + act_start = start + act_end = end else: # use existing name - if blenAction == blenActionDefault: # have we already got the name + if blenAction == blenActionDefault: # have we already got the name file.write('\n\tTake: "%s" {' % sane_name_mapping_take[blenAction.name]) else: file.write('\n\tTake: "%s" {' % sane_takename(blenAction)) @@ -2637,15 +2661,16 @@ Takes: {''') # print('\t\tSetting Action!', blenAction) # scene.update(1) - file.write('\n\t\tFileName: "Default_Take.tak"') # ??? - not sure why this is needed - file.write('\n\t\tLocalTime: %i,%i' % (fbx_time(act_start - 1), fbx_time(act_end - 1))) # ??? - not sure why this is needed - file.write('\n\t\tReferenceTime: %i,%i' % (fbx_time(act_start - 1), fbx_time(act_end - 1))) # ??? - not sure why this is needed + file.write('\n\t\tFileName: "Default_Take.tak"') # ??? - not sure why this is needed + file.write('\n\t\tLocalTime: %i,%i' % (fbx_time(act_start-1), fbx_time(act_end-1))) # ??? - not sure why this is needed + file.write('\n\t\tReferenceTime: %i,%i' % (fbx_time(act_start-1), fbx_time(act_end-1))) # ??? - not sure why this is needed file.write(''' ;Models animation ;----------------------------------------------------''') + # set pose data for all bones # do this here incase the action changes ''' @@ -2664,7 +2689,8 @@ Takes: {''') else: my_ob.setPoseFrame(i) - i += 1 + i+=1 + #for bonename, bone, obname, me, armob in ob_bones: for ob_generic in (ob_bones, ob_meshes, ob_null, ob_cameras, ob_lights, ob_arms): @@ -2676,21 +2702,19 @@ Takes: {''') pass else: - file.write('\n\t\tModel: "Model::%s" {' % my_ob.fbxName) # ??? - not sure why this is needed + file.write('\n\t\tModel: "Model::%s" {' % my_ob.fbxName) # ??? - not sure why this is needed file.write('\n\t\t\tVersion: 1.1') file.write('\n\t\t\tChannel: "Transform" {') - context_bone_anim_mats = [(my_ob.getAnimParRelMatrix(frame), my_ob.getAnimParRelMatrixRot(frame)) for frame in range(act_start, act_end + 1)] + context_bone_anim_mats = [ (my_ob.getAnimParRelMatrix(frame), my_ob.getAnimParRelMatrixRot(frame)) for frame in range(act_start, act_end+1) ] # ---------------- # ---------------- - for TX_LAYER, TX_CHAN in enumerate('TRS'): # transform, rotate, scale + for TX_LAYER, TX_CHAN in enumerate('TRS'): # transform, rotate, scale - if TX_CHAN == 'T': - context_bone_anim_vecs = [mtx[0].translation_part() for mtx in context_bone_anim_mats] - elif TX_CHAN == 'S': - context_bone_anim_vecs = [mtx[0].scale_part() for mtx in context_bone_anim_mats] - elif TX_CHAN == 'R': + if TX_CHAN=='T': context_bone_anim_vecs = [mtx[0].translation_part() for mtx in context_bone_anim_mats] + elif TX_CHAN=='S': context_bone_anim_vecs = [mtx[0].scale_part() for mtx in context_bone_anim_mats] + elif TX_CHAN=='R': # Was.... # elif TX_CHAN=='R': context_bone_anim_vecs = [mtx[1].to_euler() for mtx in context_bone_anim_mats] # @@ -2698,18 +2722,16 @@ Takes: {''') context_bone_anim_vecs = [] prev_eul = None for mtx in context_bone_anim_mats: - if prev_eul: - prev_eul = mtx[1].to_euler('XYZ', prev_eul) - else: - prev_eul = mtx[1].to_euler() + if prev_eul: prev_eul = mtx[1].to_euler('XYZ', prev_eul) + else: prev_eul = mtx[1].to_euler() context_bone_anim_vecs.append(tuple_rad_to_deg(prev_eul)) - file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation + file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation for i in range(3): # Loop on each axis of the bone - file.write('\n\t\t\t\t\tChannel: "%s" {' % ('XYZ'[i])) # translation - file.write('\n\t\t\t\t\t\tDefault: %.15f' % context_bone_anim_vecs[0][i]) + file.write('\n\t\t\t\t\tChannel: "%s" {'% ('XYZ'[i])) # translation + file.write('\n\t\t\t\t\t\tDefault: %.15f' % context_bone_anim_vecs[0][i] ) file.write('\n\t\t\t\t\t\tKeyVer: 4005') if not ANIM_OPTIMIZE: @@ -2718,45 +2740,45 @@ Takes: {''') file.write('\n\t\t\t\t\t\tKey: ') frame = act_start while frame <= act_end: - if frame != act_start: + if frame!=act_start: file.write(',') # Curve types are 'C,n' for constant, 'L' for linear # C,n is for bezier? - linear is best for now so we can do simple keyframe removal - file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame - 1), context_bone_anim_vecs[frame - act_start][i])) - frame += 1 + file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame-1), context_bone_anim_vecs[frame-act_start][i] )) + frame+=1 else: # remove unneeded keys, j is the frame, needed when some frames are removed. - context_bone_anim_keys = [(vec[i], j) for j, vec in enumerate(context_bone_anim_vecs)] + context_bone_anim_keys = [ (vec[i], j) for j, vec in enumerate(context_bone_anim_vecs) ] # last frame to fisrt frame, missing 1 frame on either side. # removeing in a backwards loop is faster #for j in xrange( (act_end-act_start)-1, 0, -1 ): # j = (act_end-act_start)-1 - j = len(context_bone_anim_keys) - 2 + j = len(context_bone_anim_keys)-2 while j > 0 and len(context_bone_anim_keys) > 2: # print j, len(context_bone_anim_keys) # Is this key the same as the ones next to it? # co-linear horizontal... - if abs(context_bone_anim_keys[j][0] - context_bone_anim_keys[j - 1][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT and \ - abs(context_bone_anim_keys[j][0] - context_bone_anim_keys[j + 1][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT: + if abs(context_bone_anim_keys[j][0] - context_bone_anim_keys[j-1][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT and\ + abs(context_bone_anim_keys[j][0] - context_bone_anim_keys[j+1][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT: del context_bone_anim_keys[j] else: - frame_range = float(context_bone_anim_keys[j + 1][1] - context_bone_anim_keys[j - 1][1]) - frame_range_fac1 = (context_bone_anim_keys[j + 1][1] - context_bone_anim_keys[j][1]) / frame_range + frame_range = float(context_bone_anim_keys[j+1][1] - context_bone_anim_keys[j-1][1]) + frame_range_fac1 = (context_bone_anim_keys[j+1][1] - context_bone_anim_keys[j][1]) / frame_range frame_range_fac2 = 1.0 - frame_range_fac1 - if abs(((context_bone_anim_keys[j - 1][0] * frame_range_fac1 + context_bone_anim_keys[j + 1][0] * frame_range_fac2)) - context_bone_anim_keys[j][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT: + if abs(((context_bone_anim_keys[j-1][0]*frame_range_fac1 + context_bone_anim_keys[j+1][0]*frame_range_fac2)) - context_bone_anim_keys[j][0]) < ANIM_OPTIMIZE_PRECISSION_FLOAT: del context_bone_anim_keys[j] else: - j -= 1 + j-=1 # keep the index below the list length - if j > len(context_bone_anim_keys) - 2: - j = len(context_bone_anim_keys) - 2 + if j > len(context_bone_anim_keys)-2: + j = len(context_bone_anim_keys)-2 if len(context_bone_anim_keys) == 2 and context_bone_anim_keys[0][0] == context_bone_anim_keys[1][0]: @@ -2766,26 +2788,23 @@ Takes: {''') # better write one, otherwise we loose poses with no animation file.write('\n\t\t\t\t\t\tKeyCount: 1') file.write('\n\t\t\t\t\t\tKey: ') - file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(start), context_bone_anim_keys[0][0])) + file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(start), context_bone_anim_keys[0][0])) else: # We only need to write these if there is at least one file.write('\n\t\t\t\t\t\tKeyCount: %i' % len(context_bone_anim_keys)) file.write('\n\t\t\t\t\t\tKey: ') for val, frame in context_bone_anim_keys: - if frame != context_bone_anim_keys[0][1]: # not the first + if frame != context_bone_anim_keys[0][1]: # not the first file.write(',') # frame is already one less then blenders frame - file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame), val)) + file.write('\n\t\t\t\t\t\t\t%i,%.15f,L' % (fbx_time(frame), val )) - if i == 0: - file.write('\n\t\t\t\t\t\tColor: 1,0,0') - elif i == 1: - file.write('\n\t\t\t\t\t\tColor: 0,1,0') - elif i == 2: - file.write('\n\t\t\t\t\t\tColor: 0,0,1') + if i==0: file.write('\n\t\t\t\t\t\tColor: 1,0,0') + elif i==1: file.write('\n\t\t\t\t\t\tColor: 0,1,0') + elif i==2: file.write('\n\t\t\t\t\t\tColor: 0,0,1') file.write('\n\t\t\t\t\t}') - file.write('\n\t\t\t\t\tLayerType: %i' % (TX_LAYER + 1)) + file.write('\n\t\t\t\t\tLayerType: %i' % (TX_LAYER+1) ) file.write('\n\t\t\t\t}') # --------------- @@ -2815,9 +2834,11 @@ Takes: {''') file.write('\n\tCurrent: ""') file.write('\n}') + # write meshes animation #for obname, ob, mtx, me, mats, arm, armname in ob_meshes: + # Clear mesh data Only when writing with modifiers applied for me in meshes_to_clear: bpy.data.meshes.remove(me) @@ -2856,8 +2877,8 @@ Takes: {''') file.write('\n\t\tTimeFormat: 1') file.write('\n\t\tSnapOnFrames: 0') file.write('\n\t\tReferenceTimeIndex: -1') - file.write('\n\t\tTimeLineStartTime: %i' % fbx_time(start - 1)) - file.write('\n\t\tTimeLineStopTime: %i' % fbx_time(end - 1)) + file.write('\n\t\tTimeLineStartTime: %i' % fbx_time(start-1)) + file.write('\n\t\tTimeLineStopTime: %i' % fbx_time(end-1)) file.write('\n\t}') file.write('\n\tRendererSetting: {') file.write('\n\t\tDefaultCamera: "Producer Perspective"') @@ -2873,17 +2894,19 @@ Takes: {''') sane_name_mapping_take.clear() sane_name_mapping_group.clear() - ob_arms[:] = [] - ob_bones[:] = [] - ob_cameras[:] = [] - ob_lights[:] = [] - ob_meshes[:] = [] - ob_null[:] = [] + ob_arms[:] = [] + ob_bones[:] = [] + ob_cameras[:] = [] + ob_lights[:] = [] + ob_meshes[:] = [] + ob_null[:] = [] + # copy images if enabled # if EXP_IMAGE_COPY: # # copy_images( basepath, [ tex[1] for tex in textures if tex[1] != None ]) # bpy.util.copy_images( [ tex[1] for tex in textures if tex[1] != None ], basepath) + file.close() print('export finished in %.4f sec.' % (time.clock() - start_time)) diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py index 0b80b52f2..bc66deec4 100644 --- a/io_scene_obj/export_obj.py +++ b/io_scene_obj/export_obj.py @@ -435,7 +435,7 @@ def write_file(filepath, objects, scene, # Cant use LC because some materials are None. # materialNames = map(lambda mat: mat.name, materials) # Bug Blender, dosent account for null materials, still broken. - # Possible there null materials, will mess up indicies + # Possible there null materials, will mess up indices # but at least it will export, wait until Blender gets fixed. materialNames.extend((16-len(materialNames)) * [None]) materialItems.extend((16-len(materialItems)) * [None]) @@ -659,7 +659,7 @@ def write_file(filepath, objects, scene, if ed.is_loose: file.write('f %d %d\n' % (ed.vertices[0] + totverts, ed.vertices[1] + totverts)) - # Make the indicies global rather then per mesh + # Make the indices global rather then per mesh totverts += len(me_verts) if faceuv: totuvco += uv_unique_count diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index 3d2b5e6da..6ed7aa799 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -46,7 +46,7 @@ def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True): Designed to be used for importers that need indices for an fgon to create from existing verts. from_data: either a mesh, or a list/tuple of vectors. - indices: a list of indicies to use this list is the ordered closed polyline to fill, and can be a subset of the data given. + indices: a list of indices to use this list is the ordered closed polyline to fill, and can be a subset of the data given. PREF_FIX_LOOPS: If this is enabled polylines that use loops to make multiple polylines are delt with correctly. ''' @@ -195,7 +195,7 @@ def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True): fill= tesselate_polygon([ [v[0] for v in loop] for loop in loop_list ]) #draw_loops(loop_list) #raise 'done loop' - # map to original indicies + # map to original indices fill= [[vert_map[i] for i in reversed(f)] for f in fill] @@ -474,17 +474,17 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP): oldkey= key - face_vert_loc_indicies= face[0] + face_vert_loc_indices= face[0] # Remap verts to new vert list and add where needed - for enum, i in enumerate(face_vert_loc_indicies): + for enum, i in enumerate(face_vert_loc_indices): if vert_remap[i] == -1: new_index= len(verts_split) vert_remap[i]= new_index # set the new remapped index so we only add once and can reference next time. - face_vert_loc_indicies[enum] = new_index # remap to the local index + face_vert_loc_indices[enum] = new_index # remap to the local index verts_split.append( verts_loc[i] ) # add the vert to the local verts else: - face_vert_loc_indicies[enum] = vert_remap[i] # remap to the local index + face_vert_loc_indices[enum] = vert_remap[i] # remap to the local index matname= face[2] if matname and matname not in unique_materials_split: @@ -516,25 +516,25 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v context_object= None - # reverse loop through face indicies + # reverse loop through face indices for f_idx in range(len(faces)-1, -1, -1): - face_vert_loc_indicies,\ - face_vert_tex_indicies,\ + face_vert_loc_indices,\ + face_vert_tex_indices,\ context_material,\ context_smooth_group,\ context_object= faces[f_idx] - len_face_vert_loc_indicies = len(face_vert_loc_indicies) + len_face_vert_loc_indices = len(face_vert_loc_indices) - if len_face_vert_loc_indicies==1: + if len_face_vert_loc_indices==1: faces.pop(f_idx)# cant add single vert faces - elif not face_vert_tex_indicies or len_face_vert_loc_indicies == 2: # faces that have no texture coords are lines + elif not face_vert_tex_indices or len_face_vert_loc_indices == 2: # faces that have no texture coords are lines if CREATE_EDGES: # generators are better in python 2.4+ but can't be used in 2.3 - # edges.extend( (face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in xrange(len_face_vert_loc_indicies-1) ) - edges.extend( [(face_vert_loc_indicies[i], face_vert_loc_indicies[i+1]) for i in range(len_face_vert_loc_indicies-1)] ) + # edges.extend( (face_vert_loc_indices[i], face_vert_loc_indices[i+1]) for i in xrange(len_face_vert_loc_indices-1) ) + edges.extend( [(face_vert_loc_indices[i], face_vert_loc_indices[i+1]) for i in range(len_face_vert_loc_indices-1)] ) faces.pop(f_idx) else: @@ -546,9 +546,9 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v edge_dict= smooth_group_users[context_smooth_group] context_smooth_group_old= context_smooth_group - for i in range(len_face_vert_loc_indicies): - i1= face_vert_loc_indicies[i] - i2= face_vert_loc_indicies[i-1] + for i in range(len_face_vert_loc_indices): + i1= face_vert_loc_indices[i] + i2= face_vert_loc_indices[i-1] if i1>i2: i1,i2= i2,i1 try: @@ -557,13 +557,13 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v edge_dict[i1,i2]= 1 # FGons into triangles - if has_ngons and len_face_vert_loc_indicies > 4: + if has_ngons and len_face_vert_loc_indices > 4: - ngon_face_indices= BPyMesh_ngon(verts_loc, face_vert_loc_indicies) + ngon_face_indices= BPyMesh_ngon(verts_loc, face_vert_loc_indices) faces.extend( [( - [face_vert_loc_indicies[ngon[0]], face_vert_loc_indicies[ngon[1]], face_vert_loc_indicies[ngon[2]] ], - [face_vert_tex_indicies[ngon[0]], face_vert_tex_indicies[ngon[1]], face_vert_tex_indicies[ngon[2]] ], + [face_vert_loc_indices[ngon[0]], face_vert_loc_indices[ngon[1]], face_vert_loc_indices[ngon[2]] ], + [face_vert_tex_indices[ngon[0]], face_vert_tex_indices[ngon[1]], face_vert_tex_indices[ngon[2]] ], context_material, context_smooth_group, context_object) @@ -575,8 +575,8 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v edge_users= {} for ngon in ngon_face_indices: for i in (0,1,2): - i1= face_vert_loc_indicies[ngon[i ]] - i2= face_vert_loc_indicies[ngon[i-1]] + i1= face_vert_loc_indices[ngon[i ]] + i2= face_vert_loc_indices[ngon[i-1]] if i1>i2: i1,i2= i2,i1 try: @@ -642,8 +642,8 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v blender_face = me.faces[i] - face_vert_loc_indicies,\ - face_vert_tex_indicies,\ + face_vert_loc_indices,\ + face_vert_tex_indices,\ context_material,\ context_smooth_group,\ context_object= face @@ -675,24 +675,24 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v blender_tface.blend_type = 'ALPHA' # BUG - Evil eekadoodle problem where faces that have vert index 0 location at 3 or 4 are shuffled. - if len(face_vert_loc_indicies)==4: - if face_vert_loc_indicies[2]==0 or face_vert_loc_indicies[3]==0: - face_vert_tex_indicies= face_vert_tex_indicies[2], face_vert_tex_indicies[3], face_vert_tex_indicies[0], face_vert_tex_indicies[1] + if len(face_vert_loc_indices)==4: + if face_vert_loc_indices[2]==0 or face_vert_loc_indices[3]==0: + face_vert_tex_indices= face_vert_tex_indices[2], face_vert_tex_indices[3], face_vert_tex_indices[0], face_vert_tex_indices[1] else: # length of 3 - if face_vert_loc_indicies[2]==0: - face_vert_tex_indicies= face_vert_tex_indicies[1], face_vert_tex_indicies[2], face_vert_tex_indicies[0] + if face_vert_loc_indices[2]==0: + face_vert_tex_indices= face_vert_tex_indices[1], face_vert_tex_indices[2], face_vert_tex_indices[0] # END EEEKADOODLE FIX # assign material, uv's and image - blender_tface.uv1= verts_tex[face_vert_tex_indicies[0]] - blender_tface.uv2= verts_tex[face_vert_tex_indicies[1]] - blender_tface.uv3= verts_tex[face_vert_tex_indicies[2]] + blender_tface.uv1= verts_tex[face_vert_tex_indices[0]] + blender_tface.uv2= verts_tex[face_vert_tex_indices[1]] + blender_tface.uv3= verts_tex[face_vert_tex_indices[2]] - if len(face_vert_loc_indicies)==4: - blender_tface.uv4= verts_tex[face_vert_tex_indicies[3]] + if len(face_vert_loc_indices)==4: + blender_tface.uv4= verts_tex[face_vert_tex_indices[3]] # for ii, uv in enumerate(blender_face.uv): -# uv.x, uv.y= verts_tex[face_vert_tex_indicies[ii]] +# uv.x, uv.y= verts_tex[face_vert_tex_indices[ii]] del me_faces # del ALPHA @@ -751,9 +751,9 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v # Create the vertex groups. No need to have the flag passed here since we test for the # content of the vertex_groups. If the user selects to NOT have vertex groups saved then # the following test will never run - for group_name, group_indicies in vertex_groups.items(): + for group_name, group_indices in vertex_groups.items(): group = ob.vertex_groups.new(group_name) - group.add(group_indicies, 1.0, 'REPLACE') + group.add(group_indices, 1.0, 'REPLACE') def create_nurbs(context_nurbs, vert_loc, new_objects): @@ -942,18 +942,18 @@ def load(operator, context, filepath, elif line.startswith('f') or context_multi_line == 'f': if context_multi_line: - # use face_vert_loc_indicies and face_vert_tex_indicies previously defined and used the obj_face + # use face_vert_loc_indices and face_vert_tex_indices previously defined and used the obj_face line_split= line.split() else: line_split= line[2:].split() - face_vert_loc_indicies= [] - face_vert_tex_indicies= [] + face_vert_loc_indices= [] + face_vert_tex_indices= [] # Instance a face faces.append((\ - face_vert_loc_indicies,\ - face_vert_tex_indicies,\ + face_vert_loc_indices,\ + face_vert_tex_indices,\ context_material,\ context_smooth_group,\ context_object\ @@ -973,45 +973,45 @@ def load(operator, context, filepath, if POLYGROUPS and context_vgroup: vertex_groups[context_vgroup].append(vert_loc_index) - # Make relative negative vert indicies absolute + # Make relative negative vert indices absolute if vert_loc_index < 0: vert_loc_index= len(verts_loc) + vert_loc_index + 1 - face_vert_loc_indicies.append(vert_loc_index) + face_vert_loc_indices.append(vert_loc_index) if len(obj_vert)>1 and obj_vert[1]: # formatting for faces with normals and textures us # loc_index/tex_index/nor_index vert_tex_index= int(obj_vert[1])-1 - # Make relative negative vert indicies absolute + # Make relative negative vert indices absolute if vert_tex_index < 0: vert_tex_index= len(verts_tex) + vert_tex_index + 1 - face_vert_tex_indicies.append(vert_tex_index) + face_vert_tex_indices.append(vert_tex_index) else: # dummy - face_vert_tex_indicies.append(0) + face_vert_tex_indices.append(0) - if len(face_vert_loc_indicies) > 4: + if len(face_vert_loc_indices) > 4: has_ngons= True elif CREATE_EDGES and (line.startswith('l ') or context_multi_line == 'l'): # very similar to the face load function above with some parts removed if context_multi_line: - # use face_vert_loc_indicies and face_vert_tex_indicies previously defined and used the obj_face + # use face_vert_loc_indices and face_vert_tex_indices previously defined and used the obj_face line_split= line.split() else: line_split= line[2:].split() - face_vert_loc_indicies= [] - face_vert_tex_indicies= [] + face_vert_loc_indices= [] + face_vert_tex_indices= [] # Instance a face faces.append((\ - face_vert_loc_indicies,\ - face_vert_tex_indicies,\ + face_vert_loc_indices,\ + face_vert_tex_indices,\ context_material,\ context_smooth_group,\ context_object\ @@ -1027,11 +1027,11 @@ def load(operator, context, filepath, for v in line_split: vert_loc_index= int(v)-1 - # Make relative negative vert indicies absolute + # Make relative negative vert indices absolute if vert_loc_index < 0: vert_loc_index= len(verts_loc) + vert_loc_index + 1 - face_vert_loc_indicies.append(vert_loc_index) + face_vert_loc_indices.append(vert_loc_index) elif line.startswith('s'): if CREATE_SMOOTH_GROUPS: diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py index f28859438..7fdb98c24 100644 --- a/io_scene_x3d/import_x3d.py +++ b/io_scene_x3d/import_x3d.py @@ -1695,7 +1695,7 @@ def importMesh_IndexedFaceSet(geom, bpyima, ancestry): bpymesh.faces.add(len(faces)) bpymesh.faces.foreach_set("vertices_raw", [a for f in faces for a in (f + [0] if len(f) == 3 else f)]) # XXX25 speed except KeyError: - print("one or more vert indicies out of range. corrupt file?") + print("one or more vert indices out of range. corrupt file?") #for f in faces: # bpymesh.faces.extend(faces, smooth=True) @@ -1716,7 +1716,7 @@ def importMesh_IndexedFaceSet(geom, bpyima, ancestry): for i, f in enumerate(uvlay.data): f.image = bpyima - fuv = faces_uv[i] # uv indicies + fuv = faces_uv[i] # uv indices for j, uv in enumerate(f.uv): # print(fuv, j, len(ifs_texpoints)) try: diff --git a/render_povray/render.py b/render_povray/render.py index c4590e43f..33ca98adc 100644 --- a/render_povray/render.py +++ b/render_povray/render.py @@ -1054,16 +1054,16 @@ def write_pov(filename, scene=None, info_callback=None): file.write('\n') tabWrite('}\n') - # Face indicies + # Face indices tabWrite('face_indices {\n') tabWrite('%d' % (len(me.faces) + quadCount)) # faces count for fi, f in enumerate(me.faces): fv = faces_verts[fi] material_index = f.material_index if len(fv) == 4: - indicies = (0, 1, 2), (0, 2, 3) + indices = (0, 1, 2), (0, 2, 3) else: - indicies = ((0, 1, 2),) + indices = ((0, 1, 2),) if vcol_layer: col = vcol_layer[fi] @@ -1075,12 +1075,12 @@ def write_pov(filename, scene=None, info_callback=None): if not me_materials or me_materials[material_index] is None: # No materials - for i1, i2, i3 in indicies: + for i1, i2, i3 in indices: file.write(',\n') tabWrite('<%d,%d,%d>' % (fv[i1], fv[i2], fv[i3])) # vert count else: material = me_materials[material_index] - for i1, i2, i3 in indicies: + for i1, i2, i3 in indices: if me.vertex_colors and material.use_vertex_color_paint: # Colour per vertex - vertex colour @@ -1103,17 +1103,17 @@ def write_pov(filename, scene=None, info_callback=None): file.write('\n') tabWrite('}\n') - # normal_indices indicies + # normal_indices indices tabWrite('normal_indices {\n') tabWrite('%d' % (len(me.faces) + quadCount)) # faces count for fi, fv in enumerate(faces_verts): if len(fv) == 4: - indicies = (0, 1, 2), (0, 2, 3) + indices = (0, 1, 2), (0, 2, 3) else: - indicies = ((0, 1, 2),) + indices = ((0, 1, 2),) - for i1, i2, i3 in indicies: + for i1, i2, i3 in indices: if f.use_smooth: file.write(',\n') tabWrite('<%d,%d,%d>' %\ @@ -1134,9 +1134,9 @@ def write_pov(filename, scene=None, info_callback=None): for fi, fv in enumerate(faces_verts): if len(fv) == 4: - indicies = (0, 1, 2), (0, 2, 3) + indices = (0, 1, 2), (0, 2, 3) else: - indicies = ((0, 1, 2),) + indices = ((0, 1, 2),) uv = uv_layer[fi] if len(faces_verts[fi]) == 4: @@ -1144,7 +1144,7 @@ def write_pov(filename, scene=None, info_callback=None): else: uvs = tuple(uv.uv1), tuple(uv.uv2), tuple(uv.uv3) - for i1, i2, i3 in indicies: + for i1, i2, i3 in indices: file.write(',\n') tabWrite('<%d,%d,%d>' %\ (uniqueUVs[uvs[i1]][0],\ -- GitLab