[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1358] trunk/py/scripts/addons/ io_export_anim_mesh_xna/export_xna.py: Fixes to work with 2.56a
John Brown
jcb at special-p.co.uk
Fri Jan 7 20:49:10 CET 2011
Revision: 1358
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1358
Author: jcbdigger
Date: 2011-01-07 19:49:09 +0000 (Fri, 07 Jan 2011)
Log Message:
-----------
Fixes to work with 2.56a
Modified Paths:
--------------
trunk/py/scripts/addons/io_export_anim_mesh_xna/export_xna.py
Modified: trunk/py/scripts/addons/io_export_anim_mesh_xna/export_xna.py
===================================================================
--- trunk/py/scripts/addons/io_export_anim_mesh_xna/export_xna.py 2011-01-07 15:57:45 UTC (rev 1357)
+++ trunk/py/scripts/addons/io_export_anim_mesh_xna/export_xna.py 2011-01-07 19:49:09 UTC (rev 1358)
@@ -347,7 +347,7 @@
print('\nFBX export starting... %r' % filepath)
start_time = time.clock()
try:
- file = open(filepath, 'w')
+ file = open(filepath, 'w', encoding='utf8')
except:
return False
@@ -1024,14 +1024,11 @@
# If the image and the blend file are on different drives the function
# relativePath = os.path.relpath(path1, path2)
# will throw an exception when trying to calculate the relative file paths.
- # To avoid this all output files are assumed to be in the same folder. (JCB)
def copy_image(image):
# The full path to the image file
fn = bpy.path.abspath(image.filepath)
# Just the file name of the image file
fn_strip = os.path.basename(fn)
- # This assumes that the image file is in the same folder as the FBX file (JCB)
- rel = fn_strip
# Copy the image to the destination folder
if EXP_IMAGE_COPY:
# Add the image filename to the output folder as previously calculated
@@ -1039,8 +1036,12 @@
# Do not overwrite existing files
if not os.path.exists(fn_abs_dest):
shutil.copy(fn, fn_abs_dest)
- #else:
- # rel = os.path.relpath(fn, basepath)
+ elif bpy.path.is_subdir(fn, basepath):
+ # Check it is a subdirectory to avoid the exception thrown for different drives
+ rel = os.path.relpath(fn, basepath)
+ else:
+ # This assumes that the image file is in the same folder as the FBX file
+ rel = fn
return (rel, fn_strip)
@@ -1238,18 +1239,18 @@
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 (CB)
+ 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))
@@ -1264,38 +1265,41 @@
file.write('\n\t\tVertices: ')
i=-1
- for v in me.vertices:
- if i==-1:
- file.write('%.6f,%.6f,%.6f' % tuple(v.co)); i=0
+ for v in me_vertices:
+ if i == -1:
+ file.write('%.6f,%.6f,%.6f' % v.co[:])
+ i = 0
else:
- if i==7:
- file.write('\n\t\t'); i=0
- file.write(',%.6f,%.6f,%.6f'% tuple(v.co))
+ if i == 7:
+ file.write('\n\t\t')
+ i = 0
+ file.write(',%.6f,%.6f,%.6f'% v.co[:])
i+=1
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
- fi[-1] = fi[-1] ^ -1
- fi = tuple(fi)
-
- if i==-1:
- if len(fi) == 3: file.write('%i,%i,%i' % fi )
- else: file.write('%i,%i,%i,%i' % fi )
- i=0
+ if i == -1:
+ if len(fi) == 3:
+ file.write('%i,%i,%i' % (fi[0], fi[1], fi[2] ^ -1))
+ else:
+ file.write('%i,%i,%i,%i' % (fi[0], fi[1], fi[2], fi[3] ^ -1))
+ i = 0
else:
- if i==13:
+ if i == 13:
file.write('\n\t\t')
- i=0
- if len(fi) == 3: file.write(',%i,%i,%i' % fi )
- else: file.write(',%i,%i,%i,%i' % fi )
- i+=1
+ i = 0
+ if len(fi) == 3:
+ file.write(',%i,%i,%i' % (fi[0], fi[1], fi[2] ^ -1))
+ else:
+ file.write(',%i,%i,%i,%i' % (fi[0], fi[1], fi[2], fi[3] ^ -1))
+ 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
@@ -1314,7 +1318,7 @@
if Include_Edges:
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
@@ -1336,13 +1340,13 @@
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
+ file.write('%.15f,%.15f,%.15f' % v.normal[:]); i=0
else:
if i==2:
file.write('\n '); i=0
- file.write(',%.15f,%.15f,%.15f' % tuple(v.normal))
+ file.write(',%.15f,%.15f,%.15f' % v.normal[:])
i+=1
file.write('\n\t\t}')
@@ -1358,7 +1362,7 @@
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:
@@ -1380,7 +1384,7 @@
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:
@@ -1394,12 +1398,12 @@
# small utility function
# returns a slice of data depending on number of face verts
# data is either a MeshTextureFace or MeshColor
- def face_data(data, face):
- totvert = len(f.vertices)
+# def face_data(data, face):
+# totvert = len(f.vertices)
+#
+# return data[:totvert]
- return data[:totvert]
-
# Write VertexColor Layers
# note, no programs seem to use this info :/
collayers = []
@@ -1418,21 +1422,22 @@
i = -1
ii = 0 # Count how many Colors we write
- for f, cf in zip(me.faces, collayer.data):
- colors = [cf.color1, cf.color2, cf.color3, cf.color4]
+ for fi, cf in enumerate(collayer.data):
+ if len(me_faces[fi].vertices) == 4:
+ colors = cf.color1[:], cf.color2[:], cf.color3[:], cf.color4[:]
+ else:
+ colors = cf.color1[:], cf.color2[:], cf.color3[:]
- # determine number of verts
- colors = face_data(colors, f)
for col in colors:
if i==-1:
- file.write('%.4f,%.4f,%.4f,1' % tuple(col))
+ file.write('%.4f,%.4f,%.4f,1' % col)
i=0
else:
if i==7:
file.write('\n\t\t\t\t')
i=0
- file.write(',%.4f,%.4f,%.4f,1' % tuple(col))
+ file.write(',%.4f,%.4f,%.4f,1' % col)
i+=1
ii+=1 # One more Color
@@ -1475,13 +1480,13 @@
# workaround, since uf.uv iteration is wrong atm
for uv in uf.uv:
if i==-1:
- file.write('%.6f,%.6f' % tuple(uv))
+ file.write('%.6f,%.6f' % uv[:])
i=0
else:
if i==7:
- file.write('\n ')
+ file.write('\n\t\t\t ')
i=0
- file.write(',%.6f,%.6f' % tuple(uv))
+ file.write(',%.6f,%.6f' % uv[:])
i+=1
ii+=1 # One more UV
@@ -1585,11 +1590,10 @@
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):
try: mat = mats[f.material_index]
except:mat = None
@@ -1745,7 +1749,6 @@
if ob_arms_orig_rest:
for ob_base in bpy.data.objects:
if ob_base.type == 'ARMATURE':
- # v2.56 was ob_base.update(scene) changed after to ob_base.update() (Campbell Barton)
ob_base.update()
# This causes the makeDisplayList command to effect the mesh
@@ -1838,6 +1841,10 @@
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:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list