diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-16 07:32:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-16 07:32:35 +0300 |
commit | f48f8d3bbc943525ce1b4db9d58e0d2cc76b5995 (patch) | |
tree | 5b65489d1a13cdc47c3e84d28a3fc14bb012a052 /release | |
parent | efcf1ac35750f36756e69ad37e0cd288111f3c95 (diff) |
FBX Export, small changes made while looking into reported bug. (no functional changes)
- Warn for armature deformed meshes which are scaled, these don't work quite the same as in blender, reported as [#24663].
- Use matrix.decompose() to convert a matrix to loc/rot/scale.
- get vert/edge/face lists for each mesh only once.
- faster euler rad -> deg conversion function.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/op/io_scene_fbx/export_fbx.py | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/release/scripts/op/io_scene_fbx/export_fbx.py b/release/scripts/op/io_scene_fbx/export_fbx.py index b6abb3ded42..d1f5c8a6d63 100644 --- a/release/scripts/op/io_scene_fbx/export_fbx.py +++ b/release/scripts/op/io_scene_fbx/export_fbx.py @@ -63,15 +63,9 @@ def copy_images(dest_dir, textures): # I guess FBX uses degrees instead of radians (Arystan). # Call this function just before writing to FBX. -def eulerRadToDeg(eul): - ret = Euler() - - ret.x = 180 / math.pi * eul[0] - ret.y = 180 / math.pi * eul[1] - ret.z = 180 / math.pi * eul[2] - - return ret - +# 180 / math.pi == 57.295779513 +def tuple_rad_to_deg(eul): + return eul[0] * 57.295779513, eul[1] * 57.295779513, eul[2] * 57.295779513 # def strip_path(p): # return p.split('\\')[-1].split('/')[-1] @@ -609,12 +603,12 @@ def save(operator, context, filepath="", # par_matrix = mtx4_z90 * parent.matrix['ARMATURESPACE'] # dont apply armature matrix anymore matrix = par_matrix.copy().invert() * matrix - matrix_rot = matrix.rotation_part() - - loc = tuple(matrix.translation_part()) - scale = tuple(matrix.scale_part()) - rot = tuple(matrix_rot.to_euler()) - + loc, rot, scale = matrix.decompose() + matrix_rot = rot.to_matrix() + + loc = tuple(loc) + 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 @@ -625,20 +619,20 @@ def save(operator, context, filepath="", # matrix = matrix_scale * matrix if matrix: - loc = tuple(matrix.translation_part()) - scale = tuple(matrix.scale_part()) + loc, rot, scale = matrix.decompose() + matrix_rot = rot.to_matrix() - matrix_rot = matrix.rotation_part() # Lamps need to be rotated if ob and ob.type =='LAMP': matrix_rot = matrix_rot * mtx_x90 - rot = tuple(matrix_rot.to_euler()) elif ob and ob.type =='CAMERA': y = Vector((0.0, 1.0, 0.0)) * matrix_rot matrix_rot = Matrix.Rotation(math.pi/2, 3, y) * matrix_rot - rot = tuple(matrix_rot.to_euler()) - else: - rot = tuple(matrix_rot.to_euler()) + # else do nothing. + + loc = tuple(loc) + rot = tuple(matrix_rot.to_euler()) + scale = tuple(scale) else: if not loc: loc = 0,0,0 @@ -656,7 +650,7 @@ def save(operator, context, filepath="", loc, rot, scale, matrix, matrix_rot = object_tx(ob, loc, matrix, matrix_mod) file.write('\n\t\t\tProperty: "Lcl Translation", "Lcl Translation", "A+",%.15f,%.15f,%.15f' % loc) - file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % tuple(eulerRadToDeg(rot))) + file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % tuple_rad_to_deg(rot)) # file.write('\n\t\t\tProperty: "Lcl Rotation", "Lcl Rotation", "A+",%.15f,%.15f,%.15f' % rot) file.write('\n\t\t\tProperty: "Lcl Scaling", "Lcl Scaling", "A+",%.15f,%.15f,%.15f' % scale) return loc, rot, scale, matrix, matrix_rot @@ -1413,18 +1407,18 @@ def save(operator, context, filepath="", me = my_mesh.blenData # if there are non NULL materials on this mesh - if my_mesh.blenMaterials: do_materials = True - else: do_materials = False - - if my_mesh.blenTextures: do_textures = True - else: do_textures = False - + do_materials = bool(my_mesh.blenMaterials) + do_textures = bool(my_mesh.blenTextures) 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 + # convert into lists once. + me_vertices = me.vertices[:] + me_edges = me.edges[:] + me_faces = me.faces[:] + poseMatrix = write_object_props(my_mesh.blenObject, None, my_mesh.parRelMatrix())[3] pose_items.append((my_mesh.fbxName, poseMatrix)) @@ -1439,7 +1433,7 @@ def save(operator, context, filepath="", file.write('\n\t\tVertices: ') i=-1 - for v in me.vertices: + for v in me_vertices: if i==-1: file.write('%.6f,%.6f,%.6f' % tuple(v.co)); i=0 else: @@ -1450,7 +1444,7 @@ def save(operator, context, filepath="", file.write('\n\t\tPolygonVertexIndex: ') i=-1 - for f in me.faces: + for f in me_faces: fi = f.vertices[:] # last index XORd w. -1 indicates end of face @@ -1470,7 +1464,7 @@ def save(operator, context, filepath="", i+=1 # write loose edges as faces. - for ed in me.edges: + for ed in me_edges: if ed.is_loose: ed_val = ed.vertices[:] ed_val = ed_val[0], ed_val[-1] ^ -1 @@ -1488,7 +1482,7 @@ def save(operator, context, filepath="", file.write('\n\t\tEdges: ') i=-1 - for ed in me.edges: + for ed in me_edges: if i==-1: file.write('%i,%i' % (ed.vertices[0], ed.vertices[1])) i=0 @@ -1510,7 +1504,7 @@ def save(operator, context, filepath="", Normals: ''') i=-1 - for v in me.vertices: + for v in me_vertices: if i==-1: file.write('%.15f,%.15f,%.15f' % tuple(v.normal)); i=0 else: @@ -1530,7 +1524,7 @@ def save(operator, context, filepath="", Smoothing: ''') i=-1 - for f in me.faces: + for f in me_faces: if i==-1: file.write('%i' % f.use_smooth); i=0 else: @@ -1551,7 +1545,7 @@ def save(operator, context, filepath="", Smoothing: ''') i=-1 - for ed in me.edges: + for ed in me_edges: if i==-1: file.write('%i' % (ed.use_edge_sharp)); i=0 else: @@ -1589,7 +1583,7 @@ def save(operator, context, filepath="", i = -1 ii = 0 # Count how many Colors we write - for f, cf in zip(me.faces, collayer.data): + for f, cf in zip(me_faces, collayer.data): colors = [cf.color1, cf.color2, cf.color3, cf.color4] # determine number of verts @@ -1756,11 +1750,11 @@ def save(operator, context, filepath="", if me.uv_textures.active: uv_faces = me.uv_textures.active.data else: - uv_faces = [None] * len(me.faces) + uv_faces = [None] * len(me_faces) i=-1 - for f, uf in zip(me.faces, uv_faces): -# for f in me.faces: + for f, uf in zip(me_faces, uv_faces): +# for f in me_faces: try: mat = mats[f.material_index] except:mat = None @@ -2028,6 +2022,10 @@ def save(operator, context, filepath="", 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))) else: blenParentBoneName = armob = None @@ -2708,7 +2706,7 @@ Takes: {''') 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() - context_bone_anim_vecs.append(eulerRadToDeg(prev_eul)) + context_bone_anim_vecs.append(tuple_rad_to_deg(prev_eul)) file.write('\n\t\t\t\tChannel: "%s" {' % TX_CHAN) # translation |